summaryrefslogtreecommitdiff
path: root/noncore/net/mail/imapwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 1acc036..725dcc9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,28 +1,29 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h"
5#include <libetpan/mailimap.h> 6#include <libetpan/mailimap.h>
6 7
7IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 8IMAPwrapper::IMAPwrapper( IMAPaccount *a )
8{ 9{
9 account = a; 10 account = a;
10 m_imap = 0; 11 m_imap = 0;
11} 12}
12 13
13IMAPwrapper::~IMAPwrapper() 14IMAPwrapper::~IMAPwrapper()
14{ 15{
15 logout(); 16 logout();
16} 17}
17 18
18void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 19void IMAPwrapper::imap_progress( size_t current, size_t maximum )
19{ 20{
20 qDebug( "IMAP: %i of %i", current, maximum ); 21 qDebug( "IMAP: %i of %i", current, maximum );
21} 22}
22 23
23void IMAPwrapper::login() 24void IMAPwrapper::login()
24{ 25{
25 logout(); 26 logout();
26 const char *server, *user, *pass; 27 const char *server, *user, *pass;
27 uint16_t port; 28 uint16_t port;
28 int err = MAILIMAP_NO_ERROR; 29 int err = MAILIMAP_NO_ERROR;
@@ -43,49 +44,49 @@ void IMAPwrapper::login()
43 m_imap = 0; 44 m_imap = 0;
44 return; 45 return;
45 } 46 }
46 47
47 /* login */ 48 /* login */
48 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 49 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
49 if ( err != MAILIMAP_NO_ERROR ) { 50 if ( err != MAILIMAP_NO_ERROR ) {
50 qDebug("error logging in imap: %s",m_imap->response); 51 qDebug("error logging in imap: %s",m_imap->response);
51 err = mailimap_close( m_imap ); 52 err = mailimap_close( m_imap );
52 mailimap_free( m_imap ); 53 mailimap_free( m_imap );
53 m_imap = 0; 54 m_imap = 0;
54 } 55 }
55} 56}
56 57
57void IMAPwrapper::logout() 58void IMAPwrapper::logout()
58{ 59{
59 int err = MAILIMAP_NO_ERROR; 60 int err = MAILIMAP_NO_ERROR;
60 if (!m_imap) return; 61 if (!m_imap) return;
61 err = mailimap_logout( m_imap ); 62 err = mailimap_logout( m_imap );
62 err = mailimap_close( m_imap ); 63 err = mailimap_close( m_imap );
63 mailimap_free( m_imap ); 64 mailimap_free( m_imap );
64 m_imap = 0; 65 m_imap = 0;
65} 66}
66 67
67void IMAPwrapper::listMessages(const QString&mailbox,Maillist&target ) 68void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
68{ 69{
69 const char *mb; 70 const char *mb;
70 int err = MAILIMAP_NO_ERROR; 71 int err = MAILIMAP_NO_ERROR;
71 clist *result; 72 clist *result;
72 clistcell *current; 73 clistcell *current;
73 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 74 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
74 mailimap_fetch_type *fetchType; 75 mailimap_fetch_type *fetchType;
75 mailimap_set *set; 76 mailimap_set *set;
76 77
77 mb = mailbox.latin1(); 78 mb = mailbox.latin1();
78 login(); 79 login();
79 if (!m_imap) { 80 if (!m_imap) {
80 return; 81 return;
81 } 82 }
82 /* select mailbox READONLY for operations */ 83 /* select mailbox READONLY for operations */
83 err = mailimap_examine( m_imap, (char*)mb); 84 err = mailimap_examine( m_imap, (char*)mb);
84 if ( err != MAILIMAP_NO_ERROR ) { 85 if ( err != MAILIMAP_NO_ERROR ) {
85 qDebug("error selecting mailbox: %s",m_imap->response); 86 qDebug("error selecting mailbox: %s",m_imap->response);
86 logout(); 87 logout();
87 return; 88 return;
88 } 89 }
89 90
90 int last = m_imap->selection_info->exists; 91 int last = m_imap->selection_info->exists;
91 92
@@ -308,88 +309,91 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
308 m->setSubject(subject); 309 m->setSubject(subject);
309 m->setFrom(from); 310 m->setFrom(from);
310 m->setDate(date); 311 m->setDate(date);
311 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 312 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) {
312 mailimap_date_time*d = item->msg_att_static->internal_date; 313 mailimap_date_time*d = item->msg_att_static->internal_date;
313 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec)); 314 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
314 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,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);
315 qDebug(da.toString()); 316 qDebug(da.toString());
316 } else { 317 } else {
317 qDebug("Another type"); 318 qDebug("Another type");
318 } 319 }
319 } 320 }
320 /* msg is already deleted */ 321 /* msg is already deleted */
321 if (mFlags.testBit(FLAG_DELETED) && m) { 322 if (mFlags.testBit(FLAG_DELETED) && m) {
322 delete m; 323 delete m;
323 m = 0; 324 m = 0;
324 } 325 }
325 if (m) { 326 if (m) {
326 m->setFlags(mFlags); 327 m->setFlags(mFlags);
327 } 328 }
328 return m; 329 return m;
329} 330}
330 331
331#if 1 332#if 1
332QString IMAPwrapper::fetchBody(const RecMail&mail) 333RecBody IMAPwrapper::fetchBody(const RecMail&mail)
333{ 334{
334 QString body = ""; 335 RecBody body;
336 QString body_text;
337
335 const char *mb; 338 const char *mb;
336 int err = MAILIMAP_NO_ERROR; 339 int err = MAILIMAP_NO_ERROR;
337 clist *result; 340 clist *result;
338 clistcell *current; 341 clistcell *current;
339 mailimap_fetch_att *fetchAtt; 342 mailimap_fetch_att *fetchAtt;
340 mailimap_fetch_type *fetchType; 343 mailimap_fetch_type *fetchType;
341 mailimap_set *set; 344 mailimap_set *set;
342 345
343 mb = mail.getMbox().latin1(); 346 mb = mail.getMbox().latin1();
344 347
345 login(); 348 login();
346 if (!m_imap) { 349 if (!m_imap) {
347 return body; 350 return body;
348 } 351 }
349 /* select mailbox READONLY for operations */ 352 /* select mailbox READONLY for operations */
350 err = mailimap_examine( m_imap, (char*)mb); 353 err = mailimap_examine( m_imap, (char*)mb);
351 if ( err != MAILIMAP_NO_ERROR ) { 354 if ( err != MAILIMAP_NO_ERROR ) {
352 qDebug("error selecting mailbox: %s",m_imap->response); 355 qDebug("error selecting mailbox: %s",m_imap->response);
353 logout(); 356 logout();
354 return body; 357 return body;
355 } 358 }
356 result = clist_new(); 359 result = clist_new();
357 /* the range has to start at 1!!! not with 0!!!! */ 360 /* the range has to start at 1!!! not with 0!!!! */
358 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 361 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
359 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 362 fetchAtt = mailimap_fetch_att_new_rfc822_text();
360 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 363 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
361 err = mailimap_fetch( m_imap, set, fetchType, &result ); 364 err = mailimap_fetch( m_imap, set, fetchType, &result );
362 mailimap_set_free( set ); 365 mailimap_set_free( set );
363 mailimap_fetch_type_free( fetchType ); 366 mailimap_fetch_type_free( fetchType );
364 367
365 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 368 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
366 mailimap_msg_att * msg_att; 369 mailimap_msg_att * msg_att;
367 msg_att = (mailimap_msg_att*)current->data; 370 msg_att = (mailimap_msg_att*)current->data;
368 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 371 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data;
369 372
370 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 373 if (item->msg_att_static && item->msg_att_static->rfc822_text) {
371 body = item->msg_att_static->rfc822_text; 374 body_text = item->msg_att_static->rfc822_text;
375 body.setBodytext(body_text);
372 } 376 }
373 } else { 377 } else {
374 qDebug("error fetching text: %s",m_imap->response); 378 qDebug("error fetching text: %s",m_imap->response);
375 } 379 }
376 380
377 clist_free(result); 381 clist_free(result);
378 logout(); 382 logout();
379 return body; 383 return body;
380} 384}
381 385
382#else 386#else
383QString IMAPwrapper::fetchBody(const RecMail&mail) 387QString IMAPwrapper::fetchBody(const RecMail&mail)
384{ 388{
385 QString body = ""; 389 QString body = "";
386 const char *mb; 390 const char *mb;
387 int err = MAILIMAP_NO_ERROR; 391 int err = MAILIMAP_NO_ERROR;
388 clist *result; 392 clist *result;
389 clistcell *current; 393 clistcell *current;
390 mailimap_fetch_att *fetchAtt; 394 mailimap_fetch_att *fetchAtt;
391 mailimap_fetch_type *fetchType; 395 mailimap_fetch_type *fetchType;
392 mailimap_set *set; 396 mailimap_set *set;
393 mailimap_body*body_desc; 397 mailimap_body*body_desc;
394 398
395 mb = mail.getMbox().latin1(); 399 mb = mail.getMbox().latin1();