-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 50 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 52 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/mailwrapper.cpp | 50 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 52 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 1 |
6 files changed, 104 insertions, 102 deletions
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 898e9d6..3ffc274 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp @@ -168,121 +168,121 @@ err_free_reply: mailimf_address_list_free( bcc ); mailimf_address_list_free( cc ); mailimf_address_list_free( to ); err_free_from: mailimf_mailbox_list_free( from ); err_free_fromBox: mailimf_mailbox_free( fromBox ); err_free_sender: mailimf_mailbox_free( sender ); err_free: free( subject ); qDebug( "createImfFields - error" ); return NULL; // Error :( } mailmime *MailWrapper::buildTxtPart( QString str ) { mailmime *txtPart; mailmime_fields *fields; mailmime_content *content; mailmime_parameter *param; char *txt = strdup( str.latin1() ); int err; param = mailmime_parameter_new( strdup( "charset" ), strdup( "iso-8859-1" ) ); if ( param == NULL ) goto err_free; content = mailmime_content_new_with_str( "text/plain" ); if ( content == NULL ) goto err_free_param; - err = clist_append( content->parameters, param ); + err = clist_append( content->ct_parameters, param ); if ( err != MAILIMF_NO_ERROR ) goto err_free_content; fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); if ( fields == NULL ) goto err_free_content; txtPart = mailmime_new_empty( content, fields ); if ( txtPart == NULL ) goto err_free_fields; err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 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: free( txt ); qDebug( "buildTxtPart - error" ); return NULL; // Error :( } mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) { mailmime * filePart; mailmime_fields * fields; mailmime_content * content; mailmime_parameter * param = NULL; int err; int pos = filename.findRev( '/' ); QString tmp = filename.right( filename.length() - ( pos + 1 ) ); char *name = strdup( tmp.latin1() ); // just filename char *file = strdup( filename.latin1() ); // full name with path char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain fields = mailmime_fields_new_filename( MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, MAILMIME_MECHANISM_BASE64 ); if ( fields == NULL ) goto err_free; content = mailmime_content_new_with_str( mime ); if ( content == NULL ) goto err_free_fields; if ( mimetype.compare( "text/plain" ) == 0 ) { param = mailmime_parameter_new( strdup( "charset" ), strdup( "iso-8859-1" ) ); if ( param == NULL ) goto err_free_content; - err = clist_append( content->parameters, param ); + err = clist_append( content->ct_parameters, param ); if ( err != MAILIMF_NO_ERROR ) goto err_free_param; } filePart = mailmime_new_empty( content, fields ); if ( filePart == NULL ) goto err_free_param; err = mailmime_set_body_file( filePart, file ); if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; return filePart; // Success :) err_free_filePart: mailmime_free( filePart ); err_free_param: if ( param != NULL ) mailmime_parameter_free( param ); err_free_content: mailmime_content_free( content ); err_free_fields: mailmime_fields_free( fields ); err_free: free( name ); free( mime ); free( file ); qDebug( "buildFilePart - error" ); return NULL; // Error :( } void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) { Attachment *it; for ( it = files.first(); it; it = files.next() ) { @@ -318,138 +318,138 @@ mailmime *MailWrapper::createMimeMail( Mail *mail ) message = mailmime_new_message_data( NULL ); if ( message == NULL ) goto err_free_fields; mailmime_set_imf_fields( message, fields ); 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() ); 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 :( } mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) { mailimf_field *field; clistiter *it; - it = clist_begin( fields->list ); + it = clist_begin( fields->fld_list ); while ( it ) { field = (mailimf_field *) it->data; - if ( field->type == type ) { + if ( field->fld_type == type ) { return field; } it = it->next; } return NULL; } static void addRcpts( clist *list, mailimf_address_list *addr_list ) { clistiter *it, *it2; - for ( it = clist_begin( addr_list->list ); it; it = it->next ) { + for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { mailimf_address *addr; addr = (mailimf_address *) it->data; - if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { - esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); - } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { - clist *l = addr->group->mb_list->list; + 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->addr_spec, 0, NULL ); + esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); } } } } clist *MailWrapper::createRcptList( mailimf_fields *fields ) { clist *rcptList; mailimf_field *field; rcptList = esmtp_address_list_new(); field = getField( fields, MAILIMF_FIELD_TO ); - if ( field && (field->type == MAILIMF_FIELD_TO) - && field->field.to->addr_list ) { - addRcpts( rcptList, field->field.to->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_TO) + && field->fld_data.fld_to->to_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); } field = getField( fields, MAILIMF_FIELD_CC ); - if ( field && (field->type == MAILIMF_FIELD_CC) - && field->field.cc->addr_list ) { - addRcpts( rcptList, field->field.cc->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_CC) + && field->fld_data.fld_cc->cc_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); } field = getField( fields, MAILIMF_FIELD_BCC ); - if ( field && (field->type == MAILIMF_FIELD_BCC) - && field->field.bcc->addr_list ) { - addRcpts( rcptList, field->field.bcc->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_BCC) + && field->fld_data.fld_bcc->bcc_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); } return rcptList; } char *MailWrapper::getFrom( mailmime *mail ) { char *from = NULL; mailimf_field *ffrom; - ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); - if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) - && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { - clist *cl = ffrom->field.from->mb_list->list; + ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); + 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->addr_spec ); + from = strdup( mb->mb_addr_spec ); } } return from; } SMTPaccount *MailWrapper::getAccount( QString from ) { 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->getMail().compare( from ) == 0 ) { qDebug( "SMTPaccount found for" ); qDebug( from ); return smtp; } } } return NULL; } QString MailWrapper::getTmpFile() { int num = 0; QString unique; QDir dir( "/tmp" ); QStringList::Iterator it; @@ -513,65 +513,65 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size ) err_free: free( buf ); err_close: close( fd ); } void progress( size_t current, size_t maximum ) { qDebug( "Current: %i of %i", current, maximum ); } void MailWrapper::smtpSend( mailmime *mail ) { mailsmtp *session; clist *rcpts; char *from, *data, *server, *user = NULL, *pass = NULL; size_t size; int err; bool ssl; uint16_t port; from = getFrom( mail ); SMTPaccount *smtp = getAccount( from ); if ( smtp == NULL ) { free(from); return; } server = strdup( smtp->getServer().latin1() ); ssl = smtp->getSSL(); port = smtp->getPort().toUInt(); - rcpts = createRcptList( mail->fields ); + rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); QString file = getTmpFile(); writeToFile( file, mail ); readFromFile( file, &data, &size ); QFile f( file ); f.remove(); session = mailsmtp_new( 20, &progress ); if ( session == NULL ) goto free_mem; qDebug( "Servername %s at port %i", server, port ); if ( ssl ) { qDebug( "SSL session" ); err = mailsmtp_ssl_connect( session, server, port ); } else { qDebug( "No SSL session" ); err = mailsmtp_socket_connect( session, server, port ); } if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; err = mailsmtp_init( session ); if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; qDebug( "INIT OK" ); if ( smtp->getLogin() ) { if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { // get'em LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 72f3c36..633faf6 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -4,240 +4,240 @@ #include <libetpan/mailpop3.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; } POP3wrapper::~POP3wrapper() { logout(); } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { qDebug( "POP3: %i of %i", current, maximum ); } void POP3wrapper::listMessages( QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char *header; size_t length; carray *messages; login(); if (!m_pop3) return; mailpop3_list( m_pop3, &messages ); for ( int i = carray_count( messages ); i > 0; i-- ) { mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); - err = mailpop3_header( m_pop3, info->index, &header, &length ); + err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving header msgid: %i", info->index ); + qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); logout(); return; } RecMail *mail = parseHeader( header ); - mail->setNumber( info->index ); + mail->setNumber( info->msg_index ); target.append( mail ); } logout(); } RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok; RecMail *mail = new RecMail(); mailimf_fields *fields; err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); - for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; - switch ( field->type ) { + switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: - mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); + mail->setFrom( *parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: - mail->setTo( *parseAddressList( field->field.to->addr_list ) ); + mail->setTo( *parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: - mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); + mail->setCC( *parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); break; case MAILIMF_FIELD_BCC: - mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); + mail->setBcc( *parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); break; case MAILIMF_FIELD_SUBJECT: - mail->setSubject( QString( field->field.subject->value ) ); + mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); break; case MAILIMF_FIELD_ORIG_DATE: - mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); + mail->setDate( *parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; default: break; } } return mail; } QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", - date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); + date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); QString *result = new QString( tmp ); return result; } QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) { QString *result = new QString( "" ); bool first = true; - for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result->append( "," ); } else { first = false; } QString *tmp; - switch ( addr->type ) { + switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: - tmp = parseMailbox( addr->mailbox ); + tmp = parseMailbox( addr->ad_data.ad_mailbox ); result->append( *tmp ); delete tmp; break; case MAILIMF_ADDRESS_GROUP: - tmp = parseGroup( addr->group ); + tmp = parseGroup( addr->ad_data.ad_group ); result->append( *tmp ); delete tmp; break; default: qDebug( "POP3: unkown mailimf address type" ); break; } } return result; } QString *POP3wrapper::parseGroup( mailimf_group *group ) { QString *result = new QString( "" ); - result->append( group->display_name ); + result->append( group->grp_display_name ); result->append( ": " ); - if ( group->mb_list != NULL ) { - QString *tmp = parseMailboxList( group->mb_list ); + if ( group->grp_mb_list != NULL ) { + QString *tmp = parseMailboxList( group->grp_mb_list ); result->append( *tmp ); delete tmp; } result->append( ";" ); return result; } QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) { QString *result = new QString( "" ); - if ( box->display_name == NULL ) { - result->append( box->addr_spec ); + if ( box->mb_display_name == NULL ) { + result->append( box->mb_addr_spec ); } else { - result->append( box->display_name ); + result->append( box->mb_display_name ); result->append( " <" ); - result->append( box->addr_spec ); + result->append( box->mb_addr_spec ); result->append( ">" ); } return result; } QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString *result = new QString( "" ); bool first = true; - for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result->append( "," ); } else { first = false; } QString *tmp = parseMailbox( box ); result->append( *tmp ); delete tmp; } return result; } void POP3wrapper::login() { if ( m_pop3 != NULL ) logout(); const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); user = account->getUser().latin1(); pass = account->getPassword().latin1(); m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, - m_pop3->response ); + m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } qDebug( "POP3: connected!" ); // login // TODO: decide if apop or plain login should be used err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error logging in: %s", m_pop3->response ); + qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); logout(); return; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; err = mailpop3_quit( m_pop3 ); mailpop3_free( m_pop3 ); m_pop3 = NULL; } diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index a8937fb..4e4abad 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -1,34 +1,35 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" class RecMail; +struct mailpop3; class POP3wrapper : public QObject { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); void listMessages( QList<RecMail> &target ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); private: RecMail *parseHeader( const char *header ); QString *parseMailboxList( mailimf_mailbox_list *list ); QString *parseMailbox( mailimf_mailbox *box ); QString *parseGroup( mailimf_group *group ); QString *parseAddressList( mailimf_address_list *list ); QString *parseDateTime( mailimf_date_time *date ); POP3account *account; mailpop3 *m_pop3; }; #endif diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index 898e9d6..3ffc274 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp @@ -168,121 +168,121 @@ err_free_reply: mailimf_address_list_free( bcc ); mailimf_address_list_free( cc ); mailimf_address_list_free( to ); err_free_from: mailimf_mailbox_list_free( from ); err_free_fromBox: mailimf_mailbox_free( fromBox ); err_free_sender: mailimf_mailbox_free( sender ); err_free: free( subject ); qDebug( "createImfFields - error" ); return NULL; // Error :( } mailmime *MailWrapper::buildTxtPart( QString str ) { mailmime *txtPart; mailmime_fields *fields; mailmime_content *content; mailmime_parameter *param; char *txt = strdup( str.latin1() ); int err; param = mailmime_parameter_new( strdup( "charset" ), strdup( "iso-8859-1" ) ); if ( param == NULL ) goto err_free; content = mailmime_content_new_with_str( "text/plain" ); if ( content == NULL ) goto err_free_param; - err = clist_append( content->parameters, param ); + err = clist_append( content->ct_parameters, param ); if ( err != MAILIMF_NO_ERROR ) goto err_free_content; fields = mailmime_fields_new_encoding( MAILMIME_MECHANISM_8BIT ); if ( fields == NULL ) goto err_free_content; txtPart = mailmime_new_empty( content, fields ); if ( txtPart == NULL ) goto err_free_fields; err = mailmime_set_body_text( txtPart, txt, strlen( txt ) ); 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: free( txt ); qDebug( "buildTxtPart - error" ); return NULL; // Error :( } mailmime *MailWrapper::buildFilePart( QString filename, QString mimetype ) { mailmime * filePart; mailmime_fields * fields; mailmime_content * content; mailmime_parameter * param = NULL; int err; int pos = filename.findRev( '/' ); QString tmp = filename.right( filename.length() - ( pos + 1 ) ); char *name = strdup( tmp.latin1() ); // just filename char *file = strdup( filename.latin1() ); // full name with path char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain fields = mailmime_fields_new_filename( MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, MAILMIME_MECHANISM_BASE64 ); if ( fields == NULL ) goto err_free; content = mailmime_content_new_with_str( mime ); if ( content == NULL ) goto err_free_fields; if ( mimetype.compare( "text/plain" ) == 0 ) { param = mailmime_parameter_new( strdup( "charset" ), strdup( "iso-8859-1" ) ); if ( param == NULL ) goto err_free_content; - err = clist_append( content->parameters, param ); + err = clist_append( content->ct_parameters, param ); if ( err != MAILIMF_NO_ERROR ) goto err_free_param; } filePart = mailmime_new_empty( content, fields ); if ( filePart == NULL ) goto err_free_param; err = mailmime_set_body_file( filePart, file ); if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; return filePart; // Success :) err_free_filePart: mailmime_free( filePart ); err_free_param: if ( param != NULL ) mailmime_parameter_free( param ); err_free_content: mailmime_content_free( content ); err_free_fields: mailmime_fields_free( fields ); err_free: free( name ); free( mime ); free( file ); qDebug( "buildFilePart - error" ); return NULL; // Error :( } void MailWrapper::addFileParts( mailmime *message, QList<Attachment> files ) { Attachment *it; for ( it = files.first(); it; it = files.next() ) { @@ -318,138 +318,138 @@ mailmime *MailWrapper::createMimeMail( Mail *mail ) message = mailmime_new_message_data( NULL ); if ( message == NULL ) goto err_free_fields; mailmime_set_imf_fields( message, fields ); 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() ); 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 :( } mailimf_field *MailWrapper::getField( mailimf_fields *fields, int type ) { mailimf_field *field; clistiter *it; - it = clist_begin( fields->list ); + it = clist_begin( fields->fld_list ); while ( it ) { field = (mailimf_field *) it->data; - if ( field->type == type ) { + if ( field->fld_type == type ) { return field; } it = it->next; } return NULL; } static void addRcpts( clist *list, mailimf_address_list *addr_list ) { clistiter *it, *it2; - for ( it = clist_begin( addr_list->list ); it; it = it->next ) { + for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { mailimf_address *addr; addr = (mailimf_address *) it->data; - if ( addr->type == MAILIMF_ADDRESS_MAILBOX ) { - esmtp_address_list_add( list, addr->mailbox->addr_spec, 0, NULL ); - } else if ( addr->type == MAILIMF_ADDRESS_GROUP ) { - clist *l = addr->group->mb_list->list; + 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->addr_spec, 0, NULL ); + esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); } } } } clist *MailWrapper::createRcptList( mailimf_fields *fields ) { clist *rcptList; mailimf_field *field; rcptList = esmtp_address_list_new(); field = getField( fields, MAILIMF_FIELD_TO ); - if ( field && (field->type == MAILIMF_FIELD_TO) - && field->field.to->addr_list ) { - addRcpts( rcptList, field->field.to->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_TO) + && field->fld_data.fld_to->to_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); } field = getField( fields, MAILIMF_FIELD_CC ); - if ( field && (field->type == MAILIMF_FIELD_CC) - && field->field.cc->addr_list ) { - addRcpts( rcptList, field->field.cc->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_CC) + && field->fld_data.fld_cc->cc_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); } field = getField( fields, MAILIMF_FIELD_BCC ); - if ( field && (field->type == MAILIMF_FIELD_BCC) - && field->field.bcc->addr_list ) { - addRcpts( rcptList, field->field.bcc->addr_list ); + if ( field && (field->fld_type == MAILIMF_FIELD_BCC) + && field->fld_data.fld_bcc->bcc_addr_list ) { + addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); } return rcptList; } char *MailWrapper::getFrom( mailmime *mail ) { char *from = NULL; mailimf_field *ffrom; - ffrom = getField( mail->fields, MAILIMF_FIELD_FROM ); - if ( ffrom && (ffrom->type == MAILIMF_FIELD_FROM) - && ffrom->field.from->mb_list && ffrom->field.from->mb_list->list ) { - clist *cl = ffrom->field.from->mb_list->list; + ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); + 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->addr_spec ); + from = strdup( mb->mb_addr_spec ); } } return from; } SMTPaccount *MailWrapper::getAccount( QString from ) { 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->getMail().compare( from ) == 0 ) { qDebug( "SMTPaccount found for" ); qDebug( from ); return smtp; } } } return NULL; } QString MailWrapper::getTmpFile() { int num = 0; QString unique; QDir dir( "/tmp" ); QStringList::Iterator it; @@ -513,65 +513,65 @@ void MailWrapper::readFromFile( QString file, char **data, size_t *size ) err_free: free( buf ); err_close: close( fd ); } void progress( size_t current, size_t maximum ) { qDebug( "Current: %i of %i", current, maximum ); } void MailWrapper::smtpSend( mailmime *mail ) { mailsmtp *session; clist *rcpts; char *from, *data, *server, *user = NULL, *pass = NULL; size_t size; int err; bool ssl; uint16_t port; from = getFrom( mail ); SMTPaccount *smtp = getAccount( from ); if ( smtp == NULL ) { free(from); return; } server = strdup( smtp->getServer().latin1() ); ssl = smtp->getSSL(); port = smtp->getPort().toUInt(); - rcpts = createRcptList( mail->fields ); + rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); QString file = getTmpFile(); writeToFile( file, mail ); readFromFile( file, &data, &size ); QFile f( file ); f.remove(); session = mailsmtp_new( 20, &progress ); if ( session == NULL ) goto free_mem; qDebug( "Servername %s at port %i", server, port ); if ( ssl ) { qDebug( "SSL session" ); err = mailsmtp_ssl_connect( session, server, port ); } else { qDebug( "No SSL session" ); err = mailsmtp_socket_connect( session, server, port ); } if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; err = mailsmtp_init( session ); if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; qDebug( "INIT OK" ); if ( smtp->getLogin() ) { if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { // get'em LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index 72f3c36..633faf6 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -4,240 +4,240 @@ #include <libetpan/mailpop3.h> POP3wrapper::POP3wrapper( POP3account *a ) { account = a; m_pop3 = NULL; } POP3wrapper::~POP3wrapper() { logout(); } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { qDebug( "POP3: %i of %i", current, maximum ); } void POP3wrapper::listMessages( QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char *header; size_t length; carray *messages; login(); if (!m_pop3) return; mailpop3_list( m_pop3, &messages ); for ( int i = carray_count( messages ); i > 0; i-- ) { mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); - err = mailpop3_header( m_pop3, info->index, &header, &length ); + err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "POP3: error retrieving header msgid: %i", info->index ); + qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); logout(); return; } RecMail *mail = parseHeader( header ); - mail->setNumber( info->index ); + mail->setNumber( info->msg_index ); target.append( mail ); } logout(); } RecMail *POP3wrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok; RecMail *mail = new RecMail(); mailimf_fields *fields; err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); - for ( clistiter *current = clist_begin( fields->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; - switch ( field->type ) { + switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: - mail->setFrom( *parseMailboxList( field->field.from->mb_list ) ); + mail->setFrom( *parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: - mail->setTo( *parseAddressList( field->field.to->addr_list ) ); + mail->setTo( *parseAddressList( field->fld_data.fld_to->to_addr_list ) ); break; case MAILIMF_FIELD_CC: - mail->setCC( *parseAddressList( field->field.cc->addr_list ) ); + mail->setCC( *parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); break; case MAILIMF_FIELD_BCC: - mail->setBcc( *parseAddressList( field->field.bcc->addr_list ) ); + mail->setBcc( *parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); break; case MAILIMF_FIELD_SUBJECT: - mail->setSubject( QString( field->field.subject->value ) ); + mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); break; case MAILIMF_FIELD_ORIG_DATE: - mail->setDate( *parseDateTime( field->field.orig_date->date_time ) ); + mail->setDate( *parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); break; default: break; } } return mail; } QString *POP3wrapper::parseDateTime( mailimf_date_time *date ) { char tmp[23]; snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", - date->day, date->month, date->year, date->hour, date->min, date->sec, date->zone ); + date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); QString *result = new QString( tmp ); return result; } QString *POP3wrapper::parseAddressList( mailimf_address_list *list ) { QString *result = new QString( "" ); bool first = true; - for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result->append( "," ); } else { first = false; } QString *tmp; - switch ( addr->type ) { + switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: - tmp = parseMailbox( addr->mailbox ); + tmp = parseMailbox( addr->ad_data.ad_mailbox ); result->append( *tmp ); delete tmp; break; case MAILIMF_ADDRESS_GROUP: - tmp = parseGroup( addr->group ); + tmp = parseGroup( addr->ad_data.ad_group ); result->append( *tmp ); delete tmp; break; default: qDebug( "POP3: unkown mailimf address type" ); break; } } return result; } QString *POP3wrapper::parseGroup( mailimf_group *group ) { QString *result = new QString( "" ); - result->append( group->display_name ); + result->append( group->grp_display_name ); result->append( ": " ); - if ( group->mb_list != NULL ) { - QString *tmp = parseMailboxList( group->mb_list ); + if ( group->grp_mb_list != NULL ) { + QString *tmp = parseMailboxList( group->grp_mb_list ); result->append( *tmp ); delete tmp; } result->append( ";" ); return result; } QString *POP3wrapper::parseMailbox( mailimf_mailbox *box ) { QString *result = new QString( "" ); - if ( box->display_name == NULL ) { - result->append( box->addr_spec ); + if ( box->mb_display_name == NULL ) { + result->append( box->mb_addr_spec ); } else { - result->append( box->display_name ); + result->append( box->mb_display_name ); result->append( " <" ); - result->append( box->addr_spec ); + result->append( box->mb_addr_spec ); result->append( ">" ); } return result; } QString *POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString *result = new QString( "" ); bool first = true; - for ( clistiter *current = clist_begin( list->list ); current != NULL; current = current->next ) { + for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result->append( "," ); } else { first = false; } QString *tmp = parseMailbox( box ); result->append( *tmp ); delete tmp; } return result; } void POP3wrapper::login() { if ( m_pop3 != NULL ) logout(); const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); user = account->getUser().latin1(); pass = account->getPassword().latin1(); m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, - m_pop3->response ); + m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } qDebug( "POP3: connected!" ); // login // TODO: decide if apop or plain login should be used err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); if ( err != MAILPOP3_NO_ERROR ) { - qDebug( "pop3: error logging in: %s", m_pop3->response ); + qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); logout(); return; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; err = mailpop3_quit( m_pop3 ); mailpop3_free( m_pop3 ); m_pop3 = NULL; } diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index a8937fb..4e4abad 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h @@ -1,34 +1,35 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" class RecMail; +struct mailpop3; class POP3wrapper : public QObject { Q_OBJECT public: POP3wrapper( POP3account *a ); virtual ~POP3wrapper(); void listMessages( QList<RecMail> &target ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); private: RecMail *parseHeader( const char *header ); QString *parseMailboxList( mailimf_mailbox_list *list ); QString *parseMailbox( mailimf_mailbox *box ); QString *parseGroup( mailimf_group *group ); QString *parseAddressList( mailimf_address_list *list ); QString *parseDateTime( mailimf_date_time *date ); POP3account *account; mailpop3 *m_pop3; }; #endif |