Diffstat (limited to 'noncore/net/mail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 54 |
1 files changed, 19 insertions, 35 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 521cd0a..30c0707 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -119,27 +119,27 @@ mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) | |||
119 | qDebug( *it ); | 119 | qDebug( *it ); |
120 | } else { | 120 | } else { |
121 | qDebug( "Parse success! %s",(*it).latin1()); | 121 | qDebug( "Parse success! %s",(*it).latin1()); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | return addresses; | 124 | return addresses; |
125 | } | 125 | } |
126 | 126 | ||
127 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | 127 | mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) |
128 | { | 128 | { |
129 | mailimf_fields *fields; | 129 | mailimf_fields *fields; |
130 | mailimf_field *xmailer; | 130 | mailimf_field *xmailer; |
131 | mailimf_mailbox *sender, *fromBox; | 131 | mailimf_mailbox *sender=0,*fromBox=0; |
132 | mailimf_mailbox_list *from; | 132 | mailimf_mailbox_list *from=0; |
133 | mailimf_address_list *to, *cc, *bcc, *reply; | 133 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
134 | char *subject = strdup( mail.getSubject().latin1() ); | 134 | char *subject = strdup( mail.getSubject().latin1() ); |
135 | int err; | 135 | int err; |
136 | 136 | ||
137 | sender = newMailbox( mail.getName(), mail.getMail() ); | 137 | sender = newMailbox( mail.getName(), mail.getMail() ); |
138 | if ( sender == NULL ) goto err_free; | 138 | if ( sender == NULL ) goto err_free; |
139 | 139 | ||
140 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | 140 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
141 | if ( fromBox == NULL ) goto err_free_sender; | 141 | if ( fromBox == NULL ) goto err_free_sender; |
142 | 142 | ||
143 | from = mailimf_mailbox_list_new_empty(); | 143 | from = mailimf_mailbox_list_new_empty(); |
144 | if ( from == NULL ) goto err_free_fromBox; | 144 | if ( from == NULL ) goto err_free_fromBox; |
145 | 145 | ||
@@ -158,64 +158,64 @@ mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) | |||
158 | if ( fields == NULL ) goto err_free_reply; | 158 | if ( fields == NULL ) goto err_free_reply; |
159 | 159 | ||
160 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 160 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), |
161 | strdup( USER_AGENT ) ); | 161 | strdup( USER_AGENT ) ); |
162 | if ( xmailer == NULL ) goto err_free_fields; | 162 | if ( xmailer == NULL ) goto err_free_fields; |
163 | 163 | ||
164 | err = mailimf_fields_add( fields, xmailer ); | 164 | err = mailimf_fields_add( fields, xmailer ); |
165 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; | 165 | if ( err != MAILIMF_NO_ERROR ) goto err_free_xmailer; |
166 | 166 | ||
167 | return fields; // Success :) | 167 | return fields; // Success :) |
168 | 168 | ||
169 | err_free_xmailer: | 169 | err_free_xmailer: |
170 | mailimf_field_free( xmailer ); | 170 | if (xmailer) mailimf_field_free( xmailer ); |
171 | err_free_fields: | 171 | err_free_fields: |
172 | mailimf_fields_free( fields ); | 172 | if (fields) mailimf_fields_free( fields ); |
173 | err_free_reply: | 173 | err_free_reply: |
174 | mailimf_address_list_free( reply ); | 174 | if (reply) mailimf_address_list_free( reply ); |
175 | mailimf_address_list_free( bcc ); | 175 | if (bcc) mailimf_address_list_free( bcc ); |
176 | mailimf_address_list_free( cc ); | 176 | if (cc) mailimf_address_list_free( cc ); |
177 | mailimf_address_list_free( to ); | 177 | if (to) mailimf_address_list_free( to ); |
178 | err_free_from: | 178 | err_free_from: |
179 | mailimf_mailbox_list_free( from ); | 179 | if (from) mailimf_mailbox_list_free( from ); |
180 | err_free_fromBox: | 180 | err_free_fromBox: |
181 | mailimf_mailbox_free( fromBox ); | 181 | mailimf_mailbox_free( fromBox ); |
182 | err_free_sender: | 182 | err_free_sender: |
183 | mailimf_mailbox_free( sender ); | 183 | if (sender) mailimf_mailbox_free( sender ); |
184 | err_free: | 184 | err_free: |
185 | free( subject ); | 185 | if (subject) free( subject ); |
186 | qDebug( "createImfFields - error" ); | 186 | qDebug( "createImfFields - error" ); |
187 | 187 | ||
188 | return NULL; // Error :( | 188 | return NULL; // Error :( |
189 | } | 189 | } |
190 | 190 | ||
191 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | 191 | mailmime *SMTPwrapper::buildTxtPart(const QString&str ) |
192 | { | 192 | { |
193 | mailmime *txtPart; | 193 | mailmime *txtPart; |
194 | mailmime_fields *fields; | 194 | mailmime_fields *fields; |
195 | mailmime_content *content; | 195 | mailmime_content *content; |
196 | mailmime_parameter *param; | 196 | mailmime_parameter *param; |
197 | int err; | 197 | int err; |
198 | 198 | ||
199 | param = mailmime_parameter_new( strdup( "charset" ), | 199 | param = mailmime_parameter_new( strdup( "charset" ), |
200 | strdup( "iso-8859-1" ) ); | 200 | strdup( "iso-8859-1" ) ); |
201 | if ( param == NULL ) goto err_free; | 201 | if ( param == NULL ) goto err_free; |
202 | 202 | ||
203 | content = mailmime_content_new_with_str( "text/plain" ); | 203 | content = mailmime_content_new_with_str( "text/plain" ); |
204 | if ( content == NULL ) goto err_free_param; | 204 | if ( content == NULL ) goto err_free_param; |
205 | 205 | ||
206 | err = clist_append( content->ct_parameters, param ); | 206 | err = clist_append( content->ct_parameters, param ); |
207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
208 | 208 | ||
209 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_QUOTED_PRINTABLE); | 209 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
210 | if ( fields == NULL ) goto err_free_content; | 210 | if ( fields == NULL ) goto err_free_content; |
211 | 211 | ||
212 | txtPart = mailmime_new_empty( content, fields ); | 212 | txtPart = mailmime_new_empty( content, fields ); |
213 | if ( txtPart == NULL ) goto err_free_fields; | 213 | if ( txtPart == NULL ) goto err_free_fields; |
214 | 214 | ||
215 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 215 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
216 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 216 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
217 | 217 | ||
218 | return txtPart; // Success :) | 218 | return txtPart; // Success :) |
219 | 219 | ||
220 | err_free_txtPart: | 220 | err_free_txtPart: |
221 | mailmime_free( txtPart ); | 221 | mailmime_free( txtPart ); |
@@ -453,44 +453,24 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom) | |||
453 | 453 | ||
454 | return from; | 454 | return from; |
455 | } | 455 | } |
456 | 456 | ||
457 | char *SMTPwrapper::getFrom( mailmime *mail ) | 457 | char *SMTPwrapper::getFrom( mailmime *mail ) |
458 | { | 458 | { |
459 | /* no need to delete - its just a pointer to structure content */ | 459 | /* no need to delete - its just a pointer to structure content */ |
460 | mailimf_field *ffrom = 0; | 460 | mailimf_field *ffrom = 0; |
461 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 461 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
462 | return getFrom(ffrom); | 462 | return getFrom(ffrom); |
463 | } | 463 | } |
464 | 464 | ||
465 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | ||
466 | { | ||
467 | SMTPaccount *smtp; | ||
468 | |||
469 | QList<Account> list = settings->getAccounts(); | ||
470 | Account *it; | ||
471 | for ( it = list.first(); it; it = list.next() ) { | ||
472 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
473 | smtp = static_cast<SMTPaccount *>(it); | ||
474 | if ( smtp->getName()== name ) { | ||
475 | qDebug( "SMTPaccount found for" ); | ||
476 | qDebug( name ); | ||
477 | return smtp; | ||
478 | } | ||
479 | } | ||
480 | } | ||
481 | |||
482 | return NULL; | ||
483 | } | ||
484 | |||
485 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 465 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
486 | { | 466 | { |
487 | if (SMTPwrapper::sendProgress) { | 467 | if (SMTPwrapper::sendProgress) { |
488 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 468 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
489 | qApp->processEvents(); | 469 | qApp->processEvents(); |
490 | } | 470 | } |
491 | } | 471 | } |
492 | 472 | ||
493 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 473 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
494 | { | 474 | { |
495 | if (!mail) return; | 475 | if (!mail) return; |
496 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 476 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
@@ -604,30 +584,34 @@ free_con_session: | |||
604 | mailsmtp_quit( session ); | 584 | mailsmtp_quit( session ); |
605 | free_mem_session: | 585 | free_mem_session: |
606 | mailsmtp_free( session ); | 586 | mailsmtp_free( session ); |
607 | free_mem: | 587 | free_mem: |
608 | if (server) free( server ); | 588 | if (server) free( server ); |
609 | if ( smtp->getLogin() ) { | 589 | if ( smtp->getLogin() ) { |
610 | free( user ); | 590 | free( user ); |
611 | free( pass ); | 591 | free( pass ); |
612 | } | 592 | } |
613 | return result; | 593 | return result; |
614 | } | 594 | } |
615 | 595 | ||
616 | void SMTPwrapper::sendMail(const Mail&mail,bool later ) | 596 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) |
617 | { | 597 | { |
618 | mailmime * mimeMail; | 598 | mailmime * mimeMail; |
619 | 599 | ||
620 | SMTPaccount *smtp = getAccount(mail.getName()); | 600 | SMTPaccount *smtp = aSmtp; |
621 | 601 | ||
602 | if (!later && !smtp) { | ||
603 | qDebug("Didn't get any send method - giving up"); | ||
604 | return; | ||
605 | } | ||
622 | mimeMail = createMimeMail(mail ); | 606 | mimeMail = createMimeMail(mail ); |
623 | if ( mimeMail == NULL ) { | 607 | if ( mimeMail == NULL ) { |
624 | qDebug( "sendMail: error creating mime mail" ); | 608 | qDebug( "sendMail: error creating mime mail" ); |
625 | } else { | 609 | } else { |
626 | sendProgress = new progressMailSend(); | 610 | sendProgress = new progressMailSend(); |
627 | sendProgress->show(); | 611 | sendProgress->show(); |
628 | sendProgress->setMaxMails(1); | 612 | sendProgress->setMaxMails(1); |
629 | smtpSend( mimeMail,later,smtp); | 613 | smtpSend( mimeMail,later,smtp); |
630 | qDebug("Clean up done"); | 614 | qDebug("Clean up done"); |
631 | sendProgress->hide(); | 615 | sendProgress->hide(); |
632 | delete sendProgress; | 616 | delete sendProgress; |
633 | sendProgress = 0; | 617 | sendProgress = 0; |