author | alwin <alwin> | 2003-12-24 14:18:28 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-24 14:18:28 (UTC) |
commit | 9d2a848b254d6c859d7054d486eedac6535d26ec (patch) (side-by-side diff) | |
tree | d3cb3479465b1cc6ef4b67898fc9649f8416c3da | |
parent | c609fd3341bccf6150e313f4fa08ff3ca9086503 (diff) | |
download | opie-9d2a848b254d6c859d7054d486eedac6535d26ec.zip opie-9d2a848b254d6c859d7054d486eedac6535d26ec.tar.gz opie-9d2a848b254d6c859d7054d486eedac6535d26ec.tar.bz2 |
hopefully fixed some memleaks and some not initialized vars
-rw-r--r-- | noncore/net/mail/genericwrapper.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 33 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 2 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 12 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 33 |
10 files changed, 84 insertions, 46 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp index 447cad0..c1b6e48 100644 --- a/noncore/net/mail/genericwrapper.cpp +++ b/noncore/net/mail/genericwrapper.cpp @@ -178,35 +178,35 @@ RecBody Genericwrapper::parseMail( mailmessage * msg ) int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBody body; memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); traverseBody(body,msg,mime); return body; } RecMail *Genericwrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok = 0; RecMail *mail = new RecMail(); - mailimf_fields *fields; - mailimf_references * refs; - mailimf_keywords*keys; + mailimf_fields *fields = 0; + mailimf_references * refs = 0; + mailimf_keywords*keys = 0; QString status; QString value; QBitArray mFlags(7); err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 853e4a2..0178e33 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp @@ -81,93 +81,91 @@ void IMAPwrapper::login() m_imap = 0; } } void IMAPwrapper::logout() { int err = MAILIMAP_NO_ERROR; if (!m_imap) return; err = mailimap_logout( m_imap ); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) { - const char *mb; + const char *mb = 0; int err = MAILIMAP_NO_ERROR; - clist *result; + clist *result = 0; clistcell *current; // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; - mailimap_fetch_type *fetchType; - mailimap_set *set; + mailimap_fetch_type *fetchType = 0; + mailimap_set *set = 0; mb = mailbox.latin1(); login(); if (!m_imap) { return; } /* select mailbox READONLY for operations */ err = mailimap_examine( m_imap, (char*)mb); if ( err != MAILIMAP_NO_ERROR ) { qDebug("error selecting mailbox: %s",m_imap->imap_response); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { qDebug("mailbox has no mails"); return; } - result = clist_new(); /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( 1, last ); fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); mailimap_fetch_type_free( fetchType ); QString date,subject,from; if ( err == MAILIMAP_NO_ERROR ) { - mailimap_msg_att * msg_att; int i = 0; for (current = clist_begin(result); current != 0; current=clist_next(current)) { ++i; msg_att = (mailimap_msg_att*)current->data; RecMail*m = parse_list_result(msg_att); if (m) { m->setNumber(i); m->setMbox(mailbox); m->setWrapper(this); target.append(m); } } } else { qDebug("Error fetching headers: %s",m_imap->imap_response); } - mailimap_fetch_list_free(result); + if (result) mailimap_fetch_list_free(result); } QList<Folder>* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); login(); if (!m_imap) { return folders; } diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index 447cad0..c1b6e48 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp @@ -178,35 +178,35 @@ RecBody Genericwrapper::parseMail( mailmessage * msg ) int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBody body; memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); traverseBody(body,msg,mime); return body; } RecMail *Genericwrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok = 0; RecMail *mail = new RecMail(); - mailimf_fields *fields; - mailimf_references * refs; - mailimf_keywords*keys; + mailimf_fields *fields = 0; + mailimf_references * refs = 0; + mailimf_keywords*keys = 0; QString status; QString value; QBitArray mFlags(7); err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 853e4a2..0178e33 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -81,93 +81,91 @@ void IMAPwrapper::login() m_imap = 0; } } void IMAPwrapper::logout() { int err = MAILIMAP_NO_ERROR; if (!m_imap) return; err = mailimap_logout( m_imap ); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) { - const char *mb; + const char *mb = 0; int err = MAILIMAP_NO_ERROR; - clist *result; + clist *result = 0; clistcell *current; // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; - mailimap_fetch_type *fetchType; - mailimap_set *set; + mailimap_fetch_type *fetchType = 0; + mailimap_set *set = 0; mb = mailbox.latin1(); login(); if (!m_imap) { return; } /* select mailbox READONLY for operations */ err = mailimap_examine( m_imap, (char*)mb); if ( err != MAILIMAP_NO_ERROR ) { qDebug("error selecting mailbox: %s",m_imap->imap_response); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { qDebug("mailbox has no mails"); return; } - result = clist_new(); /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( 1, last ); fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); err = mailimap_fetch( m_imap, set, fetchType, &result ); mailimap_set_free( set ); mailimap_fetch_type_free( fetchType ); QString date,subject,from; if ( err == MAILIMAP_NO_ERROR ) { - mailimap_msg_att * msg_att; int i = 0; for (current = clist_begin(result); current != 0; current=clist_next(current)) { ++i; msg_att = (mailimap_msg_att*)current->data; RecMail*m = parse_list_result(msg_att); if (m) { m->setNumber(i); m->setMbox(mailbox); m->setWrapper(this); target.append(m); } } } else { qDebug("Error fetching headers: %s",m_imap->imap_response); } - mailimap_fetch_list_free(result); + if (result) mailimap_fetch_list_free(result); } QList<Folder>* IMAPwrapper::listFolders() { const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result; clistcell *current; QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); login(); if (!m_imap) { return folders; } diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index f8efd09..6479783 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp @@ -42,33 +42,33 @@ IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const Q } } 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 dst = ""; QCString src = name.ascii(); /* initialize modified base64 decoding table */ memset(base64, UNDEFINED, sizeof(base64)); for (i = 0; i < sizeof(base64chars); ++i) { base64[(int)base64chars[i]] = i; } /* loop until end of string */ while (srcPtr < src.length ()) { c = src[srcPtr++]; /* deal with literal characters and &- */ if (c != '&' || src[srcPtr] == '-') { /* encode literally */ dst += c; /* skip over the '-' if this is an &- sequence */ diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 293ae1b..6d69263 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp @@ -1,68 +1,75 @@ #include "mboxwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> #include <libetpan/mailstorage.h> #include <qdir.h> +#include <stdlib.h> MBOXwrapper::MBOXwrapper(const QString & mbox_dir) : Genericwrapper(),MBOXPath(mbox_dir) { QDir dir(MBOXPath); if (!dir.exists()) { dir.mkdir(MBOXPath); } } MBOXwrapper::~MBOXwrapper() { } void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mailbox; + char*fname = 0; - int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); + fname = strdup(p.latin1()); + + int r = mbox_mailstorage_init(storage,fname,0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,strdup(p.latin1()),NULL); + folder = mailfolder_new( storage,fname,NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { qDebug("Error initializing mbox"); mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } mailmessage_list * env_list = 0; r = mailsession_get_messages_list(folder->fld_session,&env_list); if (r != MAIL_NO_ERROR) { qDebug("Error message list"); mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } r = mailsession_get_envelopes_list(folder->fld_session, env_list); if (r != MAIL_NO_ERROR) { qDebug("Error filling message list"); if (env_list) { mailmessage_list_free(env_list); } mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } mailimf_references * refs; for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { mailmessage * msg; QBitArray mFlags(7); msg = (mailmessage*)carray_get(env_list->msg_tab, i); if (msg->msg_fields == NULL) { qDebug("could not fetch envelope of message %i", i); continue; } RecMail * mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); @@ -90,32 +97,33 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) if (single_fields.fld_message_id->mid_value) mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } mailfolder_disconnect(folder); mailfolder_free(folder); mailstorage_free(storage); + free(fname); } QList<Folder>* MBOXwrapper::listFolders() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); QDir dir(MBOXPath); if (!dir.exists()) return folders; dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); QStringList entries = dir.entryList(); QStringList::ConstIterator it = entries.begin(); for (;it!=entries.end();++it) { Folder*inb=new Folder(*it,"/"); folders->append(inb); } return folders; diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index a7e4837..21992b4 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -428,33 +428,35 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom) char *from = NULL; if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; clistiter *it; for ( it = clist_begin( cl ); it; it = it->next ) { mailimf_mailbox *mb = (mailimf_mailbox *) it->data; from = strdup( mb->mb_addr_spec ); } } return from; } char *SMTPwrapper::getFrom( mailmime *mail ) { + /* no need to delete - its just a pointer to structure content */ mailimf_field *ffrom = 0; + char*f = 0; ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); return getFrom(ffrom); } SMTPaccount *SMTPwrapper::getAccount(const QString&name ) { SMTPaccount *smtp; QList<Account> list = settings->getAccounts(); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType().compare( "SMTP" ) == 0 ) { smtp = static_cast<SMTPaccount *>(it); if ( smtp->getName()== name ) { qDebug( "SMTPaccount found for" ); qDebug( name ); @@ -550,32 +552,35 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) from = data = 0; QString file = getTmpFile(); writeToFile( file, mail ); readFromFile( file, &data, &size ); QFile f( file ); f.remove(); if (later) { storeMail(data,size,"Outgoing"); if (data) free( data ); return; } from = getFrom( mail ); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); smtpSend(from,rcpts,data,size,smtp); + if (data) {free(data);} + if (from) {free(from);} + if (rcpts) smtp_address_list_free( rcpts ); } int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) { char *server, *user, *pass; bool ssl; uint16_t port; mailsmtp *session; int err,result; result = 1; server = user = pass = 0; server = strdup( smtp->getServer().latin1() ); ssl = smtp->getSSL(); port = smtp->getPort().toUInt(); @@ -617,128 +622,136 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou err = mailsmtp_auth( session, user, pass ); if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); qDebug( "Done auth!" ); } err = mailsmtp_send( session, from, rcpts, data, size ); if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} qDebug( "Mail sent." ); storeMail(data,size,"Sent"); free_con_session: mailsmtp_quit( session ); free_mem_session: mailsmtp_free( session ); free_mem: - if (rcpts) smtp_address_list_free( rcpts ); - if (data) free( data ); if (server) free( server ); - if (from) free( from ); if ( smtp->getLogin() ) { free( user ); free( pass ); } return result; } void SMTPwrapper::sendMail(const Mail&mail,bool later ) { mailmime * mimeMail; SMTPaccount *smtp = getAccount(mail.getName()); mimeMail = createMimeMail(mail ); if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { sendProgress = new progressMailSend(); -// sendProgress->showMaximized(); sendProgress->show(); sendProgress->setMaxMails(1); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); sendProgress->hide(); delete sendProgress; sendProgress = 0; } } int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) { char*data = 0; size_t length = 0; size_t curTok = 0; mailimf_fields *fields = 0; mailimf_field*ffrom = 0; clist *rcpts = 0; char*from = 0; + int res = 0; wrap->fetchRawBody(*which,&data,&length); if (!data) return 0; int err = mailimf_fields_parse( data, length, &curTok, &fields ); if (err != MAILIMF_NO_ERROR) { free(data); delete wrap; return 0; } rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { - return smtpSend(from,rcpts,data,strlen(data),smtp ); + res = smtpSend(from,rcpts,data,length,smtp ); } - return 0; + if (fields) { + mailimf_fields_free(fields); + fields = 0; + } + if (data) { + free(data); + } + if (from) { + free(from); + } + if (rcpts) { + smtp_address_list_free( rcpts ); + } + return res; } /* this is a special fun */ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { bool returnValue = true; if (!smtp) return false; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); if (!wrap) { qDebug("memory error"); return false; } QList<RecMail> mailsToSend; QList<RecMail> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; return false; } mailsToSend.setAutoDelete(false); sendProgress = new progressMailSend(); -// sendProgress->showMaximized(); - sendProgress->show(); - sendProgress->setMaxMails(mailsToSend.count()); + sendProgress->show(); + sendProgress->setMaxMails(mailsToSend.count()); while (mailsToSend.count()>0) { if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { QMessageBox::critical(0,tr("Error sending mail"), tr("Error sending queued mail - breaking")); returnValue = false; break; } mailsToRemove.append(mailsToSend.at(0)); mailsToSend.removeFirst(); sendProgress->setCurrentMails(mailsToRemove.count()); } sendProgress->hide(); delete sendProgress; sendProgress = 0; wrap->deleteMails(mbox,mailsToRemove); mailsToSend.setAutoDelete(true); delete wrap; return returnValue; - } diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index f8efd09..6479783 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp @@ -42,33 +42,33 @@ IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const Q } } 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 dst = ""; QCString src = name.ascii(); /* initialize modified base64 decoding table */ memset(base64, UNDEFINED, sizeof(base64)); for (i = 0; i < sizeof(base64chars); ++i) { base64[(int)base64chars[i]] = i; } /* loop until end of string */ while (srcPtr < src.length ()) { c = src[srcPtr++]; /* deal with literal characters and &- */ if (c != '&' || src[srcPtr] == '-') { /* encode literally */ dst += c; /* skip over the '-' if this is an &- sequence */ diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 293ae1b..6d69263 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp @@ -1,68 +1,75 @@ #include "mboxwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> #include <libetpan/mailstorage.h> #include <qdir.h> +#include <stdlib.h> MBOXwrapper::MBOXwrapper(const QString & mbox_dir) : Genericwrapper(),MBOXPath(mbox_dir) { QDir dir(MBOXPath); if (!dir.exists()) { dir.mkdir(MBOXPath); } } MBOXwrapper::~MBOXwrapper() { } void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mailbox; + char*fname = 0; - int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); + fname = strdup(p.latin1()); + + int r = mbox_mailstorage_init(storage,fname,0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,strdup(p.latin1()),NULL); + folder = mailfolder_new( storage,fname,NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { qDebug("Error initializing mbox"); mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } mailmessage_list * env_list = 0; r = mailsession_get_messages_list(folder->fld_session,&env_list); if (r != MAIL_NO_ERROR) { qDebug("Error message list"); mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } r = mailsession_get_envelopes_list(folder->fld_session, env_list); if (r != MAIL_NO_ERROR) { qDebug("Error filling message list"); if (env_list) { mailmessage_list_free(env_list); } mailfolder_free(folder); mailstorage_free(storage); + free(fname); return; } mailimf_references * refs; for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { mailmessage * msg; QBitArray mFlags(7); msg = (mailmessage*)carray_get(env_list->msg_tab, i); if (msg->msg_fields == NULL) { qDebug("could not fetch envelope of message %i", i); continue; } RecMail * mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); @@ -90,32 +97,33 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) if (single_fields.fld_message_id->mid_value) mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } mailfolder_disconnect(folder); mailfolder_free(folder); mailstorage_free(storage); + free(fname); } QList<Folder>* MBOXwrapper::listFolders() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); QDir dir(MBOXPath); if (!dir.exists()) return folders; dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); QStringList entries = dir.entryList(); QStringList::ConstIterator it = entries.begin(); for (;it!=entries.end();++it) { Folder*inb=new Folder(*it,"/"); folders->append(inb); } return folders; diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index a7e4837..21992b4 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp @@ -428,33 +428,35 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom) char *from = NULL; if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; clistiter *it; for ( it = clist_begin( cl ); it; it = it->next ) { mailimf_mailbox *mb = (mailimf_mailbox *) it->data; from = strdup( mb->mb_addr_spec ); } } return from; } char *SMTPwrapper::getFrom( mailmime *mail ) { + /* no need to delete - its just a pointer to structure content */ mailimf_field *ffrom = 0; + char*f = 0; ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); return getFrom(ffrom); } SMTPaccount *SMTPwrapper::getAccount(const QString&name ) { SMTPaccount *smtp; QList<Account> list = settings->getAccounts(); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType().compare( "SMTP" ) == 0 ) { smtp = static_cast<SMTPaccount *>(it); if ( smtp->getName()== name ) { qDebug( "SMTPaccount found for" ); qDebug( name ); @@ -550,32 +552,35 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) from = data = 0; QString file = getTmpFile(); writeToFile( file, mail ); readFromFile( file, &data, &size ); QFile f( file ); f.remove(); if (later) { storeMail(data,size,"Outgoing"); if (data) free( data ); return; } from = getFrom( mail ); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); smtpSend(from,rcpts,data,size,smtp); + if (data) {free(data);} + if (from) {free(from);} + if (rcpts) smtp_address_list_free( rcpts ); } int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) { char *server, *user, *pass; bool ssl; uint16_t port; mailsmtp *session; int err,result; result = 1; server = user = pass = 0; server = strdup( smtp->getServer().latin1() ); ssl = smtp->getSSL(); port = smtp->getPort().toUInt(); @@ -617,128 +622,136 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou err = mailsmtp_auth( session, user, pass ); if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); qDebug( "Done auth!" ); } err = mailsmtp_send( session, from, rcpts, data, size ); if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} qDebug( "Mail sent." ); storeMail(data,size,"Sent"); free_con_session: mailsmtp_quit( session ); free_mem_session: mailsmtp_free( session ); free_mem: - if (rcpts) smtp_address_list_free( rcpts ); - if (data) free( data ); if (server) free( server ); - if (from) free( from ); if ( smtp->getLogin() ) { free( user ); free( pass ); } return result; } void SMTPwrapper::sendMail(const Mail&mail,bool later ) { mailmime * mimeMail; SMTPaccount *smtp = getAccount(mail.getName()); mimeMail = createMimeMail(mail ); if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { sendProgress = new progressMailSend(); -// sendProgress->showMaximized(); sendProgress->show(); sendProgress->setMaxMails(1); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); sendProgress->hide(); delete sendProgress; sendProgress = 0; } } int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) { char*data = 0; size_t length = 0; size_t curTok = 0; mailimf_fields *fields = 0; mailimf_field*ffrom = 0; clist *rcpts = 0; char*from = 0; + int res = 0; wrap->fetchRawBody(*which,&data,&length); if (!data) return 0; int err = mailimf_fields_parse( data, length, &curTok, &fields ); if (err != MAILIMF_NO_ERROR) { free(data); delete wrap; return 0; } rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { - return smtpSend(from,rcpts,data,strlen(data),smtp ); + res = smtpSend(from,rcpts,data,length,smtp ); } - return 0; + if (fields) { + mailimf_fields_free(fields); + fields = 0; + } + if (data) { + free(data); + } + if (from) { + free(from); + } + if (rcpts) { + smtp_address_list_free( rcpts ); + } + return res; } /* this is a special fun */ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { bool returnValue = true; if (!smtp) return false; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); if (!wrap) { qDebug("memory error"); return false; } QList<RecMail> mailsToSend; QList<RecMail> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; return false; } mailsToSend.setAutoDelete(false); sendProgress = new progressMailSend(); -// sendProgress->showMaximized(); - sendProgress->show(); - sendProgress->setMaxMails(mailsToSend.count()); + sendProgress->show(); + sendProgress->setMaxMails(mailsToSend.count()); while (mailsToSend.count()>0) { if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { QMessageBox::critical(0,tr("Error sending mail"), tr("Error sending queued mail - breaking")); returnValue = false; break; } mailsToRemove.append(mailsToSend.at(0)); mailsToSend.removeFirst(); sendProgress->setCurrentMails(mailsToRemove.count()); } sendProgress->hide(); delete sendProgress; sendProgress = 0; wrap->deleteMails(mbox,mailsToRemove); mailsToSend.setAutoDelete(true); delete wrap; return returnValue; - } |