summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-12 09:12:48 (UTC)
committer alwin <alwin>2003-12-12 09:12:48 (UTC)
commit77299749e119436aab7af82e065357fca0cead96 (patch) (unidiff)
tree0f51b6faa069d88e0cb0c297b761eef0e5c50f3d
parentf6ff7965fe62f42fcb0fb1cdb93585e0c6ed80fe (diff)
downloadopie-77299749e119436aab7af82e065357fca0cead96.zip
opie-77299749e119436aab7af82e065357fca0cead96.tar.gz
opie-77299749e119436aab7af82e065357fca0cead96.tar.bz2
retrieving a body structure of a multipart mail mostly finished
the first occurence of a part of type "text/xxx" will be interpreted as body text. ToDo: fetch the parameters for a mime-part like encoding and so on.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp113
-rw-r--r--noncore/net/mail/imapwrapper.h3
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp113
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h3
4 files changed, 196 insertions, 36 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 27f1410..fa967da 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -103,503 +103,582 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
103 return; 103 return;
104 } 104 }
105 105
106 result = clist_new(); 106 result = clist_new();
107 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
108 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 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()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
114 114
115 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
116 mailimap_set_free( set ); 116 mailimap_set_free( set );
117 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
118 118
119 QString date,subject,from; 119 QString date,subject,from;
120 120
121 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
122 122
123 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
124 int i = 0; 124 int i = 0;
125 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
126 ++i; 126 ++i;
127 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
128 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
129 if (m) { 129 if (m) {
130 m->setNumber(i); 130 m->setNumber(i);
131 m->setMbox(mailbox); 131 m->setMbox(mailbox);
132 target.append(m); 132 target.append(m);
133 } 133 }
134 } 134 }
135 } else { 135 } else {
136 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
137 } 137 }
138 mailimap_fetch_list_free(result); 138 mailimap_fetch_list_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb_name; 171 temp = list->mb_name;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 if (!path) path = ""; 185 if (!path) path = "";
186 result = clist_new(); 186 result = clist_new();
187 qDebug(path); 187 qDebug(path);
188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
189 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
190 current = result->first; 190 current = result->first;
191 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
192 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
193 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
194 // instead of using strdup! 194 // instead of using strdup!
195 temp = list->mb_name; 195 temp = list->mb_name;
196 current = current->next; 196 current = current->next;
197 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
198 continue; 198 continue;
199 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
200 200
201 } 201 }
202 } else { 202 } else {
203 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
204 } 204 }
205 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
206 return folders; 206 return folders;
207} 207}
208 208
209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
210{ 210{
211 RecMail * m = 0; 211 RecMail * m = 0;
212 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
213 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
214 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
215 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size; 216 int size;
217 QBitArray mFlags(7); 217 QBitArray mFlags(7);
218 QStringList addresslist; 218 QStringList addresslist;
219 219
220 if (!m_att) { 220 if (!m_att) {
221 return m; 221 return m;
222 } 222 }
223 m = new RecMail(); 223 m = new RecMail();
224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
225 current = c; 225 current = c;
226 size = 0; 226 size = 0;
227 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
230 if (!flist->att_list) { 230 if (!flist->att_list) {
231 continue; 231 continue;
232 } 232 }
233 cf = flist->att_list->first; 233 cf = flist->att_list->first;
234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
235 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
236 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) {
237 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
239 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
240 break; 240 break;
241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
242 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
243 break; 243 break;
244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
245 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
246 break; 246 break;
247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
248 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
249 break; 249 break;
250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
251 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
252 break; 252 break;
253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
254 break; 254 break;
255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
256 break; 256 break;
257 default: 257 default:
258 break; 258 break;
259 } 259 }
260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
261 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
262 } 262 }
263 } 263 }
264 continue; 264 continue;
265 } 265 }
266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
267 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;
268 m->setDate(head->env_date); 268 m->setDate(head->env_date);
269 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
270 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
271 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
272 if (addresslist.count()) { 272 if (addresslist.count()) {
273 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
274 } 274 }
275 } 275 }
276 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
277 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
278 m->setTo(addresslist); 278 m->setTo(addresslist);
279 } 279 }
280 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
282 m->setCC(addresslist); 282 m->setCC(addresslist);
283 } 283 }
284 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
286 m->setBcc(addresslist); 286 m->setBcc(addresslist);
287 } 287 }
288 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
290 if (addresslist.count()) { 290 if (addresslist.count()) {
291 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
292 } 292 }
293 } 293 }
294 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
295 } 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) {
296 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;
297 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));
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); 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);
299 qDebug(da.toString()); 299 qDebug(da.toString());
300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
301 size = item->att_data.att_static->att_data.att_rfc822_size; 301 size = item->att_data.att_static->att_data.att_rfc822_size;
302 } 302 }
303 } 303 }
304 /* msg is already deleted */ 304 /* msg is already deleted */
305 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
306 delete m; 306 delete m;
307 m = 0; 307 m = 0;
308 } 308 }
309 if (m) { 309 if (m) {
310 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size); 311 m->setMsgsize(size);
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
317{ 317{
318 RecBody body; 318 RecBody body;
319 const char *mb; 319 const char *mb;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result; 321 clist *result;
322 clistcell *current; 322 clistcell *current;
323 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
324 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
325 mailimap_set *set; 325 mailimap_set *set;
326 mailimap_body*body_desc; 326 mailimap_body*body_desc;
327 327
328 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
329 329
330 login(); 330 login();
331 if (!m_imap) { 331 if (!m_imap) {
332 return body; 332 return body;
333 } 333 }
334 /* select mailbox READONLY for operations */ 334 /* select mailbox READONLY for operations */
335 err = mailimap_examine( m_imap, (char*)mb); 335 err = mailimap_examine( m_imap, (char*)mb);
336 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
337 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
338 return body; 338 return body;
339 } 339 }
340 340
341 result = clist_new(); 341 result = clist_new();
342 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
344 fetchAtt = mailimap_fetch_att_new_bodystructure(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
346 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
347 mailimap_set_free( set ); 347 mailimap_set_free( set );
348 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
349 349
350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
351 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
352 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
353 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;
354 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail"); 358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0); 359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
360 } 360 }
361 } else { 361 } else {
362 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
363 } 363 }
364 mailimap_fetch_list_free(result); 364 mailimap_fetch_list_free(result);
365 return body; 365 return body;
366} 366}
367 367
368/* this routine is just called when the mail has only ONE part. 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 369 for filling the parts of a multi-part-message there are other
370 routines 'cause we can not simply fetch the whole body. */ 370 routines 'cause we can not simply fetch the whole body. */
371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
372{ 372{
373 if (!mailDescription) { 373 if (!mailDescription) {
374 return; 374 return;
375 } 375 }
376 QString sub; 376 QString sub;
377 switch (mailDescription->bd_type) { 377 switch (mailDescription->bd_type) {
378 case MAILIMAP_BODY_TYPE_1PART_MSG: 378 case MAILIMAP_BODY_TYPE_1PART_MSG:
379 target_body.setType("text"); 379 target_body.setType("text");
380 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 380 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
381 target_body.setSubtype(sub.lower()); 381 target_body.setSubtype(sub.lower());
382 fillPlainBody(mail,target_body); 382 fillPlainBody(mail,target_body);
383 break; 383 break;
384 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
386 target_body.setType("text"); 386 target_body.setType("text");
387 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 387 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
388 target_body.setSubtype(sub.lower()); 388 target_body.setSubtype(sub.lower());
389 fillPlainBody(mail,target_body); 389 fillPlainBody(mail,target_body);
390 break; 390 break;
391 default: 391 default:
392 break; 392 break;
393 } 393 }
394 return; 394 return;
395} 395}
396 396
397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body) 397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
398{ 398{
399 const char *mb; 399 const char *mb;
400 QString body=""; 400 QString body="";
401 int err = MAILIMAP_NO_ERROR; 401 int err = MAILIMAP_NO_ERROR;
402 clist *result; 402 clist *result;
403 clistcell *current,*cur; 403 clistcell *current,*cur;
404 mailimap_fetch_att *fetchAtt; 404 mailimap_fetch_att *fetchAtt;
405 mailimap_fetch_type *fetchType; 405 mailimap_fetch_type *fetchType;
406 mailimap_set *set; 406 mailimap_set *set;
407 407
408 mb = mail.getMbox().latin1(); 408 mb = mail.getMbox().latin1();
409 409
410 if (!m_imap) { 410 if (!m_imap) {
411 return; 411 return;
412 } 412 }
413 413
414 result = clist_new(); 414 result = clist_new();
415 set = set = mailimap_set_new_single(mail.getNumber()); 415 set = set = mailimap_set_new_single(mail.getNumber());
416 mailimap_section * section = mailimap_section_new_text(); 416 mailimap_section * section = mailimap_section_new_text();
417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section); 417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
419 err = mailimap_fetch( m_imap, set, fetchType, &result ); 419 err = mailimap_fetch( m_imap, set, fetchType, &result );
420 mailimap_set_free( set ); 420 mailimap_set_free( set );
421 mailimap_fetch_type_free( fetchType ); 421 mailimap_fetch_type_free( fetchType );
422 422
423 423
424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
425 mailimap_msg_att * msg_att; 425 mailimap_msg_att * msg_att;
426 msg_att = (mailimap_msg_att*)current->data; 426 msg_att = (mailimap_msg_att*)current->data;
427 mailimap_msg_att_item*msg_att_item; 427 mailimap_msg_att_item*msg_att_item;
428 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)) {
429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
431 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) {
432 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;
433 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;
434 if (text) { 434 if (text) {
435 body = QString(text); 435 body = QString(text);
436 free(text); 436 free(text);
437 } else { 437 } else {
438 body = ""; 438 body = "";
439 } 439 }
440 } 440 }
441 } 441 }
442 } 442 }
443 443
444 } else { 444 } else {
445 qDebug("error fetching text: %s",m_imap->imap_response); 445 qDebug("error fetching text: %s",m_imap->imap_response);
446 } 446 }
447 mailimap_fetch_list_free(result); 447 mailimap_fetch_list_free(result);
448 target_body.setBodytext(body); 448 target_body.setBodytext(body);
449 return; 449 return;
450} 450}
451 451
452QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 452QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
453{ 453{
454 QStringList l; 454 QStringList l;
455 QString from; 455 QString from;
456 bool named_from; 456 bool named_from;
457 clistcell *current = NULL; 457 clistcell *current = NULL;
458 mailimap_address * current_address=NULL; 458 mailimap_address * current_address=NULL;
459 if (!list) { 459 if (!list) {
460 return l; 460 return l;
461 } 461 }
462 unsigned int count = 0; 462 unsigned int count = 0;
463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
464 from = ""; 464 from = "";
465 named_from = false; 465 named_from = false;
466 current_address=(mailimap_address*)current->data; 466 current_address=(mailimap_address*)current->data;
467 if (current_address->ad_personal_name){ 467 if (current_address->ad_personal_name){
468 from+=QString(current_address->ad_personal_name); 468 from+=QString(current_address->ad_personal_name);
469 from+=" "; 469 from+=" ";
470 named_from = true; 470 named_from = true;
471 } 471 }
472 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)) {
473 from+="<"; 473 from+="<";
474 } 474 }
475 if (current_address->ad_mailbox_name) { 475 if (current_address->ad_mailbox_name) {
476 from+=QString(current_address->ad_mailbox_name); 476 from+=QString(current_address->ad_mailbox_name);
477 from+="@"; 477 from+="@";
478 } 478 }
479 if (current_address->ad_host_name) { 479 if (current_address->ad_host_name) {
480 from+=QString(current_address->ad_host_name); 480 from+=QString(current_address->ad_host_name);
481 } 481 }
482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
483 from+=">"; 483 from+=">";
484 } 484 }
485 l.append(QString(from)); 485 l.append(QString(from));
486 if (++count > 99) { 486 if (++count > 99) {
487 break; 487 break;
488 } 488 }
489 } 489 }
490 return l; 490 return l;
491} 491}
492 492
493void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion) 493QString IMAPwrapper::fetchPart(const RecMail&mail,QValueList<int>&path,bool internal_call)
494{
495 QString body("");
496 const char*mb;
497 int err;
498 mailimap_fetch_type *fetchType;
499 mailimap_set *set;
500 clistcell*current,*cur;
501
502 login();
503 if (!m_imap) {
504 return body;
505 }
506 if (!internal_call) {
507 mb = mail.getMbox().latin1();
508 /* select mailbox READONLY for operations */
509 err = mailimap_examine( m_imap, (char*)mb);
510 if ( err != MAILIMAP_NO_ERROR ) {
511 qDebug("error selecting mailbox: %s",m_imap->imap_response);
512 return body;
513 }
514 }
515 set = mailimap_set_new_single(mail.getNumber());
516 clist*id_list=clist_new();
517 for (unsigned j=0; j < path.count();++j) {
518 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
519 *p_id = path[j];
520 clist_append(id_list,p_id);
521 }
522 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
523 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
524 mailimap_section * section = mailimap_section_new(section_spec);
525 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
526
527 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
528
529 clist*result = clist_new();
530
531 err = mailimap_fetch( m_imap, set, fetchType, &result );
532 mailimap_set_free( set );
533 mailimap_fetch_type_free( fetchType );
534
535 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
536 mailimap_msg_att * msg_att;
537 msg_att = (mailimap_msg_att*)current->data;
538 mailimap_msg_att_item*msg_att_item;
539 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
540 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
541 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
542 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
543 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
544 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
545 if (text) {
546 body = QString(text);
547 free(text);
548 } else {
549 body = "";
550 }
551 }
552 }
553 }
554
555 } else {
556 qDebug("error fetching text: %s",m_imap->imap_response);
557 }
558 mailimap_fetch_list_free(result);
559 return body;
560}
561
562void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
494{ 563{
495 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 564 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
496 if (!mailDescription||current_recursion==2) { 565 if (!mailDescription||current_recursion==10) {
497 return; 566 return;
498 } 567 }
499 qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
500 clistcell*current; 568 clistcell*current;
501 mailimap_body*current_body; 569 mailimap_body*current_body;
570 unsigned int count = 0;
502 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 571 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
572 /* the point in the message */
573 ++count;
503 current_body = (mailimap_body*)current->data; 574 current_body = (mailimap_body*)current->data;
504 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 575 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
505 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1); 576 QValueList<int>clist = recList;
577 clist.append(count);
578 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
506 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 579 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
507 RecPart currentPart; 580 RecPart currentPart;
508 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 581 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
509 target_body.addPart(currentPart); 582 QValueList<int>clist = recList;
583 clist.append(count);
584 /* important: Check for is NULL 'cause a body can be empty! */
585 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
586 QString body_text = fetchPart(mail,clist,true);
587 target_body.setBodytext(body_text);
588 target_body.setType(currentPart.Type());
589 target_body.setSubtype(currentPart.Subtype());
590 } else {
591 QString id("");
592 for (unsigned int j = 0; j < clist.count();++j) {
593 id+=(j>0?".":"");
594 id+=QString("%1").arg(clist[j]);
595 }
596 qDebug("ID= %s",id.latin1());
597 currentPart.setIdentifier(id);
598 target_body.addPart(currentPart);
599 }
510 } 600 }
511 } 601 }
512 if (current_recursion==0) {
513
514 }
515} 602}
516 603
517void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 604void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
518{ 605{
519 if (!Description) { 606 if (!Description) {
520 return; 607 return;
521 } 608 }
522 switch (Description->bd_type) { 609 switch (Description->bd_type) {
523 case MAILIMAP_BODY_TYPE_1PART_TEXT: 610 case MAILIMAP_BODY_TYPE_1PART_TEXT:
524 target_part.setType("text"); 611 target_part.setType("text");
525 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 612 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
526 break; 613 break;
527 case MAILIMAP_BODY_TYPE_1PART_BASIC: 614 case MAILIMAP_BODY_TYPE_1PART_BASIC:
528 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 615 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
529 break; 616 break;
530 default: 617 default:
531 break; 618 break;
532 } 619 }
533} 620}
534 621
535void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 622void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
536{ 623{
537 if (!which) { 624 if (!which) {
538 return; 625 return;
539 } 626 }
540 QString sub; 627 QString sub;
541 sub = which->bd_media_text; 628 sub = which->bd_media_text;
542 target_part.setSubtype(sub.lower()); 629 target_part.setSubtype(sub.lower());
543 target_part.setLines(which->bd_lines); 630 target_part.setLines(which->bd_lines);
544 fillBodyFields(target_part,which->bd_fields); 631 fillBodyFields(target_part,which->bd_fields);
545} 632}
546 633
547void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 634void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
548{ 635{
549 if (!which) { 636 if (!which) {
550 return; 637 return;
551 } 638 }
552 QString type,sub; 639 QString type,sub;
553 switch (which->bd_media_basic->med_type) { 640 switch (which->bd_media_basic->med_type) {
554 case MAILIMAP_MEDIA_BASIC_APPLICATION: 641 case MAILIMAP_MEDIA_BASIC_APPLICATION:
555 type = "application"; 642 type = "application";
556 break; 643 break;
557 case MAILIMAP_MEDIA_BASIC_AUDIO: 644 case MAILIMAP_MEDIA_BASIC_AUDIO:
558 type = "audio"; 645 type = "audio";
559 break; 646 break;
560 case MAILIMAP_MEDIA_BASIC_IMAGE: 647 case MAILIMAP_MEDIA_BASIC_IMAGE:
561 type = "image"; 648 type = "image";
562 break; 649 break;
563 case MAILIMAP_MEDIA_BASIC_MESSAGE: 650 case MAILIMAP_MEDIA_BASIC_MESSAGE:
564 type = "message"; 651 type = "message";
565 break; 652 break;
566 case MAILIMAP_MEDIA_BASIC_VIDEO: 653 case MAILIMAP_MEDIA_BASIC_VIDEO:
567 type = "video"; 654 type = "video";
568 break; 655 break;
569 case MAILIMAP_MEDIA_BASIC_OTHER: 656 case MAILIMAP_MEDIA_BASIC_OTHER:
570 default: 657 default:
571 if (which->bd_media_basic->med_basic_type) { 658 if (which->bd_media_basic->med_basic_type) {
572 type = which->bd_media_basic->med_basic_type; 659 type = which->bd_media_basic->med_basic_type;
573 } else { 660 } else {
574 type = ""; 661 type = "";
575 } 662 }
576 break; 663 break;
577 } 664 }
578 if (which->bd_media_basic->med_subtype) { 665 if (which->bd_media_basic->med_subtype) {
579 sub = which->bd_media_basic->med_subtype; 666 sub = which->bd_media_basic->med_subtype;
580 } else { 667 } else {
581 sub = ""; 668 sub = "";
582 } 669 }
583 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 670 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
584 target_part.setType(type.lower()); 671 target_part.setType(type.lower());
585 target_part.setSubtype(sub.lower()); 672 target_part.setSubtype(sub.lower());
586 fillBodyFields(target_part,which->bd_fields); 673 fillBodyFields(target_part,which->bd_fields);
587} 674}
588 675
589void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 676void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
590{ 677{
591 if (!which) return; 678 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; 679 clistcell*cur;
601 mailimap_single_body_fld_param*param; 680 mailimap_single_body_fld_param*param;
602 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
603 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
604 } 683 }
605} 684}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index f809edb..5ea45f3 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,52 +1,53 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_body_type_basic; 10struct mailimap_body_type_basic;
11struct mailimap_body_type_mpart; 11struct mailimap_body_type_mpart;
12struct mailimap_body_fields; 12struct mailimap_body_fields;
13struct mailimap_msg_att; 13struct mailimap_msg_att;
14class RecMail; 14class RecMail;
15class RecBody; 15class RecBody;
16class RecPart; 16class RecPart;
17 17
18class IMAPwrapper : public QObject 18class IMAPwrapper : public QObject
19{ 19{
20 Q_OBJECT 20 Q_OBJECT
21 21
22public: 22public:
23 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
24 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
25 QList<IMAPFolder>* listFolders(); 25 QList<IMAPFolder>* listFolders();
26 void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 void listMessages(const QString & mailbox,QList<RecMail>&target );
27 RecBody fetchBody(const RecMail&mail); 27 RecBody fetchBody(const RecMail&mail);
28 QString fetchPart(const RecMail&mail,QValueList<int>&path,bool internal_call=false);
28 static void imap_progress( size_t current, size_t maximum ); 29 static void imap_progress( size_t current, size_t maximum );
29 30
30protected: 31protected:
31 RecMail*parse_list_result(mailimap_msg_att*); 32 RecMail*parse_list_result(mailimap_msg_att*);
32 void login(); 33 void login();
33 void logout(); 34 void logout();
34 35
35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion); 37 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
37 38
38 void fillPlainBody(const RecMail&mail,RecBody&target_body); 39 void fillPlainBody(const RecMail&mail,RecBody&target_body);
39 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 40 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
40 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 41 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
41 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 42 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
42 43
43 /* just helpers */ 44 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 45 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
45 static QStringList address_list_to_stringlist(clist*list); 46 static QStringList address_list_to_stringlist(clist*list);
46 47
47private: 48private:
48 IMAPaccount *account; 49 IMAPaccount *account;
49 mailimap *m_imap; 50 mailimap *m_imap;
50}; 51};
51 52
52#endif 53#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 27f1410..fa967da 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -103,503 +103,582 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
103 return; 103 return;
104 } 104 }
105 105
106 result = clist_new(); 106 result = clist_new();
107 /* the range has to start at 1!!! not with 0!!!! */ 107 /* the range has to start at 1!!! not with 0!!!! */
108 set = mailimap_set_new_interval( 1, last ); 108 set = mailimap_set_new_interval( 1, last );
109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 109 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 110 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 111 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 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()); 113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
114 114
115 err = mailimap_fetch( m_imap, set, fetchType, &result ); 115 err = mailimap_fetch( m_imap, set, fetchType, &result );
116 mailimap_set_free( set ); 116 mailimap_set_free( set );
117 mailimap_fetch_type_free( fetchType ); 117 mailimap_fetch_type_free( fetchType );
118 118
119 QString date,subject,from; 119 QString date,subject,from;
120 120
121 if ( err == MAILIMAP_NO_ERROR ) { 121 if ( err == MAILIMAP_NO_ERROR ) {
122 122
123 mailimap_msg_att * msg_att; 123 mailimap_msg_att * msg_att;
124 int i = 0; 124 int i = 0;
125 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 125 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
126 ++i; 126 ++i;
127 msg_att = (mailimap_msg_att*)current->data; 127 msg_att = (mailimap_msg_att*)current->data;
128 RecMail*m = parse_list_result(msg_att); 128 RecMail*m = parse_list_result(msg_att);
129 if (m) { 129 if (m) {
130 m->setNumber(i); 130 m->setNumber(i);
131 m->setMbox(mailbox); 131 m->setMbox(mailbox);
132 target.append(m); 132 target.append(m);
133 } 133 }
134 } 134 }
135 } else { 135 } else {
136 qDebug("Error fetching headers: %s",m_imap->imap_response); 136 qDebug("Error fetching headers: %s",m_imap->imap_response);
137 } 137 }
138 mailimap_fetch_list_free(result); 138 mailimap_fetch_list_free(result);
139} 139}
140 140
141QList<IMAPFolder>* IMAPwrapper::listFolders() 141QList<IMAPFolder>* IMAPwrapper::listFolders()
142{ 142{
143 const char *path, *mask; 143 const char *path, *mask;
144 int err = MAILIMAP_NO_ERROR; 144 int err = MAILIMAP_NO_ERROR;
145 clist *result; 145 clist *result;
146 clistcell *current; 146 clistcell *current;
147 147
148 QList<IMAPFolder> * folders = new QList<IMAPFolder>(); 148 QList<IMAPFolder> * folders = new QList<IMAPFolder>();
149 folders->setAutoDelete( true ); 149 folders->setAutoDelete( true );
150 login(); 150 login();
151 if (!m_imap) { 151 if (!m_imap) {
152 return folders; 152 return folders;
153 } 153 }
154 154
155/* 155/*
156 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 156 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
157 * We must not forget to filter them out in next loop! 157 * We must not forget to filter them out in next loop!
158 * it seems like ugly code. and yes - it is ugly code. but the best way. 158 * it seems like ugly code. and yes - it is ugly code. but the best way.
159 */ 159 */
160 QString temp; 160 QString temp;
161 mask = "INBOX" ; 161 mask = "INBOX" ;
162 result = clist_new(); 162 result = clist_new();
163 mailimap_mailbox_list *list; 163 mailimap_mailbox_list *list;
164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 164 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
165 if ( err == MAILIMAP_NO_ERROR ) { 165 if ( err == MAILIMAP_NO_ERROR ) {
166 current = result->first; 166 current = result->first;
167 for ( int i = result->count; i > 0; i-- ) { 167 for ( int i = result->count; i > 0; i-- ) {
168 list = (mailimap_mailbox_list *) current->data; 168 list = (mailimap_mailbox_list *) current->data;
169 // it is better use the deep copy mechanism of qt itself 169 // it is better use the deep copy mechanism of qt itself
170 // instead of using strdup! 170 // instead of using strdup!
171 temp = list->mb_name; 171 temp = list->mb_name;
172 folders->append( new IMAPFolder(temp)); 172 folders->append( new IMAPFolder(temp));
173 current = current->next; 173 current = current->next;
174 } 174 }
175 } else { 175 } else {
176 qDebug("error fetching folders: %s",m_imap->imap_response); 176 qDebug("error fetching folders: %s",m_imap->imap_response);
177 } 177 }
178 mailimap_list_result_free( result ); 178 mailimap_list_result_free( result );
179 179
180/* 180/*
181 * second stage - get the other then inbox folders 181 * second stage - get the other then inbox folders
182 */ 182 */
183 mask = "*" ; 183 mask = "*" ;
184 path = account->getPrefix().latin1(); 184 path = account->getPrefix().latin1();
185 if (!path) path = ""; 185 if (!path) path = "";
186 result = clist_new(); 186 result = clist_new();
187 qDebug(path); 187 qDebug(path);
188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 188 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
189 if ( err == MAILIMAP_NO_ERROR ) { 189 if ( err == MAILIMAP_NO_ERROR ) {
190 current = result->first; 190 current = result->first;
191 for ( int i = result->count; i > 0; i-- ) { 191 for ( int i = result->count; i > 0; i-- ) {
192 list = (mailimap_mailbox_list *) current->data; 192 list = (mailimap_mailbox_list *) current->data;
193 // it is better use the deep copy mechanism of qt itself 193 // it is better use the deep copy mechanism of qt itself
194 // instead of using strdup! 194 // instead of using strdup!
195 temp = list->mb_name; 195 temp = list->mb_name;
196 current = current->next; 196 current = current->next;
197 if (temp.lower()=="inbox") 197 if (temp.lower()=="inbox")
198 continue; 198 continue;
199 folders->append(new IMAPFolder(temp)); 199 folders->append(new IMAPFolder(temp));
200 200
201 } 201 }
202 } else { 202 } else {
203 qDebug("error fetching folders %s",m_imap->imap_response); 203 qDebug("error fetching folders %s",m_imap->imap_response);
204 } 204 }
205 mailimap_list_result_free( result ); 205 mailimap_list_result_free( result );
206 return folders; 206 return folders;
207} 207}
208 208
209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 209RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
210{ 210{
211 RecMail * m = 0; 211 RecMail * m = 0;
212 mailimap_msg_att_item *item=0; 212 mailimap_msg_att_item *item=0;
213 clistcell *current,*c,*cf; 213 clistcell *current,*c,*cf;
214 mailimap_msg_att_dynamic*flist; 214 mailimap_msg_att_dynamic*flist;
215 mailimap_flag_fetch*cflag; 215 mailimap_flag_fetch*cflag;
216 int size; 216 int size;
217 QBitArray mFlags(7); 217 QBitArray mFlags(7);
218 QStringList addresslist; 218 QStringList addresslist;
219 219
220 if (!m_att) { 220 if (!m_att) {
221 return m; 221 return m;
222 } 222 }
223 m = new RecMail(); 223 m = new RecMail();
224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 224 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
225 current = c; 225 current = c;
226 size = 0; 226 size = 0;
227 item = (mailimap_msg_att_item*)current->data; 227 item = (mailimap_msg_att_item*)current->data;
228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 228 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 229 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
230 if (!flist->att_list) { 230 if (!flist->att_list) {
231 continue; 231 continue;
232 } 232 }
233 cf = flist->att_list->first; 233 cf = flist->att_list->first;
234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 234 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
235 cflag = (mailimap_flag_fetch*)cf->data; 235 cflag = (mailimap_flag_fetch*)cf->data;
236 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) {
237 switch (cflag->fl_flag->fl_type) { 237 switch (cflag->fl_flag->fl_type) {
238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 238 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
239 mFlags.setBit(FLAG_ANSWERED); 239 mFlags.setBit(FLAG_ANSWERED);
240 break; 240 break;
241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 241 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
242 mFlags.setBit(FLAG_FLAGGED); 242 mFlags.setBit(FLAG_FLAGGED);
243 break; 243 break;
244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 244 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
245 mFlags.setBit(FLAG_DELETED); 245 mFlags.setBit(FLAG_DELETED);
246 break; 246 break;
247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 247 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
248 mFlags.setBit(FLAG_SEEN); 248 mFlags.setBit(FLAG_SEEN);
249 break; 249 break;
250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 250 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
251 mFlags.setBit(FLAG_DRAFT); 251 mFlags.setBit(FLAG_DRAFT);
252 break; 252 break;
253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 253 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
254 break; 254 break;
255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 255 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
256 break; 256 break;
257 default: 257 default:
258 break; 258 break;
259 } 259 }
260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 260 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
261 mFlags.setBit(FLAG_RECENT); 261 mFlags.setBit(FLAG_RECENT);
262 } 262 }
263 } 263 }
264 continue; 264 continue;
265 } 265 }
266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 266 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
267 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;
268 m->setDate(head->env_date); 268 m->setDate(head->env_date);
269 m->setSubject(head->env_subject); 269 m->setSubject(head->env_subject);
270 if (head->env_from!=NULL) { 270 if (head->env_from!=NULL) {
271 addresslist = address_list_to_stringlist(head->env_from->frm_list); 271 addresslist = address_list_to_stringlist(head->env_from->frm_list);
272 if (addresslist.count()) { 272 if (addresslist.count()) {
273 m->setFrom(addresslist.first()); 273 m->setFrom(addresslist.first());
274 } 274 }
275 } 275 }
276 if (head->env_to!=NULL) { 276 if (head->env_to!=NULL) {
277 addresslist = address_list_to_stringlist(head->env_to->to_list); 277 addresslist = address_list_to_stringlist(head->env_to->to_list);
278 m->setTo(addresslist); 278 m->setTo(addresslist);
279 } 279 }
280 if (head->env_cc!=NULL) { 280 if (head->env_cc!=NULL) {
281 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 281 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
282 m->setCC(addresslist); 282 m->setCC(addresslist);
283 } 283 }
284 if (head->env_bcc!=NULL) { 284 if (head->env_bcc!=NULL) {
285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 285 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
286 m->setBcc(addresslist); 286 m->setBcc(addresslist);
287 } 287 }
288 if (head->env_reply_to!=NULL) { 288 if (head->env_reply_to!=NULL) {
289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 289 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
290 if (addresslist.count()) { 290 if (addresslist.count()) {
291 m->setReplyto(addresslist.first()); 291 m->setReplyto(addresslist.first());
292 } 292 }
293 } 293 }
294 m->setMsgid(QString(head->env_message_id)); 294 m->setMsgid(QString(head->env_message_id));
295 } 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) {
296 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;
297 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));
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); 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);
299 qDebug(da.toString()); 299 qDebug(da.toString());
300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 300 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
301 size = item->att_data.att_static->att_data.att_rfc822_size; 301 size = item->att_data.att_static->att_data.att_rfc822_size;
302 } 302 }
303 } 303 }
304 /* msg is already deleted */ 304 /* msg is already deleted */
305 if (mFlags.testBit(FLAG_DELETED) && m) { 305 if (mFlags.testBit(FLAG_DELETED) && m) {
306 delete m; 306 delete m;
307 m = 0; 307 m = 0;
308 } 308 }
309 if (m) { 309 if (m) {
310 m->setFlags(mFlags); 310 m->setFlags(mFlags);
311 m->setMsgsize(size); 311 m->setMsgsize(size);
312 } 312 }
313 return m; 313 return m;
314} 314}
315 315
316RecBody IMAPwrapper::fetchBody(const RecMail&mail) 316RecBody IMAPwrapper::fetchBody(const RecMail&mail)
317{ 317{
318 RecBody body; 318 RecBody body;
319 const char *mb; 319 const char *mb;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result; 321 clist *result;
322 clistcell *current; 322 clistcell *current;
323 mailimap_fetch_att *fetchAtt; 323 mailimap_fetch_att *fetchAtt;
324 mailimap_fetch_type *fetchType; 324 mailimap_fetch_type *fetchType;
325 mailimap_set *set; 325 mailimap_set *set;
326 mailimap_body*body_desc; 326 mailimap_body*body_desc;
327 327
328 mb = mail.getMbox().latin1(); 328 mb = mail.getMbox().latin1();
329 329
330 login(); 330 login();
331 if (!m_imap) { 331 if (!m_imap) {
332 return body; 332 return body;
333 } 333 }
334 /* select mailbox READONLY for operations */ 334 /* select mailbox READONLY for operations */
335 err = mailimap_examine( m_imap, (char*)mb); 335 err = mailimap_examine( m_imap, (char*)mb);
336 if ( err != MAILIMAP_NO_ERROR ) { 336 if ( err != MAILIMAP_NO_ERROR ) {
337 qDebug("error selecting mailbox: %s",m_imap->imap_response); 337 qDebug("error selecting mailbox: %s",m_imap->imap_response);
338 return body; 338 return body;
339 } 339 }
340 340
341 result = clist_new(); 341 result = clist_new();
342 /* the range has to start at 1!!! not with 0!!!! */ 342 /* the range has to start at 1!!! not with 0!!!! */
343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 343 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
344 fetchAtt = mailimap_fetch_att_new_bodystructure(); 344 fetchAtt = mailimap_fetch_att_new_bodystructure();
345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 345 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
346 err = mailimap_fetch( m_imap, set, fetchType, &result ); 346 err = mailimap_fetch( m_imap, set, fetchType, &result );
347 mailimap_set_free( set ); 347 mailimap_set_free( set );
348 mailimap_fetch_type_free( fetchType ); 348 mailimap_fetch_type_free( fetchType );
349 349
350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 350 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
351 mailimap_msg_att * msg_att; 351 mailimap_msg_att * msg_att;
352 msg_att = (mailimap_msg_att*)current->data; 352 msg_att = (mailimap_msg_att*)current->data;
353 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;
354 body_desc = item->att_data.att_static->att_data.att_body; 354 body_desc = item->att_data.att_static->att_data.att_body;
355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 355 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 356 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 357 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
358 qDebug("Mulitpart mail"); 358 qDebug("Mulitpart mail");
359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0); 359 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
360 } 360 }
361 } else { 361 } else {
362 qDebug("error fetching body: %s",m_imap->imap_response); 362 qDebug("error fetching body: %s",m_imap->imap_response);
363 } 363 }
364 mailimap_fetch_list_free(result); 364 mailimap_fetch_list_free(result);
365 return body; 365 return body;
366} 366}
367 367
368/* this routine is just called when the mail has only ONE part. 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 369 for filling the parts of a multi-part-message there are other
370 routines 'cause we can not simply fetch the whole body. */ 370 routines 'cause we can not simply fetch the whole body. */
371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 371void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
372{ 372{
373 if (!mailDescription) { 373 if (!mailDescription) {
374 return; 374 return;
375 } 375 }
376 QString sub; 376 QString sub;
377 switch (mailDescription->bd_type) { 377 switch (mailDescription->bd_type) {
378 case MAILIMAP_BODY_TYPE_1PART_MSG: 378 case MAILIMAP_BODY_TYPE_1PART_MSG:
379 target_body.setType("text"); 379 target_body.setType("text");
380 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 380 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
381 target_body.setSubtype(sub.lower()); 381 target_body.setSubtype(sub.lower());
382 fillPlainBody(mail,target_body); 382 fillPlainBody(mail,target_body);
383 break; 383 break;
384 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
386 target_body.setType("text"); 386 target_body.setType("text");
387 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 387 sub = mailDescription->bd_data.bd_type_text->bd_media_text;
388 target_body.setSubtype(sub.lower()); 388 target_body.setSubtype(sub.lower());
389 fillPlainBody(mail,target_body); 389 fillPlainBody(mail,target_body);
390 break; 390 break;
391 default: 391 default:
392 break; 392 break;
393 } 393 }
394 return; 394 return;
395} 395}
396 396
397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body) 397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
398{ 398{
399 const char *mb; 399 const char *mb;
400 QString body=""; 400 QString body="";
401 int err = MAILIMAP_NO_ERROR; 401 int err = MAILIMAP_NO_ERROR;
402 clist *result; 402 clist *result;
403 clistcell *current,*cur; 403 clistcell *current,*cur;
404 mailimap_fetch_att *fetchAtt; 404 mailimap_fetch_att *fetchAtt;
405 mailimap_fetch_type *fetchType; 405 mailimap_fetch_type *fetchType;
406 mailimap_set *set; 406 mailimap_set *set;
407 407
408 mb = mail.getMbox().latin1(); 408 mb = mail.getMbox().latin1();
409 409
410 if (!m_imap) { 410 if (!m_imap) {
411 return; 411 return;
412 } 412 }
413 413
414 result = clist_new(); 414 result = clist_new();
415 set = set = mailimap_set_new_single(mail.getNumber()); 415 set = set = mailimap_set_new_single(mail.getNumber());
416 mailimap_section * section = mailimap_section_new_text(); 416 mailimap_section * section = mailimap_section_new_text();
417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section); 417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
419 err = mailimap_fetch( m_imap, set, fetchType, &result ); 419 err = mailimap_fetch( m_imap, set, fetchType, &result );
420 mailimap_set_free( set ); 420 mailimap_set_free( set );
421 mailimap_fetch_type_free( fetchType ); 421 mailimap_fetch_type_free( fetchType );
422 422
423 423
424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
425 mailimap_msg_att * msg_att; 425 mailimap_msg_att * msg_att;
426 msg_att = (mailimap_msg_att*)current->data; 426 msg_att = (mailimap_msg_att*)current->data;
427 mailimap_msg_att_item*msg_att_item; 427 mailimap_msg_att_item*msg_att_item;
428 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)) {
429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
431 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) {
432 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;
433 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;
434 if (text) { 434 if (text) {
435 body = QString(text); 435 body = QString(text);
436 free(text); 436 free(text);
437 } else { 437 } else {
438 body = ""; 438 body = "";
439 } 439 }
440 } 440 }
441 } 441 }
442 } 442 }
443 443
444 } else { 444 } else {
445 qDebug("error fetching text: %s",m_imap->imap_response); 445 qDebug("error fetching text: %s",m_imap->imap_response);
446 } 446 }
447 mailimap_fetch_list_free(result); 447 mailimap_fetch_list_free(result);
448 target_body.setBodytext(body); 448 target_body.setBodytext(body);
449 return; 449 return;
450} 450}
451 451
452QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 452QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
453{ 453{
454 QStringList l; 454 QStringList l;
455 QString from; 455 QString from;
456 bool named_from; 456 bool named_from;
457 clistcell *current = NULL; 457 clistcell *current = NULL;
458 mailimap_address * current_address=NULL; 458 mailimap_address * current_address=NULL;
459 if (!list) { 459 if (!list) {
460 return l; 460 return l;
461 } 461 }
462 unsigned int count = 0; 462 unsigned int count = 0;
463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 463 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
464 from = ""; 464 from = "";
465 named_from = false; 465 named_from = false;
466 current_address=(mailimap_address*)current->data; 466 current_address=(mailimap_address*)current->data;
467 if (current_address->ad_personal_name){ 467 if (current_address->ad_personal_name){
468 from+=QString(current_address->ad_personal_name); 468 from+=QString(current_address->ad_personal_name);
469 from+=" "; 469 from+=" ";
470 named_from = true; 470 named_from = true;
471 } 471 }
472 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)) {
473 from+="<"; 473 from+="<";
474 } 474 }
475 if (current_address->ad_mailbox_name) { 475 if (current_address->ad_mailbox_name) {
476 from+=QString(current_address->ad_mailbox_name); 476 from+=QString(current_address->ad_mailbox_name);
477 from+="@"; 477 from+="@";
478 } 478 }
479 if (current_address->ad_host_name) { 479 if (current_address->ad_host_name) {
480 from+=QString(current_address->ad_host_name); 480 from+=QString(current_address->ad_host_name);
481 } 481 }
482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 482 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
483 from+=">"; 483 from+=">";
484 } 484 }
485 l.append(QString(from)); 485 l.append(QString(from));
486 if (++count > 99) { 486 if (++count > 99) {
487 break; 487 break;
488 } 488 }
489 } 489 }
490 return l; 490 return l;
491} 491}
492 492
493void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion) 493QString IMAPwrapper::fetchPart(const RecMail&mail,QValueList<int>&path,bool internal_call)
494{
495 QString body("");
496 const char*mb;
497 int err;
498 mailimap_fetch_type *fetchType;
499 mailimap_set *set;
500 clistcell*current,*cur;
501
502 login();
503 if (!m_imap) {
504 return body;
505 }
506 if (!internal_call) {
507 mb = mail.getMbox().latin1();
508 /* select mailbox READONLY for operations */
509 err = mailimap_examine( m_imap, (char*)mb);
510 if ( err != MAILIMAP_NO_ERROR ) {
511 qDebug("error selecting mailbox: %s",m_imap->imap_response);
512 return body;
513 }
514 }
515 set = mailimap_set_new_single(mail.getNumber());
516 clist*id_list=clist_new();
517 for (unsigned j=0; j < path.count();++j) {
518 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
519 *p_id = path[j];
520 clist_append(id_list,p_id);
521 }
522 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
523 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
524 mailimap_section * section = mailimap_section_new(section_spec);
525 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
526
527 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
528
529 clist*result = clist_new();
530
531 err = mailimap_fetch( m_imap, set, fetchType, &result );
532 mailimap_set_free( set );
533 mailimap_fetch_type_free( fetchType );
534
535 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
536 mailimap_msg_att * msg_att;
537 msg_att = (mailimap_msg_att*)current->data;
538 mailimap_msg_att_item*msg_att_item;
539 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
540 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
541 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
542 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
543 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
544 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
545 if (text) {
546 body = QString(text);
547 free(text);
548 } else {
549 body = "";
550 }
551 }
552 }
553 }
554
555 } else {
556 qDebug("error fetching text: %s",m_imap->imap_response);
557 }
558 mailimap_fetch_list_free(result);
559 return body;
560}
561
562void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
494{ 563{
495 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 564 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
496 if (!mailDescription||current_recursion==2) { 565 if (!mailDescription||current_recursion==10) {
497 return; 566 return;
498 } 567 }
499 qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
500 clistcell*current; 568 clistcell*current;
501 mailimap_body*current_body; 569 mailimap_body*current_body;
570 unsigned int count = 0;
502 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 571 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
572 /* the point in the message */
573 ++count;
503 current_body = (mailimap_body*)current->data; 574 current_body = (mailimap_body*)current->data;
504 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 575 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
505 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1); 576 QValueList<int>clist = recList;
577 clist.append(count);
578 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
506 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 579 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
507 RecPart currentPart; 580 RecPart currentPart;
508 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 581 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
509 target_body.addPart(currentPart); 582 QValueList<int>clist = recList;
583 clist.append(count);
584 /* important: Check for is NULL 'cause a body can be empty! */
585 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
586 QString body_text = fetchPart(mail,clist,true);
587 target_body.setBodytext(body_text);
588 target_body.setType(currentPart.Type());
589 target_body.setSubtype(currentPart.Subtype());
590 } else {
591 QString id("");
592 for (unsigned int j = 0; j < clist.count();++j) {
593 id+=(j>0?".":"");
594 id+=QString("%1").arg(clist[j]);
595 }
596 qDebug("ID= %s",id.latin1());
597 currentPart.setIdentifier(id);
598 target_body.addPart(currentPart);
599 }
510 } 600 }
511 } 601 }
512 if (current_recursion==0) {
513
514 }
515} 602}
516 603
517void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 604void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
518{ 605{
519 if (!Description) { 606 if (!Description) {
520 return; 607 return;
521 } 608 }
522 switch (Description->bd_type) { 609 switch (Description->bd_type) {
523 case MAILIMAP_BODY_TYPE_1PART_TEXT: 610 case MAILIMAP_BODY_TYPE_1PART_TEXT:
524 target_part.setType("text"); 611 target_part.setType("text");
525 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 612 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
526 break; 613 break;
527 case MAILIMAP_BODY_TYPE_1PART_BASIC: 614 case MAILIMAP_BODY_TYPE_1PART_BASIC:
528 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 615 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
529 break; 616 break;
530 default: 617 default:
531 break; 618 break;
532 } 619 }
533} 620}
534 621
535void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 622void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
536{ 623{
537 if (!which) { 624 if (!which) {
538 return; 625 return;
539 } 626 }
540 QString sub; 627 QString sub;
541 sub = which->bd_media_text; 628 sub = which->bd_media_text;
542 target_part.setSubtype(sub.lower()); 629 target_part.setSubtype(sub.lower());
543 target_part.setLines(which->bd_lines); 630 target_part.setLines(which->bd_lines);
544 fillBodyFields(target_part,which->bd_fields); 631 fillBodyFields(target_part,which->bd_fields);
545} 632}
546 633
547void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 634void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
548{ 635{
549 if (!which) { 636 if (!which) {
550 return; 637 return;
551 } 638 }
552 QString type,sub; 639 QString type,sub;
553 switch (which->bd_media_basic->med_type) { 640 switch (which->bd_media_basic->med_type) {
554 case MAILIMAP_MEDIA_BASIC_APPLICATION: 641 case MAILIMAP_MEDIA_BASIC_APPLICATION:
555 type = "application"; 642 type = "application";
556 break; 643 break;
557 case MAILIMAP_MEDIA_BASIC_AUDIO: 644 case MAILIMAP_MEDIA_BASIC_AUDIO:
558 type = "audio"; 645 type = "audio";
559 break; 646 break;
560 case MAILIMAP_MEDIA_BASIC_IMAGE: 647 case MAILIMAP_MEDIA_BASIC_IMAGE:
561 type = "image"; 648 type = "image";
562 break; 649 break;
563 case MAILIMAP_MEDIA_BASIC_MESSAGE: 650 case MAILIMAP_MEDIA_BASIC_MESSAGE:
564 type = "message"; 651 type = "message";
565 break; 652 break;
566 case MAILIMAP_MEDIA_BASIC_VIDEO: 653 case MAILIMAP_MEDIA_BASIC_VIDEO:
567 type = "video"; 654 type = "video";
568 break; 655 break;
569 case MAILIMAP_MEDIA_BASIC_OTHER: 656 case MAILIMAP_MEDIA_BASIC_OTHER:
570 default: 657 default:
571 if (which->bd_media_basic->med_basic_type) { 658 if (which->bd_media_basic->med_basic_type) {
572 type = which->bd_media_basic->med_basic_type; 659 type = which->bd_media_basic->med_basic_type;
573 } else { 660 } else {
574 type = ""; 661 type = "";
575 } 662 }
576 break; 663 break;
577 } 664 }
578 if (which->bd_media_basic->med_subtype) { 665 if (which->bd_media_basic->med_subtype) {
579 sub = which->bd_media_basic->med_subtype; 666 sub = which->bd_media_basic->med_subtype;
580 } else { 667 } else {
581 sub = ""; 668 sub = "";
582 } 669 }
583 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 670 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
584 target_part.setType(type.lower()); 671 target_part.setType(type.lower());
585 target_part.setSubtype(sub.lower()); 672 target_part.setSubtype(sub.lower());
586 fillBodyFields(target_part,which->bd_fields); 673 fillBodyFields(target_part,which->bd_fields);
587} 674}
588 675
589void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 676void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
590{ 677{
591 if (!which) return; 678 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; 679 clistcell*cur;
601 mailimap_single_body_fld_param*param; 680 mailimap_single_body_fld_param*param;
602 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
603 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
604 } 683 }
605} 684}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index f809edb..5ea45f3 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,52 +1,53 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_body_type_basic; 10struct mailimap_body_type_basic;
11struct mailimap_body_type_mpart; 11struct mailimap_body_type_mpart;
12struct mailimap_body_fields; 12struct mailimap_body_fields;
13struct mailimap_msg_att; 13struct mailimap_msg_att;
14class RecMail; 14class RecMail;
15class RecBody; 15class RecBody;
16class RecPart; 16class RecPart;
17 17
18class IMAPwrapper : public QObject 18class IMAPwrapper : public QObject
19{ 19{
20 Q_OBJECT 20 Q_OBJECT
21 21
22public: 22public:
23 IMAPwrapper( IMAPaccount *a ); 23 IMAPwrapper( IMAPaccount *a );
24 virtual ~IMAPwrapper(); 24 virtual ~IMAPwrapper();
25 QList<IMAPFolder>* listFolders(); 25 QList<IMAPFolder>* listFolders();
26 void listMessages(const QString & mailbox,QList<RecMail>&target ); 26 void listMessages(const QString & mailbox,QList<RecMail>&target );
27 RecBody fetchBody(const RecMail&mail); 27 RecBody fetchBody(const RecMail&mail);
28 QString fetchPart(const RecMail&mail,QValueList<int>&path,bool internal_call=false);
28 static void imap_progress( size_t current, size_t maximum ); 29 static void imap_progress( size_t current, size_t maximum );
29 30
30protected: 31protected:
31 RecMail*parse_list_result(mailimap_msg_att*); 32 RecMail*parse_list_result(mailimap_msg_att*);
32 void login(); 33 void login();
33 void logout(); 34 void logout();
34 35
35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 36 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion); 37 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
37 38
38 void fillPlainBody(const RecMail&mail,RecBody&target_body); 39 void fillPlainBody(const RecMail&mail,RecBody&target_body);
39 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 40 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
40 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 41 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
41 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 42 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
42 43
43 /* just helpers */ 44 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 45 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
45 static QStringList address_list_to_stringlist(clist*list); 46 static QStringList address_list_to_stringlist(clist*list);
46 47
47private: 48private:
48 IMAPaccount *account; 49 IMAPaccount *account;
49 mailimap *m_imap; 50 mailimap *m_imap;
50}; 51};
51 52
52#endif 53#endif