summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp30
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.h6
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/storemail.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/storemail.h2
8 files changed, 31 insertions, 23 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
index 48fa02e..4f7ec0c 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.cpp
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -1,32 +1,32 @@
#include "generatemail.h"
#include "mailwrapper.h"
#include <libetpan/libetpan.h>
#include <qt.h>
-const char* Generatemail::USER_AGENT="OpieMail v0.5";
+const char* Generatemail::USER_AGENT="OpieMail v0.6";
Generatemail::Generatemail()
{
}
Generatemail::~Generatemail()
{
}
void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
clistiter *it, *it2;
for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
mailimf_address *addr;
addr = (mailimf_address *) it->data;
if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
} else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
mailimf_mailbox *mbox;
mbox = (mailimf_mailbox *) it2->data;
esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
@@ -258,97 +258,97 @@ mailmime *Generatemail::buildTxtPart(const QString&str ) {
if ( err != MAILIMF_NO_ERROR )
goto err_free_txtPart;
return txtPart; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_fields:
mailmime_fields_free( fields );
err_free_content:
mailmime_content_free( content );
err_free_param:
mailmime_parameter_free( param );
err_free:
qDebug( "buildTxtPart - error" );
return NULL; // Error :(
}
mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
return mailimf_mailbox_new( strdup( name.latin1() ),
strdup( mail.latin1() ) );
}
-mailimf_fields *Generatemail::createImfFields(const Mail&mail )
+mailimf_fields *Generatemail::createImfFields(const Opie::osmart_pointer<Mail>&mail )
{
mailimf_fields *fields = NULL;
mailimf_field *xmailer = NULL;
mailimf_mailbox *sender=0,*fromBox=0;
mailimf_mailbox_list *from=0;
mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
clist*in_reply_to = 0;
- char *subject = strdup( mail.getSubject().latin1() );
+ char *subject = strdup( mail->getSubject().latin1() );
int err;
int res = 1;
- sender = newMailbox( mail.getName(), mail.getMail() );
+ sender = newMailbox( mail->getName(), mail->getMail() );
if ( sender == NULL ) {
res = 0;
}
if (res) {
- fromBox = newMailbox( mail.getName(), mail.getMail() );
+ fromBox = newMailbox( mail->getName(), mail->getMail() );
}
if ( fromBox == NULL ) {
res = 0;
}
if (res) {
from = mailimf_mailbox_list_new_empty();
}
if ( from == NULL ) {
res = 0;
}
if (res && from) {
err = mailimf_mailbox_list_add( from, fromBox );
if ( err != MAILIMF_NO_ERROR ) {
res = 0;
}
}
- if (res) to = parseAddresses( mail.getTo() );
- if (res) cc = parseAddresses( mail.getCC() );
- if (res) bcc = parseAddresses( mail.getBCC() );
- if (res) reply = parseAddresses( mail.getReply() );
+ if (res) to = parseAddresses( mail->getTo() );
+ if (res) cc = parseAddresses( mail->getCC() );
+ if (res) bcc = parseAddresses( mail->getBCC() );
+ if (res) reply = parseAddresses( mail->getReply() );
- if (res && mail.Inreply().count()>0) {
+ if (res && mail->Inreply().count()>0) {
in_reply_to = clist_new();
char*c_reply;
unsigned int nsize = 0;
- for (QStringList::ConstIterator it=mail.Inreply().begin();
- it != mail.Inreply().end();++it) {
+ for (QStringList::ConstIterator it=mail->Inreply().begin();
+ it != mail->Inreply().end();++it) {
if ((*it).isEmpty())
continue;
QString h((*it));
while (h.length()>0 && h[0]=='<') {
h.remove(0,1);
}
while (h.length()>0 && h[h.length()-1]=='>') {
h.remove(h.length()-1,1);
}
if (h.isEmpty()) continue;
nsize = strlen(h.latin1());
/* yes! must be malloc! */
c_reply = (char*)malloc( (nsize+1)*sizeof(char));
memset(c_reply,0,nsize+1);
memcpy(c_reply,h.latin1(),nsize);
clist_append(in_reply_to,c_reply);
qDebug("In reply to: %s",c_reply);
}
}
if (res) {
fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
in_reply_to, NULL, subject );
if ( fields == NULL ) {
@@ -378,73 +378,73 @@ mailimf_fields *Generatemail::createImfFields(const Mail&mail )
if (reply)
mailimf_address_list_free( reply );
if (bcc)
mailimf_address_list_free( bcc );
if (cc)
mailimf_address_list_free( cc );
if (to)
mailimf_address_list_free( to );
if (fromBox) {
mailimf_mailbox_free( fromBox );
} else if (from) {
mailimf_mailbox_list_free( from );
}
if (sender) {
mailimf_mailbox_free( sender );
}
if (subject) {
free( subject );
}
}
}
return fields;
}
-mailmime *Generatemail::createMimeMail(const Mail &mail ) {
+mailmime *Generatemail::createMimeMail(const Opie::osmart_pointer<Mail> &mail ) {
mailmime *message, *txtPart;
mailimf_fields *fields;
int err;
fields = createImfFields( mail );
if ( fields == NULL )
goto err_free;
message = mailmime_new_message_data( NULL );
if ( message == NULL )
goto err_free_fields;
mailmime_set_imf_fields( message, fields );
- txtPart = buildTxtPart( mail.getMessage() );
+ txtPart = buildTxtPart( mail->getMessage() );
if ( txtPart == NULL )
goto err_free_message;
err = mailmime_smart_add_part( message, txtPart );
if ( err != MAILIMF_NO_ERROR )
goto err_free_txtPart;
- addFileParts( message, mail.getAttachments() );
+ addFileParts( message, mail->getAttachments() );
return message; // Success :)
err_free_txtPart:
mailmime_free( txtPart );
err_free_message:
mailmime_free( message );
err_free_fields:
mailimf_fields_free( fields );
err_free:
qDebug( "createMimeMail: error" );
return NULL; // Error :(
}
clist *Generatemail::createRcptList( mailimf_fields *fields ) {
clist *rcptList;
mailimf_field *field;
rcptList = esmtp_address_list_new();
field = getField( fields, MAILIMF_FIELD_TO );
if ( field && (field->fld_type == MAILIMF_FIELD_TO)
&& field->fld_data.fld_to->to_addr_list ) {
diff --git a/noncore/net/mail/libmailwrapper/generatemail.h b/noncore/net/mail/libmailwrapper/generatemail.h
index 8be5a2b..409a55e 100644
--- a/noncore/net/mail/libmailwrapper/generatemail.h
+++ b/noncore/net/mail/libmailwrapper/generatemail.h
@@ -1,44 +1,46 @@
#ifndef __GENERATE_MAIL_H
#define __GENERATE_MAIL_H
#include <qpe/applnk.h>
#include <qobject.h>
#include <libetpan/clist.h>
+#include <opie2/osmart_pointer.h>
+
class Mail;
class RecMail;
class Attachment;
struct mailimf_fields;
struct mailimf_field;
struct mailimf_mailbox;
struct mailmime;
struct mailimf_address_list;
class progressMailSend;
struct mailsmtp;
class Generatemail : public QObject
{
Q_OBJECT
public:
Generatemail();
virtual ~Generatemail();
protected:
static void addRcpts( clist *list, mailimf_address_list *addr_list );
static char *getFrom( mailmime *mail );
static char *getFrom( mailimf_field *ffrom);
static mailimf_field *getField( mailimf_fields *fields, int type );
mailimf_address_list *parseAddresses(const QString&addr );
void addFileParts( mailmime *message,const QList<Attachment>&files );
mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
mailmime *buildTxtPart(const QString&str );
mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
- mailimf_fields *createImfFields(const Mail &mail );
- mailmime *createMimeMail(const Mail&mail );
+ mailimf_fields *createImfFields(const Opie::osmart_pointer<Mail> &mail );
+ mailmime *createMimeMail(const Opie::osmart_pointer<Mail>&mail );
clist *createRcptList( mailimf_fields *fields );
static const char* USER_AGENT;
};
#endif
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index ebdbf4b..6bd98f6 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -24,49 +24,51 @@
Attachment::Attachment( DocLnk lnk )
{
doc = lnk;
size = QFileInfo( doc.file() ).size();
}
Folder::Folder(const QString&tmp_name, const QString&sep )
{
name = tmp_name;
nameDisplay = name;
separator = sep;
prefix = "";
}
const QString& Folder::Separator()const
{
return separator;
}
IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
: Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
{
// Decode IMAP foldername
nameDisplay = IMAPFolder::decodeFolderName( name );
+ /*
qDebug( "folder " + name + " - displayed as " + nameDisplay );
+ */
prefix = aprefix;
if (prefix.length()>0) {
if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
}
}
}
static unsigned char base64chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
/**
* Decodes base64 encoded parts of the imapfolder name
* Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
*/
QString IMAPFolder::decodeFolderName( const QString &name )
{
unsigned char c, i, bitcount;
unsigned long ucs4, utf16, bitbuf;
unsigned char base64[256], utf8[6];
unsigned long srcPtr = 0;
QCString dst = "";
QCString src = name.ascii();
@@ -124,41 +126,41 @@ QString IMAPFolder::decodeFolderName( const QString &name )
i = 3;
} else {
utf8[0] = 0xf0 | (ucs4 >> 18);
utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
utf8[3] = 0x80 | (ucs4 & 0x3f);
i = 4;
}
/* copy it */
for (c = 0; c < i; ++c) {
dst += utf8[c];
}
}
}
/* skip over trailing '-' in modified UTF-7 encoding */
if (src[srcPtr] == '-')
++srcPtr;
}
}
return QString::fromUtf8( dst.data() );
}
Mail::Mail()
- :name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
+ :Opie::oref_count(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
{
}
MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
: Folder( disp_name,"/" )
{
separator = "/";
name = mbox;
if (!disp_name.startsWith("/") && disp_name.length()>0)
name+="/";
name+=disp_name;
if (disp_name.length()==0) {
nameDisplay = separator;
}
prefix = mbox;
}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index 3a9f97b..c66572c 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -1,53 +1,55 @@
#ifndef MAILWRAPPER_H
#define MAILWRAPPER_H
#include <qpe/applnk.h>
#include <qbitarray.h>
#include <qdatetime.h>
#include "settings.h"
+#include <opie2/osmart_pointer.h>
+
class Attachment
{
public:
Attachment( DocLnk lnk );
virtual ~Attachment(){}
const QString getFileName()const{ return doc.file(); }
const QString getName()const{ return doc.name(); }
const QString getMimeType()const{ return doc.type(); }
const QPixmap getPixmap()const{ return doc.pixmap(); }
const int getSize()const { return size; }
DocLnk getDocLnk() { return doc; }
protected:
DocLnk doc;
int size;
};
-class Mail
+class Mail:public Opie::oref_count
{
public:
Mail();
/* Possible that this destructor must not be declared virtual
* 'cause it seems that it will never have some child classes.
* in this case this object will not get a virtual table -> memory and
* speed will be a little bit better?
*/
virtual ~Mail(){}
void addAttachment( Attachment *att ) { attList.append( att ); }
const QList<Attachment>& getAttachments()const { return attList; }
void removeAttachment( Attachment *att ) { attList.remove( att ); }
const QString&getName()const { return name; }
void setName( QString s ) { name = s; }
const QString&getMail()const{ return mail; }
void setMail( const QString&s ) { mail = s; }
const QString&getTo()const{ return to; }
void setTo( const QString&s ) { to = s; }
const QString&getCC()const{ return cc; }
void setCC( const QString&s ) { cc = s; }
const QString&getBCC()const { return bcc; }
void setBCC( const QString&s ) { bcc = s; }
const QString&getMessage()const { return message; }
void setMessage( const QString&s ) { message = s; }
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index a4e0beb..afc5618 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -291,49 +291,49 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
QString failuretext = "";
connect_server();
result = 1;
if (m_smtp) {
err = mailsmtp_send( m_smtp, from, rcpts, data, size );
if ( err != MAILSMTP_NO_ERROR ) {
failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
result = 0;
}
} else {
result = 0;
}
if (!result) {
storeFailedMail(data,size,failuretext);
} else {
qDebug( "Mail sent." );
storeMail(data,size,"Sent");
}
return result;
}
-void SMTPwrapper::sendMail(const Mail&mail,bool later )
+void SMTPwrapper::sendMail(const Opie::osmart_pointer<Mail>&mail,bool later )
{
mailmime * mimeMail;
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "sendMail: error creating mime mail" );
} else {
sendProgress = new progressMailSend();
sendProgress->show();
sendProgress->setMaxMails(1);
smtpSend( mimeMail,later);
qDebug("Clean up done");
sendProgress->hide();
delete sendProgress;
sendProgress = 0;
mailmime_free( mimeMail );
}
}
int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) {
size_t curTok = 0;
mailimf_fields *fields = 0;
mailimf_field*ffrom = 0;
clist *rcpts = 0;
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 1796df7..08bde74 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,48 +1,50 @@
// -*- Mode: C++; -*-
#ifndef SMTPwrapper_H
#define SMTPwrapper_H
#include <qpe/applnk.h>
#include <qbitarray.h>
#include <qdatetime.h>
#include <libetpan/clist.h>
#include "settings.h"
#include "generatemail.h"
+#include <opie2/osmart_pointer.h>
+
class SMTPaccount;
class AbstractMail;
class SMTPwrapper : public Generatemail
{
Q_OBJECT
public:
SMTPwrapper(SMTPaccount * aSmtp);
virtual ~SMTPwrapper();
- void sendMail(const Mail& mail,bool later=false );
+ void sendMail(const Opie::osmart_pointer<Mail>& mail,bool later=false );
bool flushOutbox();
static progressMailSend*sendProgress;
signals:
void queuedMails( int );
protected:
mailsmtp *m_smtp;
SMTPaccount * m_SmtpAccount;
void connect_server();
void disc_server();
int start_smtp_tls();
void smtpSend( mailmime *mail,bool later);
static void storeMail(const char*mail, size_t length, const QString&box);
static QString mailsmtpError( int err );
static void progress( size_t current, size_t maximum );
int smtpSend(char*from,clist*rcpts,const char*data,size_t size);
diff --git a/noncore/net/mail/libmailwrapper/storemail.cpp b/noncore/net/mail/libmailwrapper/storemail.cpp
index 53101f8..052e0f1 100644
--- a/noncore/net/mail/libmailwrapper/storemail.cpp
+++ b/noncore/net/mail/libmailwrapper/storemail.cpp
@@ -28,49 +28,49 @@ Storemail::Storemail(const QString&dir,const QString&aFolder)
m_Account = 0;
m_tfolder = aFolder;
wrapper = AbstractMail::getWrapper(dir);
if (wrapper) {
wrapper->createMbox(m_tfolder);
}
}
Storemail::Storemail(const QString&aFolder)
: Generatemail()
{
wrapper = 0;
m_Account = 0;
m_tfolder = aFolder;
wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder());
if (wrapper) {
wrapper->createMbox(m_tfolder);
}
}
Storemail::~Storemail()
{
}
-int Storemail::storeMail(const Mail&mail)
+int Storemail::storeMail(const Opie::osmart_pointer<Mail>&mail)
{
if (!wrapper) return 0;
int ret = 1;
mailmime * mimeMail = 0;
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "storeMail: error creating mime mail" );
return 0;
}
char *data;
size_t size;
data = 0;
mailmessage * msg = 0;
msg = mime_message_init(mimeMail);
mime_message_set_tmpdir(msg,getenv( "HOME" ));
int r = mailmessage_fetch(msg,&data,&size);
mime_message_detach_mime(msg);
mailmessage_free(msg);
msg = 0;
if (r != MAIL_NO_ERROR || !data) {
qDebug("Error fetching mime...");
ret = 0;
diff --git a/noncore/net/mail/libmailwrapper/storemail.h b/noncore/net/mail/libmailwrapper/storemail.h
index 872c981..7d8ea3d 100644
--- a/noncore/net/mail/libmailwrapper/storemail.h
+++ b/noncore/net/mail/libmailwrapper/storemail.h
@@ -1,29 +1,29 @@
#ifndef __STORE_MAIL_H
#define __STORE_MAIL_H
#include <qpe/applnk.h>
#include "generatemail.h"
class Account;
class Mail;
class AbstractMail;
class Storemail : public Generatemail
{
Q_OBJECT
public:
Storemail(Account*aAccount,const QString&aFolder);
Storemail(const QString&dir,const QString&aFolder);
Storemail(const QString&aFolder);
virtual ~Storemail();
- int storeMail(const Mail&mail);
+ int storeMail(const Opie::osmart_pointer<Mail>&mail);
protected:
Account* m_Account;
QString m_tfolder;
AbstractMail*wrapper;
};
#endif