author | alwin <alwin> | 2003-12-23 01:58:59 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-23 01:58:59 (UTC) |
commit | 127c50cc446de489c702400ebc5fc4874f6311b2 (patch) (unidiff) | |
tree | 86ba684107eb2258e22b613c8c0dfa1a0c8a1bda /noncore/net/mail/libmailwrapper | |
parent | 04a7006c0392c02941e263d4d35edeeb2f98223d (diff) | |
download | opie-127c50cc446de489c702400ebc5fc4874f6311b2.zip opie-127c50cc446de489c702400ebc5fc4874f6311b2.tar.gz opie-127c50cc446de489c702400ebc5fc4874f6311b2.tar.bz2 |
UFFFFFFF
flushing send queue mostly finished.
Attention: To get it work you must apply the patches from the libetpan/
directory!
ToDo:
- when flush then select a smtp-account to use for when there are more
than one smtp accounts. (opiemail.cpp) This moment I just use the first one.
- the special funs in mboxwrapper (deleting range of mail, storing a message
to a folder) should go to all mailbox wrappers, means into the global interface
of them.
- cleanup/review the code of the smtp-wrapper.
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 66 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 333 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 18 |
5 files changed, 283 insertions, 138 deletions
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index c5d4265..f8efd09 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp | |||
@@ -10,3 +10,2 @@ | |||
10 | #include "logindialog.h" | 10 | #include "logindialog.h" |
11 | //#include "mail.h" | ||
12 | #include "defines.h" | 11 | #include "defines.h" |
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 8117cef..293ae1b 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |||
@@ -219 +219,67 @@ void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folde | |||
219 | } | 219 | } |
220 | |||
221 | void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | ||
222 | { | ||
223 | RecBody body; | ||
224 | mailstorage*storage = mailstorage_new(NULL); | ||
225 | QString p = MBOXPath+"/"; | ||
226 | p+=mail.getMbox(); | ||
227 | mailmessage * msg; | ||
228 | char*data=0; | ||
229 | size_t size; | ||
230 | |||
231 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
232 | mailfolder*folder; | ||
233 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | ||
234 | r = mailfolder_connect(folder); | ||
235 | if (r != MAIL_NO_ERROR) { | ||
236 | qDebug("Error initializing mbox"); | ||
237 | mailfolder_free(folder); | ||
238 | mailstorage_free(storage); | ||
239 | return; | ||
240 | } | ||
241 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | ||
242 | if (r != MAIL_NO_ERROR) { | ||
243 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
244 | mailfolder_free(folder); | ||
245 | mailstorage_free(storage); | ||
246 | return; | ||
247 | } | ||
248 | r = mailmessage_fetch(msg,&data,&size); | ||
249 | if (r != MAIL_NO_ERROR) { | ||
250 | qDebug("Error fetching mail %i",mail.getNumber()); | ||
251 | mailfolder_free(folder); | ||
252 | mailstorage_free(storage); | ||
253 | mailmessage_free(msg); | ||
254 | return; | ||
255 | } | ||
256 | *target = data; | ||
257 | *length = size; | ||
258 | mailfolder_free(folder); | ||
259 | mailstorage_free(storage); | ||
260 | mailmessage_free(msg); | ||
261 | } | ||
262 | |||
263 | void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | ||
264 | { | ||
265 | QString p = MBOXPath+"/"; | ||
266 | p+=mailbox; | ||
267 | mailmbox_folder*f = 0; | ||
268 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | ||
269 | if (r != MAIL_NO_ERROR) { | ||
270 | qDebug("Error init folder"); | ||
271 | return; | ||
272 | } | ||
273 | for (unsigned int i=0; i < target.count();++i) { | ||
274 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | ||
275 | if (r!=MAILMBOX_NO_ERROR) { | ||
276 | qDebug("error delete mail"); | ||
277 | } | ||
278 | } | ||
279 | r = mailmbox_expunge(f); | ||
280 | if (r != MAILMBOX_NO_ERROR) { | ||
281 | qDebug("error expunge mailbox"); | ||
282 | } | ||
283 | mailmbox_done(f); | ||
284 | } | ||
285 | |||
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 1bbaf79..f64ad52 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h | |||
@@ -27,2 +27,5 @@ public: | |||
27 | 27 | ||
28 | virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); | ||
29 | virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); | ||
30 | |||
28 | protected: | 31 | protected: |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index a6a46ba..b81a87f 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -7,10 +7,5 @@ | |||
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | ||
8 | 9 | ||
9 | #include <libetpan/libetpan.h> | 10 | #include <libetpan/libetpan.h> |
10 | #if 0 | ||
11 | #include <libetpan/mailimf.h> | ||
12 | #include <libetpan/mailsmtp.h> | ||
13 | #include <libetpan/mailstorage.h> | ||
14 | #include <libetpan/maildriver.h> | ||
15 | #endif | ||
16 | 11 | ||
@@ -20,2 +15,3 @@ | |||
20 | #include "logindialog.h" | 15 | #include "logindialog.h" |
16 | #include "mailtypes.h" | ||
21 | #include "defines.h" | 17 | #include "defines.h" |
@@ -210,8 +206,10 @@ err_free: | |||
210 | 206 | ||
211 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype ) | 207 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
212 | { | 208 | { |
213 | mailmime * filePart; | 209 | mailmime * filePart = 0; |
214 | mailmime_fields * fields; | 210 | mailmime_fields * fields = 0; |
215 | mailmime_content * content; | 211 | mailmime_content * content = 0; |
216 | mailmime_parameter * param = NULL; | 212 | mailmime_parameter * param = 0; |
213 | char*name = 0; | ||
214 | char*file = 0; | ||
217 | int err; | 215 | int err; |
@@ -219,47 +217,74 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
219 | int pos = filename.findRev( '/' ); | 217 | int pos = filename.findRev( '/' ); |
220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 218 | |
221 | char *name = strdup( tmp.latin1() ); // just filename | 219 | if (filename.length()>0) { |
222 | char *file = strdup( filename.latin1() ); // full name with path | 220 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
221 | name = strdup( tmp.latin1() ); // just filename | ||
222 | file = strdup( filename.latin1() ); // full name with path | ||
223 | } | ||
223 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain | 224 | char *mime = strdup( mimetype.latin1() ); // mimetype -e.g. text/plain |
224 | 225 | ||
225 | fields = mailmime_fields_new_filename( | 226 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
226 | MAILMIME_DISPOSITION_TYPE_ATTACHMENT, name, | 227 | int mechanism = MAILMIME_MECHANISM_BASE64; |
227 | MAILMIME_MECHANISM_BASE64 ); | 228 | |
228 | if ( fields == NULL ) goto err_free; | 229 | if ( mimetype.startsWith( "text/" ) ) { |
229 | |||
230 | content = mailmime_content_new_with_str( mime ); | ||
231 | if ( content == NULL ) goto err_free_fields; | ||
232 | |||
233 | if ( mimetype.compare( "text/plain" ) == 0 ) { | ||
234 | param = mailmime_parameter_new( strdup( "charset" ), | 230 | param = mailmime_parameter_new( strdup( "charset" ), |
235 | strdup( "iso-8859-1" ) ); | 231 | strdup( "iso-8859-1" ) ); |
236 | if ( param == NULL ) goto err_free_content; | 232 | disptype = MAILMIME_DISPOSITION_TYPE_INLINE; |
237 | 233 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | |
238 | err = clist_append( content->ct_parameters, param ); | ||
239 | if ( err != MAILIMF_NO_ERROR ) goto err_free_param; | ||
240 | } | 234 | } |
241 | 235 | ||
242 | filePart = mailmime_new_empty( content, fields ); | 236 | fields = mailmime_fields_new_filename( |
243 | if ( filePart == NULL ) goto err_free_param; | 237 | disptype, name, |
244 | 238 | mechanism ); | |
245 | err = mailmime_set_body_file( filePart, file ); | 239 | content = mailmime_content_new_with_str( mime ); |
246 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 240 | if (content!=0 && fields != 0) { |
241 | if (param) { | ||
242 | clist_append(content->ct_parameters,param); | ||
243 | param = 0; | ||
244 | } | ||
245 | if (filename.length()>0) { | ||
246 | QFileInfo f(filename); | ||
247 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | ||
248 | clist_append(content->ct_parameters,param); | ||
249 | param = 0; | ||
250 | } | ||
251 | filePart = mailmime_new_empty( content, fields ); | ||
252 | } | ||
253 | if (filePart) { | ||
254 | if (filename.length()>0) { | ||
255 | err = mailmime_set_body_file( filePart, file ); | ||
256 | } else { | ||
257 | err = mailmime_set_body_text(filePart,strdup(TextContent.ascii()),TextContent.length()); | ||
258 | } | ||
259 | if (err != MAILIMF_NO_ERROR) { | ||
260 | qDebug("Error setting body with file %s",file); | ||
261 | mailmime_free( filePart ); | ||
262 | filePart = 0; | ||
263 | } | ||
264 | } | ||
247 | 265 | ||
266 | if (!filePart) { | ||
267 | if ( param != NULL ) { | ||
268 | mailmime_parameter_free( param ); | ||
269 | } | ||
270 | if (content) { | ||
271 | mailmime_content_free( content ); | ||
272 | } else { | ||
273 | if (mime) { | ||
274 | free( mime ); | ||
275 | } | ||
276 | } | ||
277 | if (fields) { | ||
278 | mailmime_fields_free( fields ); | ||
279 | } else { | ||
280 | if (name) { | ||
281 | free( name ); | ||
282 | } | ||
283 | if (file) { | ||
284 | free( file ); | ||
285 | } | ||
286 | } | ||
287 | } | ||
248 | return filePart; // Success :) | 288 | return filePart; // Success :) |
249 | 289 | ||
250 | err_free_filePart: | ||
251 | mailmime_free( filePart ); | ||
252 | err_free_param: | ||
253 | if ( param != NULL ) mailmime_parameter_free( param ); | ||
254 | err_free_content: | ||
255 | mailmime_content_free( content ); | ||
256 | err_free_fields: | ||
257 | mailmime_fields_free( fields ); | ||
258 | err_free: | ||
259 | free( name ); | ||
260 | free( mime ); | ||
261 | free( file ); | ||
262 | qDebug( "buildFilePart - error" ); | ||
263 | |||
264 | return NULL; // Error :( | ||
265 | } | 290 | } |
@@ -269,4 +294,5 @@ void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files | |||
269 | const Attachment *it; | 294 | const Attachment *it; |
270 | /* work around for the brainfucked qlist which can not act with const values */ | 295 | unsigned int count = files.count(); |
271 | for ( it = ((QList<Attachment>)files).first(); it; it = ((QList<Attachment>)files).next() ) { | 296 | qDebug("List contains %i values",count); |
297 | for ( unsigned int i = 0; i < count; ++i ) { | ||
272 | qDebug( "Adding file" ); | 298 | qDebug( "Adding file" ); |
@@ -274,16 +300,15 @@ void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files | |||
274 | int err; | 300 | int err; |
301 | it = ((QList<Attachment>)files).at(i); | ||
275 | 302 | ||
276 | filePart = buildFilePart( it->getFileName(), it->getMimeType() ); | 303 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
277 | if ( filePart == NULL ) goto err_free; | 304 | if ( filePart == NULL ) { |
278 | 305 | qDebug( "addFileParts: error adding file:" ); | |
306 | qDebug( it->getFileName() ); | ||
307 | continue; | ||
308 | } | ||
279 | err = mailmime_smart_add_part( message, filePart ); | 309 | err = mailmime_smart_add_part( message, filePart ); |
280 | if ( err != MAILIMF_NO_ERROR ) goto err_free_filePart; | 310 | if ( err != MAILIMF_NO_ERROR ) { |
281 | 311 | mailmime_free( filePart ); | |
282 | continue; // Success :) | 312 | qDebug("error smart add"); |
283 | 313 | } | |
284 | err_free_filePart: | ||
285 | mailmime_free( filePart ); | ||
286 | err_free: | ||
287 | qDebug( "addFileParts: error adding file:" ); | ||
288 | qDebug( it->getFileName() ); | ||
289 | } | 314 | } |
@@ -305,3 +330,7 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | |||
305 | 330 | ||
306 | txtPart = buildTxtPart( mail.getMessage() ); | 331 | if (mail.getAttachments().count()==0) { |
332 | txtPart = buildTxtPart( mail.getMessage() ); | ||
333 | } else { | ||
334 | txtPart = buildFilePart("","text/plain",mail.getMessage()); | ||
335 | } | ||
307 | if ( txtPart == NULL ) goto err_free_message; | 336 | if ( txtPart == NULL ) goto err_free_message; |
@@ -393,8 +422,5 @@ clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) | |||
393 | 422 | ||
394 | char *SMTPwrapper::getFrom( mailmime *mail ) | 423 | char *SMTPwrapper::getFrom( mailimf_field *ffrom) |
395 | { | 424 | { |
396 | char *from = NULL; | 425 | char *from = NULL; |
397 | |||
398 | mailimf_field *ffrom; | ||
399 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
400 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 426 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
@@ -412,3 +438,10 @@ char *SMTPwrapper::getFrom( mailmime *mail ) | |||
412 | 438 | ||
413 | SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | 439 | char *SMTPwrapper::getFrom( mailmime *mail ) |
440 | { | ||
441 | mailimf_field *ffrom = 0; | ||
442 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | ||
443 | return getFrom(ffrom); | ||
444 | } | ||
445 | |||
446 | SMTPaccount *SMTPwrapper::getAccount(const QString&name ) | ||
414 | { | 447 | { |
@@ -421,5 +454,5 @@ SMTPaccount *SMTPwrapper::getAccount(const QString&from ) | |||
421 | smtp = static_cast<SMTPaccount *>(it); | 454 | smtp = static_cast<SMTPaccount *>(it); |
422 | if ( smtp->getMail().compare( from ) == 0 ) { | 455 | if ( smtp->getName()== name ) { |
423 | qDebug( "SMTPaccount found for" ); | 456 | qDebug( "SMTPaccount found for" ); |
424 | qDebug( from ); | 457 | qDebug( name ); |
425 | return smtp; | 458 | return smtp; |
@@ -437,5 +470,5 @@ QString SMTPwrapper::getTmpFile() { | |||
437 | QDir dir( "/tmp" ); | 470 | QDir dir( "/tmp" ); |
438 | QStringList::Iterator it; | ||
439 | 471 | ||
440 | QStringList list = dir.entryList( "opiemail-tmp-*" ); | 472 | QStringList list = dir.entryList( "opiemail-tmp-*" ); |
473 | |||
441 | do { | 474 | do { |
@@ -485,35 +518,2 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) | |||
485 | *size=msg.length(); | 518 | *size=msg.length(); |
486 | |||
487 | #if 0 | ||
488 | char *buf; | ||
489 | struct stat st; | ||
490 | int fd, count = 0, total = 0; | ||
491 | |||
492 | fd = open( file.latin1(), O_RDONLY, 0 ); | ||
493 | if ( fd == -1 ) return; | ||
494 | |||
495 | if ( fstat( fd, &st ) != 0 ) goto err_close; | ||
496 | if ( !st.st_size ) goto err_close; | ||
497 | |||
498 | buf = (char *) malloc( st.st_size ); | ||
499 | if ( !buf ) goto err_close; | ||
500 | |||
501 | while ( ( total < st.st_size ) && ( count >= 0 ) ) { | ||
502 | count = read( fd, buf + total, st.st_size - total ); | ||
503 | total += count; | ||
504 | } | ||
505 | if ( count < 0 ) goto err_free; | ||
506 | |||
507 | *data = buf; | ||
508 | *size = st.st_size; | ||
509 | |||
510 | close( fd ); | ||
511 | |||
512 | return; // Success :) | ||
513 | |||
514 | err_free: | ||
515 | free( buf ); | ||
516 | err_close: | ||
517 | close( fd ); | ||
518 | #endif | ||
519 | } | 519 | } |
@@ -522,3 +522,3 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) | |||
522 | { | 522 | { |
523 | qDebug( "Current: %i of %i", current, maximum ); | 523 | // qDebug( "Current: %i of %i", current, maximum ); |
524 | } | 524 | } |
@@ -534,24 +534,15 @@ void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | |||
534 | 534 | ||
535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | 535 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
536 | { | 536 | { |
537 | mailsmtp *session; | 537 | clist *rcpts = 0; |
538 | clist *rcpts; | 538 | char *from, *data; |
539 | char *from, *data, *server, *user = NULL, *pass = NULL; | ||
540 | size_t size; | 539 | size_t size; |
541 | int err; | ||
542 | bool ssl; | ||
543 | uint16_t port; | ||
544 | 540 | ||
545 | |||
546 | from = getFrom( mail ); | ||
547 | SMTPaccount *smtp = getAccount( from ); | ||
548 | if ( smtp == NULL ) { | 541 | if ( smtp == NULL ) { |
549 | free(from); | ||
550 | return; | 542 | return; |
551 | } | 543 | } |
552 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 544 | from = data = 0; |
553 | 545 | ||
554 | QString file = getTmpFile(); | 546 | QString file = getTmpFile(); |
555 | writeToFile( file, mail ); | 547 | writeToFile( file, mail ); |
556 | |||
557 | readFromFile( file, &data, &size ); | 548 | readFromFile( file, &data, &size ); |
@@ -560,10 +551,22 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | |||
560 | 551 | ||
561 | storeMail(data,size,(later?"Outgoing":"Sent")); | ||
562 | |||
563 | if (later) { | 552 | if (later) { |
564 | smtp_address_list_free( rcpts ); | 553 | storeMail(data,size,"Outgoing"); |
565 | if (data) free( data ); | 554 | if (data) free( data ); |
566 | if (from) free(from); | ||
567 | return; | 555 | return; |
568 | } | 556 | } |
557 | from = getFrom( mail ); | ||
558 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | ||
559 | smtpSend(from,rcpts,data,size,smtp); | ||
560 | } | ||
561 | |||
562 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | ||
563 | { | ||
564 | char *server, *user, *pass; | ||
565 | bool ssl; | ||
566 | uint16_t port; | ||
567 | mailsmtp *session; | ||
568 | int err,result; | ||
569 | |||
570 | result = 1; | ||
571 | server = user = pass = 0; | ||
569 | server = strdup( smtp->getServer().latin1() ); | 572 | server = strdup( smtp->getServer().latin1() ); |
@@ -583,6 +586,6 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | |||
583 | } | 586 | } |
584 | if ( err != MAILSMTP_NO_ERROR ) goto free_mem_session; | 587 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
585 | 588 | ||
586 | err = mailsmtp_init( session ); | 589 | err = mailsmtp_init( session ); |
587 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 590 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
588 | 591 | ||
@@ -600,3 +603,3 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | |||
600 | } else { | 603 | } else { |
601 | goto free_con_session; | 604 | result = 0; goto free_con_session; |
602 | } | 605 | } |
@@ -613,5 +616,6 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later ) | |||
613 | err = mailsmtp_send( session, from, rcpts, data, size ); | 616 | err = mailsmtp_send( session, from, rcpts, data, size ); |
614 | if ( err != MAILSMTP_NO_ERROR ) goto free_con_session; | 617 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
615 | 618 | ||
616 | qDebug( "Mail sent." ); | 619 | qDebug( "Mail sent." ); |
620 | storeMail(data,size,"Sent"); | ||
617 | 621 | ||
@@ -622,6 +626,6 @@ free_mem_session: | |||
622 | free_mem: | 626 | free_mem: |
623 | smtp_address_list_free( rcpts ); | 627 | if (rcpts) smtp_address_list_free( rcpts ); |
624 | if (data) free( data ); | 628 | if (data) free( data ); |
625 | if (from) free(from); | ||
626 | if (server) free( server ); | 629 | if (server) free( server ); |
630 | if (from) free( from ); | ||
627 | if ( smtp->getLogin() ) { | 631 | if ( smtp->getLogin() ) { |
@@ -630,3 +634,3 @@ free_mem: | |||
630 | } | 634 | } |
631 | free( from ); | 635 | return result; |
632 | } | 636 | } |
@@ -636,3 +640,5 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) | |||
636 | mailmime * mimeMail; | 640 | mailmime * mimeMail; |
637 | 641 | ||
642 | SMTPaccount *smtp = getAccount(mail.getName()); | ||
643 | |||
638 | mimeMail = createMimeMail(mail ); | 644 | mimeMail = createMimeMail(mail ); |
@@ -641,5 +647,68 @@ void SMTPwrapper::sendMail(const Mail&mail,bool later ) | |||
641 | } else { | 647 | } else { |
642 | smtpSend( mimeMail,later ); | 648 | smtpSend( mimeMail,later,smtp); |
643 | mailmime_free( mimeMail ); | 649 | mailmime_free( mimeMail ); |
650 | qDebug("Clean up done"); | ||
651 | } | ||
652 | } | ||
653 | |||
654 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | ||
655 | { | ||
656 | char*data = 0; | ||
657 | size_t length = 0; | ||
658 | size_t curTok = 0; | ||
659 | mailimf_fields *fields = 0; | ||
660 | mailimf_field*ffrom = 0; | ||
661 | clist *rcpts = 0; | ||
662 | char*from = 0; | ||
663 | |||
664 | wrap->fetchRawBody(*which,&data,&length); | ||
665 | if (!data) return 0; | ||
666 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | ||
667 | if (err != MAILIMF_NO_ERROR) { | ||
668 | free(data); | ||
669 | delete wrap; | ||
670 | return 0; | ||
671 | } | ||
672 | |||
673 | rcpts = createRcptList( fields ); | ||
674 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | ||
675 | from = getFrom(ffrom); | ||
676 | qDebug("Size: %i vs. %i",length,strlen(data)); | ||
677 | if (rcpts && from) { | ||
678 | return smtpSend(from,rcpts,data,strlen(data),smtp ); | ||
644 | } | 679 | } |
680 | return 0; | ||
681 | } | ||
682 | |||
683 | /* this is a special fun */ | ||
684 | void SMTPwrapper::flushOutbox(SMTPaccount*smtp) | ||
685 | { | ||
686 | if (!smtp) return; | ||
687 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | ||
688 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | ||
689 | if (!wrap) { | ||
690 | qDebug("memory error"); | ||
691 | return; | ||
692 | } | ||
693 | QList<RecMail> mailsToSend; | ||
694 | QList<RecMail> mailsToRemove; | ||
695 | QString mbox("Outgoing"); | ||
696 | wrap->listMessages(mbox,mailsToSend); | ||
697 | if (mailsToSend.count()==0) { | ||
698 | delete wrap; | ||
699 | return; | ||
700 | } | ||
701 | mailsToSend.setAutoDelete(false); | ||
702 | while (mailsToSend.count()>0) { | ||
703 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | ||
704 | QMessageBox::critical(0,tr("Error sending mail"), | ||
705 | tr("Error sending queued mail - breaking")); | ||
706 | break; | ||
707 | } | ||
708 | mailsToRemove.append(mailsToSend.at(0)); | ||
709 | mailsToSend.removeFirst(); | ||
710 | } | ||
711 | wrap->deleteMails(mbox,mailsToRemove); | ||
712 | mailsToSend.setAutoDelete(true); | ||
713 | delete wrap; | ||
645 | } | 714 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 41e9a8c..c0dcc11 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -12,2 +12,4 @@ | |||
12 | class Mail; | 12 | class Mail; |
13 | class MBOXwrapper; | ||
14 | class RecMail; | ||
13 | class Attachment; | 15 | class Attachment; |
@@ -27,2 +29,3 @@ public: | |||
27 | void sendMail(const Mail& mail,bool later=false ); | 29 | void sendMail(const Mail& mail,bool later=false ); |
30 | void flushOutbox(SMTPaccount*smtp); | ||
28 | 31 | ||
@@ -36,7 +39,5 @@ protected: | |||
36 | mailmime *buildTxtPart(const QString&str ); | 39 | mailmime *buildTxtPart(const QString&str ); |
37 | mailmime *buildFilePart(const QString&filename,const QString&mimetype ); | 40 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
38 | void smtpSend( mailmime *mail,bool later ); | 41 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
39 | mailimf_field *getField( mailimf_fields *fields, int type ); | ||
40 | clist *createRcptList( mailimf_fields *fields ); | 42 | clist *createRcptList( mailimf_fields *fields ); |
41 | char *getFrom( mailmime *mail ); | ||
42 | SMTPaccount *getAccount(const QString&from ); | 43 | SMTPaccount *getAccount(const QString&from ); |
@@ -44,4 +45,4 @@ protected: | |||
44 | void readFromFile(const QString&file, char **data, size_t *size ); | 45 | void readFromFile(const QString&file, char **data, size_t *size ); |
45 | void storeMail(char*mail, size_t length, const QString&box); | ||
46 | 46 | ||
47 | static void storeMail(char*mail, size_t length, const QString&box); | ||
47 | static QString mailsmtpError( int err ); | 48 | static QString mailsmtpError( int err ); |
@@ -50,4 +51,11 @@ protected: | |||
50 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 51 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
52 | static char *getFrom( mailmime *mail ); | ||
53 | static char *getFrom( mailimf_field *ffrom); | ||
54 | static mailimf_field *getField( mailimf_fields *fields, int type ); | ||
55 | static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); | ||
56 | |||
51 | void storeMail(mailmime*mail, const QString&box); | 57 | void storeMail(mailmime*mail, const QString&box); |
52 | Settings *settings; | 58 | Settings *settings; |
59 | |||
60 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); | ||
53 | }; | 61 | }; |