Diffstat (limited to 'noncore/net/mail/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 214 |
1 files changed, 166 insertions, 48 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index e6e9fc9..27f1410 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -20,26 +20,29 @@ void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | |||
20 | { | 20 | { |
21 | qDebug( "IMAP: %i of %i", current, maximum ); | 21 | qDebug( "IMAP: %i of %i", current, maximum ); |
22 | } | 22 | } |
23 | 23 | ||
24 | void IMAPwrapper::login() | 24 | void IMAPwrapper::login() |
25 | { | 25 | { |
26 | logout(); | ||
27 | const char *server, *user, *pass; | 26 | const char *server, *user, *pass; |
28 | uint16_t port; | 27 | uint16_t port; |
29 | int err = MAILIMAP_NO_ERROR; | 28 | int err = MAILIMAP_NO_ERROR; |
30 | 29 | ||
30 | /* we are connected this moment */ | ||
31 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | ||
32 | if (m_imap) { | ||
33 | return; | ||
34 | } | ||
31 | server = account->getServer().latin1(); | 35 | server = account->getServer().latin1(); |
32 | port = account->getPort().toUInt(); | 36 | port = account->getPort().toUInt(); |
33 | user = account->getUser().latin1(); | 37 | user = account->getUser().latin1(); |
34 | pass = account->getPassword().latin1(); | 38 | pass = account->getPassword().latin1(); |
35 | 39 | ||
36 | m_imap = mailimap_new( 20, &imap_progress ); | 40 | m_imap = mailimap_new( 20, &imap_progress ); |
37 | /* connect */ | 41 | /* connect */ |
38 | // err = mailimap_socket_connect( m_imap, (char*)server, port ); | 42 | if (account->getSSL()) { |
39 | if (account->getSSL()) { | ||
40 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 43 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
41 | } else { | 44 | } else { |
42 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 45 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
43 | } | 46 | } |
44 | 47 | ||
45 | if ( err != MAILIMAP_NO_ERROR && | 48 | if ( err != MAILIMAP_NO_ERROR && |
@@ -74,77 +77,68 @@ void IMAPwrapper::logout() | |||
74 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | 77 | void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) |
75 | { | 78 | { |
76 | const char *mb; | 79 | const char *mb; |
77 | int err = MAILIMAP_NO_ERROR; | 80 | int err = MAILIMAP_NO_ERROR; |
78 | clist *result; | 81 | clist *result; |
79 | clistcell *current; | 82 | clistcell *current; |
80 | mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; | 83 | // mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; |
81 | mailimap_fetch_type *fetchType; | 84 | mailimap_fetch_type *fetchType; |
82 | mailimap_set *set; | 85 | mailimap_set *set; |
83 | 86 | ||
84 | mb = mailbox.latin1(); | 87 | mb = mailbox.latin1(); |
85 | login(); | 88 | login(); |
86 | if (!m_imap) { | 89 | if (!m_imap) { |
87 | return; | 90 | return; |
88 | } | 91 | } |
89 | /* select mailbox READONLY for operations */ | 92 | /* select mailbox READONLY for operations */ |
90 | err = mailimap_examine( m_imap, (char*)mb); | 93 | err = mailimap_examine( m_imap, (char*)mb); |
91 | if ( err != MAILIMAP_NO_ERROR ) { | 94 | if ( err != MAILIMAP_NO_ERROR ) { |
92 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 95 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
93 | logout(); | ||
94 | return; | 96 | return; |
95 | } | 97 | } |
96 | 98 | ||
97 | int last = m_imap->imap_selection_info->sel_exists; | 99 | int last = m_imap->imap_selection_info->sel_exists; |
98 | 100 | ||
99 | if (last == 0) { | 101 | if (last == 0) { |
100 | qDebug("mailbox has no mails"); | 102 | qDebug("mailbox has no mails"); |
101 | logout(); | ||
102 | return; | 103 | return; |
103 | } | 104 | } |
104 | 105 | ||
105 | result = clist_new(); | 106 | result = clist_new(); |
106 | /* the range has to start at 1!!! not with 0!!!! */ | 107 | /* the range has to start at 1!!! not with 0!!!! */ |
107 | set = mailimap_set_new_interval( 1, last ); | 108 | set = mailimap_set_new_interval( 1, last ); |
108 | fetchAtt = mailimap_fetch_att_new_envelope(); | ||
109 | fetchAttFlags = mailimap_fetch_att_new_flags(); | ||
110 | fetchAttDate = mailimap_fetch_att_new_internaldate(); | ||
111 | |||
112 | //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | ||
113 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 109 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
114 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt); | 110 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
115 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags); | 111 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
116 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate); | 112 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
113 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | ||
117 | 114 | ||
118 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 115 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
119 | mailimap_set_free( set ); | 116 | mailimap_set_free( set ); |
120 | /* cleans up the fetch_att's too! */ | ||
121 | mailimap_fetch_type_free( fetchType ); | 117 | mailimap_fetch_type_free( fetchType ); |
122 | 118 | ||
123 | QString date,subject,from; | 119 | QString date,subject,from; |
124 | 120 | ||
125 | if ( err == MAILIMAP_NO_ERROR ) { | 121 | if ( err == MAILIMAP_NO_ERROR ) { |
126 | current = clist_begin(result); | 122 | |
127 | mailimap_msg_att * msg_att; | 123 | mailimap_msg_att * msg_att; |
128 | int i = 0; | 124 | int i = 0; |
129 | while ( current != 0 ) { | 125 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
130 | ++i; | 126 | ++i; |
131 | msg_att = (mailimap_msg_att*)current->data; | 127 | msg_att = (mailimap_msg_att*)current->data; |
132 | RecMail*m = parse_list_result(msg_att); | 128 | RecMail*m = parse_list_result(msg_att); |
133 | if (m) { | 129 | if (m) { |
134 | m->setNumber(i); | 130 | m->setNumber(i); |
135 | m->setMbox(mailbox); | 131 | m->setMbox(mailbox); |
136 | target.append(m); | 132 | target.append(m); |
137 | } | 133 | } |
138 | current = current->next; | ||
139 | } | 134 | } |
140 | } else { | 135 | } else { |
141 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 136 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
142 | } | 137 | } |
143 | logout(); | 138 | mailimap_fetch_list_free(result); |
144 | clist_free(result); | ||
145 | } | 139 | } |
146 | 140 | ||
147 | QList<IMAPFolder>* IMAPwrapper::listFolders() | 141 | QList<IMAPFolder>* IMAPwrapper::listFolders() |
148 | { | 142 | { |
149 | const char *path, *mask; | 143 | const char *path, *mask; |
150 | int err = MAILIMAP_NO_ERROR; | 144 | int err = MAILIMAP_NO_ERROR; |
@@ -216,31 +210,31 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
216 | { | 210 | { |
217 | RecMail * m = 0; | 211 | RecMail * m = 0; |
218 | mailimap_msg_att_item *item=0; | 212 | mailimap_msg_att_item *item=0; |
219 | clistcell *current,*c,*cf; | 213 | clistcell *current,*c,*cf; |
220 | mailimap_msg_att_dynamic*flist; | 214 | mailimap_msg_att_dynamic*flist; |
221 | mailimap_flag_fetch*cflag; | 215 | mailimap_flag_fetch*cflag; |
216 | int size; | ||
222 | QBitArray mFlags(7); | 217 | QBitArray mFlags(7); |
223 | QStringList addresslist; | 218 | QStringList addresslist; |
224 | 219 | ||
225 | if (!m_att) { | 220 | if (!m_att) { |
226 | return m; | 221 | return m; |
227 | } | 222 | } |
228 | 223 | m = new RecMail(); | |
229 | c = clist_begin(m_att->att_list); | 224 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
230 | while ( c ) { | ||
231 | current = c; | 225 | current = c; |
232 | c = c->next; | 226 | size = 0; |
233 | item = (mailimap_msg_att_item*)current->data; | 227 | item = (mailimap_msg_att_item*)current->data; |
234 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 228 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
235 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 229 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
236 | if (!flist->att_list) { | 230 | if (!flist->att_list) { |
237 | continue; | 231 | continue; |
238 | } | 232 | } |
239 | cf = flist->att_list->first; | 233 | cf = flist->att_list->first; |
240 | while (cf) { | 234 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
241 | cflag = (mailimap_flag_fetch*)cf->data; | 235 | cflag = (mailimap_flag_fetch*)cf->data; |
242 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 236 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
243 | switch (cflag->fl_flag->fl_type) { | 237 | switch (cflag->fl_flag->fl_type) { |
244 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 238 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
245 | mFlags.setBit(FLAG_ANSWERED); | 239 | mFlags.setBit(FLAG_ANSWERED); |
246 | break; | 240 | break; |
@@ -263,21 +257,17 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
263 | default: | 257 | default: |
264 | break; | 258 | break; |
265 | } | 259 | } |
266 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 260 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
267 | mFlags.setBit(FLAG_RECENT); | 261 | mFlags.setBit(FLAG_RECENT); |
268 | } | 262 | } |
269 | cf = cf->next; | ||
270 | } | 263 | } |
271 | continue; | 264 | continue; |
272 | } | 265 | } |
273 | if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { | 266 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
274 | qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header ); | ||
275 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | ||
276 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 267 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
277 | m = new RecMail(); | ||
278 | m->setDate(head->env_date); | 268 | m->setDate(head->env_date); |
279 | m->setSubject(head->env_subject); | 269 | m->setSubject(head->env_subject); |
280 | if (head->env_from!=NULL) { | 270 | if (head->env_from!=NULL) { |
281 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 271 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
282 | if (addresslist.count()) { | 272 | if (addresslist.count()) { |
283 | m->setFrom(addresslist.first()); | 273 | m->setFrom(addresslist.first()); |
@@ -304,23 +294,24 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
304 | m->setMsgid(QString(head->env_message_id)); | 294 | m->setMsgid(QString(head->env_message_id)); |
305 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 295 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
306 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 296 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 297 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
308 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); | 298 | qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); |
309 | qDebug(da.toString()); | 299 | qDebug(da.toString()); |
310 | } else { | 300 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
311 | qDebug("Another type"); | 301 | size = item->att_data.att_static->att_data.att_rfc822_size; |
312 | } | 302 | } |
313 | } | 303 | } |
314 | /* msg is already deleted */ | 304 | /* msg is already deleted */ |
315 | if (mFlags.testBit(FLAG_DELETED) && m) { | 305 | if (mFlags.testBit(FLAG_DELETED) && m) { |
316 | delete m; | 306 | delete m; |
317 | m = 0; | 307 | m = 0; |
318 | } | 308 | } |
319 | if (m) { | 309 | if (m) { |
320 | m->setFlags(mFlags); | 310 | m->setFlags(mFlags); |
311 | m->setMsgsize(size); | ||
321 | } | 312 | } |
322 | return m; | 313 | return m; |
323 | } | 314 | } |
324 | 315 | ||
325 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 316 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
326 | { | 317 | { |
@@ -341,59 +332,72 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) | |||
341 | return body; | 332 | return body; |
342 | } | 333 | } |
343 | /* select mailbox READONLY for operations */ | 334 | /* select mailbox READONLY for operations */ |
344 | err = mailimap_examine( m_imap, (char*)mb); | 335 | err = mailimap_examine( m_imap, (char*)mb); |
345 | if ( err != MAILIMAP_NO_ERROR ) { | 336 | if ( err != MAILIMAP_NO_ERROR ) { |
346 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 337 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
347 | logout(); | ||
348 | return body; | 338 | return body; |
349 | } | 339 | } |
340 | |||
350 | result = clist_new(); | 341 | result = clist_new(); |
351 | /* the range has to start at 1!!! not with 0!!!! */ | 342 | /* the range has to start at 1!!! not with 0!!!! */ |
352 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 343 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
353 | fetchAtt = mailimap_fetch_att_new_body(); | 344 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
354 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 345 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
355 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 346 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
356 | mailimap_set_free( set ); | 347 | mailimap_set_free( set ); |
357 | mailimap_fetch_type_free( fetchType ); | 348 | mailimap_fetch_type_free( fetchType ); |
358 | 349 | ||
359 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 350 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
360 | mailimap_msg_att * msg_att; | 351 | mailimap_msg_att * msg_att; |
361 | msg_att = (mailimap_msg_att*)current->data; | 352 | msg_att = (mailimap_msg_att*)current->data; |
362 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 353 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
363 | body_desc = item->att_data.att_static->att_data.att_body; | 354 | body_desc = item->att_data.att_static->att_data.att_body; |
364 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 355 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
365 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 356 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
366 | } else { | 357 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
358 | qDebug("Mulitpart mail"); | ||
359 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0); | ||
367 | } | 360 | } |
368 | |||
369 | } else { | 361 | } else { |
370 | qDebug("error fetching body: %s",m_imap->imap_response); | 362 | qDebug("error fetching body: %s",m_imap->imap_response); |
371 | } | 363 | } |
372 | 364 | mailimap_fetch_list_free(result); | |
373 | clist_free(result); | ||
374 | logout(); | ||
375 | return body; | 365 | return body; |
376 | } | 366 | } |
377 | 367 | ||
368 | /* this routine is just called when the mail has only ONE part. | ||
369 | for filling the parts of a multi-part-message there are other | ||
370 | routines 'cause we can not simply fetch the whole body. */ | ||
378 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 371 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
379 | { | 372 | { |
380 | if (!mailDescription) { | 373 | if (!mailDescription) { |
381 | return; | 374 | return; |
382 | } | 375 | } |
376 | QString sub; | ||
383 | switch (mailDescription->bd_type) { | 377 | switch (mailDescription->bd_type) { |
378 | case MAILIMAP_BODY_TYPE_1PART_MSG: | ||
379 | target_body.setType("text"); | ||
380 | sub = mailDescription->bd_data.bd_type_text->bd_media_text; | ||
381 | target_body.setSubtype(sub.lower()); | ||
382 | fillPlainBody(mail,target_body); | ||
383 | break; | ||
384 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 384 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
385 | fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text); | 385 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
386 | target_body.setType("text"); | ||
387 | sub = mailDescription->bd_data.bd_type_text->bd_media_text; | ||
388 | target_body.setSubtype(sub.lower()); | ||
389 | fillPlainBody(mail,target_body); | ||
386 | break; | 390 | break; |
387 | default: | 391 | default: |
388 | break; | 392 | break; |
389 | } | 393 | } |
390 | return; | 394 | return; |
391 | } | 395 | } |
392 | 396 | ||
393 | void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd) | 397 | void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body) |
394 | { | 398 | { |
395 | const char *mb; | 399 | const char *mb; |
396 | QString body=""; | 400 | QString body=""; |
397 | int err = MAILIMAP_NO_ERROR; | 401 | int err = MAILIMAP_NO_ERROR; |
398 | clist *result; | 402 | clist *result; |
399 | clistcell *current,*cur; | 403 | clistcell *current,*cur; |
@@ -423,24 +427,26 @@ void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap | |||
423 | mailimap_msg_att_item*msg_att_item; | 427 | mailimap_msg_att_item*msg_att_item; |
424 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 428 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
425 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 429 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
426 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 430 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
427 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 431 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
428 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 432 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
429 | int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length; | ||
430 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 433 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
431 | body = QString(text); | 434 | if (text) { |
432 | free(text); | 435 | body = QString(text); |
436 | free(text); | ||
437 | } else { | ||
438 | body = ""; | ||
439 | } | ||
433 | } | 440 | } |
434 | } | 441 | } |
435 | } | 442 | } |
436 | 443 | ||
437 | } else { | 444 | } else { |
438 | qDebug("error fetching text: %s",m_imap->imap_response); | 445 | qDebug("error fetching text: %s",m_imap->imap_response); |
439 | } | 446 | } |
440 | //clist_free(result); | ||
441 | mailimap_fetch_list_free(result); | 447 | mailimap_fetch_list_free(result); |
442 | target_body.setBodytext(body); | 448 | target_body.setBodytext(body); |
443 | return; | 449 | return; |
444 | } | 450 | } |
445 | 451 | ||
446 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 452 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
@@ -450,19 +456,17 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
450 | bool named_from; | 456 | bool named_from; |
451 | clistcell *current = NULL; | 457 | clistcell *current = NULL; |
452 | mailimap_address * current_address=NULL; | 458 | mailimap_address * current_address=NULL; |
453 | if (!list) { | 459 | if (!list) { |
454 | return l; | 460 | return l; |
455 | } | 461 | } |
456 | current = clist_begin(list); | ||
457 | unsigned int count = 0; | 462 | unsigned int count = 0; |
458 | while (current!= NULL) { | 463 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
459 | from = ""; | 464 | from = ""; |
460 | named_from = false; | 465 | named_from = false; |
461 | current_address=(mailimap_address*)current->data; | 466 | current_address=(mailimap_address*)current->data; |
462 | current = current->next; | ||
463 | if (current_address->ad_personal_name){ | 467 | if (current_address->ad_personal_name){ |
464 | from+=QString(current_address->ad_personal_name); | 468 | from+=QString(current_address->ad_personal_name); |
465 | from+=" "; | 469 | from+=" "; |
466 | named_from = true; | 470 | named_from = true; |
467 | } | 471 | } |
468 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 472 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
@@ -482,6 +486,120 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
482 | if (++count > 99) { | 486 | if (++count > 99) { |
483 | break; | 487 | break; |
484 | } | 488 | } |
485 | } | 489 | } |
486 | return l; | 490 | return l; |
487 | } | 491 | } |
492 | |||
493 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion) | ||
494 | { | ||
495 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | ||
496 | if (!mailDescription||current_recursion==2) { | ||
497 | return; | ||
498 | } | ||
499 | qDebug("Mediatype: %s",mailDescription->bd_media_subtype); | ||
500 | clistcell*current; | ||
501 | mailimap_body*current_body; | ||
502 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | ||
503 | current_body = (mailimap_body*)current->data; | ||
504 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | ||
505 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1); | ||
506 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | ||
507 | RecPart currentPart; | ||
508 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | ||
509 | target_body.addPart(currentPart); | ||
510 | } | ||
511 | } | ||
512 | if (current_recursion==0) { | ||
513 | |||
514 | } | ||
515 | } | ||
516 | |||
517 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | ||
518 | { | ||
519 | if (!Description) { | ||
520 | return; | ||
521 | } | ||
522 | switch (Description->bd_type) { | ||
523 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | ||
524 | target_part.setType("text"); | ||
525 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | ||
526 | break; | ||
527 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | ||
528 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | ||
529 | break; | ||
530 | default: | ||
531 | break; | ||
532 | } | ||
533 | } | ||
534 | |||
535 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | ||
536 | { | ||
537 | if (!which) { | ||
538 | return; | ||
539 | } | ||
540 | QString sub; | ||
541 | sub = which->bd_media_text; | ||
542 | target_part.setSubtype(sub.lower()); | ||
543 | target_part.setLines(which->bd_lines); | ||
544 | fillBodyFields(target_part,which->bd_fields); | ||
545 | } | ||
546 | |||
547 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | ||
548 | { | ||
549 | if (!which) { | ||
550 | return; | ||
551 | } | ||
552 | QString type,sub; | ||
553 | switch (which->bd_media_basic->med_type) { | ||
554 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | ||
555 | type = "application"; | ||
556 | break; | ||
557 | case MAILIMAP_MEDIA_BASIC_AUDIO: | ||
558 | type = "audio"; | ||
559 | break; | ||
560 | case MAILIMAP_MEDIA_BASIC_IMAGE: | ||
561 | type = "image"; | ||
562 | break; | ||
563 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | ||
564 | type = "message"; | ||
565 | break; | ||
566 | case MAILIMAP_MEDIA_BASIC_VIDEO: | ||
567 | type = "video"; | ||
568 | break; | ||
569 | case MAILIMAP_MEDIA_BASIC_OTHER: | ||
570 | default: | ||
571 | if (which->bd_media_basic->med_basic_type) { | ||
572 | type = which->bd_media_basic->med_basic_type; | ||
573 | } else { | ||
574 | type = ""; | ||
575 | } | ||
576 | break; | ||
577 | } | ||
578 | if (which->bd_media_basic->med_subtype) { | ||
579 | sub = which->bd_media_basic->med_subtype; | ||
580 | } else { | ||
581 | sub = ""; | ||
582 | } | ||
583 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | ||
584 | target_part.setType(type.lower()); | ||
585 | target_part.setSubtype(sub.lower()); | ||
586 | fillBodyFields(target_part,which->bd_fields); | ||
587 | } | ||
588 | |||
589 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | ||
590 | { | ||
591 | if (!which) return; | ||
592 | if (which->bd_id) { | ||
593 | qDebug("Part ID = %s",which->bd_id); | ||
594 | target_part.setIdentifier(which->bd_id); | ||
595 | } else { | ||
596 | qDebug("ID empty"); | ||
597 | target_part.setIdentifier(""); | ||
598 | } | ||
599 | |||
600 | clistcell*cur; | ||
601 | mailimap_single_body_fld_param*param; | ||
602 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | ||
603 | param = (mailimap_single_body_fld_param*)cur->data; | ||
604 | } | ||
605 | } | ||