summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-25 02:10:29 (UTC)
committer alwin <alwin>2003-12-25 02:10:29 (UTC)
commitaf6b80a3d184e8984575a2cf7741058302c1c30b (patch) (side-by-side diff)
treef6f66284fd9f1fd3403b188c1a1afae58ec951dc
parent52ccb19535d332f38dcd49f9d115192668c45357 (diff)
downloadopie-af6b80a3d184e8984575a2cf7741058302c1c30b.zip
opie-af6b80a3d184e8984575a2cf7741058302c1c30b.tar.gz
opie-af6b80a3d184e8984575a2cf7741058302c1c30b.tar.bz2
fixed an address parsing bug
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp39
-rw-r--r--noncore/net/mail/smtpwrapper.cpp39
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
@@ -78,26 +78,54 @@ 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;
@@ -622,13 +650,16 @@ 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;}
+ 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 );
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
@@ -78,26 +78,54 @@ 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;
@@ -622,13 +650,16 @@ 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;}
+ 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 );