-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index 714396b..2d1596d 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp | |||
@@ -235,269 +235,270 @@ RecMail *Genericwrapper::parseHeader( const char *header ) | |||
235 | int err = MAILIMF_NO_ERROR; | 235 | int err = MAILIMF_NO_ERROR; |
236 | size_t curTok = 0; | 236 | size_t curTok = 0; |
237 | RecMail *mail = new RecMail(); | 237 | RecMail *mail = new RecMail(); |
238 | mailimf_fields *fields = 0; | 238 | mailimf_fields *fields = 0; |
239 | mailimf_references * refs = 0; | 239 | mailimf_references * refs = 0; |
240 | mailimf_keywords*keys = 0; | 240 | mailimf_keywords*keys = 0; |
241 | QString status; | 241 | QString status; |
242 | QString value; | 242 | QString value; |
243 | QBitArray mFlags(7); | 243 | QBitArray mFlags(7); |
244 | 244 | ||
245 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); | 245 | err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); |
246 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { | 246 | for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { |
247 | mailimf_field *field = (mailimf_field *) current->data; | 247 | mailimf_field *field = (mailimf_field *) current->data; |
248 | switch ( field->fld_type ) { | 248 | switch ( field->fld_type ) { |
249 | case MAILIMF_FIELD_FROM: | 249 | case MAILIMF_FIELD_FROM: |
250 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); | 250 | mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); |
251 | break; | 251 | break; |
252 | case MAILIMF_FIELD_TO: | 252 | case MAILIMF_FIELD_TO: |
253 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); | 253 | mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); |
254 | break; | 254 | break; |
255 | case MAILIMF_FIELD_CC: | 255 | case MAILIMF_FIELD_CC: |
256 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); | 256 | mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); |
257 | break; | 257 | break; |
258 | case MAILIMF_FIELD_BCC: | 258 | case MAILIMF_FIELD_BCC: |
259 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); | 259 | mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); |
260 | break; | 260 | break; |
261 | case MAILIMF_FIELD_SUBJECT: | 261 | case MAILIMF_FIELD_SUBJECT: |
262 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); | 262 | mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); |
263 | break; | 263 | break; |
264 | case MAILIMF_FIELD_ORIG_DATE: | 264 | case MAILIMF_FIELD_ORIG_DATE: |
265 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); | 265 | mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); |
266 | break; | 266 | break; |
267 | case MAILIMF_FIELD_MESSAGE_ID: | 267 | case MAILIMF_FIELD_MESSAGE_ID: |
268 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); | 268 | mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); |
269 | break; | 269 | break; |
270 | case MAILIMF_FIELD_REFERENCES: | 270 | case MAILIMF_FIELD_REFERENCES: |
271 | refs = field->fld_data.fld_references; | 271 | refs = field->fld_data.fld_references; |
272 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 272 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
273 | char * text = (char*)refs->mid_list->first->data; | 273 | char * text = (char*)refs->mid_list->first->data; |
274 | mail->setReplyto(QString(text)); | 274 | mail->setReplyto(QString(text)); |
275 | } | 275 | } |
276 | break; | 276 | break; |
277 | case MAILIMF_FIELD_KEYWORDS: | 277 | case MAILIMF_FIELD_KEYWORDS: |
278 | keys = field->fld_data.fld_keywords; | 278 | keys = field->fld_data.fld_keywords; |
279 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { | 279 | for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { |
280 | qDebug("Keyword: %s",(char*)cur->data); | 280 | qDebug("Keyword: %s",(char*)cur->data); |
281 | } | 281 | } |
282 | break; | 282 | break; |
283 | case MAILIMF_FIELD_OPTIONAL_FIELD: | 283 | case MAILIMF_FIELD_OPTIONAL_FIELD: |
284 | status = field->fld_data.fld_optional_field->fld_name; | 284 | status = field->fld_data.fld_optional_field->fld_name; |
285 | value = field->fld_data.fld_optional_field->fld_value; | 285 | value = field->fld_data.fld_optional_field->fld_value; |
286 | if (status.lower()=="status") { | 286 | if (status.lower()=="status") { |
287 | if (value.lower()=="ro") { | 287 | if (value.lower()=="ro") { |
288 | mFlags.setBit(FLAG_SEEN); | 288 | mFlags.setBit(FLAG_SEEN); |
289 | } | 289 | } |
290 | } else if (status.lower()=="x-status") { | 290 | } else if (status.lower()=="x-status") { |
291 | qDebug("X-Status: %s",value.latin1()); | 291 | qDebug("X-Status: %s",value.latin1()); |
292 | if (value.lower()=="a") { | 292 | if (value.lower()=="a") { |
293 | mFlags.setBit(FLAG_ANSWERED); | 293 | mFlags.setBit(FLAG_ANSWERED); |
294 | } | 294 | } |
295 | } else { | 295 | } else { |
296 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, | 296 | // qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, |
297 | // field->fld_data.fld_optional_field->fld_value); | 297 | // field->fld_data.fld_optional_field->fld_value); |
298 | } | 298 | } |
299 | break; | 299 | break; |
300 | default: | 300 | default: |
301 | qDebug("Non parsed field"); | 301 | qDebug("Non parsed field"); |
302 | break; | 302 | break; |
303 | } | 303 | } |
304 | } | 304 | } |
305 | if (fields) mailimf_fields_free(fields); | 305 | if (fields) mailimf_fields_free(fields); |
306 | mail->setFlags(mFlags); | 306 | mail->setFlags(mFlags); |
307 | return mail; | 307 | return mail; |
308 | } | 308 | } |
309 | 309 | ||
310 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) | 310 | QString Genericwrapper::parseDateTime( mailimf_date_time *date ) |
311 | { | 311 | { |
312 | char tmp[23]; | 312 | char tmp[23]; |
313 | 313 | ||
314 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", | 314 | snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", |
315 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); | 315 | date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); |
316 | 316 | ||
317 | return QString( tmp ); | 317 | return QString( tmp ); |
318 | } | 318 | } |
319 | 319 | ||
320 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 320 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
321 | { | 321 | { |
322 | QString result( "" ); | 322 | QString result( "" ); |
323 | 323 | ||
324 | bool first = true; | 324 | bool first = true; |
325 | if (list == 0) return result; | 325 | if (list == 0) return result; |
326 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 326 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
327 | mailimf_address *addr = (mailimf_address *) current->data; | 327 | mailimf_address *addr = (mailimf_address *) current->data; |
328 | 328 | ||
329 | if ( !first ) { | 329 | if ( !first ) { |
330 | result.append( "," ); | 330 | result.append( "," ); |
331 | } else { | 331 | } else { |
332 | first = false; | 332 | first = false; |
333 | } | 333 | } |
334 | 334 | ||
335 | switch ( addr->ad_type ) { | 335 | switch ( addr->ad_type ) { |
336 | case MAILIMF_ADDRESS_MAILBOX: | 336 | case MAILIMF_ADDRESS_MAILBOX: |
337 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 337 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
338 | break; | 338 | break; |
339 | case MAILIMF_ADDRESS_GROUP: | 339 | case MAILIMF_ADDRESS_GROUP: |
340 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 340 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
341 | break; | 341 | break; |
342 | default: | 342 | default: |
343 | qDebug( "Generic: unkown mailimf address type" ); | 343 | qDebug( "Generic: unkown mailimf address type" ); |
344 | break; | 344 | break; |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | return result; | 348 | return result; |
349 | } | 349 | } |
350 | 350 | ||
351 | QString Genericwrapper::parseGroup( mailimf_group *group ) | 351 | QString Genericwrapper::parseGroup( mailimf_group *group ) |
352 | { | 352 | { |
353 | QString result( "" ); | 353 | QString result( "" ); |
354 | 354 | ||
355 | result.append( group->grp_display_name ); | 355 | result.append( group->grp_display_name ); |
356 | result.append( ": " ); | 356 | result.append( ": " ); |
357 | 357 | ||
358 | if ( group->grp_mb_list != NULL ) { | 358 | if ( group->grp_mb_list != NULL ) { |
359 | result.append( parseMailboxList( group->grp_mb_list ) ); | 359 | result.append( parseMailboxList( group->grp_mb_list ) ); |
360 | } | 360 | } |
361 | 361 | ||
362 | result.append( ";" ); | 362 | result.append( ";" ); |
363 | 363 | ||
364 | return result; | 364 | return result; |
365 | } | 365 | } |
366 | 366 | ||
367 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) | 367 | QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) |
368 | { | 368 | { |
369 | QString result( "" ); | 369 | QString result( "" ); |
370 | 370 | ||
371 | if ( box->mb_display_name == NULL ) { | 371 | if ( box->mb_display_name == NULL ) { |
372 | result.append( box->mb_addr_spec ); | 372 | result.append( box->mb_addr_spec ); |
373 | } else { | 373 | } else { |
374 | result.append( convert_String(box->mb_display_name).latin1() ); | 374 | result.append( convert_String(box->mb_display_name).latin1() ); |
375 | result.append( " <" ); | 375 | result.append( " <" ); |
376 | result.append( box->mb_addr_spec ); | 376 | result.append( box->mb_addr_spec ); |
377 | result.append( ">" ); | 377 | result.append( ">" ); |
378 | } | 378 | } |
379 | 379 | ||
380 | return result; | 380 | return result; |
381 | } | 381 | } |
382 | 382 | ||
383 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) | 383 | QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) |
384 | { | 384 | { |
385 | QString result( "" ); | 385 | QString result( "" ); |
386 | 386 | ||
387 | bool first = true; | 387 | bool first = true; |
388 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { | 388 | for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { |
389 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; | 389 | mailimf_mailbox *box = (mailimf_mailbox *) current->data; |
390 | 390 | ||
391 | if ( !first ) { | 391 | if ( !first ) { |
392 | result.append( "," ); | 392 | result.append( "," ); |
393 | } else { | 393 | } else { |
394 | first = false; | 394 | first = false; |
395 | } | 395 | } |
396 | 396 | ||
397 | result.append( parseMailbox( box ) ); | 397 | result.append( parseMailbox( box ) ); |
398 | } | 398 | } |
399 | 399 | ||
400 | return result; | 400 | return result; |
401 | } | 401 | } |
402 | 402 | ||
403 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) | 403 | encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
404 | { | 404 | { |
405 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 405 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
406 | if (it==bodyCache.end()) return new encodedString(); | 406 | if (it==bodyCache.end()) return new encodedString(); |
407 | encodedString*t = decode_String(it.data(),part.Encoding()); | 407 | encodedString*t = decode_String(it.data(),part.Encoding()); |
408 | return t; | 408 | return t; |
409 | } | 409 | } |
410 | 410 | ||
411 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 411 | encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
412 | { | 412 | { |
413 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); | 413 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
414 | if (it==bodyCache.end()) return new encodedString(); | 414 | if (it==bodyCache.end()) return new encodedString(); |
415 | encodedString*t = it.data(); | 415 | encodedString*t = it.data(); |
416 | return t; | 416 | return t; |
417 | } | 417 | } |
418 | 418 | ||
419 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 419 | QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
420 | { | 420 | { |
421 | encodedString*t = fetchDecodedPart(mail,part); | 421 | encodedString*t = fetchDecodedPart(mail,part); |
422 | QString text=t->Content(); | 422 | QString text=t->Content(); |
423 | delete t; | 423 | delete t; |
424 | return text; | 424 | return text; |
425 | } | 425 | } |
426 | 426 | ||
427 | void Genericwrapper::cleanMimeCache() | 427 | void Genericwrapper::cleanMimeCache() |
428 | { | 428 | { |
429 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 429 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
430 | for (;it!=bodyCache.end();++it) { | 430 | for (;it!=bodyCache.end();++it) { |
431 | encodedString*t = it.data(); | 431 | encodedString*t = it.data(); |
432 | //it.setValue(0); | 432 | //it.setValue(0); |
433 | if (t) delete t; | 433 | if (t) delete t; |
434 | } | 434 | } |
435 | bodyCache.clear(); | 435 | bodyCache.clear(); |
436 | qDebug("Genericwrapper: cache cleaned"); | 436 | qDebug("Genericwrapper: cache cleaned"); |
437 | } | 437 | } |
438 | 438 | ||
439 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) | 439 | void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) |
440 | { | 440 | { |
441 | int r; | 441 | int r; |
442 | mailmessage_list * env_list = 0; | 442 | mailmessage_list * env_list = 0; |
443 | r = mailsession_get_messages_list(session,&env_list); | 443 | r = mailsession_get_messages_list(session,&env_list); |
444 | if (r != MAIL_NO_ERROR) { | 444 | if (r != MAIL_NO_ERROR) { |
445 | qDebug("Error message list"); | 445 | qDebug("Error message list"); |
446 | return; | 446 | return; |
447 | } | 447 | } |
448 | r = mailsession_get_envelopes_list(session, env_list); | 448 | r = mailsession_get_envelopes_list(session, env_list); |
449 | if (r != MAIL_NO_ERROR) { | 449 | if (r != MAIL_NO_ERROR) { |
450 | qDebug("Error filling message list"); | 450 | qDebug("Error filling message list"); |
451 | if (env_list) { | 451 | if (env_list) { |
452 | mailmessage_list_free(env_list); | 452 | mailmessage_list_free(env_list); |
453 | } | 453 | } |
454 | return; | 454 | return; |
455 | } | 455 | } |
456 | mailimf_references * refs; | 456 | mailimf_references * refs; |
457 | uint32_t i = 0; | 457 | uint32_t i = 0; |
458 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 458 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
459 | mailmessage * msg; | 459 | mailmessage * msg; |
460 | QBitArray mFlags(7); | 460 | QBitArray mFlags(7); |
461 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 461 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
462 | if (msg->msg_fields == NULL) { | 462 | if (msg->msg_fields == NULL) { |
463 | qDebug("could not fetch envelope of message %i", i); | 463 | qDebug("could not fetch envelope of message %i", i); |
464 | continue; | 464 | continue; |
465 | } | 465 | } |
466 | RecMail * mail = new RecMail(); | 466 | RecMail * mail = new RecMail(); |
467 | mail->setWrapper(this); | 467 | mail->setWrapper(this); |
468 | mail_flags * flag_result = 0; | 468 | mail_flags * flag_result = 0; |
469 | r = mailmessage_get_flags(msg,&flag_result); | 469 | r = mailmessage_get_flags(msg,&flag_result); |
470 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 470 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |
471 | mFlags.setBit(FLAG_SEEN); | 471 | mFlags.setBit(FLAG_SEEN); |
472 | } | 472 | } |
473 | mailimf_single_fields single_fields; | 473 | mailimf_single_fields single_fields; |
474 | mailimf_single_fields_init(&single_fields, msg->msg_fields); | 474 | mailimf_single_fields_init(&single_fields, msg->msg_fields); |
475 | mail->setMsgsize(msg->msg_size); | 475 | mail->setMsgsize(msg->msg_size); |
476 | mail->setFlags(mFlags); | 476 | mail->setFlags(mFlags); |
477 | mail->setMbox(mailbox); | 477 | mail->setMbox(mailbox); |
478 | mail->setNumber(msg->msg_index); | 478 | mail->setNumber(msg->msg_index); |
479 | if (single_fields.fld_subject) | 479 | if (single_fields.fld_subject) |
480 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); | 480 | mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); |
481 | if (single_fields.fld_from) | 481 | if (single_fields.fld_from) |
482 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); | 482 | mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); |
483 | if (single_fields.fld_to) | 483 | if (single_fields.fld_to) |
484 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); | 484 | mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); |
485 | if (single_fields.fld_cc) | 485 | if (single_fields.fld_cc) |
486 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); | 486 | mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); |
487 | if (single_fields.fld_bcc) | 487 | if (single_fields.fld_bcc) |
488 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); | 488 | mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); |
489 | if (single_fields.fld_orig_date) | 489 | if (single_fields.fld_orig_date) |
490 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); | 490 | mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); |
491 | if (single_fields.fld_message_id->mid_value) | 491 | // crashes when accessing pop3 account |
492 | mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | 492 | // if (single_fields.fld_message_id->mid_value) |
493 | // mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); | ||
493 | refs = single_fields.fld_references; | 494 | refs = single_fields.fld_references; |
494 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { | 495 | if (refs && refs->mid_list && clist_count(refs->mid_list)) { |
495 | char * text = (char*)refs->mid_list->first->data; | 496 | char * text = (char*)refs->mid_list->first->data; |
496 | mail->setReplyto(QString(text)); | 497 | mail->setReplyto(QString(text)); |
497 | } | 498 | } |
498 | target.append(mail); | 499 | target.append(mail); |
499 | } | 500 | } |
500 | if (env_list) { | 501 | if (env_list) { |
501 | mailmessage_list_free(env_list); | 502 | mailmessage_list_free(env_list); |
502 | } | 503 | } |
503 | } | 504 | } |