summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/smtpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp206
1 files changed, 121 insertions, 85 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 08f6bb7..085d5e4 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -27,4 +27,3 @@ progressMailSend*SMTPwrapper::sendProgress = 0;
27SMTPwrapper::SMTPwrapper( Settings *s ) 27SMTPwrapper::SMTPwrapper( Settings *s )
28 : QObject() 28: QObject() {
29{
30 settings = s; 29 settings = s;
@@ -42,4 +41,3 @@ void SMTPwrapper::emitQCop( int queued ) {
42 41
43QString SMTPwrapper::mailsmtpError( int errnum ) 42QString SMTPwrapper::mailsmtpError( int errnum ) {
44{
45 switch ( errnum ) { 43 switch ( errnum ) {
@@ -84,4 +82,3 @@ QString SMTPwrapper::mailsmtpError( int errnum )
84 82
85mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) 83mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) {
86{
87 return mailimf_mailbox_new( strdup( name.latin1() ), 84 return mailimf_mailbox_new( strdup( name.latin1() ),
@@ -90,7 +87,7 @@ mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail
90 87
91mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) 88mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) {
92{
93 mailimf_address_list *addresses; 89 mailimf_address_list *addresses;
94 90
95 if ( addr.isEmpty() ) return NULL; 91 if ( addr.isEmpty() )
92 return NULL;
96 93
@@ -141,4 +138,3 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr )
141 138
142mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) 139mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) {
143{
144 mailimf_fields *fields; 140 mailimf_fields *fields;
@@ -152,15 +148,20 @@ mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
152 sender = newMailbox( mail.getName(), mail.getMail() ); 148 sender = newMailbox( mail.getName(), mail.getMail() );
153 if ( sender == NULL ) goto err_free; 149 if ( sender == NULL )
150 goto err_free;
154 151
155 fromBox = newMailbox( mail.getName(), mail.getMail() ); 152 fromBox = newMailbox( mail.getName(), mail.getMail() );
156 if ( fromBox == NULL ) goto err_free_sender; 153 if ( fromBox == NULL )
154 goto err_free_sender;
157 155
158 from = mailimf_mailbox_list_new_empty(); 156 from = mailimf_mailbox_list_new_empty();
159 if ( from == NULL ) goto err_free_fromBox; 157 if ( from == NULL )
158 goto err_free_fromBox;
160 159
161 err = mailimf_mailbox_list_add( from, fromBox ); 160 err = mailimf_mailbox_list_add( from, fromBox );
162 if ( err != MAILIMF_NO_ERROR ) goto err_free_from; 161 if ( err != MAILIMF_NO_ERROR )
162 goto err_free_from;
163 163
164 to = parseAddresses( mail.getTo() ); 164 to = parseAddresses( mail.getTo() );
165 if ( to == NULL ) goto err_free_from; 165 if ( to == NULL )
166 goto err_free_from;
166 167
@@ -172,3 +173,4 @@ mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
172 NULL, NULL, subject ); 173 NULL, NULL, subject );
173 if ( fields == NULL ) goto err_free_reply; 174 if ( fields == NULL )
175 goto err_free_reply;
174 176
@@ -176,6 +178,8 @@ mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
176 strdup( USER_AGENT ) ); 178 strdup( USER_AGENT ) );
177 if ( xmailer == NULL ) goto err_free_fields; 179 if ( xmailer == NULL )
180 goto err_free_fields;
178 181
179 err = mailimf_fields_add( fields, xmailer ); 182 err = mailimf_fields_add( fields, xmailer );
180 if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; 183 if ( err != MAILIMF_NO_ERROR )
184 goto err_free_xmailer;
181 185
@@ -184,12 +188,19 @@ mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail )
184err_free_xmailer: 188err_free_xmailer:
185 if (xmailer) mailimf_field_free( xmailer ); 189 if (xmailer)
190 mailimf_field_free( xmailer );
186err_free_fields: 191err_free_fields:
187 if (fields) mailimf_fields_free( fields ); 192 if (fields)
193 mailimf_fields_free( fields );
188err_free_reply: 194err_free_reply:
189 if (reply) mailimf_address_list_free( reply ); 195 if (reply)
190 if (bcc) mailimf_address_list_free( bcc ); 196 mailimf_address_list_free( reply );
191 if (cc) mailimf_address_list_free( cc ); 197 if (bcc)
192 if (to) mailimf_address_list_free( to ); 198 mailimf_address_list_free( bcc );
199 if (cc)
200 mailimf_address_list_free( cc );
201 if (to)
202 mailimf_address_list_free( to );
193err_free_from: 203err_free_from:
194 if (from) mailimf_mailbox_list_free( from ); 204 if (from)
205 mailimf_mailbox_list_free( from );
195err_free_fromBox: 206err_free_fromBox:
@@ -197,5 +208,7 @@ err_free_fromBox:
197err_free_sender: 208err_free_sender:
198 if (sender) mailimf_mailbox_free( sender ); 209 if (sender)
210 mailimf_mailbox_free( sender );
199err_free: 211err_free:
200 if (subject) free( subject ); 212 if (subject)
213 free( subject );
201 qDebug( "createImfFields - error" ); 214 qDebug( "createImfFields - error" );
@@ -205,4 +218,3 @@ err_free:
205 218
206mailmime *SMTPwrapper::buildTxtPart(const QString&str ) 219mailmime *SMTPwrapper::buildTxtPart(const QString&str ) {
207{
208 mailmime *txtPart; 220 mailmime *txtPart;
@@ -215,18 +227,24 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str )
215 strdup( "iso-8859-1" ) ); 227 strdup( "iso-8859-1" ) );
216 if ( param == NULL ) goto err_free; 228 if ( param == NULL )
229 goto err_free;
217 230
218 content = mailmime_content_new_with_str( "text/plain" ); 231 content = mailmime_content_new_with_str( "text/plain" );
219 if ( content == NULL ) goto err_free_param; 232 if ( content == NULL )
233 goto err_free_param;
220 234
221 err = clist_append( content->ct_parameters, param ); 235 err = clist_append( content->ct_parameters, param );
222 if ( err != MAILIMF_NO_ERROR ) goto err_free_content; 236 if ( err != MAILIMF_NO_ERROR )
237 goto err_free_content;
223 238
224 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 239 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
225 if ( fields == NULL ) goto err_free_content; 240 if ( fields == NULL )
241 goto err_free_content;
226 242
227 txtPart = mailmime_new_empty( content, fields ); 243 txtPart = mailmime_new_empty( content, fields );
228 if ( txtPart == NULL ) goto err_free_fields; 244 if ( txtPart == NULL )
245 goto err_free_fields;
229 246
230 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); 247 err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
231 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 248 if ( err != MAILIMF_NO_ERROR )
249 goto err_free_txtPart;
232 250
@@ -248,4 +266,3 @@ err_free:
248 266
249mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) 267mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
250{
251 mailmime * filePart = 0; 268 mailmime * filePart = 0;
@@ -327,4 +344,3 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
327 344
328void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) 345void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) {
329{
330 const Attachment *it; 346 const Attachment *it;
@@ -352,4 +368,3 @@ void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files
352 368
353mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) 369mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) {
354{
355 mailmime *message, *txtPart; 370 mailmime *message, *txtPart;
@@ -359,6 +374,8 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
359 fields = createImfFields( mail ); 374 fields = createImfFields( mail );
360 if ( fields == NULL ) goto err_free; 375 if ( fields == NULL )
376 goto err_free;
361 377
362 message = mailmime_new_message_data( NULL ); 378 message = mailmime_new_message_data( NULL );
363 if ( message == NULL ) goto err_free_fields; 379 if ( message == NULL )
380 goto err_free_fields;
364 381
@@ -368,6 +385,8 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
368 385
369 if ( txtPart == NULL ) goto err_free_message; 386 if ( txtPart == NULL )
387 goto err_free_message;
370 388
371 err = mailmime_smart_add_part( message, txtPart ); 389 err = mailmime_smart_add_part( message, txtPart );
372 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 390 if ( err != MAILIMF_NO_ERROR )
391 goto err_free_txtPart;
373 392
@@ -389,4 +408,3 @@ err_free:
389 408
390mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) 409mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) {
391{
392 mailimf_field *field; 410 mailimf_field *field;
@@ -406,4 +424,3 @@ mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type )
406 424
407void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) 425void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) {
408{
409 clistiter *it, *it2; 426 clistiter *it, *it2;
@@ -427,4 +444,3 @@ void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list )
427 444
428clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) 445clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) {
429{
430 clist *rcptList; 446 clist *rcptList;
@@ -455,4 +471,3 @@ clist *SMTPwrapper::createRcptList( mailimf_fields *fields )
455 471
456char *SMTPwrapper::getFrom( mailimf_field *ffrom) 472char *SMTPwrapper::getFrom( mailimf_field *ffrom) {
457{
458 char *from = NULL; 473 char *from = NULL;
@@ -471,4 +486,3 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom)
471 486
472char *SMTPwrapper::getFrom( mailmime *mail ) 487char *SMTPwrapper::getFrom( mailmime *mail ) {
473{
474 /* no need to delete - its just a pointer to structure content */ 488 /* no need to delete - its just a pointer to structure content */
@@ -479,4 +493,3 @@ char *SMTPwrapper::getFrom( mailmime *mail )
479 493
480void SMTPwrapper::progress( size_t current, size_t maximum ) 494void SMTPwrapper::progress( size_t current, size_t maximum ) {
481{
482 if (SMTPwrapper::sendProgress) { 495 if (SMTPwrapper::sendProgress) {
@@ -487,5 +500,5 @@ void SMTPwrapper::progress( size_t current, size_t maximum )
487 500
488void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) 501void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
489{ 502 if (!mail)
490 if (!mail) return; 503 return;
491 QString localfolders = AbstractMail::defaultLocalfolder(); 504 QString localfolders = AbstractMail::defaultLocalfolder();
@@ -497,4 +510,3 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box)
497 510
498void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 511void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
499{
500 clist *rcpts = 0; 512 clist *rcpts = 0;
@@ -515,3 +527,4 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
515 if (r != MAIL_NO_ERROR || !data) { 527 if (r != MAIL_NO_ERROR || !data) {
516 if (data) free(data); 528 if (data)
529 free(data);
517 qDebug("Error fetching mime..."); 530 qDebug("Error fetching mime...");
@@ -522,3 +535,4 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
522 storeMail(data,size,"Outgoing"); 535 storeMail(data,size,"Outgoing");
523 if (data) free( data ); 536 if (data)
537 free( data );
524 Config cfg( "mail" ); 538 Config cfg( "mail" );
@@ -532,9 +546,13 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
532 smtpSend(from,rcpts,data,size,smtp); 546 smtpSend(from,rcpts,data,size,smtp);
533 if (data) {free(data);} 547 if (data) {
534 if (from) {free(from);} 548 free(data);
535 if (rcpts) smtp_address_list_free( rcpts ); 549 }
550 if (from) {
551 free(from);
552 }
553 if (rcpts)
554 smtp_address_list_free( rcpts );
536} 555}
537 556
538int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) 557int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) {
539{
540 const char *server, *user, *pass; 558 const char *server, *user, *pass;
@@ -548,3 +566,11 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
548 server = smtp->getServer().latin1(); 566 server = smtp->getServer().latin1();
549 ssl = smtp->getSSL(); 567
568 // FIXME: currently only TLS and Plain work.
569
570 ssl = false;
571
572 if ( smtp->ConnectionType() == 2 ) {
573 ssl = true;
574 }
575
550 port = smtp->getPort().toUInt(); 576 port = smtp->getPort().toUInt();
@@ -552,3 +578,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
552 session = mailsmtp_new( 20, &progress ); 578 session = mailsmtp_new( 20, &progress );
553 if ( session == NULL ) goto free_mem; 579 if ( session == NULL )
580 goto free_mem;
554 581
@@ -562,6 +589,13 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
562 } 589 }
563 if ( err != MAILSMTP_NO_ERROR ) {qDebug("Error init connection");result = 0;goto free_mem_session;} 590 if ( err != MAILSMTP_NO_ERROR ) {
591 qDebug("Error init connection");
592 result = 0;
593 goto free_mem_session;
594 }
564 595
565 err = mailsmtp_init( session ); 596 err = mailsmtp_init( session );
566 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 597 if ( err != MAILSMTP_NO_ERROR ) {
598 result = 0;
599 goto free_con_session;
600 }
567 601
@@ -580,3 +614,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
580 } else { 614 } else {
581 result = 0; goto free_con_session; 615 result = 0;
616 goto free_con_session;
582 } 617 }
@@ -588,3 +623,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
588 err = mailsmtp_auth( session, (char*)user, (char*)pass ); 623 err = mailsmtp_auth( session, (char*)user, (char*)pass );
589 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 624 if ( err == MAILSMTP_NO_ERROR )
625 qDebug("auth ok");
590 qDebug( "Done auth!" ); 626 qDebug( "Done auth!" );
@@ -597,3 +633,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
597 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 633 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
598 result = 0; goto free_con_session; 634 result = 0;
635 goto free_con_session;
599 } 636 }
@@ -611,4 +648,3 @@ free_mem:
611 648
612void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) 649void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) {
613{
614 mailmime * mimeMail; 650 mailmime * mimeMail;
@@ -637,4 +673,3 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later )
637 673
638int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) 674int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) {
639{
640 size_t curTok = 0; 675 size_t curTok = 0;
@@ -647,3 +682,4 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
647 encodedString * data = wrap->fetchRawBody(*which); 682 encodedString * data = wrap->fetchRawBody(*which);
648 if (!data) return 0; 683 if (!data)
684 return 0;
649 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 685 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
@@ -679,7 +715,7 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
679/* this is a special fun */ 715/* this is a special fun */
680bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 716bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
681{
682 bool returnValue = true; 717 bool returnValue = true;
683 718
684 if (!smtp) return false; 719 if (!smtp)
720 return false;
685 721