author | harlekin <harlekin> | 2004-01-03 20:49:34 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-01-03 20:49:34 (UTC) |
commit | 02b7e56d865847ce8f4a35b7075f7b3bb7b0de76 (patch) (unidiff) | |
tree | f8e0272523f9080ef2dee6901545febf854b2122 | |
parent | a89470252ffae1670e12ef5d81db08d0e27af265 (diff) | |
download | opie-02b7e56d865847ce8f4a35b7075f7b3bb7b0de76.zip opie-02b7e56d865847ce8f4a35b7075f7b3bb7b0de76.tar.gz opie-02b7e56d865847ce8f4a35b7075f7b3bb7b0de76.tar.bz2 |
communicate outgoing mails status to the QPE/Pim channel ( to which the todayplugin listens for example)
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 30 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 10 | ||||
-rw-r--r-- | noncore/net/mail/opiemail.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 30 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 10 |
5 files changed, 75 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 30c0707..7e03af9 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,73 +1,86 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | 8 | #include <qt.h> |
9 | 9 | ||
10 | #include <qpe/config.h> | ||
11 | #include <qpe/qcopenvelope_qws.h> | ||
12 | |||
10 | #include <libetpan/libetpan.h> | 13 | #include <libetpan/libetpan.h> |
11 | 14 | ||
12 | #include "smtpwrapper.h" | 15 | #include "smtpwrapper.h" |
13 | #include "mailwrapper.h" | 16 | #include "mailwrapper.h" |
14 | #include "mboxwrapper.h" | 17 | #include "mboxwrapper.h" |
15 | #include "logindialog.h" | 18 | #include "logindialog.h" |
16 | #include "mailtypes.h" | 19 | #include "mailtypes.h" |
17 | #include "defines.h" | 20 | #include "defines.h" |
18 | #include "sendmailprogress.h" | 21 | #include "sendmailprogress.h" |
19 | 22 | ||
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 23 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 24 | ||
22 | SMTPwrapper::SMTPwrapper( Settings *s ) | 25 | SMTPwrapper::SMTPwrapper( Settings *s ) |
23 | : QObject() | 26 | : QObject() |
24 | { | 27 | { |
25 | settings = s; | 28 | settings = s; |
29 | Config cfg( "mail" ); | ||
30 | cfg.setGroup( "Status" ); | ||
31 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | ||
32 | emit queuedMails( m_queuedMail ); | ||
33 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); | ||
34 | } | ||
35 | |||
36 | void SMTPwrapper::emitQCop( int queued ) { | ||
37 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | ||
38 | env << queued; | ||
26 | } | 39 | } |
27 | 40 | ||
28 | QString SMTPwrapper::mailsmtpError( int errnum ) | 41 | QString SMTPwrapper::mailsmtpError( int errnum ) |
29 | { | 42 | { |
30 | switch ( errnum ) { | 43 | switch ( errnum ) { |
31 | case MAILSMTP_NO_ERROR: | 44 | case MAILSMTP_NO_ERROR: |
32 | return tr( "No error" ); | 45 | return tr( "No error" ); |
33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 46 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
34 | return tr( "Unexpected error code" ); | 47 | return tr( "Unexpected error code" ); |
35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 48 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
36 | return tr( "Service not available" ); | 49 | return tr( "Service not available" ); |
37 | case MAILSMTP_ERROR_STREAM: | 50 | case MAILSMTP_ERROR_STREAM: |
38 | return tr( "Stream error" ); | 51 | return tr( "Stream error" ); |
39 | case MAILSMTP_ERROR_HOSTNAME: | 52 | case MAILSMTP_ERROR_HOSTNAME: |
40 | return tr( "gethostname() failed" ); | 53 | return tr( "gethostname() failed" ); |
41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 54 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
42 | return tr( "Not implemented" ); | 55 | return tr( "Not implemented" ); |
43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 56 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
44 | return tr( "Error, action not taken" ); | 57 | return tr( "Error, action not taken" ); |
45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 58 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
46 | return tr( "Data exceeds storage allocation" ); | 59 | return tr( "Data exceeds storage allocation" ); |
47 | case MAILSMTP_ERROR_IN_PROCESSING: | 60 | case MAILSMTP_ERROR_IN_PROCESSING: |
48 | return tr( "Error in processing" ); | 61 | return tr( "Error in processing" ); |
49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 62 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
50 | // return tr( "Insufficient system storage" ); | 63 | // return tr( "Insufficient system storage" ); |
51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 64 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
52 | return tr( "Mailbox unavailable" ); | 65 | return tr( "Mailbox unavailable" ); |
53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 66 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
54 | return tr( "Mailbox name not allowed" ); | 67 | return tr( "Mailbox name not allowed" ); |
55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 68 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
56 | return tr( "Bad command sequence" ); | 69 | return tr( "Bad command sequence" ); |
57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 70 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
58 | return tr( "User not local" ); | 71 | return tr( "User not local" ); |
59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
60 | return tr( "Transaction failed" ); | 73 | return tr( "Transaction failed" ); |
61 | case MAILSMTP_ERROR_MEMORY: | 74 | case MAILSMTP_ERROR_MEMORY: |
62 | return tr( "Memory error" ); | 75 | return tr( "Memory error" ); |
63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
64 | return tr( "Connection refused" ); | 77 | return tr( "Connection refused" ); |
65 | default: | 78 | default: |
66 | return tr( "Unknown error code" ); | 79 | return tr( "Unknown error code" ); |
67 | } | 80 | } |
68 | } | 81 | } |
69 | 82 | ||
70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 83 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
71 | { | 84 | { |
72 | return mailimf_mailbox_new( strdup( name.latin1() ), | 85 | return mailimf_mailbox_new( strdup( name.latin1() ), |
73 | strdup( mail.latin1() ) ); | 86 | strdup( mail.latin1() ) ); |
@@ -203,97 +216,97 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
203 | content = mailmime_content_new_with_str( "text/plain" ); | 216 | content = mailmime_content_new_with_str( "text/plain" ); |
204 | if ( content == NULL ) goto err_free_param; | 217 | if ( content == NULL ) goto err_free_param; |
205 | 218 | ||
206 | err = clist_append( content->ct_parameters, param ); | 219 | err = clist_append( content->ct_parameters, param ); |
207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 220 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
208 | 221 | ||
209 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 222 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
210 | if ( fields == NULL ) goto err_free_content; | 223 | if ( fields == NULL ) goto err_free_content; |
211 | 224 | ||
212 | txtPart = mailmime_new_empty( content, fields ); | 225 | txtPart = mailmime_new_empty( content, fields ); |
213 | if ( txtPart == NULL ) goto err_free_fields; | 226 | if ( txtPart == NULL ) goto err_free_fields; |
214 | 227 | ||
215 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 228 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
216 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 229 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
217 | 230 | ||
218 | return txtPart; // Success :) | 231 | return txtPart; // Success :) |
219 | 232 | ||
220 | err_free_txtPart: | 233 | err_free_txtPart: |
221 | mailmime_free( txtPart ); | 234 | mailmime_free( txtPart ); |
222 | err_free_fields: | 235 | err_free_fields: |
223 | mailmime_fields_free( fields ); | 236 | mailmime_fields_free( fields ); |
224 | err_free_content: | 237 | err_free_content: |
225 | mailmime_content_free( content ); | 238 | mailmime_content_free( content ); |
226 | err_free_param: | 239 | err_free_param: |
227 | mailmime_parameter_free( param ); | 240 | mailmime_parameter_free( param ); |
228 | err_free: | 241 | err_free: |
229 | qDebug( "buildTxtPart - error" ); | 242 | qDebug( "buildTxtPart - error" ); |
230 | 243 | ||
231 | return NULL; // Error :( | 244 | return NULL; // Error :( |
232 | } | 245 | } |
233 | 246 | ||
234 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) | 247 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
235 | { | 248 | { |
236 | mailmime * filePart = 0; | 249 | mailmime * filePart = 0; |
237 | mailmime_fields * fields = 0; | 250 | mailmime_fields * fields = 0; |
238 | mailmime_content * content = 0; | 251 | mailmime_content * content = 0; |
239 | mailmime_parameter * param = 0; | 252 | mailmime_parameter * param = 0; |
240 | char*name = 0; | 253 | char*name = 0; |
241 | char*file = 0; | 254 | char*file = 0; |
242 | int err; | 255 | int err; |
243 | 256 | ||
244 | int pos = filename.findRev( '/' ); | 257 | int pos = filename.findRev( '/' ); |
245 | 258 | ||
246 | if (filename.length()>0) { | 259 | if (filename.length()>0) { |
247 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 260 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
248 | name = strdup( tmp.latin1() ); // just filename | 261 | name = strdup( tmp.latin1() ); // just filename |
249 | file = strdup( filename.latin1() ); // full name with path | 262 | file = strdup( filename.latin1() ); // full name with path |
250 | } | 263 | } |
251 | 264 | ||
252 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 265 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
253 | int mechanism = MAILMIME_MECHANISM_BASE64; | 266 | int mechanism = MAILMIME_MECHANISM_BASE64; |
254 | 267 | ||
255 | if ( mimetype.startsWith( "text/" ) ) { | 268 | if ( mimetype.startsWith( "text/" ) ) { |
256 | param = mailmime_parameter_new( strdup( "charset" ), | 269 | param = mailmime_parameter_new( strdup( "charset" ), |
257 | strdup( "iso-8859-1" ) ); | 270 | strdup( "iso-8859-1" ) ); |
258 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 271 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
259 | } | 272 | } |
260 | 273 | ||
261 | fields = mailmime_fields_new_filename( | 274 | fields = mailmime_fields_new_filename( |
262 | disptype, name, | 275 | disptype, name, |
263 | mechanism ); | 276 | mechanism ); |
264 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 277 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
265 | if (content!=0 && fields != 0) { | 278 | if (content!=0 && fields != 0) { |
266 | if (param) { | 279 | if (param) { |
267 | clist_append(content->ct_parameters,param); | 280 | clist_append(content->ct_parameters,param); |
268 | param = 0; | 281 | param = 0; |
269 | } | 282 | } |
270 | if (filename.length()>0) { | 283 | if (filename.length()>0) { |
271 | QFileInfo f(filename); | 284 | QFileInfo f(filename); |
272 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 285 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
273 | clist_append(content->ct_parameters,param); | 286 | clist_append(content->ct_parameters,param); |
274 | param = 0; | 287 | param = 0; |
275 | } | 288 | } |
276 | filePart = mailmime_new_empty( content, fields ); | 289 | filePart = mailmime_new_empty( content, fields ); |
277 | } | 290 | } |
278 | if (filePart) { | 291 | if (filePart) { |
279 | if (filename.length()>0) { | 292 | if (filename.length()>0) { |
280 | err = mailmime_set_body_file( filePart, file ); | 293 | err = mailmime_set_body_file( filePart, file ); |
281 | } else { | 294 | } else { |
282 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | 295 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); |
283 | } | 296 | } |
284 | if (err != MAILIMF_NO_ERROR) { | 297 | if (err != MAILIMF_NO_ERROR) { |
285 | qDebug("Error setting body with file %s",file); | 298 | qDebug("Error setting body with file %s",file); |
286 | mailmime_free( filePart ); | 299 | mailmime_free( filePart ); |
287 | filePart = 0; | 300 | filePart = 0; |
288 | } | 301 | } |
289 | } | 302 | } |
290 | 303 | ||
291 | if (!filePart) { | 304 | if (!filePart) { |
292 | if ( param != NULL ) { | 305 | if ( param != NULL ) { |
293 | mailmime_parameter_free( param ); | 306 | mailmime_parameter_free( param ); |
294 | } | 307 | } |
295 | if (content) { | 308 | if (content) { |
296 | mailmime_content_free( content ); | 309 | mailmime_content_free( content ); |
297 | } | 310 | } |
298 | if (fields) { | 311 | if (fields) { |
299 | mailmime_fields_free( fields ); | 312 | mailmime_fields_free( fields ); |
@@ -305,97 +318,97 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
305 | free( file ); | 318 | free( file ); |
306 | } | 319 | } |
307 | } | 320 | } |
308 | } | 321 | } |
309 | return filePart; // Success :) | 322 | return filePart; // Success :) |
310 | 323 | ||
311 | } | 324 | } |
312 | 325 | ||
313 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 326 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
314 | { | 327 | { |
315 | const Attachment *it; | 328 | const Attachment *it; |
316 | unsigned int count = files.count(); | 329 | unsigned int count = files.count(); |
317 | qDebug("List contains %i values",count); | 330 | qDebug("List contains %i values",count); |
318 | for ( unsigned int i = 0; i < count; ++i ) { | 331 | for ( unsigned int i = 0; i < count; ++i ) { |
319 | qDebug( "Adding file" ); | 332 | qDebug( "Adding file" ); |
320 | mailmime *filePart; | 333 | mailmime *filePart; |
321 | int err; | 334 | int err; |
322 | it = ((QList<Attachment>)files).at(i); | 335 | it = ((QList<Attachment>)files).at(i); |
323 | 336 | ||
324 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 337 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
325 | if ( filePart == NULL ) { | 338 | if ( filePart == NULL ) { |
326 | qDebug( "addFileParts: error adding file:" ); | 339 | qDebug( "addFileParts: error adding file:" ); |
327 | qDebug( it->getFileName() ); | 340 | qDebug( it->getFileName() ); |
328 | continue; | 341 | continue; |
329 | } | 342 | } |
330 | err = mailmime_smart_add_part( message, filePart ); | 343 | err = mailmime_smart_add_part( message, filePart ); |
331 | if ( err != MAILIMF_NO_ERROR ) { | 344 | if ( err != MAILIMF_NO_ERROR ) { |
332 | mailmime_free( filePart ); | 345 | mailmime_free( filePart ); |
333 | qDebug("error smart add"); | 346 | qDebug("error smart add"); |
334 | } | 347 | } |
335 | } | 348 | } |
336 | } | 349 | } |
337 | 350 | ||
338 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 351 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
339 | { | 352 | { |
340 | mailmime *message, *txtPart; | 353 | mailmime *message, *txtPart; |
341 | mailimf_fields *fields; | 354 | mailimf_fields *fields; |
342 | int err; | 355 | int err; |
343 | 356 | ||
344 | fields = createImfFields( mail ); | 357 | fields = createImfFields( mail ); |
345 | if ( fields == NULL ) goto err_free; | 358 | if ( fields == NULL ) goto err_free; |
346 | 359 | ||
347 | message = mailmime_new_message_data( NULL ); | 360 | message = mailmime_new_message_data( NULL ); |
348 | if ( message == NULL ) goto err_free_fields; | 361 | if ( message == NULL ) goto err_free_fields; |
349 | 362 | ||
350 | mailmime_set_imf_fields( message, fields ); | 363 | mailmime_set_imf_fields( message, fields ); |
351 | 364 | ||
352 | txtPart = buildTxtPart( mail.getMessage() ); | 365 | txtPart = buildTxtPart( mail.getMessage() ); |
353 | 366 | ||
354 | if ( txtPart == NULL ) goto err_free_message; | 367 | if ( txtPart == NULL ) goto err_free_message; |
355 | 368 | ||
356 | err = mailmime_smart_add_part( message, txtPart ); | 369 | err = mailmime_smart_add_part( message, txtPart ); |
357 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 370 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
358 | 371 | ||
359 | addFileParts( message, mail.getAttachments() ); | 372 | addFileParts( message, mail.getAttachments() ); |
360 | 373 | ||
361 | return message; // Success :) | 374 | return message; // Success :) |
362 | 375 | ||
363 | err_free_txtPart: | 376 | err_free_txtPart: |
364 | mailmime_free( txtPart ); | 377 | mailmime_free( txtPart ); |
365 | err_free_message: | 378 | err_free_message: |
366 | mailmime_free( message ); | 379 | mailmime_free( message ); |
367 | err_free_fields: | 380 | err_free_fields: |
368 | mailimf_fields_free( fields ); | 381 | mailimf_fields_free( fields ); |
369 | err_free: | 382 | err_free: |
370 | qDebug( "createMimeMail: error" ); | 383 | qDebug( "createMimeMail: error" ); |
371 | 384 | ||
372 | return NULL; // Error :( | 385 | return NULL; // Error :( |
373 | } | 386 | } |
374 | 387 | ||
375 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 388 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
376 | { | 389 | { |
377 | mailimf_field *field; | 390 | mailimf_field *field; |
378 | clistiter *it; | 391 | clistiter *it; |
379 | 392 | ||
380 | it = clist_begin( fields->fld_list ); | 393 | it = clist_begin( fields->fld_list ); |
381 | while ( it ) { | 394 | while ( it ) { |
382 | field = (mailimf_field *) it->data; | 395 | field = (mailimf_field *) it->data; |
383 | if ( field->fld_type == type ) { | 396 | if ( field->fld_type == type ) { |
384 | return field; | 397 | return field; |
385 | } | 398 | } |
386 | it = it->next; | 399 | it = it->next; |
387 | } | 400 | } |
388 | 401 | ||
389 | return NULL; | 402 | return NULL; |
390 | } | 403 | } |
391 | 404 | ||
392 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 405 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
393 | { | 406 | { |
394 | clistiter *it, *it2; | 407 | clistiter *it, *it2; |
395 | 408 | ||
396 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 409 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
397 | mailimf_address *addr; | 410 | mailimf_address *addr; |
398 | addr = (mailimf_address *) it->data; | 411 | addr = (mailimf_address *) it->data; |
399 | 412 | ||
400 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 413 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
401 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 414 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
@@ -444,114 +457,118 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom) | |||
444 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 457 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
445 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 458 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
446 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 459 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
447 | clistiter *it; | 460 | clistiter *it; |
448 | for ( it = clist_begin( cl ); it; it = it->next ) { | 461 | for ( it = clist_begin( cl ); it; it = it->next ) { |
449 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 462 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
450 | from = strdup( mb->mb_addr_spec ); | 463 | from = strdup( mb->mb_addr_spec ); |
451 | } | 464 | } |
452 | } | 465 | } |
453 | 466 | ||
454 | return from; | 467 | return from; |
455 | } | 468 | } |
456 | 469 | ||
457 | char *SMTPwrapper::getFrom( mailmime *mail ) | 470 | char *SMTPwrapper::getFrom( mailmime *mail ) |
458 | { | 471 | { |
459 | /* no need to delete - its just a pointer to structure content */ | 472 | /* no need to delete - its just a pointer to structure content */ |
460 | mailimf_field *ffrom = 0; | 473 | mailimf_field *ffrom = 0; |
461 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 474 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
462 | return getFrom(ffrom); | 475 | return getFrom(ffrom); |
463 | } | 476 | } |
464 | 477 | ||
465 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 478 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
466 | { | 479 | { |
467 | if (SMTPwrapper::sendProgress) { | 480 | if (SMTPwrapper::sendProgress) { |
468 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 481 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
469 | qApp->processEvents(); | 482 | qApp->processEvents(); |
470 | } | 483 | } |
471 | } | 484 | } |
472 | 485 | ||
473 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 486 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
474 | { | 487 | { |
475 | if (!mail) return; | 488 | if (!mail) return; |
476 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 489 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
477 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 490 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
478 | wrap->storeMessage(mail,length,box); | 491 | wrap->storeMessage(mail,length,box); |
479 | delete wrap; | 492 | delete wrap; |
480 | } | 493 | } |
481 | 494 | ||
482 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | 495 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
483 | { | 496 | { |
484 | clist *rcpts = 0; | 497 | clist *rcpts = 0; |
485 | char *from, *data; | 498 | char *from, *data; |
486 | size_t size; | 499 | size_t size; |
487 | 500 | ||
488 | if ( smtp == NULL ) { | 501 | if ( smtp == NULL ) { |
489 | return; | 502 | return; |
490 | } | 503 | } |
491 | from = data = 0; | 504 | from = data = 0; |
492 | 505 | ||
493 | mailmessage * msg = 0; | 506 | mailmessage * msg = 0; |
494 | msg = mime_message_init(mail); | 507 | msg = mime_message_init(mail); |
495 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 508 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
496 | int r = mailmessage_fetch(msg,&data,&size); | 509 | int r = mailmessage_fetch(msg,&data,&size); |
497 | mime_message_detach_mime(msg); | 510 | mime_message_detach_mime(msg); |
498 | mailmessage_free(msg); | 511 | mailmessage_free(msg); |
499 | if (r != MAIL_NO_ERROR || !data) { | 512 | if (r != MAIL_NO_ERROR || !data) { |
500 | if (data) free(data); | 513 | if (data) free(data); |
501 | qDebug("Error fetching mime..."); | 514 | qDebug("Error fetching mime..."); |
502 | return; | 515 | return; |
503 | } | 516 | } |
504 | QString tmp = data; | 517 | QString tmp = data; |
505 | tmp.replace(QRegExp("\r+",true,false),""); | 518 | tmp.replace(QRegExp("\r+",true,false),""); |
506 | msg = 0; | 519 | msg = 0; |
507 | if (later) { | 520 | if (later) { |
508 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); | 521 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); |
509 | if (data) free( data ); | 522 | if (data) free( data ); |
523 | Config cfg( "mail" ); | ||
524 | cfg.setGroup( "Status" ); | ||
525 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | ||
526 | emit queuedMails( m_queuedMail ); | ||
510 | return; | 527 | return; |
511 | } | 528 | } |
512 | from = getFrom( mail ); | 529 | from = getFrom( mail ); |
513 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 530 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
514 | smtpSend(from,rcpts,data,size,smtp); | 531 | smtpSend(from,rcpts,data,size,smtp); |
515 | if (data) {free(data);} | 532 | if (data) {free(data);} |
516 | if (from) {free(from);} | 533 | if (from) {free(from);} |
517 | if (rcpts) smtp_address_list_free( rcpts ); | 534 | if (rcpts) smtp_address_list_free( rcpts ); |
518 | } | 535 | } |
519 | 536 | ||
520 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | 537 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) |
521 | { | 538 | { |
522 | char *server, *user, *pass; | 539 | char *server, *user, *pass; |
523 | bool ssl; | 540 | bool ssl; |
524 | uint16_t port; | 541 | uint16_t port; |
525 | mailsmtp *session; | 542 | mailsmtp *session; |
526 | int err,result; | 543 | int err,result; |
527 | 544 | ||
528 | result = 1; | 545 | result = 1; |
529 | server = user = pass = 0; | 546 | server = user = pass = 0; |
530 | server = strdup( smtp->getServer().latin1() ); | 547 | server = strdup( smtp->getServer().latin1() ); |
531 | ssl = smtp->getSSL(); | 548 | ssl = smtp->getSSL(); |
532 | port = smtp->getPort().toUInt(); | 549 | port = smtp->getPort().toUInt(); |
533 | 550 | ||
534 | session = mailsmtp_new( 20, &progress ); | 551 | session = mailsmtp_new( 20, &progress ); |
535 | if ( session == NULL ) goto free_mem; | 552 | if ( session == NULL ) goto free_mem; |
536 | 553 | ||
537 | qDebug( "Servername %s at port %i", server, port ); | 554 | qDebug( "Servername %s at port %i", server, port ); |
538 | if ( ssl ) { | 555 | if ( ssl ) { |
539 | qDebug( "SSL session" ); | 556 | qDebug( "SSL session" ); |
540 | err = mailsmtp_ssl_connect( session, server, port ); | 557 | err = mailsmtp_ssl_connect( session, server, port ); |
541 | } else { | 558 | } else { |
542 | qDebug( "No SSL session" ); | 559 | qDebug( "No SSL session" ); |
543 | err = mailsmtp_socket_connect( session, server, port ); | 560 | err = mailsmtp_socket_connect( session, server, port ); |
544 | } | 561 | } |
545 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} | 562 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
546 | 563 | ||
547 | err = mailsmtp_init( session ); | 564 | err = mailsmtp_init( session ); |
548 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 565 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
549 | 566 | ||
550 | qDebug( "INIT OK" ); | 567 | qDebug( "INIT OK" ); |
551 | 568 | ||
552 | if ( smtp->getLogin() ) { | 569 | if ( smtp->getLogin() ) { |
553 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 570 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
554 | // get'em | 571 | // get'em |
555 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 572 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
556 | login.show(); | 573 | login.show(); |
557 | if ( QDialog::Accepted == login.exec() ) { | 574 | if ( QDialog::Accepted == login.exec() ) { |
@@ -608,103 +625,108 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) | |||
608 | qDebug( "sendMail: error creating mime mail" ); | 625 | qDebug( "sendMail: error creating mime mail" ); |
609 | } else { | 626 | } else { |
610 | sendProgress = new progressMailSend(); | 627 | sendProgress = new progressMailSend(); |
611 | sendProgress->show(); | 628 | sendProgress->show(); |
612 | sendProgress->setMaxMails(1); | 629 | sendProgress->setMaxMails(1); |
613 | smtpSend( mimeMail,later,smtp); | 630 | smtpSend( mimeMail,later,smtp); |
614 | qDebug("Clean up done"); | 631 | qDebug("Clean up done"); |
615 | sendProgress->hide(); | 632 | sendProgress->hide(); |
616 | delete sendProgress; | 633 | delete sendProgress; |
617 | sendProgress = 0; | 634 | sendProgress = 0; |
618 | mailmime_free( mimeMail ); | 635 | mailmime_free( mimeMail ); |
619 | } | 636 | } |
620 | } | 637 | } |
621 | 638 | ||
622 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | 639 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) |
623 | { | 640 | { |
624 | char*data = 0; | 641 | char*data = 0; |
625 | size_t length = 0; | 642 | size_t length = 0; |
626 | size_t curTok = 0; | 643 | size_t curTok = 0; |
627 | mailimf_fields *fields = 0; | 644 | mailimf_fields *fields = 0; |
628 | mailimf_field*ffrom = 0; | 645 | mailimf_field*ffrom = 0; |
629 | clist *rcpts = 0; | 646 | clist *rcpts = 0; |
630 | char*from = 0; | 647 | char*from = 0; |
631 | int res = 0; | 648 | int res = 0; |
632 | 649 | ||
633 | wrap->fetchRawBody(*which,&data,&length); | 650 | wrap->fetchRawBody(*which,&data,&length); |
634 | if (!data) return 0; | 651 | if (!data) return 0; |
635 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | 652 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); |
636 | if (err != MAILIMF_NO_ERROR) { | 653 | if (err != MAILIMF_NO_ERROR) { |
637 | free(data); | 654 | free(data); |
638 | delete wrap; | 655 | delete wrap; |
639 | return 0; | 656 | return 0; |
640 | } | 657 | } |
641 | 658 | ||
642 | rcpts = createRcptList( fields ); | 659 | rcpts = createRcptList( fields ); |
643 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 660 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
644 | from = getFrom(ffrom); | 661 | from = getFrom(ffrom); |
645 | 662 | ||
646 | qDebug("Size: %i vs. %i",length,strlen(data)); | 663 | qDebug("Size: %i vs. %i",length,strlen(data)); |
647 | if (rcpts && from) { | 664 | if (rcpts && from) { |
648 | res = smtpSend(from,rcpts,data,length,smtp ); | 665 | res = smtpSend(from,rcpts,data,length,smtp ); |
649 | } | 666 | } |
650 | if (fields) { | 667 | if (fields) { |
651 | mailimf_fields_free(fields); | 668 | mailimf_fields_free(fields); |
652 | fields = 0; | 669 | fields = 0; |
653 | } | 670 | } |
654 | if (data) { | 671 | if (data) { |
655 | free(data); | 672 | free(data); |
656 | } | 673 | } |
657 | if (from) { | 674 | if (from) { |
658 | free(from); | 675 | free(from); |
659 | } | 676 | } |
660 | if (rcpts) { | 677 | if (rcpts) { |
661 | smtp_address_list_free( rcpts ); | 678 | smtp_address_list_free( rcpts ); |
662 | } | 679 | } |
663 | return res; | 680 | return res; |
664 | } | 681 | } |
665 | 682 | ||
666 | /* this is a special fun */ | 683 | /* this is a special fun */ |
667 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | 684 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) |
668 | { | 685 | { |
669 | bool returnValue = true; | 686 | bool returnValue = true; |
670 | 687 | ||
671 | if (!smtp) return false; | 688 | if (!smtp) return false; |
672 | 689 | ||
673 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 690 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
674 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 691 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
675 | if (!wrap) { | 692 | if (!wrap) { |
676 | qDebug("memory error"); | 693 | qDebug("memory error"); |
677 | return false; | 694 | return false; |
678 | } | 695 | } |
679 | QList<RecMail> mailsToSend; | 696 | QList<RecMail> mailsToSend; |
680 | QList<RecMail> mailsToRemove; | 697 | QList<RecMail> mailsToRemove; |
681 | QString mbox("Outgoing"); | 698 | QString mbox("Outgoing"); |
682 | wrap->listMessages(mbox,mailsToSend); | 699 | wrap->listMessages(mbox,mailsToSend); |
683 | if (mailsToSend.count()==0) { | 700 | if (mailsToSend.count()==0) { |
684 | delete wrap; | 701 | delete wrap; |
685 | return false; | 702 | return false; |
686 | } | 703 | } |
687 | mailsToSend.setAutoDelete(false); | 704 | mailsToSend.setAutoDelete(false); |
688 | sendProgress = new progressMailSend(); | 705 | sendProgress = new progressMailSend(); |
689 | sendProgress->show(); | 706 | sendProgress->show(); |
690 | sendProgress->setMaxMails(mailsToSend.count()); | 707 | sendProgress->setMaxMails(mailsToSend.count()); |
691 | 708 | ||
692 | while (mailsToSend.count()>0) { | 709 | while (mailsToSend.count()>0) { |
693 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 710 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
694 | QMessageBox::critical(0,tr("Error sending mail"), | 711 | QMessageBox::critical(0,tr("Error sending mail"), |
695 | tr("Error sending queued mail - breaking")); | 712 | tr("Error sending queued mail - breaking")); |
696 | returnValue = false; | 713 | returnValue = false; |
697 | break; | 714 | break; |
698 | } | 715 | } |
699 | mailsToRemove.append(mailsToSend.at(0)); | 716 | mailsToRemove.append(mailsToSend.at(0)); |
700 | mailsToSend.removeFirst(); | 717 | mailsToSend.removeFirst(); |
701 | sendProgress->setCurrentMails(mailsToRemove.count()); | 718 | sendProgress->setCurrentMails(mailsToRemove.count()); |
702 | } | 719 | } |
720 | Config cfg( "mail" ); | ||
721 | cfg.setGroup( "Status" ); | ||
722 | m_queuedMail = 0; | ||
723 | cfg.writeEntry( "outgoing", m_queuedMail ); | ||
724 | emit queuedMails( m_queuedMail ); | ||
703 | sendProgress->hide(); | 725 | sendProgress->hide(); |
704 | delete sendProgress; | 726 | delete sendProgress; |
705 | sendProgress = 0; | 727 | sendProgress = 0; |
706 | wrap->deleteMails(mbox,mailsToRemove); | 728 | wrap->deleteMails(mbox,mailsToRemove); |
707 | mailsToSend.setAutoDelete(true); | 729 | mailsToSend.setAutoDelete(true); |
708 | delete wrap; | 730 | delete wrap; |
709 | return returnValue; | 731 | return returnValue; |
710 | } | 732 | } |
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 0535983..05becf2 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h | |||
@@ -1,61 +1,71 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class MBOXwrapper; | 13 | class MBOXwrapper; |
14 | class RecMail; | 14 | class RecMail; |
15 | class Attachment; | 15 | class Attachment; |
16 | struct mailimf_fields; | 16 | struct mailimf_fields; |
17 | struct mailimf_field; | 17 | struct mailimf_field; |
18 | struct mailimf_mailbox; | 18 | struct mailimf_mailbox; |
19 | struct mailmime; | 19 | struct mailmime; |
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | class progressMailSend; | 21 | class progressMailSend; |
22 | 22 | ||
23 | class SMTPwrapper : public QObject | 23 | class SMTPwrapper : public QObject |
24 | { | 24 | { |
25 | Q_OBJECT | 25 | Q_OBJECT |
26 | 26 | ||
27 | public: | 27 | public: |
28 | SMTPwrapper( Settings *s ); | 28 | SMTPwrapper( Settings *s ); |
29 | virtual ~SMTPwrapper(){} | 29 | virtual ~SMTPwrapper(){} |
30 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); | 30 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); |
31 | bool flushOutbox(SMTPaccount*smtp); | 31 | bool flushOutbox(SMTPaccount*smtp); |
32 | 32 | ||
33 | static progressMailSend*sendProgress; | 33 | static progressMailSend*sendProgress; |
34 | |||
35 | signals: | ||
36 | void queuedMails( int ); | ||
37 | |||
34 | protected: | 38 | protected: |
35 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 39 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
36 | mailimf_fields *createImfFields(const Mail &mail ); | 40 | mailimf_fields *createImfFields(const Mail &mail ); |
37 | mailmime *createMimeMail(const Mail&mail ); | 41 | mailmime *createMimeMail(const Mail&mail ); |
38 | 42 | ||
39 | mailimf_address_list *parseAddresses(const QString&addr ); | 43 | mailimf_address_list *parseAddresses(const QString&addr ); |
40 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 44 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
41 | mailmime *buildTxtPart(const QString&str ); | 45 | mailmime *buildTxtPart(const QString&str ); |
42 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | 46 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
43 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); | 47 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
44 | clist *createRcptList( mailimf_fields *fields ); | 48 | clist *createRcptList( mailimf_fields *fields ); |
45 | 49 | ||
46 | static void storeMail(char*mail, size_t length, const QString&box); | 50 | static void storeMail(char*mail, size_t length, const QString&box); |
47 | static QString mailsmtpError( int err ); | 51 | static QString mailsmtpError( int err ); |
48 | static void progress( size_t current, size_t maximum ); | 52 | static void progress( size_t current, size_t maximum ); |
49 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 53 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
50 | static char *getFrom( mailmime *mail ); | 54 | static char *getFrom( mailmime *mail ); |
51 | static char *getFrom( mailimf_field *ffrom); | 55 | static char *getFrom( mailimf_field *ffrom); |
52 | static mailimf_field *getField( mailimf_fields *fields, int type ); | 56 | static mailimf_field *getField( mailimf_fields *fields, int type ); |
53 | int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); | 57 | int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); |
54 | 58 | ||
55 | void storeMail(mailmime*mail, const QString&box); | 59 | void storeMail(mailmime*mail, const QString&box); |
56 | Settings *settings; | 60 | Settings *settings; |
57 | 61 | ||
58 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); | 62 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); |
63 | |||
64 | int m_queuedMail; | ||
65 | |||
66 | protected slots: | ||
67 | void emitQCop( int queued ); | ||
68 | |||
59 | }; | 69 | }; |
60 | 70 | ||
61 | #endif | 71 | #endif |
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp index e35f5b6..54453b7 100644 --- a/noncore/net/mail/opiemail.cpp +++ b/noncore/net/mail/opiemail.cpp | |||
@@ -1,75 +1,78 @@ | |||
1 | #include <qmessagebox.h> | 1 | #include <qmessagebox.h> |
2 | #include "settingsdialog.h" | 2 | #include "settingsdialog.h" |
3 | #include "opiemail.h" | 3 | #include "opiemail.h" |
4 | #include "editaccounts.h" | 4 | #include "editaccounts.h" |
5 | #include "composemail.h" | 5 | #include "composemail.h" |
6 | #include "smtpwrapper.h" | 6 | #include "smtpwrapper.h" |
7 | #include <qpe/qcopenvelope_qws.h> | 7 | #include <qpe/qcopenvelope_qws.h> |
8 | #include <qaction.h> | 8 | #include <qaction.h> |
9 | #include <qapplication.h> | 9 | #include <qapplication.h> |
10 | 10 | ||
11 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) | 11 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags ) |
12 | : MainWindow( parent, name, flags ) | 12 | : MainWindow( parent, name, flags ) |
13 | { | 13 | { |
14 | settings = new Settings(); | 14 | settings = new Settings(); |
15 | 15 | ||
16 | folderView->populate( settings->getAccounts() ); | 16 | folderView->populate( settings->getAccounts() ); |
17 | 17 | ||
18 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); | 18 | connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); |
19 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); | 19 | connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); |
20 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); | 20 | // connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); |
21 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); | 21 | connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); |
22 | // Added by Stefan Eilers to allow starting by addressbook.. | 22 | // Added by Stefan Eilers to allow starting by addressbook.. |
23 | // copied from old mail2 | 23 | // copied from old mail2 |
24 | #if !defined(QT_NO_COP) | 24 | #if !defined(QT_NO_COP) |
25 | connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), | 25 | connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), |
26 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); | 26 | this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); |
27 | #endif | 27 | #endif |
28 | |||
29 | |||
30 | |||
28 | } | 31 | } |
29 | 32 | ||
30 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) | 33 | void OpieMail::appMessage(const QCString &msg, const QByteArray &data) |
31 | { | 34 | { |
32 | // copied from old mail2 | 35 | // copied from old mail2 |
33 | if (msg == "writeMail(QString,QString)") { | 36 | if (msg == "writeMail(QString,QString)") { |
34 | QDataStream stream(data,IO_ReadOnly); | 37 | QDataStream stream(data,IO_ReadOnly); |
35 | QString name, email; | 38 | QString name, email; |
36 | stream >> name >> email; | 39 | stream >> name >> email; |
37 | // removing the whitespaces at beginning and end is needed! | 40 | // removing the whitespaces at beginning and end is needed! |
38 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); | 41 | slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); |
39 | } else if (msg == "newMail()") { | 42 | } else if (msg == "newMail()") { |
40 | slotComposeMail(); | 43 | slotComposeMail(); |
41 | } | 44 | } |
42 | } | 45 | } |
43 | 46 | ||
44 | void OpieMail::slotwriteMail(const QString&name,const QString&email) | 47 | void OpieMail::slotwriteMail(const QString&name,const QString&email) |
45 | { | 48 | { |
46 | ComposeMail compose( settings, this, 0 , true ); | 49 | ComposeMail compose( settings, this, 0 , true ); |
47 | if (!email.isEmpty()) { | 50 | if (!email.isEmpty()) { |
48 | if (!name.isEmpty()) { | 51 | if (!name.isEmpty()) { |
49 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); | 52 | compose.setTo("\"" + name + "\"" + " " + "<"+ email + ">"); |
50 | } else { | 53 | } else { |
51 | compose.setTo(email); | 54 | compose.setTo(email); |
52 | } | 55 | } |
53 | } | 56 | } |
54 | compose.showMaximized(); | 57 | compose.showMaximized(); |
55 | compose.slotAdjustColumns(); | 58 | compose.slotAdjustColumns(); |
56 | compose.exec(); | 59 | compose.exec(); |
57 | } | 60 | } |
58 | 61 | ||
59 | void OpieMail::slotComposeMail() | 62 | void OpieMail::slotComposeMail() |
60 | { | 63 | { |
61 | qDebug( "Compose Mail" ); | 64 | qDebug( "Compose Mail" ); |
62 | slotwriteMail(0l,0l); | 65 | slotwriteMail(0l,0l); |
63 | } | 66 | } |
64 | 67 | ||
65 | void OpieMail::slotSendQueued() | 68 | void OpieMail::slotSendQueued() |
66 | { | 69 | { |
67 | qDebug( "Send Queued" ); | 70 | qDebug( "Send Queued" ); |
68 | SMTPaccount *smtp = 0; | 71 | SMTPaccount *smtp = 0; |
69 | 72 | ||
70 | QList<Account> list = settings->getAccounts(); | 73 | QList<Account> list = settings->getAccounts(); |
71 | Account *it; | 74 | Account *it; |
72 | // if (list.count()==1) { | 75 | // if (list.count()==1) { |
73 | for ( it = list.first(); it; it = list.next() ) { | 76 | for ( it = list.first(); it; it = list.next() ) { |
74 | if ( it->getType().compare( "SMTP" ) == 0 ) { | 77 | if ( it->getType().compare( "SMTP" ) == 0 ) { |
75 | smtp = static_cast<SMTPaccount *>(it); | 78 | smtp = static_cast<SMTPaccount *>(it); |
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 30c0707..7e03af9 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp | |||
@@ -1,73 +1,86 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <sys/stat.h> | 2 | #include <sys/stat.h> |
3 | #include <sys/types.h> | 3 | #include <sys/types.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <qdir.h> | 7 | #include <qdir.h> |
8 | #include <qt.h> | 8 | #include <qt.h> |
9 | 9 | ||
10 | #include <qpe/config.h> | ||
11 | #include <qpe/qcopenvelope_qws.h> | ||
12 | |||
10 | #include <libetpan/libetpan.h> | 13 | #include <libetpan/libetpan.h> |
11 | 14 | ||
12 | #include "smtpwrapper.h" | 15 | #include "smtpwrapper.h" |
13 | #include "mailwrapper.h" | 16 | #include "mailwrapper.h" |
14 | #include "mboxwrapper.h" | 17 | #include "mboxwrapper.h" |
15 | #include "logindialog.h" | 18 | #include "logindialog.h" |
16 | #include "mailtypes.h" | 19 | #include "mailtypes.h" |
17 | #include "defines.h" | 20 | #include "defines.h" |
18 | #include "sendmailprogress.h" | 21 | #include "sendmailprogress.h" |
19 | 22 | ||
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 23 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 24 | ||
22 | SMTPwrapper::SMTPwrapper( Settings *s ) | 25 | SMTPwrapper::SMTPwrapper( Settings *s ) |
23 | : QObject() | 26 | : QObject() |
24 | { | 27 | { |
25 | settings = s; | 28 | settings = s; |
29 | Config cfg( "mail" ); | ||
30 | cfg.setGroup( "Status" ); | ||
31 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | ||
32 | emit queuedMails( m_queuedMail ); | ||
33 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); | ||
34 | } | ||
35 | |||
36 | void SMTPwrapper::emitQCop( int queued ) { | ||
37 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | ||
38 | env << queued; | ||
26 | } | 39 | } |
27 | 40 | ||
28 | QString SMTPwrapper::mailsmtpError( int errnum ) | 41 | QString SMTPwrapper::mailsmtpError( int errnum ) |
29 | { | 42 | { |
30 | switch ( errnum ) { | 43 | switch ( errnum ) { |
31 | case MAILSMTP_NO_ERROR: | 44 | case MAILSMTP_NO_ERROR: |
32 | return tr( "No error" ); | 45 | return tr( "No error" ); |
33 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 46 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
34 | return tr( "Unexpected error code" ); | 47 | return tr( "Unexpected error code" ); |
35 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 48 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
36 | return tr( "Service not available" ); | 49 | return tr( "Service not available" ); |
37 | case MAILSMTP_ERROR_STREAM: | 50 | case MAILSMTP_ERROR_STREAM: |
38 | return tr( "Stream error" ); | 51 | return tr( "Stream error" ); |
39 | case MAILSMTP_ERROR_HOSTNAME: | 52 | case MAILSMTP_ERROR_HOSTNAME: |
40 | return tr( "gethostname() failed" ); | 53 | return tr( "gethostname() failed" ); |
41 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 54 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
42 | return tr( "Not implemented" ); | 55 | return tr( "Not implemented" ); |
43 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 56 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
44 | return tr( "Error, action not taken" ); | 57 | return tr( "Error, action not taken" ); |
45 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 58 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
46 | return tr( "Data exceeds storage allocation" ); | 59 | return tr( "Data exceeds storage allocation" ); |
47 | case MAILSMTP_ERROR_IN_PROCESSING: | 60 | case MAILSMTP_ERROR_IN_PROCESSING: |
48 | return tr( "Error in processing" ); | 61 | return tr( "Error in processing" ); |
49 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 62 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
50 | // return tr( "Insufficient system storage" ); | 63 | // return tr( "Insufficient system storage" ); |
51 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 64 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
52 | return tr( "Mailbox unavailable" ); | 65 | return tr( "Mailbox unavailable" ); |
53 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 66 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
54 | return tr( "Mailbox name not allowed" ); | 67 | return tr( "Mailbox name not allowed" ); |
55 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 68 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
56 | return tr( "Bad command sequence" ); | 69 | return tr( "Bad command sequence" ); |
57 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 70 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
58 | return tr( "User not local" ); | 71 | return tr( "User not local" ); |
59 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 72 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
60 | return tr( "Transaction failed" ); | 73 | return tr( "Transaction failed" ); |
61 | case MAILSMTP_ERROR_MEMORY: | 74 | case MAILSMTP_ERROR_MEMORY: |
62 | return tr( "Memory error" ); | 75 | return tr( "Memory error" ); |
63 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 76 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
64 | return tr( "Connection refused" ); | 77 | return tr( "Connection refused" ); |
65 | default: | 78 | default: |
66 | return tr( "Unknown error code" ); | 79 | return tr( "Unknown error code" ); |
67 | } | 80 | } |
68 | } | 81 | } |
69 | 82 | ||
70 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) | 83 | mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) |
71 | { | 84 | { |
72 | return mailimf_mailbox_new( strdup( name.latin1() ), | 85 | return mailimf_mailbox_new( strdup( name.latin1() ), |
73 | strdup( mail.latin1() ) ); | 86 | strdup( mail.latin1() ) ); |
@@ -203,97 +216,97 @@ mailmime *SMTPwrapper::buildTxtPart(const QString&str ) | |||
203 | content = mailmime_content_new_with_str( "text/plain" ); | 216 | content = mailmime_content_new_with_str( "text/plain" ); |
204 | if ( content == NULL ) goto err_free_param; | 217 | if ( content == NULL ) goto err_free_param; |
205 | 218 | ||
206 | err = clist_append( content->ct_parameters, param ); | 219 | err = clist_append( content->ct_parameters, param ); |
207 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; | 220 | if ( err != MAILIMF_NO_ERROR ) goto err_free_content; |
208 | 221 | ||
209 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); | 222 | fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); |
210 | if ( fields == NULL ) goto err_free_content; | 223 | if ( fields == NULL ) goto err_free_content; |
211 | 224 | ||
212 | txtPart = mailmime_new_empty( content, fields ); | 225 | txtPart = mailmime_new_empty( content, fields ); |
213 | if ( txtPart == NULL ) goto err_free_fields; | 226 | if ( txtPart == NULL ) goto err_free_fields; |
214 | 227 | ||
215 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); | 228 | err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() ); |
216 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 229 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
217 | 230 | ||
218 | return txtPart; // Success :) | 231 | return txtPart; // Success :) |
219 | 232 | ||
220 | err_free_txtPart: | 233 | err_free_txtPart: |
221 | mailmime_free( txtPart ); | 234 | mailmime_free( txtPart ); |
222 | err_free_fields: | 235 | err_free_fields: |
223 | mailmime_fields_free( fields ); | 236 | mailmime_fields_free( fields ); |
224 | err_free_content: | 237 | err_free_content: |
225 | mailmime_content_free( content ); | 238 | mailmime_content_free( content ); |
226 | err_free_param: | 239 | err_free_param: |
227 | mailmime_parameter_free( param ); | 240 | mailmime_parameter_free( param ); |
228 | err_free: | 241 | err_free: |
229 | qDebug( "buildTxtPart - error" ); | 242 | qDebug( "buildTxtPart - error" ); |
230 | 243 | ||
231 | return NULL; // Error :( | 244 | return NULL; // Error :( |
232 | } | 245 | } |
233 | 246 | ||
234 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) | 247 | mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) |
235 | { | 248 | { |
236 | mailmime * filePart = 0; | 249 | mailmime * filePart = 0; |
237 | mailmime_fields * fields = 0; | 250 | mailmime_fields * fields = 0; |
238 | mailmime_content * content = 0; | 251 | mailmime_content * content = 0; |
239 | mailmime_parameter * param = 0; | 252 | mailmime_parameter * param = 0; |
240 | char*name = 0; | 253 | char*name = 0; |
241 | char*file = 0; | 254 | char*file = 0; |
242 | int err; | 255 | int err; |
243 | 256 | ||
244 | int pos = filename.findRev( '/' ); | 257 | int pos = filename.findRev( '/' ); |
245 | 258 | ||
246 | if (filename.length()>0) { | 259 | if (filename.length()>0) { |
247 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); | 260 | QString tmp = filename.right( filename.length() - ( pos + 1 ) ); |
248 | name = strdup( tmp.latin1() ); // just filename | 261 | name = strdup( tmp.latin1() ); // just filename |
249 | file = strdup( filename.latin1() ); // full name with path | 262 | file = strdup( filename.latin1() ); // full name with path |
250 | } | 263 | } |
251 | 264 | ||
252 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; | 265 | int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; |
253 | int mechanism = MAILMIME_MECHANISM_BASE64; | 266 | int mechanism = MAILMIME_MECHANISM_BASE64; |
254 | 267 | ||
255 | if ( mimetype.startsWith( "text/" ) ) { | 268 | if ( mimetype.startsWith( "text/" ) ) { |
256 | param = mailmime_parameter_new( strdup( "charset" ), | 269 | param = mailmime_parameter_new( strdup( "charset" ), |
257 | strdup( "iso-8859-1" ) ); | 270 | strdup( "iso-8859-1" ) ); |
258 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; | 271 | mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; |
259 | } | 272 | } |
260 | 273 | ||
261 | fields = mailmime_fields_new_filename( | 274 | fields = mailmime_fields_new_filename( |
262 | disptype, name, | 275 | disptype, name, |
263 | mechanism ); | 276 | mechanism ); |
264 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); | 277 | content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); |
265 | if (content!=0 && fields != 0) { | 278 | if (content!=0 && fields != 0) { |
266 | if (param) { | 279 | if (param) { |
267 | clist_append(content->ct_parameters,param); | 280 | clist_append(content->ct_parameters,param); |
268 | param = 0; | 281 | param = 0; |
269 | } | 282 | } |
270 | if (filename.length()>0) { | 283 | if (filename.length()>0) { |
271 | QFileInfo f(filename); | 284 | QFileInfo f(filename); |
272 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); | 285 | param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); |
273 | clist_append(content->ct_parameters,param); | 286 | clist_append(content->ct_parameters,param); |
274 | param = 0; | 287 | param = 0; |
275 | } | 288 | } |
276 | filePart = mailmime_new_empty( content, fields ); | 289 | filePart = mailmime_new_empty( content, fields ); |
277 | } | 290 | } |
278 | if (filePart) { | 291 | if (filePart) { |
279 | if (filename.length()>0) { | 292 | if (filename.length()>0) { |
280 | err = mailmime_set_body_file( filePart, file ); | 293 | err = mailmime_set_body_file( filePart, file ); |
281 | } else { | 294 | } else { |
282 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); | 295 | err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length()); |
283 | } | 296 | } |
284 | if (err != MAILIMF_NO_ERROR) { | 297 | if (err != MAILIMF_NO_ERROR) { |
285 | qDebug("Error setting body with file %s",file); | 298 | qDebug("Error setting body with file %s",file); |
286 | mailmime_free( filePart ); | 299 | mailmime_free( filePart ); |
287 | filePart = 0; | 300 | filePart = 0; |
288 | } | 301 | } |
289 | } | 302 | } |
290 | 303 | ||
291 | if (!filePart) { | 304 | if (!filePart) { |
292 | if ( param != NULL ) { | 305 | if ( param != NULL ) { |
293 | mailmime_parameter_free( param ); | 306 | mailmime_parameter_free( param ); |
294 | } | 307 | } |
295 | if (content) { | 308 | if (content) { |
296 | mailmime_content_free( content ); | 309 | mailmime_content_free( content ); |
297 | } | 310 | } |
298 | if (fields) { | 311 | if (fields) { |
299 | mailmime_fields_free( fields ); | 312 | mailmime_fields_free( fields ); |
@@ -305,97 +318,97 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety | |||
305 | free( file ); | 318 | free( file ); |
306 | } | 319 | } |
307 | } | 320 | } |
308 | } | 321 | } |
309 | return filePart; // Success :) | 322 | return filePart; // Success :) |
310 | 323 | ||
311 | } | 324 | } |
312 | 325 | ||
313 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) | 326 | void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) |
314 | { | 327 | { |
315 | const Attachment *it; | 328 | const Attachment *it; |
316 | unsigned int count = files.count(); | 329 | unsigned int count = files.count(); |
317 | qDebug("List contains %i values",count); | 330 | qDebug("List contains %i values",count); |
318 | for ( unsigned int i = 0; i < count; ++i ) { | 331 | for ( unsigned int i = 0; i < count; ++i ) { |
319 | qDebug( "Adding file" ); | 332 | qDebug( "Adding file" ); |
320 | mailmime *filePart; | 333 | mailmime *filePart; |
321 | int err; | 334 | int err; |
322 | it = ((QList<Attachment>)files).at(i); | 335 | it = ((QList<Attachment>)files).at(i); |
323 | 336 | ||
324 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); | 337 | filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); |
325 | if ( filePart == NULL ) { | 338 | if ( filePart == NULL ) { |
326 | qDebug( "addFileParts: error adding file:" ); | 339 | qDebug( "addFileParts: error adding file:" ); |
327 | qDebug( it->getFileName() ); | 340 | qDebug( it->getFileName() ); |
328 | continue; | 341 | continue; |
329 | } | 342 | } |
330 | err = mailmime_smart_add_part( message, filePart ); | 343 | err = mailmime_smart_add_part( message, filePart ); |
331 | if ( err != MAILIMF_NO_ERROR ) { | 344 | if ( err != MAILIMF_NO_ERROR ) { |
332 | mailmime_free( filePart ); | 345 | mailmime_free( filePart ); |
333 | qDebug("error smart add"); | 346 | qDebug("error smart add"); |
334 | } | 347 | } |
335 | } | 348 | } |
336 | } | 349 | } |
337 | 350 | ||
338 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) | 351 | mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) |
339 | { | 352 | { |
340 | mailmime *message, *txtPart; | 353 | mailmime *message, *txtPart; |
341 | mailimf_fields *fields; | 354 | mailimf_fields *fields; |
342 | int err; | 355 | int err; |
343 | 356 | ||
344 | fields = createImfFields( mail ); | 357 | fields = createImfFields( mail ); |
345 | if ( fields == NULL ) goto err_free; | 358 | if ( fields == NULL ) goto err_free; |
346 | 359 | ||
347 | message = mailmime_new_message_data( NULL ); | 360 | message = mailmime_new_message_data( NULL ); |
348 | if ( message == NULL ) goto err_free_fields; | 361 | if ( message == NULL ) goto err_free_fields; |
349 | 362 | ||
350 | mailmime_set_imf_fields( message, fields ); | 363 | mailmime_set_imf_fields( message, fields ); |
351 | 364 | ||
352 | txtPart = buildTxtPart( mail.getMessage() ); | 365 | txtPart = buildTxtPart( mail.getMessage() ); |
353 | 366 | ||
354 | if ( txtPart == NULL ) goto err_free_message; | 367 | if ( txtPart == NULL ) goto err_free_message; |
355 | 368 | ||
356 | err = mailmime_smart_add_part( message, txtPart ); | 369 | err = mailmime_smart_add_part( message, txtPart ); |
357 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; | 370 | if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; |
358 | 371 | ||
359 | addFileParts( message, mail.getAttachments() ); | 372 | addFileParts( message, mail.getAttachments() ); |
360 | 373 | ||
361 | return message; // Success :) | 374 | return message; // Success :) |
362 | 375 | ||
363 | err_free_txtPart: | 376 | err_free_txtPart: |
364 | mailmime_free( txtPart ); | 377 | mailmime_free( txtPart ); |
365 | err_free_message: | 378 | err_free_message: |
366 | mailmime_free( message ); | 379 | mailmime_free( message ); |
367 | err_free_fields: | 380 | err_free_fields: |
368 | mailimf_fields_free( fields ); | 381 | mailimf_fields_free( fields ); |
369 | err_free: | 382 | err_free: |
370 | qDebug( "createMimeMail: error" ); | 383 | qDebug( "createMimeMail: error" ); |
371 | 384 | ||
372 | return NULL; // Error :( | 385 | return NULL; // Error :( |
373 | } | 386 | } |
374 | 387 | ||
375 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) | 388 | mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) |
376 | { | 389 | { |
377 | mailimf_field *field; | 390 | mailimf_field *field; |
378 | clistiter *it; | 391 | clistiter *it; |
379 | 392 | ||
380 | it = clist_begin( fields->fld_list ); | 393 | it = clist_begin( fields->fld_list ); |
381 | while ( it ) { | 394 | while ( it ) { |
382 | field = (mailimf_field *) it->data; | 395 | field = (mailimf_field *) it->data; |
383 | if ( field->fld_type == type ) { | 396 | if ( field->fld_type == type ) { |
384 | return field; | 397 | return field; |
385 | } | 398 | } |
386 | it = it->next; | 399 | it = it->next; |
387 | } | 400 | } |
388 | 401 | ||
389 | return NULL; | 402 | return NULL; |
390 | } | 403 | } |
391 | 404 | ||
392 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) | 405 | void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) |
393 | { | 406 | { |
394 | clistiter *it, *it2; | 407 | clistiter *it, *it2; |
395 | 408 | ||
396 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { | 409 | for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { |
397 | mailimf_address *addr; | 410 | mailimf_address *addr; |
398 | addr = (mailimf_address *) it->data; | 411 | addr = (mailimf_address *) it->data; |
399 | 412 | ||
400 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { | 413 | if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { |
401 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); | 414 | esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); |
@@ -444,114 +457,118 @@ char *SMTPwrapper::getFrom( mailimf_field *ffrom) | |||
444 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) | 457 | if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) |
445 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { | 458 | && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { |
446 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; | 459 | clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; |
447 | clistiter *it; | 460 | clistiter *it; |
448 | for ( it = clist_begin( cl ); it; it = it->next ) { | 461 | for ( it = clist_begin( cl ); it; it = it->next ) { |
449 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; | 462 | mailimf_mailbox *mb = (mailimf_mailbox *) it->data; |
450 | from = strdup( mb->mb_addr_spec ); | 463 | from = strdup( mb->mb_addr_spec ); |
451 | } | 464 | } |
452 | } | 465 | } |
453 | 466 | ||
454 | return from; | 467 | return from; |
455 | } | 468 | } |
456 | 469 | ||
457 | char *SMTPwrapper::getFrom( mailmime *mail ) | 470 | char *SMTPwrapper::getFrom( mailmime *mail ) |
458 | { | 471 | { |
459 | /* no need to delete - its just a pointer to structure content */ | 472 | /* no need to delete - its just a pointer to structure content */ |
460 | mailimf_field *ffrom = 0; | 473 | mailimf_field *ffrom = 0; |
461 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); | 474 | ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); |
462 | return getFrom(ffrom); | 475 | return getFrom(ffrom); |
463 | } | 476 | } |
464 | 477 | ||
465 | void SMTPwrapper::progress( size_t current, size_t maximum ) | 478 | void SMTPwrapper::progress( size_t current, size_t maximum ) |
466 | { | 479 | { |
467 | if (SMTPwrapper::sendProgress) { | 480 | if (SMTPwrapper::sendProgress) { |
468 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 481 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
469 | qApp->processEvents(); | 482 | qApp->processEvents(); |
470 | } | 483 | } |
471 | } | 484 | } |
472 | 485 | ||
473 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) | 486 | void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) |
474 | { | 487 | { |
475 | if (!mail) return; | 488 | if (!mail) return; |
476 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 489 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
477 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 490 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
478 | wrap->storeMessage(mail,length,box); | 491 | wrap->storeMessage(mail,length,box); |
479 | delete wrap; | 492 | delete wrap; |
480 | } | 493 | } |
481 | 494 | ||
482 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) | 495 | void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) |
483 | { | 496 | { |
484 | clist *rcpts = 0; | 497 | clist *rcpts = 0; |
485 | char *from, *data; | 498 | char *from, *data; |
486 | size_t size; | 499 | size_t size; |
487 | 500 | ||
488 | if ( smtp == NULL ) { | 501 | if ( smtp == NULL ) { |
489 | return; | 502 | return; |
490 | } | 503 | } |
491 | from = data = 0; | 504 | from = data = 0; |
492 | 505 | ||
493 | mailmessage * msg = 0; | 506 | mailmessage * msg = 0; |
494 | msg = mime_message_init(mail); | 507 | msg = mime_message_init(mail); |
495 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 508 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
496 | int r = mailmessage_fetch(msg,&data,&size); | 509 | int r = mailmessage_fetch(msg,&data,&size); |
497 | mime_message_detach_mime(msg); | 510 | mime_message_detach_mime(msg); |
498 | mailmessage_free(msg); | 511 | mailmessage_free(msg); |
499 | if (r != MAIL_NO_ERROR || !data) { | 512 | if (r != MAIL_NO_ERROR || !data) { |
500 | if (data) free(data); | 513 | if (data) free(data); |
501 | qDebug("Error fetching mime..."); | 514 | qDebug("Error fetching mime..."); |
502 | return; | 515 | return; |
503 | } | 516 | } |
504 | QString tmp = data; | 517 | QString tmp = data; |
505 | tmp.replace(QRegExp("\r+",true,false),""); | 518 | tmp.replace(QRegExp("\r+",true,false),""); |
506 | msg = 0; | 519 | msg = 0; |
507 | if (later) { | 520 | if (later) { |
508 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); | 521 | storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); |
509 | if (data) free( data ); | 522 | if (data) free( data ); |
523 | Config cfg( "mail" ); | ||
524 | cfg.setGroup( "Status" ); | ||
525 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | ||
526 | emit queuedMails( m_queuedMail ); | ||
510 | return; | 527 | return; |
511 | } | 528 | } |
512 | from = getFrom( mail ); | 529 | from = getFrom( mail ); |
513 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 530 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
514 | smtpSend(from,rcpts,data,size,smtp); | 531 | smtpSend(from,rcpts,data,size,smtp); |
515 | if (data) {free(data);} | 532 | if (data) {free(data);} |
516 | if (from) {free(from);} | 533 | if (from) {free(from);} |
517 | if (rcpts) smtp_address_list_free( rcpts ); | 534 | if (rcpts) smtp_address_list_free( rcpts ); |
518 | } | 535 | } |
519 | 536 | ||
520 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) | 537 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) |
521 | { | 538 | { |
522 | char *server, *user, *pass; | 539 | char *server, *user, *pass; |
523 | bool ssl; | 540 | bool ssl; |
524 | uint16_t port; | 541 | uint16_t port; |
525 | mailsmtp *session; | 542 | mailsmtp *session; |
526 | int err,result; | 543 | int err,result; |
527 | 544 | ||
528 | result = 1; | 545 | result = 1; |
529 | server = user = pass = 0; | 546 | server = user = pass = 0; |
530 | server = strdup( smtp->getServer().latin1() ); | 547 | server = strdup( smtp->getServer().latin1() ); |
531 | ssl = smtp->getSSL(); | 548 | ssl = smtp->getSSL(); |
532 | port = smtp->getPort().toUInt(); | 549 | port = smtp->getPort().toUInt(); |
533 | 550 | ||
534 | session = mailsmtp_new( 20, &progress ); | 551 | session = mailsmtp_new( 20, &progress ); |
535 | if ( session == NULL ) goto free_mem; | 552 | if ( session == NULL ) goto free_mem; |
536 | 553 | ||
537 | qDebug( "Servername %s at port %i", server, port ); | 554 | qDebug( "Servername %s at port %i", server, port ); |
538 | if ( ssl ) { | 555 | if ( ssl ) { |
539 | qDebug( "SSL session" ); | 556 | qDebug( "SSL session" ); |
540 | err = mailsmtp_ssl_connect( session, server, port ); | 557 | err = mailsmtp_ssl_connect( session, server, port ); |
541 | } else { | 558 | } else { |
542 | qDebug( "No SSL session" ); | 559 | qDebug( "No SSL session" ); |
543 | err = mailsmtp_socket_connect( session, server, port ); | 560 | err = mailsmtp_socket_connect( session, server, port ); |
544 | } | 561 | } |
545 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} | 562 | if ( err != MAILSMTP_NO_ERROR ) {result = 0;goto free_mem_session;} |
546 | 563 | ||
547 | err = mailsmtp_init( session ); | 564 | err = mailsmtp_init( session ); |
548 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} | 565 | if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} |
549 | 566 | ||
550 | qDebug( "INIT OK" ); | 567 | qDebug( "INIT OK" ); |
551 | 568 | ||
552 | if ( smtp->getLogin() ) { | 569 | if ( smtp->getLogin() ) { |
553 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 570 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
554 | // get'em | 571 | // get'em |
555 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 572 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
556 | login.show(); | 573 | login.show(); |
557 | if ( QDialog::Accepted == login.exec() ) { | 574 | if ( QDialog::Accepted == login.exec() ) { |
@@ -608,103 +625,108 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) | |||
608 | qDebug( "sendMail: error creating mime mail" ); | 625 | qDebug( "sendMail: error creating mime mail" ); |
609 | } else { | 626 | } else { |
610 | sendProgress = new progressMailSend(); | 627 | sendProgress = new progressMailSend(); |
611 | sendProgress->show(); | 628 | sendProgress->show(); |
612 | sendProgress->setMaxMails(1); | 629 | sendProgress->setMaxMails(1); |
613 | smtpSend( mimeMail,later,smtp); | 630 | smtpSend( mimeMail,later,smtp); |
614 | qDebug("Clean up done"); | 631 | qDebug("Clean up done"); |
615 | sendProgress->hide(); | 632 | sendProgress->hide(); |
616 | delete sendProgress; | 633 | delete sendProgress; |
617 | sendProgress = 0; | 634 | sendProgress = 0; |
618 | mailmime_free( mimeMail ); | 635 | mailmime_free( mimeMail ); |
619 | } | 636 | } |
620 | } | 637 | } |
621 | 638 | ||
622 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) | 639 | int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) |
623 | { | 640 | { |
624 | char*data = 0; | 641 | char*data = 0; |
625 | size_t length = 0; | 642 | size_t length = 0; |
626 | size_t curTok = 0; | 643 | size_t curTok = 0; |
627 | mailimf_fields *fields = 0; | 644 | mailimf_fields *fields = 0; |
628 | mailimf_field*ffrom = 0; | 645 | mailimf_field*ffrom = 0; |
629 | clist *rcpts = 0; | 646 | clist *rcpts = 0; |
630 | char*from = 0; | 647 | char*from = 0; |
631 | int res = 0; | 648 | int res = 0; |
632 | 649 | ||
633 | wrap->fetchRawBody(*which,&data,&length); | 650 | wrap->fetchRawBody(*which,&data,&length); |
634 | if (!data) return 0; | 651 | if (!data) return 0; |
635 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); | 652 | int err = mailimf_fields_parse( data, length, &curTok, &fields ); |
636 | if (err != MAILIMF_NO_ERROR) { | 653 | if (err != MAILIMF_NO_ERROR) { |
637 | free(data); | 654 | free(data); |
638 | delete wrap; | 655 | delete wrap; |
639 | return 0; | 656 | return 0; |
640 | } | 657 | } |
641 | 658 | ||
642 | rcpts = createRcptList( fields ); | 659 | rcpts = createRcptList( fields ); |
643 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 660 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
644 | from = getFrom(ffrom); | 661 | from = getFrom(ffrom); |
645 | 662 | ||
646 | qDebug("Size: %i vs. %i",length,strlen(data)); | 663 | qDebug("Size: %i vs. %i",length,strlen(data)); |
647 | if (rcpts && from) { | 664 | if (rcpts && from) { |
648 | res = smtpSend(from,rcpts,data,length,smtp ); | 665 | res = smtpSend(from,rcpts,data,length,smtp ); |
649 | } | 666 | } |
650 | if (fields) { | 667 | if (fields) { |
651 | mailimf_fields_free(fields); | 668 | mailimf_fields_free(fields); |
652 | fields = 0; | 669 | fields = 0; |
653 | } | 670 | } |
654 | if (data) { | 671 | if (data) { |
655 | free(data); | 672 | free(data); |
656 | } | 673 | } |
657 | if (from) { | 674 | if (from) { |
658 | free(from); | 675 | free(from); |
659 | } | 676 | } |
660 | if (rcpts) { | 677 | if (rcpts) { |
661 | smtp_address_list_free( rcpts ); | 678 | smtp_address_list_free( rcpts ); |
662 | } | 679 | } |
663 | return res; | 680 | return res; |
664 | } | 681 | } |
665 | 682 | ||
666 | /* this is a special fun */ | 683 | /* this is a special fun */ |
667 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) | 684 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) |
668 | { | 685 | { |
669 | bool returnValue = true; | 686 | bool returnValue = true; |
670 | 687 | ||
671 | if (!smtp) return false; | 688 | if (!smtp) return false; |
672 | 689 | ||
673 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); | 690 | QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); |
674 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); | 691 | MBOXwrapper*wrap = new MBOXwrapper(localfolders); |
675 | if (!wrap) { | 692 | if (!wrap) { |
676 | qDebug("memory error"); | 693 | qDebug("memory error"); |
677 | return false; | 694 | return false; |
678 | } | 695 | } |
679 | QList<RecMail> mailsToSend; | 696 | QList<RecMail> mailsToSend; |
680 | QList<RecMail> mailsToRemove; | 697 | QList<RecMail> mailsToRemove; |
681 | QString mbox("Outgoing"); | 698 | QString mbox("Outgoing"); |
682 | wrap->listMessages(mbox,mailsToSend); | 699 | wrap->listMessages(mbox,mailsToSend); |
683 | if (mailsToSend.count()==0) { | 700 | if (mailsToSend.count()==0) { |
684 | delete wrap; | 701 | delete wrap; |
685 | return false; | 702 | return false; |
686 | } | 703 | } |
687 | mailsToSend.setAutoDelete(false); | 704 | mailsToSend.setAutoDelete(false); |
688 | sendProgress = new progressMailSend(); | 705 | sendProgress = new progressMailSend(); |
689 | sendProgress->show(); | 706 | sendProgress->show(); |
690 | sendProgress->setMaxMails(mailsToSend.count()); | 707 | sendProgress->setMaxMails(mailsToSend.count()); |
691 | 708 | ||
692 | while (mailsToSend.count()>0) { | 709 | while (mailsToSend.count()>0) { |
693 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 710 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
694 | QMessageBox::critical(0,tr("Error sending mail"), | 711 | QMessageBox::critical(0,tr("Error sending mail"), |
695 | tr("Error sending queued mail - breaking")); | 712 | tr("Error sending queued mail - breaking")); |
696 | returnValue = false; | 713 | returnValue = false; |
697 | break; | 714 | break; |
698 | } | 715 | } |
699 | mailsToRemove.append(mailsToSend.at(0)); | 716 | mailsToRemove.append(mailsToSend.at(0)); |
700 | mailsToSend.removeFirst(); | 717 | mailsToSend.removeFirst(); |
701 | sendProgress->setCurrentMails(mailsToRemove.count()); | 718 | sendProgress->setCurrentMails(mailsToRemove.count()); |
702 | } | 719 | } |
720 | Config cfg( "mail" ); | ||
721 | cfg.setGroup( "Status" ); | ||
722 | m_queuedMail = 0; | ||
723 | cfg.writeEntry( "outgoing", m_queuedMail ); | ||
724 | emit queuedMails( m_queuedMail ); | ||
703 | sendProgress->hide(); | 725 | sendProgress->hide(); |
704 | delete sendProgress; | 726 | delete sendProgress; |
705 | sendProgress = 0; | 727 | sendProgress = 0; |
706 | wrap->deleteMails(mbox,mailsToRemove); | 728 | wrap->deleteMails(mbox,mailsToRemove); |
707 | mailsToSend.setAutoDelete(true); | 729 | mailsToSend.setAutoDelete(true); |
708 | delete wrap; | 730 | delete wrap; |
709 | return returnValue; | 731 | return returnValue; |
710 | } | 732 | } |
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index 0535983..05becf2 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h | |||
@@ -1,61 +1,71 @@ | |||
1 | #ifndef SMTPwrapper_H | 1 | #ifndef SMTPwrapper_H |
2 | #define SMTPwrapper_H | 2 | #define SMTPwrapper_H |
3 | 3 | ||
4 | #include <qpe/applnk.h> | 4 | #include <qpe/applnk.h> |
5 | 5 | ||
6 | #include <qbitarray.h> | 6 | #include <qbitarray.h> |
7 | #include <qdatetime.h> | 7 | #include <qdatetime.h> |
8 | #include <libetpan/clist.h> | 8 | #include <libetpan/clist.h> |
9 | 9 | ||
10 | #include "settings.h" | 10 | #include "settings.h" |
11 | 11 | ||
12 | class Mail; | 12 | class Mail; |
13 | class MBOXwrapper; | 13 | class MBOXwrapper; |
14 | class RecMail; | 14 | class RecMail; |
15 | class Attachment; | 15 | class Attachment; |
16 | struct mailimf_fields; | 16 | struct mailimf_fields; |
17 | struct mailimf_field; | 17 | struct mailimf_field; |
18 | struct mailimf_mailbox; | 18 | struct mailimf_mailbox; |
19 | struct mailmime; | 19 | struct mailmime; |
20 | struct mailimf_address_list; | 20 | struct mailimf_address_list; |
21 | class progressMailSend; | 21 | class progressMailSend; |
22 | 22 | ||
23 | class SMTPwrapper : public QObject | 23 | class SMTPwrapper : public QObject |
24 | { | 24 | { |
25 | Q_OBJECT | 25 | Q_OBJECT |
26 | 26 | ||
27 | public: | 27 | public: |
28 | SMTPwrapper( Settings *s ); | 28 | SMTPwrapper( Settings *s ); |
29 | virtual ~SMTPwrapper(){} | 29 | virtual ~SMTPwrapper(){} |
30 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); | 30 | void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); |
31 | bool flushOutbox(SMTPaccount*smtp); | 31 | bool flushOutbox(SMTPaccount*smtp); |
32 | 32 | ||
33 | static progressMailSend*sendProgress; | 33 | static progressMailSend*sendProgress; |
34 | |||
35 | signals: | ||
36 | void queuedMails( int ); | ||
37 | |||
34 | protected: | 38 | protected: |
35 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); | 39 | mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); |
36 | mailimf_fields *createImfFields(const Mail &mail ); | 40 | mailimf_fields *createImfFields(const Mail &mail ); |
37 | mailmime *createMimeMail(const Mail&mail ); | 41 | mailmime *createMimeMail(const Mail&mail ); |
38 | 42 | ||
39 | mailimf_address_list *parseAddresses(const QString&addr ); | 43 | mailimf_address_list *parseAddresses(const QString&addr ); |
40 | void addFileParts( mailmime *message,const QList<Attachment>&files ); | 44 | void addFileParts( mailmime *message,const QList<Attachment>&files ); |
41 | mailmime *buildTxtPart(const QString&str ); | 45 | mailmime *buildTxtPart(const QString&str ); |
42 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); | 46 | mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); |
43 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); | 47 | void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); |
44 | clist *createRcptList( mailimf_fields *fields ); | 48 | clist *createRcptList( mailimf_fields *fields ); |
45 | 49 | ||
46 | static void storeMail(char*mail, size_t length, const QString&box); | 50 | static void storeMail(char*mail, size_t length, const QString&box); |
47 | static QString mailsmtpError( int err ); | 51 | static QString mailsmtpError( int err ); |
48 | static void progress( size_t current, size_t maximum ); | 52 | static void progress( size_t current, size_t maximum ); |
49 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); | 53 | static void addRcpts( clist *list, mailimf_address_list *addr_list ); |
50 | static char *getFrom( mailmime *mail ); | 54 | static char *getFrom( mailmime *mail ); |
51 | static char *getFrom( mailimf_field *ffrom); | 55 | static char *getFrom( mailimf_field *ffrom); |
52 | static mailimf_field *getField( mailimf_fields *fields, int type ); | 56 | static mailimf_field *getField( mailimf_fields *fields, int type ); |
53 | int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); | 57 | int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); |
54 | 58 | ||
55 | void storeMail(mailmime*mail, const QString&box); | 59 | void storeMail(mailmime*mail, const QString&box); |
56 | Settings *settings; | 60 | Settings *settings; |
57 | 61 | ||
58 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); | 62 | int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); |
63 | |||
64 | int m_queuedMail; | ||
65 | |||
66 | protected slots: | ||
67 | void emitQCop( int queued ); | ||
68 | |||
59 | }; | 69 | }; |
60 | 70 | ||
61 | #endif | 71 | #endif |