-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 39 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 39 |
2 files changed, 70 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 21992b4..285561c 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -72,38 +72,66 @@ mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail return mailimf_mailbox_new( strdup( name.latin1() ), strdup( mail.latin1() ) ); } mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { mailimf_address_list *addresses; if ( addr.isEmpty() ) return NULL; addresses = mailimf_address_list_new_empty(); - QStringList list = QStringList::split( ',', addr ); + bool literal_open = false; + unsigned int startpos = 0; + QStringList list; + QString s; + unsigned int i = 0; + for (; i < addr.length();++i) { + switch (addr[i]) { + case '\"': + literal_open = !literal_open; + break; + case ',': + if (!literal_open) { + s = addr.mid(startpos,i-startpos); + if (!s.isEmpty()) { + list.append(s); + qDebug("Appended %s",s.latin1()); + } + // !!!! this is a MUST BE! + startpos = ++i; + } + break; + default: + break; + } + } + s = addr.mid(startpos,i-startpos); + if (!s.isEmpty()) { + list.append(s); + qDebug("Appended %s",s.latin1()); + } QStringList::Iterator it; for ( it = list.begin(); it != list.end(); it++ ) { char *str = strdup( (*it).latin1() ); int err = mailimf_address_list_add_parse( addresses, str ); if ( err != MAILIMF_NO_ERROR ) { qDebug( "Error parsing" ); qDebug( *it ); free( str ); } else { - qDebug( "Parse success! :)" ); + qDebug( "Parse success! %s",(*it).latin1()); } } - return addresses; } mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { mailimf_fields *fields; mailimf_field *xmailer; mailimf_mailbox *sender, *fromBox; mailimf_mailbox_list *from; mailimf_address_list *to, *cc, *bcc, *reply; char *subject = strdup( mail.getSubject().latin1() ); int err; @@ -616,25 +644,28 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou } } else { user = strdup( smtp->getUser().latin1() ); pass = strdup( smtp->getPassword().latin1() ); } qDebug( "session->auth: %i", session->auth); 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;} + if ( err != MAILSMTP_NO_ERROR ) { + qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); + 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 (server) free( server ); if ( smtp->getLogin() ) { free( user ); diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 21992b4..285561c 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp @@ -72,38 +72,66 @@ mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail return mailimf_mailbox_new( strdup( name.latin1() ), strdup( mail.latin1() ) ); } mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) { mailimf_address_list *addresses; if ( addr.isEmpty() ) return NULL; addresses = mailimf_address_list_new_empty(); - QStringList list = QStringList::split( ',', addr ); + bool literal_open = false; + unsigned int startpos = 0; + QStringList list; + QString s; + unsigned int i = 0; + for (; i < addr.length();++i) { + switch (addr[i]) { + case '\"': + literal_open = !literal_open; + break; + case ',': + if (!literal_open) { + s = addr.mid(startpos,i-startpos); + if (!s.isEmpty()) { + list.append(s); + qDebug("Appended %s",s.latin1()); + } + // !!!! this is a MUST BE! + startpos = ++i; + } + break; + default: + break; + } + } + s = addr.mid(startpos,i-startpos); + if (!s.isEmpty()) { + list.append(s); + qDebug("Appended %s",s.latin1()); + } QStringList::Iterator it; for ( it = list.begin(); it != list.end(); it++ ) { char *str = strdup( (*it).latin1() ); int err = mailimf_address_list_add_parse( addresses, str ); if ( err != MAILIMF_NO_ERROR ) { qDebug( "Error parsing" ); qDebug( *it ); free( str ); } else { - qDebug( "Parse success! :)" ); + qDebug( "Parse success! %s",(*it).latin1()); } } - return addresses; } mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) { mailimf_fields *fields; mailimf_field *xmailer; mailimf_mailbox *sender, *fromBox; mailimf_mailbox_list *from; mailimf_address_list *to, *cc, *bcc, *reply; char *subject = strdup( mail.getSubject().latin1() ); int err; @@ -616,25 +644,28 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou } } else { user = strdup( smtp->getUser().latin1() ); pass = strdup( smtp->getPassword().latin1() ); } qDebug( "session->auth: %i", session->auth); 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;} + if ( err != MAILSMTP_NO_ERROR ) { + qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); + 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 (server) free( server ); if ( smtp->getLogin() ) { free( user ); |