Diffstat (limited to 'noncore/net/mail/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 170 |
1 files changed, 72 insertions, 98 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 725dcc9..5ce140e 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -208,33 +208,30 @@ QList<IMAPFolder>* IMAPwrapper::listFolders() | |||
208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 208 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
209 | { | 209 | { |
210 | RecMail * m = 0; | 210 | RecMail * m = 0; |
211 | mailimap_msg_att_item *item=0; | 211 | mailimap_msg_att_item *item=0; |
212 | bool named_from = false; | 212 | bool named_from = false; |
213 | QString from,date,subject; | 213 | QString from,date,subject; |
214 | date = from = subject = ""; | 214 | date = from = subject = ""; |
215 | clistcell *current,*c,*cf, *current_from = NULL; | 215 | clistcell *current,*c,*cf, *current_from = NULL; |
216 | mailimap_address * current_address = NULL; | 216 | mailimap_address * current_address = NULL; |
217 | mailimap_msg_att_dynamic*flist; | 217 | mailimap_msg_att_dynamic*flist; |
218 | mailimap_flag_fetch*cflag; | 218 | mailimap_flag_fetch*cflag; |
219 | QBitArray mFlags(7); | 219 | QBitArray mFlags(7); |
220 | QStringList addresslist; | ||
220 | 221 | ||
221 | if (!m_att) { | 222 | if (!m_att) { |
222 | return m; | 223 | return m; |
223 | } | 224 | } |
224 | 225 | ||
225 | #if 0 | ||
226 | MAILIMAP_FLAG_KEYWORD, /* keyword flag */ | ||
227 | MAILIMAP_FLAG_EXTENSION, /* \extension flag */ | ||
228 | #endif | ||
229 | c = clist_begin(m_att->list); | 226 | c = clist_begin(m_att->list); |
230 | while ( c ) { | 227 | while ( c ) { |
231 | current = c; | 228 | current = c; |
232 | c = c->next; | 229 | c = c->next; |
233 | item = (mailimap_msg_att_item*)current->data; | 230 | item = (mailimap_msg_att_item*)current->data; |
234 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 231 | if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
235 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; | 232 | flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; |
236 | if (!flist->list) { | 233 | if (!flist->list) { |
237 | continue; | 234 | continue; |
238 | } | 235 | } |
239 | cf = flist->list->first; | 236 | cf = flist->list->first; |
240 | while (cf) { | 237 | while (cf) { |
@@ -267,135 +264,73 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
267 | mFlags.setBit(FLAG_RECENT); | 264 | mFlags.setBit(FLAG_RECENT); |
268 | } | 265 | } |
269 | cf = cf->next; | 266 | cf = cf->next; |
270 | } | 267 | } |
271 | continue; | 268 | continue; |
272 | } | 269 | } |
273 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 270 | if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { |
274 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); | 271 | qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); |
275 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { | 272 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { |
276 | mailimap_envelope * head = item->msg_att_static->env; | 273 | mailimap_envelope * head = item->msg_att_static->env; |
277 | date = head->date; | 274 | date = head->date; |
278 | subject = head->subject; | 275 | subject = head->subject; |
279 | if (head->from!=NULL) | 276 | m = new RecMail(); |
280 | current_from = head->from->list->first; | 277 | if (head->from!=NULL) { |
281 | while (current_from != NULL) { | 278 | addresslist = address_list_to_stringlist(head->from->list); |
282 | from = ""; | 279 | if (addresslist.count()) { |
283 | named_from = false; | 280 | from = addresslist.first(); |
284 | current_address=(mailimap_address*)current_from->data; | ||
285 | current_from = current_from->next; | ||
286 | if (current_address->personal_name){ | ||
287 | from+=QString(current_address->personal_name); | ||
288 | from+=" "; | ||
289 | named_from = true; | ||
290 | } | ||
291 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
292 | from+="<"; | ||
293 | } | ||
294 | if (current_address->mailbox_name) { | ||
295 | from+=QString(current_address->mailbox_name); | ||
296 | from+="@"; | ||
297 | } | ||
298 | if (current_address->host_name) { | ||
299 | from+=QString(current_address->host_name); | ||
300 | } | ||
301 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
302 | from+=">"; | ||
303 | } | 281 | } |
304 | } | 282 | } |
305 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s", | 283 | if (head->to!=NULL) { |
306 | from.latin1(), | 284 | addresslist = address_list_to_stringlist(head->to->list); |
307 | subject.latin1(),date.latin1()); | 285 | m->setTo(addresslist); |
308 | m = new RecMail(); | 286 | } |
287 | if (head->cc!=NULL) { | ||
288 | addresslist = address_list_to_stringlist(head->cc->list); | ||
289 | m->setCC(addresslist); | ||
290 | } | ||
291 | if (head->bcc!=NULL) { | ||
292 | addresslist = address_list_to_stringlist(head->bcc->list); | ||
293 | m->setBcc(addresslist); | ||
294 | } | ||
309 | m->setSubject(subject); | 295 | m->setSubject(subject); |
310 | m->setFrom(from); | 296 | m->setFrom(from); |
311 | m->setDate(date); | 297 | m->setDate(date); |
298 | m->setMsgid(QString(head->message_id)); | ||
299 | qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", | ||
300 | from.latin1(), | ||
301 | subject.latin1(),date.latin1(),m->Msgid().latin1()); | ||
312 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 302 | } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
313 | mailimap_date_time*d = item->msg_att_static->internal_date; | 303 | mailimap_date_time*d = item->msg_att_static->internal_date; |
314 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); | 304 | QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); |
315 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); | 305 | qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec); |
316 | qDebug(da.toString()); | 306 | qDebug(da.toString()); |
317 | } else { | 307 | } else { |
318 | qDebug("Another type"); | 308 | qDebug("Another type"); |
319 | } | 309 | } |
320 | } | 310 | } |
321 | /* msg is already deleted */ | 311 | /* msg is already deleted */ |
322 | if (mFlags.testBit(FLAG_DELETED) && m) { | 312 | if (mFlags.testBit(FLAG_DELETED) && m) { |
323 | delete m; | 313 | delete m; |
324 | m = 0; | 314 | m = 0; |
325 | } | 315 | } |
326 | if (m) { | 316 | if (m) { |
327 | m->setFlags(mFlags); | 317 | m->setFlags(mFlags); |
328 | } | 318 | } |
329 | return m; | 319 | return m; |
330 | } | 320 | } |
331 | 321 | ||
332 | #if 1 | ||
333 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 322 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
334 | { | 323 | { |
335 | RecBody body; | 324 | RecBody body; |
336 | QString body_text; | ||
337 | |||
338 | const char *mb; | ||
339 | int err = MAILIMAP_NO_ERROR; | ||
340 | clist *result; | ||
341 | clistcell *current; | ||
342 | mailimap_fetch_att *fetchAtt; | ||
343 | mailimap_fetch_type *fetchType; | ||
344 | mailimap_set *set; | ||
345 | |||
346 | mb = mail.getMbox().latin1(); | ||
347 | |||
348 | login(); | ||
349 | if (!m_imap) { | ||
350 | return body; | ||
351 | } | ||
352 | /* select mailbox READONLY for operations */ | ||
353 | err = mailimap_examine( m_imap, (char*)mb); | ||
354 | if ( err != MAILIMAP_NO_ERROR ) { | ||
355 | qDebug("error selecting mailbox: %s",m_imap->response); | ||
356 | logout(); | ||
357 | return body; | ||
358 | } | ||
359 | result = clist_new(); | ||
360 | /* the range has to start at 1!!! not with 0!!!! */ | ||
361 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | ||
362 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | ||
363 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
364 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | ||
365 | mailimap_set_free( set ); | ||
366 | mailimap_fetch_type_free( fetchType ); | ||
367 | |||
368 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | ||
369 | mailimap_msg_att * msg_att; | ||
370 | msg_att = (mailimap_msg_att*)current->data; | ||
371 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | ||
372 | |||
373 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | ||
374 | body_text = item->msg_att_static->rfc822_text; | ||
375 | body.setBodytext(body_text); | ||
376 | } | ||
377 | } else { | ||
378 | qDebug("error fetching text: %s",m_imap->response); | ||
379 | } | ||
380 | |||
381 | clist_free(result); | ||
382 | logout(); | ||
383 | return body; | ||
384 | } | ||
385 | |||
386 | #else | ||
387 | QString IMAPwrapper::fetchBody(const RecMail&mail) | ||
388 | { | ||
389 | QString body = ""; | ||
390 | const char *mb; | 325 | const char *mb; |
391 | int err = MAILIMAP_NO_ERROR; | 326 | int err = MAILIMAP_NO_ERROR; |
392 | clist *result; | 327 | clist *result; |
393 | clistcell *current; | 328 | clistcell *current; |
394 | mailimap_fetch_att *fetchAtt; | 329 | mailimap_fetch_att *fetchAtt; |
395 | mailimap_fetch_type *fetchType; | 330 | mailimap_fetch_type *fetchType; |
396 | mailimap_set *set; | 331 | mailimap_set *set; |
397 | mailimap_body*body_desc; | 332 | mailimap_body*body_desc; |
398 | 333 | ||
399 | mb = mail.getMbox().latin1(); | 334 | mb = mail.getMbox().latin1(); |
400 | 335 | ||
401 | login(); | 336 | login(); |
@@ -415,80 +350,119 @@ QString IMAPwrapper::fetchBody(const RecMail&mail) | |||
415 | fetchAtt = mailimap_fetch_att_new_body(); | 350 | fetchAtt = mailimap_fetch_att_new_body(); |
416 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 351 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
417 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 352 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
418 | mailimap_set_free( set ); | 353 | mailimap_set_free( set ); |
419 | mailimap_fetch_type_free( fetchType ); | 354 | mailimap_fetch_type_free( fetchType ); |
420 | 355 | ||
421 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 356 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
422 | mailimap_msg_att * msg_att; | 357 | mailimap_msg_att * msg_att; |
423 | msg_att = (mailimap_msg_att*)current->data; | 358 | msg_att = (mailimap_msg_att*)current->data; |
424 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 359 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
425 | body_desc = item->msg_att_static->body; | 360 | body_desc = item->msg_att_static->body; |
426 | if (body_desc->type==MAILIMAP_BODY_1PART) { | 361 | if (body_desc->type==MAILIMAP_BODY_1PART) { |
427 | body = searchBodyText(mail,body_desc->body_1part); | 362 | searchBodyText(mail,body_desc->body_1part,body); |
428 | } else { | 363 | } else { |
429 | } | 364 | } |
430 | 365 | ||
431 | } else { | 366 | } else { |
432 | qDebug("error fetching body: %s",m_imap->response); | 367 | qDebug("error fetching body: %s",m_imap->response); |
433 | } | 368 | } |
434 | 369 | ||
435 | clist_free(result); | 370 | clist_free(result); |
436 | logout(); | 371 | logout(); |
437 | return body; | 372 | return body; |
438 | } | 373 | } |
439 | #endif | ||
440 | 374 | ||
441 | QString IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription) | 375 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
442 | { | 376 | { |
443 | QString Body=""; | ||
444 | if (!mailDescription) { | 377 | if (!mailDescription) { |
445 | return Body; | 378 | return; |
446 | } | 379 | } |
447 | switch (mailDescription->type) { | 380 | switch (mailDescription->type) { |
448 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 381 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
449 | return getPlainBody(mail); | 382 | fillPlainBody(mail,target_body,mailDescription->body_type_text); |
450 | break; | 383 | break; |
451 | default: | 384 | default: |
452 | break; | 385 | break; |
453 | } | 386 | } |
454 | return Body; | 387 | return; |
455 | } | 388 | } |
456 | 389 | ||
457 | QString IMAPwrapper::getPlainBody(const RecMail&mail) | 390 | void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) |
458 | { | 391 | { |
459 | QString body = ""; | ||
460 | const char *mb; | 392 | const char *mb; |
393 | QString body=""; | ||
461 | int err = MAILIMAP_NO_ERROR; | 394 | int err = MAILIMAP_NO_ERROR; |
462 | clist *result; | 395 | clist *result; |
463 | clistcell *current; | 396 | clistcell *current; |
464 | mailimap_fetch_att *fetchAtt; | 397 | mailimap_fetch_att *fetchAtt; |
465 | mailimap_fetch_type *fetchType; | 398 | mailimap_fetch_type *fetchType; |
466 | mailimap_set *set; | 399 | mailimap_set *set; |
467 | 400 | ||
468 | mb = mail.getMbox().latin1(); | 401 | mb = mail.getMbox().latin1(); |
469 | 402 | ||
470 | if (!m_imap) { | 403 | if (!m_imap) { |
471 | return body; | 404 | return; |
472 | } | 405 | } |
406 | |||
473 | result = clist_new(); | 407 | result = clist_new(); |
474 | /* the range has to start at 1!!! not with 0!!!! */ | 408 | /* the range has to start at 1!!! not with 0!!!! */ |
475 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 409 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
476 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); | 410 | fetchAtt = mailimap_fetch_att_new_rfc822_text(); |
477 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 411 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
478 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 412 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
479 | mailimap_set_free( set ); | 413 | mailimap_set_free( set ); |
480 | mailimap_fetch_type_free( fetchType ); | 414 | mailimap_fetch_type_free( fetchType ); |
481 | 415 | ||
482 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 416 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
483 | mailimap_msg_att * msg_att; | 417 | mailimap_msg_att * msg_att; |
484 | msg_att = (mailimap_msg_att*)current->data; | 418 | msg_att = (mailimap_msg_att*)current->data; |
485 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; | 419 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; |
486 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { | 420 | if (item->msg_att_static && item->msg_att_static->rfc822_text) { |
487 | body = item->msg_att_static->rfc822_text; | 421 | body = item->msg_att_static->rfc822_text; |
488 | } | 422 | } |
489 | } else { | 423 | } else { |
490 | qDebug("error fetching text: %s",m_imap->response); | 424 | qDebug("error fetching text: %s",m_imap->response); |
491 | } | 425 | } |
492 | clist_free(result); | 426 | clist_free(result); |
493 | return body; | 427 | target_body.setBodytext(body); |
428 | return; | ||
429 | } | ||
430 | |||
431 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | ||
432 | { | ||
433 | QStringList l; | ||
434 | QString from; | ||
435 | bool named_from; | ||
436 | clistcell *current = NULL; | ||
437 | mailimap_address * current_address=NULL; | ||
438 | if (!list) { | ||
439 | return l; | ||
440 | } | ||
441 | current = clist_begin(list); | ||
442 | while (current!= NULL) { | ||
443 | from = ""; | ||
444 | named_from = false; | ||
445 | current_address=(mailimap_address*)current->data; | ||
446 | current = current->next; | ||
447 | if (current_address->personal_name){ | ||
448 | from+=QString(current_address->personal_name); | ||
449 | from+=" "; | ||
450 | named_from = true; | ||
451 | } | ||
452 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
453 | from+="<"; | ||
454 | } | ||
455 | if (current_address->mailbox_name) { | ||
456 | from+=QString(current_address->mailbox_name); | ||
457 | from+="@"; | ||
458 | } | ||
459 | if (current_address->host_name) { | ||
460 | from+=QString(current_address->host_name); | ||
461 | } | ||
462 | if (named_from && (current_address->mailbox_name || current_address->host_name)) { | ||
463 | from+=">"; | ||
464 | } | ||
465 | l.append(QString(from)); | ||
466 | } | ||
467 | return l; | ||
494 | } | 468 | } |