-rw-r--r-- | noncore/net/mail/libmailwrapper/generatemail.cpp | 143 |
1 files changed, 78 insertions, 65 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp index 9272d0c..48fa02e 100644 --- a/noncore/net/mail/libmailwrapper/generatemail.cpp +++ b/noncore/net/mail/libmailwrapper/generatemail.cpp | |||
@@ -270,59 +270,68 @@ err_free_param: | |||
270 | mailmime_parameter_free( param ); | 270 | mailmime_parameter_free( param ); |
271 | err_free: | 271 | err_free: |
272 | qDebug( "buildTxtPart - error" ); | 272 | qDebug( "buildTxtPart - error" ); |
273 | 273 | ||
274 | return NULL; // Error :( | 274 | return NULL; // Error :( |
275 | } | 275 | } |
276 | 276 | ||
277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { | 277 | mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { |
278 | return mailimf_mailbox_new( strdup( name.latin1() ), | 278 | return mailimf_mailbox_new( strdup( name.latin1() ), |
279 | strdup( mail.latin1() ) ); | 279 | strdup( mail.latin1() ) ); |
280 | } | 280 | } |
281 | 281 | ||
282 | mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { | 282 | mailimf_fields *Generatemail::createImfFields(const Mail&mail ) |
283 | mailimf_fields *fields; | 283 | { |
284 | mailimf_field *xmailer; | 284 | mailimf_fields *fields = NULL; |
285 | mailimf_field *xmailer = NULL; | ||
285 | mailimf_mailbox *sender=0,*fromBox=0; | 286 | mailimf_mailbox *sender=0,*fromBox=0; |
286 | mailimf_mailbox_list *from=0; | 287 | mailimf_mailbox_list *from=0; |
287 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; | 288 | mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; |
288 | clist*in_reply_to = 0; | 289 | clist*in_reply_to = 0; |
289 | char *subject = strdup( mail.getSubject().latin1() ); | 290 | char *subject = strdup( mail.getSubject().latin1() ); |
290 | int err; | 291 | int err; |
292 | int res = 1; | ||
291 | 293 | ||
292 | sender = newMailbox( mail.getName(), mail.getMail() ); | 294 | sender = newMailbox( mail.getName(), mail.getMail() ); |
293 | if ( sender == NULL ) | 295 | if ( sender == NULL ) { |
294 | goto err_free; | 296 | res = 0; |
295 | 297 | } | |
296 | fromBox = newMailbox( mail.getName(), mail.getMail() ); | ||
297 | if ( fromBox == NULL ) | ||
298 | goto err_free_sender; | ||
299 | 298 | ||
300 | from = mailimf_mailbox_list_new_empty(); | 299 | if (res) { |
301 | if ( from == NULL ) | 300 | fromBox = newMailbox( mail.getName(), mail.getMail() ); |
302 | goto err_free_fromBox; | 301 | } |
302 | if ( fromBox == NULL ) { | ||
303 | res = 0; | ||
304 | } | ||
303 | 305 | ||
304 | err = mailimf_mailbox_list_add( from, fromBox ); | 306 | if (res) { |
305 | if ( err != MAILIMF_NO_ERROR ) | 307 | from = mailimf_mailbox_list_new_empty(); |
306 | goto err_free_from; | 308 | } |
309 | if ( from == NULL ) { | ||
310 | res = 0; | ||
311 | } | ||
307 | 312 | ||
308 | to = parseAddresses( mail.getTo() ); | 313 | if (res && from) { |
309 | if ( to == NULL ) | 314 | err = mailimf_mailbox_list_add( from, fromBox ); |
310 | goto err_free_from; | 315 | if ( err != MAILIMF_NO_ERROR ) { |
316 | res = 0; | ||
317 | } | ||
318 | } | ||
311 | 319 | ||
312 | cc = parseAddresses( mail.getCC() ); | 320 | if (res) to = parseAddresses( mail.getTo() ); |
313 | bcc = parseAddresses( mail.getBCC() ); | 321 | if (res) cc = parseAddresses( mail.getCC() ); |
314 | reply = parseAddresses( mail.getReply() ); | 322 | if (res) bcc = parseAddresses( mail.getBCC() ); |
323 | if (res) reply = parseAddresses( mail.getReply() ); | ||
315 | 324 | ||
316 | if (mail.Inreply().count()>0) { | 325 | if (res && mail.Inreply().count()>0) { |
317 | in_reply_to = clist_new(); | 326 | in_reply_to = clist_new(); |
318 | char*c_reply; | 327 | char*c_reply; |
319 | unsigned int nsize = 0; | 328 | unsigned int nsize = 0; |
320 | for (QStringList::ConstIterator it=mail.Inreply().begin(); | 329 | for (QStringList::ConstIterator it=mail.Inreply().begin(); |
321 | it != mail.Inreply().end();++it) { | 330 | it != mail.Inreply().end();++it) { |
322 | if ((*it).isEmpty()) | 331 | if ((*it).isEmpty()) |
323 | continue; | 332 | continue; |
324 | QString h((*it)); | 333 | QString h((*it)); |
325 | while (h.length()>0 && h[0]=='<') { | 334 | while (h.length()>0 && h[0]=='<') { |
326 | h.remove(0,1); | 335 | h.remove(0,1); |
327 | } | 336 | } |
328 | while (h.length()>0 && h[h.length()-1]=='>') { | 337 | while (h.length()>0 && h[h.length()-1]=='>') { |
@@ -330,69 +339,73 @@ mailimf_fields *Generatemail::createImfFields(const Mail&mail ) { | |||
330 | } | 339 | } |
331 | if (h.isEmpty()) continue; | 340 | if (h.isEmpty()) continue; |
332 | nsize = strlen(h.latin1()); | 341 | nsize = strlen(h.latin1()); |
333 | /* yes! must be malloc! */ | 342 | /* yes! must be malloc! */ |
334 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); | 343 | c_reply = (char*)malloc( (nsize+1)*sizeof(char)); |
335 | memset(c_reply,0,nsize+1); | 344 | memset(c_reply,0,nsize+1); |
336 | memcpy(c_reply,h.latin1(),nsize); | 345 | memcpy(c_reply,h.latin1(),nsize); |
337 | clist_append(in_reply_to,c_reply); | 346 | clist_append(in_reply_to,c_reply); |
338 | qDebug("In reply to: %s",c_reply); | 347 | qDebug("In reply to: %s",c_reply); |
339 | } | 348 | } |
340 | } | 349 | } |
341 | 350 | ||
342 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | 351 | if (res) { |
352 | fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, | ||
343 | in_reply_to, NULL, subject ); | 353 | in_reply_to, NULL, subject ); |
344 | if ( fields == NULL ) | 354 | if ( fields == NULL ) { |
345 | goto err_free_reply; | 355 | qDebug("Error creating mailimf fields"); |
346 | 356 | res = 0; | |
347 | xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | 357 | } |
358 | } | ||
359 | if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), | ||
348 | strdup( USER_AGENT ) ); | 360 | strdup( USER_AGENT ) ); |
349 | if ( xmailer == NULL ) | 361 | if ( xmailer == NULL ) { |
350 | goto err_free_fields; | 362 | res = 0; |
351 | 363 | } else { | |
352 | err = mailimf_fields_add( fields, xmailer ); | 364 | err = mailimf_fields_add( fields, xmailer ); |
353 | if ( err != MAILIMF_NO_ERROR ) | 365 | if ( err != MAILIMF_NO_ERROR ) { |
354 | goto err_free_xmailer; | 366 | res = 0; |
355 | 367 | } | |
356 | return fields; // Success :) | 368 | } |
357 | 369 | if (!res ) { | |
358 | err_free_xmailer: | 370 | if (xmailer) { |
359 | if (xmailer) | 371 | mailimf_field_free( xmailer ); |
360 | mailimf_field_free( xmailer ); | 372 | xmailer = NULL; |
361 | err_free_fields: | 373 | } |
362 | if (fields) | 374 | if (fields) { |
363 | mailimf_fields_free( fields ); | 375 | mailimf_fields_free( fields ); |
364 | err_free_reply: | 376 | fields = NULL; |
365 | if (reply) | 377 | } else { |
366 | mailimf_address_list_free( reply ); | 378 | if (reply) |
367 | if (bcc) | 379 | mailimf_address_list_free( reply ); |
368 | mailimf_address_list_free( bcc ); | 380 | if (bcc) |
369 | if (cc) | 381 | mailimf_address_list_free( bcc ); |
370 | mailimf_address_list_free( cc ); | 382 | if (cc) |
371 | if (to) | 383 | mailimf_address_list_free( cc ); |
372 | mailimf_address_list_free( to ); | 384 | if (to) |
373 | err_free_from: | 385 | mailimf_address_list_free( to ); |
374 | if (from) | 386 | if (fromBox) { |
375 | mailimf_mailbox_list_free( from ); | 387 | mailimf_mailbox_free( fromBox ); |
376 | err_free_fromBox: | 388 | } else if (from) { |
377 | mailimf_mailbox_free( fromBox ); | 389 | mailimf_mailbox_list_free( from ); |
378 | err_free_sender: | 390 | } |
379 | if (sender) | 391 | if (sender) { |
380 | mailimf_mailbox_free( sender ); | 392 | mailimf_mailbox_free( sender ); |
381 | err_free: | 393 | } |
382 | if (subject) | 394 | if (subject) { |
383 | free( subject ); | 395 | free( subject ); |
384 | qDebug( "createImfFields - error" ); | 396 | } |
385 | 397 | } | |
386 | return NULL; // Error :( | 398 | } |
399 | return fields; | ||
387 | } | 400 | } |
388 | 401 | ||
389 | mailmime *Generatemail::createMimeMail(const Mail &mail ) { | 402 | mailmime *Generatemail::createMimeMail(const Mail &mail ) { |
390 | mailmime *message, *txtPart; | 403 | mailmime *message, *txtPart; |
391 | mailimf_fields *fields; | 404 | mailimf_fields *fields; |
392 | int err; | 405 | int err; |
393 | 406 | ||
394 | fields = createImfFields( mail ); | 407 | fields = createImfFields( mail ); |
395 | if ( fields == NULL ) | 408 | if ( fields == NULL ) |
396 | goto err_free; | 409 | goto err_free; |
397 | 410 | ||
398 | message = mailmime_new_message_data( NULL ); | 411 | message = mailmime_new_message_data( NULL ); |