author | alwin <alwin> | 2003-12-20 13:36:34 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-20 13:36:34 (UTC) |
commit | adb369c28cac7600b3912d6a3fdb645f1b1d571d (patch) (unidiff) | |
tree | 554fc2f00a3ea97aad6ef0382e4cc1aec3def070 /noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |
parent | d9ffcee06ec97f4a9e00ff0a9071d7a58e5075a1 (diff) | |
download | opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.zip opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.tar.gz opie-adb369c28cac7600b3912d6a3fdb645f1b1d571d.tar.bz2 |
fetching attachments from a pop3mail works.
this moment the whole message will be hold in memory until
I have an idea for a clean(!) filebased cache which will not get to
large.
Thats why the biggest pop3 mail we can fetch is 5MB, this should be
enough.
Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 65cd4ba..d3447f4 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -13,21 +13,34 @@ | |||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::POP3wrapper( POP3account *a ) |
14 | { | 14 | { |
15 | account = a; | 15 | account = a; |
16 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
17 | msgTempName = a->getFileName()+"_msg_cache"; | 17 | msgTempName = a->getFileName()+"_msg_cache"; |
18 | last_msg_id = 0; | 18 | last_msg_id = 0; |
19 | bodyCache.clear(); | ||
19 | } | 20 | } |
20 | 21 | ||
21 | POP3wrapper::~POP3wrapper() | 22 | POP3wrapper::~POP3wrapper() |
22 | { | 23 | { |
23 | logout(); | 24 | logout(); |
24 | QFile msg_cache(msgTempName); | 25 | QFile msg_cache(msgTempName); |
25 | if (msg_cache.exists()) { | 26 | if (msg_cache.exists()) { |
26 | msg_cache.remove(); | 27 | msg_cache.remove(); |
27 | } | 28 | } |
29 | cleanUpCache(); | ||
30 | } | ||
31 | |||
32 | void POP3wrapper::cleanUpCache() | ||
33 | { | ||
34 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | ||
35 | for (;it!=bodyCache.end();++it) { | ||
36 | encodedString*t = it.data(); | ||
37 | //it.setValue(0); | ||
38 | if (t) delete t; | ||
39 | } | ||
40 | bodyCache.clear(); | ||
28 | } | 41 | } |
29 | 42 | ||
30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 43 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) |
31 | { | 44 | { |
32 | //qDebug( "POP3: %i of %i", current, maximum ); | 45 | //qDebug( "POP3: %i of %i", current, maximum ); |
33 | } | 46 | } |
@@ -48,12 +61,13 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
48 | QFile msg_cache(msgTempName); | 61 | QFile msg_cache(msgTempName); |
49 | 62 | ||
50 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { | 63 | if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { |
51 | qDebug("Message to large: %i",mail.Msgsize()); | 64 | qDebug("Message to large: %i",mail.Msgsize()); |
52 | return body; | 65 | return body; |
53 | } | 66 | } |
67 | cleanUpCache(); | ||
54 | if (mail.getNumber()!=last_msg_id) { | 68 | if (mail.getNumber()!=last_msg_id) { |
55 | if (msg_cache.exists()) { | 69 | if (msg_cache.exists()) { |
56 | msg_cache.remove(); | 70 | msg_cache.remove(); |
57 | } | 71 | } |
58 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 72 | msg_cache.open(IO_ReadWrite|IO_Truncate); |
59 | last_msg_id = mail.getNumber(); | 73 | last_msg_id = mail.getNumber(); |
@@ -402,15 +416,18 @@ QList<Folder>* POP3wrapper::listFolders() | |||
402 | folders->setAutoDelete( false ); | 416 | folders->setAutoDelete( false ); |
403 | Folder*inb=new Folder("INBOX","/"); | 417 | Folder*inb=new Folder("INBOX","/"); |
404 | folders->append(inb); | 418 | folders->append(inb); |
405 | return folders; | 419 | return folders; |
406 | } | 420 | } |
407 | 421 | ||
408 | QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) | 422 | QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
409 | { | 423 | { |
410 | return ""; | 424 | encodedString*t = fetchDecodedPart(mail,part); |
425 | QString text=t->Content(); | ||
426 | delete t; | ||
427 | return text; | ||
411 | } | 428 | } |
412 | 429 | ||
413 | void POP3wrapper::deleteMail(const RecMail&mail) | 430 | void POP3wrapper::deleteMail(const RecMail&mail) |
414 | { | 431 | { |
415 | login(); | 432 | login(); |
416 | if (!m_pop3) return; | 433 | if (!m_pop3) return; |
@@ -421,20 +438,26 @@ void POP3wrapper::deleteMail(const RecMail&mail) | |||
421 | } | 438 | } |
422 | 439 | ||
423 | void POP3wrapper::answeredMail(const RecMail&) | 440 | void POP3wrapper::answeredMail(const RecMail&) |
424 | { | 441 | { |
425 | } | 442 | } |
426 | 443 | ||
427 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) | 444 | encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) |
428 | { | 445 | { |
429 | return new encodedString(); | 446 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
447 | if (it==bodyCache.end()) return new encodedString(); | ||
448 | encodedString*t = decode_String(it.data(),part.Encoding()); | ||
449 | return t; | ||
430 | } | 450 | } |
431 | 451 | ||
432 | encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | 452 | encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
433 | { | 453 | { |
434 | return new encodedString(); | 454 | QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); |
455 | if (it==bodyCache.end()) return new encodedString(); | ||
456 | encodedString*t = it.data(); | ||
457 | return t; | ||
435 | } | 458 | } |
436 | 459 | ||
437 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | 460 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) |
438 | { | 461 | { |
439 | if (current_rec >= 10) { | 462 | if (current_rec >= 10) { |
440 | qDebug("too deep recursion!"); | 463 | qDebug("too deep recursion!"); |
@@ -462,14 +485,15 @@ void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime, | |||
462 | b = QString(res->Content()); | 485 | b = QString(res->Content()); |
463 | delete r; | 486 | delete r; |
464 | delete res; | 487 | delete res; |
465 | target.setBodytext(b); | 488 | target.setBodytext(b); |
466 | target.setDescription(part); | 489 | target.setDescription(part); |
467 | } else { | 490 | } else { |
468 | /* TODO: Add the content to a list and store it for later use */ | 491 | b = gen_attachment_id(); |
469 | if (data) free(data); | 492 | part.setIdentifier(b); |
493 | bodyCache[b]=new encodedString(data,len); | ||
470 | target.addPart(part); | 494 | target.addPart(part); |
471 | } | 495 | } |
472 | break; | 496 | break; |
473 | case MAILMIME_MULTIPLE: | 497 | case MAILMIME_MULTIPLE: |
474 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 498 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
475 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | 499 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); |