summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp25
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp25
2 files changed, 22 insertions, 28 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 0178e33..89ec7ab 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -66,567 +66,564 @@ void IMAPwrapper::login()
66 if ( err != MAILIMAP_NO_ERROR && 66 if ( err != MAILIMAP_NO_ERROR &&
67 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 67 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
69 qDebug("error connecting server: %s",m_imap->imap_response); 69 qDebug("error connecting server: %s",m_imap->imap_response);
70 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
71 m_imap = 0; 71 m_imap = 0;
72 return; 72 return;
73 } 73 }
74 74
75 /* login */ 75 /* login */
76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
77 if ( err != MAILIMAP_NO_ERROR ) { 77 if ( err != MAILIMAP_NO_ERROR ) {
78 qDebug("error logging in imap: %s",m_imap->imap_response); 78 qDebug("error logging in imap: %s",m_imap->imap_response);
79 err = mailimap_close( m_imap ); 79 err = mailimap_close( m_imap );
80 mailimap_free( m_imap ); 80 mailimap_free( m_imap );
81 m_imap = 0; 81 m_imap = 0;
82 } 82 }
83} 83}
84 84
85void IMAPwrapper::logout() 85void IMAPwrapper::logout()
86{ 86{
87 int err = MAILIMAP_NO_ERROR; 87 int err = MAILIMAP_NO_ERROR;
88 if (!m_imap) return; 88 if (!m_imap) return;
89 err = mailimap_logout( m_imap ); 89 err = mailimap_logout( m_imap );
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93} 93}
94 94
95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
96{ 96{
97 const char *mb = 0; 97 const char *mb = 0;
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 clist *result = 0; 99 clist *result = 0;
100 clistcell *current; 100 clistcell *current;
101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
102 mailimap_fetch_type *fetchType = 0; 102 mailimap_fetch_type *fetchType = 0;
103 mailimap_set *set = 0; 103 mailimap_set *set = 0;
104 104
105 mb = mailbox.latin1(); 105 mb = mailbox.latin1();
106 login(); 106 login();
107 if (!m_imap) { 107 if (!m_imap) {
108 return; 108 return;
109 } 109 }
110 /* select mailbox READONLY for operations */ 110 /* select mailbox READONLY for operations */
111 err = mailimap_examine( m_imap, (char*)mb); 111 err = mailimap_examine( m_imap, (char*)mb);
112 if ( err != MAILIMAP_NO_ERROR ) { 112 if ( err != MAILIMAP_NO_ERROR ) {
113 qDebug("error selecting mailbox: %s",m_imap->imap_response); 113 qDebug("error selecting mailbox: %s",m_imap->imap_response);
114 return; 114 return;
115 } 115 }
116 116
117 int last = m_imap->imap_selection_info->sel_exists; 117 int last = m_imap->imap_selection_info->sel_exists;
118 118
119 if (last == 0) { 119 if (last == 0) {
120 qDebug("mailbox has no mails"); 120 qDebug("mailbox has no mails");
121 return; 121 return;
122 } 122 }
123 123
124 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
125 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
131 131
132 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
133 mailimap_set_free( set ); 133 mailimap_set_free( set );
134 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
135 135
136 QString date,subject,from; 136 QString date,subject,from;
137 137
138 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
139 mailimap_msg_att * msg_att; 139 mailimap_msg_att * msg_att;
140 int i = 0; 140 int i = 0;
141 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 141 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
142 ++i; 142 ++i;
143 msg_att = (mailimap_msg_att*)current->data; 143 msg_att = (mailimap_msg_att*)current->data;
144 RecMail*m = parse_list_result(msg_att); 144 RecMail*m = parse_list_result(msg_att);
145 if (m) { 145 if (m) {
146 m->setNumber(i); 146 m->setNumber(i);
147 m->setMbox(mailbox); 147 m->setMbox(mailbox);
148 m->setWrapper(this); 148 m->setWrapper(this);
149 target.append(m); 149 target.append(m);
150 } 150 }
151 } 151 }
152 } else { 152 } else {
153 qDebug("Error fetching headers: %s",m_imap->imap_response); 153 qDebug("Error fetching headers: %s",m_imap->imap_response);
154 } 154 }
155 if (result) mailimap_fetch_list_free(result); 155 if (result) mailimap_fetch_list_free(result);
156} 156}
157 157
158QList<Folder>* IMAPwrapper::listFolders() 158QList<Folder>* IMAPwrapper::listFolders()
159{ 159{
160 const char *path, *mask; 160 const char *path, *mask;
161 int err = MAILIMAP_NO_ERROR; 161 int err = MAILIMAP_NO_ERROR;
162 clist *result; 162 clist *result = 0;
163 clistcell *current; 163 clistcell *current = 0;
164 164
165 QList<Folder> * folders = new QList<Folder>(); 165 QList<Folder> * folders = new QList<Folder>();
166 folders->setAutoDelete( false ); 166 folders->setAutoDelete( false );
167 login(); 167 login();
168 if (!m_imap) { 168 if (!m_imap) {
169 return folders; 169 return folders;
170 } 170 }
171 171
172/* 172/*
173 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 173 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
174 * We must not forget to filter them out in next loop! 174 * We must not forget to filter them out in next loop!
175 * it seems like ugly code. and yes - it is ugly code. but the best way. 175 * it seems like ugly code. and yes - it is ugly code. but the best way.
176 */ 176 */
177 QString temp; 177 QString temp;
178 mask = "INBOX" ; 178 mask = "INBOX" ;
179 result = clist_new();
180 mailimap_mailbox_list *list; 179 mailimap_mailbox_list *list;
181 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 180 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
182 QString del; 181 QString del;
183 if ( err == MAILIMAP_NO_ERROR ) { 182 if ( err == MAILIMAP_NO_ERROR ) {
184 current = result->first; 183 current = result->first;
185 for ( int i = result->count; i > 0; i-- ) { 184 for ( int i = result->count; i > 0; i-- ) {
186 list = (mailimap_mailbox_list *) current->data; 185 list = (mailimap_mailbox_list *) current->data;
187 // it is better use the deep copy mechanism of qt itself 186 // it is better use the deep copy mechanism of qt itself
188 // instead of using strdup! 187 // instead of using strdup!
189 temp = list->mb_name; 188 temp = list->mb_name;
190 del = list->mb_delimiter; 189 del = list->mb_delimiter;
191 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 190 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
192 current = current->next; 191 current = current->next;
193 } 192 }
194 } else { 193 } else {
195 qDebug("error fetching folders: %s",m_imap->imap_response); 194 qDebug("error fetching folders: %s",m_imap->imap_response);
196 } 195 }
197 mailimap_list_result_free( result ); 196 mailimap_list_result_free( result );
198 197
199/* 198/*
200 * second stage - get the other then inbox folders 199 * second stage - get the other then inbox folders
201 */ 200 */
202 mask = "*" ; 201 mask = "*" ;
203 path = account->getPrefix().latin1(); 202 path = account->getPrefix().latin1();
204 if (!path) path = ""; 203 if (!path) path = "";
205 result = clist_new();
206 qDebug(path); 204 qDebug(path);
207 bool selectable = true; 205 bool selectable = true;
208 mailimap_mbx_list_flags*bflags; 206 mailimap_mbx_list_flags*bflags;
209 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 207 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
210 if ( err == MAILIMAP_NO_ERROR ) { 208 if ( err == MAILIMAP_NO_ERROR ) {
211 current = result->first; 209 current = result->first;
212 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 210 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
213 list = (mailimap_mailbox_list *) current->data; 211 list = (mailimap_mailbox_list *) current->data;
214 // it is better use the deep copy mechanism of qt itself 212 // it is better use the deep copy mechanism of qt itself
215 // instead of using strdup! 213 // instead of using strdup!
216 temp = list->mb_name; 214 temp = list->mb_name;
217 if (temp.lower()=="inbox") 215 if (temp.lower()=="inbox")
218 continue; 216 continue;
219 if (temp.lower()==account->getPrefix().lower()) 217 if (temp.lower()==account->getPrefix().lower())
220 continue; 218 continue;
221 if ( (bflags = list->mb_flag) ) { 219 if ( (bflags = list->mb_flag) ) {
222 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 220 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
223 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 221 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
224 } 222 }
225 del = list->mb_delimiter; 223 del = list->mb_delimiter;
226 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 224 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
227 } 225 }
228 } else { 226 } else {
229 qDebug("error fetching folders %s",m_imap->imap_response); 227 qDebug("error fetching folders %s",m_imap->imap_response);
230 } 228 }
231 mailimap_list_result_free( result ); 229 if (result) mailimap_list_result_free( result );
232 return folders; 230 return folders;
233} 231}
234 232
235RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 233RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
236{ 234{
237 RecMail * m = 0; 235 RecMail * m = 0;
238 mailimap_msg_att_item *item=0; 236 mailimap_msg_att_item *item=0;
239 clistcell *current,*c,*cf; 237 clistcell *current,*c,*cf;
240 mailimap_msg_att_dynamic*flist; 238 mailimap_msg_att_dynamic*flist;
241 mailimap_flag_fetch*cflag; 239 mailimap_flag_fetch*cflag;
242 int size; 240 int size;
243 QBitArray mFlags(7); 241 QBitArray mFlags(7);
244 QStringList addresslist; 242 QStringList addresslist;
245 243
246 if (!m_att) { 244 if (!m_att) {
247 return m; 245 return m;
248 } 246 }
249 m = new RecMail(); 247 m = new RecMail();
250 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 248 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
251 current = c; 249 current = c;
252 size = 0; 250 size = 0;
253 item = (mailimap_msg_att_item*)current->data; 251 item = (mailimap_msg_att_item*)current->data;
254 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 252 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
255 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 253 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
256 if (!flist->att_list) { 254 if (!flist->att_list) {
257 continue; 255 continue;
258 } 256 }
259 cf = flist->att_list->first; 257 cf = flist->att_list->first;
260 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 258 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
261 cflag = (mailimap_flag_fetch*)cf->data; 259 cflag = (mailimap_flag_fetch*)cf->data;
262 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 260 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
263 switch (cflag->fl_flag->fl_type) { 261 switch (cflag->fl_flag->fl_type) {
264 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 262 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
265 mFlags.setBit(FLAG_ANSWERED); 263 mFlags.setBit(FLAG_ANSWERED);
266 break; 264 break;
267 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 265 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
268 mFlags.setBit(FLAG_FLAGGED); 266 mFlags.setBit(FLAG_FLAGGED);
269 break; 267 break;
270 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 268 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
271 mFlags.setBit(FLAG_DELETED); 269 mFlags.setBit(FLAG_DELETED);
272 break; 270 break;
273 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 271 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
274 mFlags.setBit(FLAG_SEEN); 272 mFlags.setBit(FLAG_SEEN);
275 break; 273 break;
276 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 274 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
277 mFlags.setBit(FLAG_DRAFT); 275 mFlags.setBit(FLAG_DRAFT);
278 break; 276 break;
279 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 277 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
280 break; 278 break;
281 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 279 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
282 break; 280 break;
283 default: 281 default:
284 break; 282 break;
285 } 283 }
286 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 284 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
287 mFlags.setBit(FLAG_RECENT); 285 mFlags.setBit(FLAG_RECENT);
288 } 286 }
289 } 287 }
290 continue; 288 continue;
291 } 289 }
292 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 290 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
293 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 291 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
294 m->setDate(head->env_date); 292 m->setDate(head->env_date);
295 m->setSubject(convert_String((const char*)head->env_subject)); 293 m->setSubject(convert_String((const char*)head->env_subject));
296 //m->setSubject(head->env_subject); 294 //m->setSubject(head->env_subject);
297 if (head->env_from!=NULL) { 295 if (head->env_from!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_from->frm_list); 296 addresslist = address_list_to_stringlist(head->env_from->frm_list);
299 if (addresslist.count()) { 297 if (addresslist.count()) {
300 m->setFrom(addresslist.first()); 298 m->setFrom(addresslist.first());
301 } 299 }
302 } 300 }
303 if (head->env_to!=NULL) { 301 if (head->env_to!=NULL) {
304 addresslist = address_list_to_stringlist(head->env_to->to_list); 302 addresslist = address_list_to_stringlist(head->env_to->to_list);
305 m->setTo(addresslist); 303 m->setTo(addresslist);
306 } 304 }
307 if (head->env_cc!=NULL) { 305 if (head->env_cc!=NULL) {
308 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 306 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
309 m->setCC(addresslist); 307 m->setCC(addresslist);
310 } 308 }
311 if (head->env_bcc!=NULL) { 309 if (head->env_bcc!=NULL) {
312 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 310 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
313 m->setBcc(addresslist); 311 m->setBcc(addresslist);
314 } 312 }
315 if (head->env_reply_to!=NULL) { 313 if (head->env_reply_to!=NULL) {
316 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 314 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
317 if (addresslist.count()) { 315 if (addresslist.count()) {
318 m->setReplyto(addresslist.first()); 316 m->setReplyto(addresslist.first());
319 } 317 }
320 } 318 }
321 m->setMsgid(QString(head->env_message_id)); 319 m->setMsgid(QString(head->env_message_id));
322 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 320 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
323#if 0 321#if 0
324 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 322 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
325 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 323 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
326 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); 324 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);
327 qDebug(da.toString()); 325 qDebug(da.toString());
328#endif 326#endif
329 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 327 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
330 size = item->att_data.att_static->att_data.att_rfc822_size; 328 size = item->att_data.att_static->att_data.att_rfc822_size;
331 } 329 }
332 } 330 }
333 /* msg is already deleted */ 331 /* msg is already deleted */
334 if (mFlags.testBit(FLAG_DELETED) && m) { 332 if (mFlags.testBit(FLAG_DELETED) && m) {
335 delete m; 333 delete m;
336 m = 0; 334 m = 0;
337 } 335 }
338 if (m) { 336 if (m) {
339 m->setFlags(mFlags); 337 m->setFlags(mFlags);
340 m->setMsgsize(size); 338 m->setMsgsize(size);
341 } 339 }
342 return m; 340 return m;
343} 341}
344 342
345RecBody IMAPwrapper::fetchBody(const RecMail&mail) 343RecBody IMAPwrapper::fetchBody(const RecMail&mail)
346{ 344{
347 RecBody body; 345 RecBody body;
348 const char *mb; 346 const char *mb;
349 int err = MAILIMAP_NO_ERROR; 347 int err = MAILIMAP_NO_ERROR;
350 clist *result; 348 clist *result = 0;
351 clistcell *current; 349 clistcell *current;
352 mailimap_fetch_att *fetchAtt; 350 mailimap_fetch_att *fetchAtt = 0;
353 mailimap_fetch_type *fetchType; 351 mailimap_fetch_type *fetchType = 0;
354 mailimap_set *set; 352 mailimap_set *set = 0;
355 mailimap_body*body_desc; 353 mailimap_body*body_desc = 0;
356 354
357 mb = mail.getMbox().latin1(); 355 mb = mail.getMbox().latin1();
358 356
359 login(); 357 login();
360 if (!m_imap) { 358 if (!m_imap) {
361 return body; 359 return body;
362 } 360 }
363 361
364 err = mailimap_select( m_imap, (char*)mb); 362 err = mailimap_select( m_imap, (char*)mb);
365 if ( err != MAILIMAP_NO_ERROR ) { 363 if ( err != MAILIMAP_NO_ERROR ) {
366 qDebug("error selecting mailbox: %s",m_imap->imap_response); 364 qDebug("error selecting mailbox: %s",m_imap->imap_response);
367 return body; 365 return body;
368 } 366 }
369 367
370 result = clist_new();
371 /* the range has to start at 1!!! not with 0!!!! */ 368 /* the range has to start at 1!!! not with 0!!!! */
372 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 369 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
373 fetchAtt = mailimap_fetch_att_new_bodystructure(); 370 fetchAtt = mailimap_fetch_att_new_bodystructure();
374 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 371 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
375 err = mailimap_fetch( m_imap, set, fetchType, &result ); 372 err = mailimap_fetch( m_imap, set, fetchType, &result );
376 mailimap_set_free( set ); 373 mailimap_set_free( set );
377 mailimap_fetch_type_free( fetchType ); 374 mailimap_fetch_type_free( fetchType );
378 375
379 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 376 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
380 mailimap_msg_att * msg_att; 377 mailimap_msg_att * msg_att;
381 msg_att = (mailimap_msg_att*)current->data; 378 msg_att = (mailimap_msg_att*)current->data;
382 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 379 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
383 body_desc = item->att_data.att_static->att_data.att_body; 380 body_desc = item->att_data.att_static->att_data.att_body;
384 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 381 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
385 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 382 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
386 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 383 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
387 qDebug("Mulitpart mail"); 384 qDebug("Mulitpart mail");
388 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 385 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
389 } 386 }
390 } else { 387 } else {
391 qDebug("error fetching body: %s",m_imap->imap_response); 388 qDebug("error fetching body: %s",m_imap->imap_response);
392 } 389 }
393 mailimap_fetch_list_free(result); 390 if (result) mailimap_fetch_list_free(result);
394 return body; 391 return body;
395} 392}
396 393
397/* this routine is just called when the mail has only ONE part. 394/* this routine is just called when the mail has only ONE part.
398 for filling the parts of a multi-part-message there are other 395 for filling the parts of a multi-part-message there are other
399 routines 'cause we can not simply fetch the whole body. */ 396 routines 'cause we can not simply fetch the whole body. */
400void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 397void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
401{ 398{
402 if (!mailDescription) { 399 if (!mailDescription) {
403 return; 400 return;
404 } 401 }
405 QString sub,body_text; 402 QString sub,body_text;
406 RecPart singlePart; 403 RecPart singlePart;
407 QValueList<int> path; 404 QValueList<int> path;
408 fillSinglePart(singlePart,mailDescription); 405 fillSinglePart(singlePart,mailDescription);
409 switch (mailDescription->bd_type) { 406 switch (mailDescription->bd_type) {
410 case MAILIMAP_BODY_TYPE_1PART_MSG: 407 case MAILIMAP_BODY_TYPE_1PART_MSG:
411 path.append(1); 408 path.append(1);
412 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 409 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
413 target_body.setBodytext(body_text); 410 target_body.setBodytext(body_text);
414 target_body.setDescription(singlePart); 411 target_body.setDescription(singlePart);
415 break; 412 break;
416 case MAILIMAP_BODY_TYPE_1PART_TEXT: 413 case MAILIMAP_BODY_TYPE_1PART_TEXT:
417 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 414 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
418 path.append(1); 415 path.append(1);
419 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 416 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
420 target_body.setBodytext(body_text); 417 target_body.setBodytext(body_text);
421 target_body.setDescription(singlePart); 418 target_body.setDescription(singlePart);
422 break; 419 break;
423 case MAILIMAP_BODY_TYPE_1PART_BASIC: 420 case MAILIMAP_BODY_TYPE_1PART_BASIC:
424 qDebug("Single attachment"); 421 qDebug("Single attachment");
425 target_body.setBodytext(""); 422 target_body.setBodytext("");
426 target_body.addPart(singlePart); 423 target_body.addPart(singlePart);
427 break; 424 break;
428 default: 425 default:
429 break; 426 break;
430 } 427 }
431 428
432 return; 429 return;
433} 430}
434 431
435QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 432QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
436{ 433{
437 QStringList l; 434 QStringList l;
438 QString from; 435 QString from;
439 bool named_from; 436 bool named_from;
440 clistcell *current = NULL; 437 clistcell *current = NULL;
441 mailimap_address * current_address=NULL; 438 mailimap_address * current_address=NULL;
442 if (!list) { 439 if (!list) {
443 return l; 440 return l;
444 } 441 }
445 unsigned int count = 0; 442 unsigned int count = 0;
446 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 443 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
447 from = ""; 444 from = "";
448 named_from = false; 445 named_from = false;
449 current_address=(mailimap_address*)current->data; 446 current_address=(mailimap_address*)current->data;
450 if (current_address->ad_personal_name){ 447 if (current_address->ad_personal_name){
451 from+=convert_String((const char*)current_address->ad_personal_name); 448 from+=convert_String((const char*)current_address->ad_personal_name);
452 //from+=QString(current_address->ad_personal_name); 449 //from+=QString(current_address->ad_personal_name);
453 from+=" "; 450 from+=" ";
454 named_from = true; 451 named_from = true;
455 } 452 }
456 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
457 from+="<"; 454 from+="<";
458 } 455 }
459 if (current_address->ad_mailbox_name) { 456 if (current_address->ad_mailbox_name) {
460 from+=QString(current_address->ad_mailbox_name); 457 from+=QString(current_address->ad_mailbox_name);
461 from+="@"; 458 from+="@";
462 } 459 }
463 if (current_address->ad_host_name) { 460 if (current_address->ad_host_name) {
464 from+=QString(current_address->ad_host_name); 461 from+=QString(current_address->ad_host_name);
465 } 462 }
466 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 463 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
467 from+=">"; 464 from+=">";
468 } 465 }
469 l.append(QString(from)); 466 l.append(QString(from));
470 if (++count > 99) { 467 if (++count > 99) {
471 break; 468 break;
472 } 469 }
473 } 470 }
474 return l; 471 return l;
475} 472}
476 473
477encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 474encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
478{ 475{
479 encodedString*res=new encodedString; 476 encodedString*res=new encodedString;
480 const char*mb; 477 const char*mb;
481 int err; 478 int err;
482 mailimap_fetch_type *fetchType; 479 mailimap_fetch_type *fetchType;
483 mailimap_set *set; 480 mailimap_set *set;
484 clistcell*current,*cur; 481 clistcell*current,*cur;
485 482
486 login(); 483 login();
487 if (!m_imap) { 484 if (!m_imap) {
488 return res; 485 return res;
489 } 486 }
490 if (!internal_call) { 487 if (!internal_call) {
491 mb = mail.getMbox().latin1(); 488 mb = mail.getMbox().latin1();
492 err = mailimap_select( m_imap, (char*)mb); 489 err = mailimap_select( m_imap, (char*)mb);
493 if ( err != MAILIMAP_NO_ERROR ) { 490 if ( err != MAILIMAP_NO_ERROR ) {
494 qDebug("error selecting mailbox: %s",m_imap->imap_response); 491 qDebug("error selecting mailbox: %s",m_imap->imap_response);
495 return res; 492 return res;
496 } 493 }
497 } 494 }
498 set = mailimap_set_new_single(mail.getNumber()); 495 set = mailimap_set_new_single(mail.getNumber());
499 clist*id_list=clist_new(); 496 clist*id_list=clist_new();
500 for (unsigned j=0; j < path.count();++j) { 497 for (unsigned j=0; j < path.count();++j) {
501 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 498 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
502 *p_id = path[j]; 499 *p_id = path[j];
503 clist_append(id_list,p_id); 500 clist_append(id_list,p_id);
504 } 501 }
505 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 502 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
506 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 503 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
507 mailimap_section * section = mailimap_section_new(section_spec); 504 mailimap_section * section = mailimap_section_new(section_spec);
508 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 505 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
509 506
510 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 507 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
511 508
512 clist*result = clist_new(); 509 clist*result = 0;
513 510
514 err = mailimap_fetch( m_imap, set, fetchType, &result ); 511 err = mailimap_fetch( m_imap, set, fetchType, &result );
515 mailimap_set_free( set ); 512 mailimap_set_free( set );
516 mailimap_fetch_type_free( fetchType ); 513 mailimap_fetch_type_free( fetchType );
517 514
518 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 515 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
519 mailimap_msg_att * msg_att; 516 mailimap_msg_att * msg_att;
520 msg_att = (mailimap_msg_att*)current->data; 517 msg_att = (mailimap_msg_att*)current->data;
521 mailimap_msg_att_item*msg_att_item; 518 mailimap_msg_att_item*msg_att_item;
522 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 519 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
523 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 520 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
524 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 521 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
525 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 522 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
526 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 523 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
527 /* detach - we take over the content */ 524 /* detach - we take over the content */
528 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 525 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
529 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 526 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
530 } 527 }
531 } 528 }
532 } 529 }
533 } else { 530 } else {
534 qDebug("error fetching text: %s",m_imap->imap_response); 531 qDebug("error fetching text: %s",m_imap->imap_response);
535 } 532 }
536 mailimap_fetch_list_free(result); 533 if (result) mailimap_fetch_list_free(result);
537 return res; 534 return res;
538} 535}
539 536
540void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 537void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
541{ 538{
542 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 539 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
543 if (!mailDescription||current_recursion==10) { 540 if (!mailDescription||current_recursion==10) {
544 return; 541 return;
545 } 542 }
546 clistcell*current; 543 clistcell*current;
547 mailimap_body*current_body; 544 mailimap_body*current_body;
548 unsigned int count = 0; 545 unsigned int count = 0;
549 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 546 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
550 /* the point in the message */ 547 /* the point in the message */
551 ++count; 548 ++count;
552 current_body = (mailimap_body*)current->data; 549 current_body = (mailimap_body*)current->data;
553 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 550 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
554 QValueList<int>countlist = recList; 551 QValueList<int>countlist = recList;
555 countlist.append(count); 552 countlist.append(count);
556 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); 553 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist);
557 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 554 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
558 RecPart currentPart; 555 RecPart currentPart;
559 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 556 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
560 QValueList<int>countlist = recList; 557 QValueList<int>countlist = recList;
561 countlist.append(count); 558 countlist.append(count);
562 /* important: Check for is NULL 'cause a body can be empty! */ 559 /* important: Check for is NULL 'cause a body can be empty! */
563 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 560 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
564 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 561 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
565 target_body.setDescription(currentPart); 562 target_body.setDescription(currentPart);
566 target_body.setBodytext(body_text); 563 target_body.setBodytext(body_text);
567 } else { 564 } else {
568 QString id(""); 565 QString id("");
569 for (unsigned int j = 0; j < countlist.count();++j) { 566 for (unsigned int j = 0; j < countlist.count();++j) {
570 id+=(j>0?" ":""); 567 id+=(j>0?" ":"");
571 id+=QString("%1").arg(countlist[j]); 568 id+=QString("%1").arg(countlist[j]);
572 } 569 }
573 qDebug("ID= %s",id.latin1()); 570 qDebug("ID= %s",id.latin1());
574 currentPart.setIdentifier(id); 571 currentPart.setIdentifier(id);
575 currentPart.setPositionlist(countlist); 572 currentPart.setPositionlist(countlist);
576 target_body.addPart(currentPart); 573 target_body.addPart(currentPart);
577 } 574 }
578 } 575 }
579 } 576 }
580} 577}
581 578
582void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 579void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
583{ 580{
584 if (!Description) { 581 if (!Description) {
585 return; 582 return;
586 } 583 }
587 switch (Description->bd_type) { 584 switch (Description->bd_type) {
588 case MAILIMAP_BODY_TYPE_1PART_TEXT: 585 case MAILIMAP_BODY_TYPE_1PART_TEXT:
589 target_part.setType("text"); 586 target_part.setType("text");
590 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 587 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
591 break; 588 break;
592 case MAILIMAP_BODY_TYPE_1PART_BASIC: 589 case MAILIMAP_BODY_TYPE_1PART_BASIC:
593 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 590 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
594 break; 591 break;
595 case MAILIMAP_BODY_TYPE_1PART_MSG: 592 case MAILIMAP_BODY_TYPE_1PART_MSG:
596 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 593 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
597 break; 594 break;
598 default: 595 default:
599 break; 596 break;
600 } 597 }
601} 598}
602 599
603void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 600void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
604{ 601{
605 if (!which) { 602 if (!which) {
606 return; 603 return;
607 } 604 }
608 QString sub; 605 QString sub;
609 sub = which->bd_media_text; 606 sub = which->bd_media_text;
610 target_part.setSubtype(sub.lower()); 607 target_part.setSubtype(sub.lower());
611 target_part.setLines(which->bd_lines); 608 target_part.setLines(which->bd_lines);
612 fillBodyFields(target_part,which->bd_fields); 609 fillBodyFields(target_part,which->bd_fields);
613} 610}
614 611
615void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 612void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
616{ 613{
617 if (!which) { 614 if (!which) {
618 return; 615 return;
619 } 616 }
620// QString sub; 617// QString sub;
621// sub = which->bd_media_text; 618// sub = which->bd_media_text;
622// target_part.setSubtype(sub.lower()); 619// target_part.setSubtype(sub.lower());
623 qDebug("Message part"); 620 qDebug("Message part");
624 /* we set this type to text/plain */ 621 /* we set this type to text/plain */
625 target_part.setType("text"); 622 target_part.setType("text");
626 target_part.setSubtype("plain"); 623 target_part.setSubtype("plain");
627 target_part.setLines(which->bd_lines); 624 target_part.setLines(which->bd_lines);
628 fillBodyFields(target_part,which->bd_fields); 625 fillBodyFields(target_part,which->bd_fields);
629} 626}
630 627
631void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 628void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
632{ 629{
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 0178e33..89ec7ab 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -66,567 +66,564 @@ void IMAPwrapper::login()
66 if ( err != MAILIMAP_NO_ERROR && 66 if ( err != MAILIMAP_NO_ERROR &&
67 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 67 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
69 qDebug("error connecting server: %s",m_imap->imap_response); 69 qDebug("error connecting server: %s",m_imap->imap_response);
70 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
71 m_imap = 0; 71 m_imap = 0;
72 return; 72 return;
73 } 73 }
74 74
75 /* login */ 75 /* login */
76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
77 if ( err != MAILIMAP_NO_ERROR ) { 77 if ( err != MAILIMAP_NO_ERROR ) {
78 qDebug("error logging in imap: %s",m_imap->imap_response); 78 qDebug("error logging in imap: %s",m_imap->imap_response);
79 err = mailimap_close( m_imap ); 79 err = mailimap_close( m_imap );
80 mailimap_free( m_imap ); 80 mailimap_free( m_imap );
81 m_imap = 0; 81 m_imap = 0;
82 } 82 }
83} 83}
84 84
85void IMAPwrapper::logout() 85void IMAPwrapper::logout()
86{ 86{
87 int err = MAILIMAP_NO_ERROR; 87 int err = MAILIMAP_NO_ERROR;
88 if (!m_imap) return; 88 if (!m_imap) return;
89 err = mailimap_logout( m_imap ); 89 err = mailimap_logout( m_imap );
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93} 93}
94 94
95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
96{ 96{
97 const char *mb = 0; 97 const char *mb = 0;
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 clist *result = 0; 99 clist *result = 0;
100 clistcell *current; 100 clistcell *current;
101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
102 mailimap_fetch_type *fetchType = 0; 102 mailimap_fetch_type *fetchType = 0;
103 mailimap_set *set = 0; 103 mailimap_set *set = 0;
104 104
105 mb = mailbox.latin1(); 105 mb = mailbox.latin1();
106 login(); 106 login();
107 if (!m_imap) { 107 if (!m_imap) {
108 return; 108 return;
109 } 109 }
110 /* select mailbox READONLY for operations */ 110 /* select mailbox READONLY for operations */
111 err = mailimap_examine( m_imap, (char*)mb); 111 err = mailimap_examine( m_imap, (char*)mb);
112 if ( err != MAILIMAP_NO_ERROR ) { 112 if ( err != MAILIMAP_NO_ERROR ) {
113 qDebug("error selecting mailbox: %s",m_imap->imap_response); 113 qDebug("error selecting mailbox: %s",m_imap->imap_response);
114 return; 114 return;
115 } 115 }
116 116
117 int last = m_imap->imap_selection_info->sel_exists; 117 int last = m_imap->imap_selection_info->sel_exists;
118 118
119 if (last == 0) { 119 if (last == 0) {
120 qDebug("mailbox has no mails"); 120 qDebug("mailbox has no mails");
121 return; 121 return;
122 } 122 }
123 123
124 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
125 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
131 131
132 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
133 mailimap_set_free( set ); 133 mailimap_set_free( set );
134 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
135 135
136 QString date,subject,from; 136 QString date,subject,from;
137 137
138 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
139 mailimap_msg_att * msg_att; 139 mailimap_msg_att * msg_att;
140 int i = 0; 140 int i = 0;
141 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 141 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
142 ++i; 142 ++i;
143 msg_att = (mailimap_msg_att*)current->data; 143 msg_att = (mailimap_msg_att*)current->data;
144 RecMail*m = parse_list_result(msg_att); 144 RecMail*m = parse_list_result(msg_att);
145 if (m) { 145 if (m) {
146 m->setNumber(i); 146 m->setNumber(i);
147 m->setMbox(mailbox); 147 m->setMbox(mailbox);
148 m->setWrapper(this); 148 m->setWrapper(this);
149 target.append(m); 149 target.append(m);
150 } 150 }
151 } 151 }
152 } else { 152 } else {
153 qDebug("Error fetching headers: %s",m_imap->imap_response); 153 qDebug("Error fetching headers: %s",m_imap->imap_response);
154 } 154 }
155 if (result) mailimap_fetch_list_free(result); 155 if (result) mailimap_fetch_list_free(result);
156} 156}
157 157
158QList<Folder>* IMAPwrapper::listFolders() 158QList<Folder>* IMAPwrapper::listFolders()
159{ 159{
160 const char *path, *mask; 160 const char *path, *mask;
161 int err = MAILIMAP_NO_ERROR; 161 int err = MAILIMAP_NO_ERROR;
162 clist *result; 162 clist *result = 0;
163 clistcell *current; 163 clistcell *current = 0;
164 164
165 QList<Folder> * folders = new QList<Folder>(); 165 QList<Folder> * folders = new QList<Folder>();
166 folders->setAutoDelete( false ); 166 folders->setAutoDelete( false );
167 login(); 167 login();
168 if (!m_imap) { 168 if (!m_imap) {
169 return folders; 169 return folders;
170 } 170 }
171 171
172/* 172/*
173 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 173 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
174 * We must not forget to filter them out in next loop! 174 * We must not forget to filter them out in next loop!
175 * it seems like ugly code. and yes - it is ugly code. but the best way. 175 * it seems like ugly code. and yes - it is ugly code. but the best way.
176 */ 176 */
177 QString temp; 177 QString temp;
178 mask = "INBOX" ; 178 mask = "INBOX" ;
179 result = clist_new();
180 mailimap_mailbox_list *list; 179 mailimap_mailbox_list *list;
181 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 180 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
182 QString del; 181 QString del;
183 if ( err == MAILIMAP_NO_ERROR ) { 182 if ( err == MAILIMAP_NO_ERROR ) {
184 current = result->first; 183 current = result->first;
185 for ( int i = result->count; i > 0; i-- ) { 184 for ( int i = result->count; i > 0; i-- ) {
186 list = (mailimap_mailbox_list *) current->data; 185 list = (mailimap_mailbox_list *) current->data;
187 // it is better use the deep copy mechanism of qt itself 186 // it is better use the deep copy mechanism of qt itself
188 // instead of using strdup! 187 // instead of using strdup!
189 temp = list->mb_name; 188 temp = list->mb_name;
190 del = list->mb_delimiter; 189 del = list->mb_delimiter;
191 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 190 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
192 current = current->next; 191 current = current->next;
193 } 192 }
194 } else { 193 } else {
195 qDebug("error fetching folders: %s",m_imap->imap_response); 194 qDebug("error fetching folders: %s",m_imap->imap_response);
196 } 195 }
197 mailimap_list_result_free( result ); 196 mailimap_list_result_free( result );
198 197
199/* 198/*
200 * second stage - get the other then inbox folders 199 * second stage - get the other then inbox folders
201 */ 200 */
202 mask = "*" ; 201 mask = "*" ;
203 path = account->getPrefix().latin1(); 202 path = account->getPrefix().latin1();
204 if (!path) path = ""; 203 if (!path) path = "";
205 result = clist_new();
206 qDebug(path); 204 qDebug(path);
207 bool selectable = true; 205 bool selectable = true;
208 mailimap_mbx_list_flags*bflags; 206 mailimap_mbx_list_flags*bflags;
209 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 207 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
210 if ( err == MAILIMAP_NO_ERROR ) { 208 if ( err == MAILIMAP_NO_ERROR ) {
211 current = result->first; 209 current = result->first;
212 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 210 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
213 list = (mailimap_mailbox_list *) current->data; 211 list = (mailimap_mailbox_list *) current->data;
214 // it is better use the deep copy mechanism of qt itself 212 // it is better use the deep copy mechanism of qt itself
215 // instead of using strdup! 213 // instead of using strdup!
216 temp = list->mb_name; 214 temp = list->mb_name;
217 if (temp.lower()=="inbox") 215 if (temp.lower()=="inbox")
218 continue; 216 continue;
219 if (temp.lower()==account->getPrefix().lower()) 217 if (temp.lower()==account->getPrefix().lower())
220 continue; 218 continue;
221 if ( (bflags = list->mb_flag) ) { 219 if ( (bflags = list->mb_flag) ) {
222 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 220 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
223 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 221 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
224 } 222 }
225 del = list->mb_delimiter; 223 del = list->mb_delimiter;
226 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 224 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
227 } 225 }
228 } else { 226 } else {
229 qDebug("error fetching folders %s",m_imap->imap_response); 227 qDebug("error fetching folders %s",m_imap->imap_response);
230 } 228 }
231 mailimap_list_result_free( result ); 229 if (result) mailimap_list_result_free( result );
232 return folders; 230 return folders;
233} 231}
234 232
235RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 233RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
236{ 234{
237 RecMail * m = 0; 235 RecMail * m = 0;
238 mailimap_msg_att_item *item=0; 236 mailimap_msg_att_item *item=0;
239 clistcell *current,*c,*cf; 237 clistcell *current,*c,*cf;
240 mailimap_msg_att_dynamic*flist; 238 mailimap_msg_att_dynamic*flist;
241 mailimap_flag_fetch*cflag; 239 mailimap_flag_fetch*cflag;
242 int size; 240 int size;
243 QBitArray mFlags(7); 241 QBitArray mFlags(7);
244 QStringList addresslist; 242 QStringList addresslist;
245 243
246 if (!m_att) { 244 if (!m_att) {
247 return m; 245 return m;
248 } 246 }
249 m = new RecMail(); 247 m = new RecMail();
250 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 248 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
251 current = c; 249 current = c;
252 size = 0; 250 size = 0;
253 item = (mailimap_msg_att_item*)current->data; 251 item = (mailimap_msg_att_item*)current->data;
254 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 252 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
255 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 253 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
256 if (!flist->att_list) { 254 if (!flist->att_list) {
257 continue; 255 continue;
258 } 256 }
259 cf = flist->att_list->first; 257 cf = flist->att_list->first;
260 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 258 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
261 cflag = (mailimap_flag_fetch*)cf->data; 259 cflag = (mailimap_flag_fetch*)cf->data;
262 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 260 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
263 switch (cflag->fl_flag->fl_type) { 261 switch (cflag->fl_flag->fl_type) {
264 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 262 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
265 mFlags.setBit(FLAG_ANSWERED); 263 mFlags.setBit(FLAG_ANSWERED);
266 break; 264 break;
267 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 265 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
268 mFlags.setBit(FLAG_FLAGGED); 266 mFlags.setBit(FLAG_FLAGGED);
269 break; 267 break;
270 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 268 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
271 mFlags.setBit(FLAG_DELETED); 269 mFlags.setBit(FLAG_DELETED);
272 break; 270 break;
273 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 271 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
274 mFlags.setBit(FLAG_SEEN); 272 mFlags.setBit(FLAG_SEEN);
275 break; 273 break;
276 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 274 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
277 mFlags.setBit(FLAG_DRAFT); 275 mFlags.setBit(FLAG_DRAFT);
278 break; 276 break;
279 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 277 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
280 break; 278 break;
281 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 279 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
282 break; 280 break;
283 default: 281 default:
284 break; 282 break;
285 } 283 }
286 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 284 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
287 mFlags.setBit(FLAG_RECENT); 285 mFlags.setBit(FLAG_RECENT);
288 } 286 }
289 } 287 }
290 continue; 288 continue;
291 } 289 }
292 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 290 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
293 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 291 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
294 m->setDate(head->env_date); 292 m->setDate(head->env_date);
295 m->setSubject(convert_String((const char*)head->env_subject)); 293 m->setSubject(convert_String((const char*)head->env_subject));
296 //m->setSubject(head->env_subject); 294 //m->setSubject(head->env_subject);
297 if (head->env_from!=NULL) { 295 if (head->env_from!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_from->frm_list); 296 addresslist = address_list_to_stringlist(head->env_from->frm_list);
299 if (addresslist.count()) { 297 if (addresslist.count()) {
300 m->setFrom(addresslist.first()); 298 m->setFrom(addresslist.first());
301 } 299 }
302 } 300 }
303 if (head->env_to!=NULL) { 301 if (head->env_to!=NULL) {
304 addresslist = address_list_to_stringlist(head->env_to->to_list); 302 addresslist = address_list_to_stringlist(head->env_to->to_list);
305 m->setTo(addresslist); 303 m->setTo(addresslist);
306 } 304 }
307 if (head->env_cc!=NULL) { 305 if (head->env_cc!=NULL) {
308 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 306 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
309 m->setCC(addresslist); 307 m->setCC(addresslist);
310 } 308 }
311 if (head->env_bcc!=NULL) { 309 if (head->env_bcc!=NULL) {
312 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 310 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
313 m->setBcc(addresslist); 311 m->setBcc(addresslist);
314 } 312 }
315 if (head->env_reply_to!=NULL) { 313 if (head->env_reply_to!=NULL) {
316 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 314 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
317 if (addresslist.count()) { 315 if (addresslist.count()) {
318 m->setReplyto(addresslist.first()); 316 m->setReplyto(addresslist.first());
319 } 317 }
320 } 318 }
321 m->setMsgid(QString(head->env_message_id)); 319 m->setMsgid(QString(head->env_message_id));
322 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 320 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
323#if 0 321#if 0
324 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 322 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
325 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 323 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
326 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); 324 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);
327 qDebug(da.toString()); 325 qDebug(da.toString());
328#endif 326#endif
329 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 327 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
330 size = item->att_data.att_static->att_data.att_rfc822_size; 328 size = item->att_data.att_static->att_data.att_rfc822_size;
331 } 329 }
332 } 330 }
333 /* msg is already deleted */ 331 /* msg is already deleted */
334 if (mFlags.testBit(FLAG_DELETED) && m) { 332 if (mFlags.testBit(FLAG_DELETED) && m) {
335 delete m; 333 delete m;
336 m = 0; 334 m = 0;
337 } 335 }
338 if (m) { 336 if (m) {
339 m->setFlags(mFlags); 337 m->setFlags(mFlags);
340 m->setMsgsize(size); 338 m->setMsgsize(size);
341 } 339 }
342 return m; 340 return m;
343} 341}
344 342
345RecBody IMAPwrapper::fetchBody(const RecMail&mail) 343RecBody IMAPwrapper::fetchBody(const RecMail&mail)
346{ 344{
347 RecBody body; 345 RecBody body;
348 const char *mb; 346 const char *mb;
349 int err = MAILIMAP_NO_ERROR; 347 int err = MAILIMAP_NO_ERROR;
350 clist *result; 348 clist *result = 0;
351 clistcell *current; 349 clistcell *current;
352 mailimap_fetch_att *fetchAtt; 350 mailimap_fetch_att *fetchAtt = 0;
353 mailimap_fetch_type *fetchType; 351 mailimap_fetch_type *fetchType = 0;
354 mailimap_set *set; 352 mailimap_set *set = 0;
355 mailimap_body*body_desc; 353 mailimap_body*body_desc = 0;
356 354
357 mb = mail.getMbox().latin1(); 355 mb = mail.getMbox().latin1();
358 356
359 login(); 357 login();
360 if (!m_imap) { 358 if (!m_imap) {
361 return body; 359 return body;
362 } 360 }
363 361
364 err = mailimap_select( m_imap, (char*)mb); 362 err = mailimap_select( m_imap, (char*)mb);
365 if ( err != MAILIMAP_NO_ERROR ) { 363 if ( err != MAILIMAP_NO_ERROR ) {
366 qDebug("error selecting mailbox: %s",m_imap->imap_response); 364 qDebug("error selecting mailbox: %s",m_imap->imap_response);
367 return body; 365 return body;
368 } 366 }
369 367
370 result = clist_new();
371 /* the range has to start at 1!!! not with 0!!!! */ 368 /* the range has to start at 1!!! not with 0!!!! */
372 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 369 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
373 fetchAtt = mailimap_fetch_att_new_bodystructure(); 370 fetchAtt = mailimap_fetch_att_new_bodystructure();
374 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 371 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
375 err = mailimap_fetch( m_imap, set, fetchType, &result ); 372 err = mailimap_fetch( m_imap, set, fetchType, &result );
376 mailimap_set_free( set ); 373 mailimap_set_free( set );
377 mailimap_fetch_type_free( fetchType ); 374 mailimap_fetch_type_free( fetchType );
378 375
379 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 376 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
380 mailimap_msg_att * msg_att; 377 mailimap_msg_att * msg_att;
381 msg_att = (mailimap_msg_att*)current->data; 378 msg_att = (mailimap_msg_att*)current->data;
382 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 379 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
383 body_desc = item->att_data.att_static->att_data.att_body; 380 body_desc = item->att_data.att_static->att_data.att_body;
384 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 381 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
385 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 382 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
386 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 383 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
387 qDebug("Mulitpart mail"); 384 qDebug("Mulitpart mail");
388 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 385 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
389 } 386 }
390 } else { 387 } else {
391 qDebug("error fetching body: %s",m_imap->imap_response); 388 qDebug("error fetching body: %s",m_imap->imap_response);
392 } 389 }
393 mailimap_fetch_list_free(result); 390 if (result) mailimap_fetch_list_free(result);
394 return body; 391 return body;
395} 392}
396 393
397/* this routine is just called when the mail has only ONE part. 394/* this routine is just called when the mail has only ONE part.
398 for filling the parts of a multi-part-message there are other 395 for filling the parts of a multi-part-message there are other
399 routines 'cause we can not simply fetch the whole body. */ 396 routines 'cause we can not simply fetch the whole body. */
400void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 397void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
401{ 398{
402 if (!mailDescription) { 399 if (!mailDescription) {
403 return; 400 return;
404 } 401 }
405 QString sub,body_text; 402 QString sub,body_text;
406 RecPart singlePart; 403 RecPart singlePart;
407 QValueList<int> path; 404 QValueList<int> path;
408 fillSinglePart(singlePart,mailDescription); 405 fillSinglePart(singlePart,mailDescription);
409 switch (mailDescription->bd_type) { 406 switch (mailDescription->bd_type) {
410 case MAILIMAP_BODY_TYPE_1PART_MSG: 407 case MAILIMAP_BODY_TYPE_1PART_MSG:
411 path.append(1); 408 path.append(1);
412 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 409 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
413 target_body.setBodytext(body_text); 410 target_body.setBodytext(body_text);
414 target_body.setDescription(singlePart); 411 target_body.setDescription(singlePart);
415 break; 412 break;
416 case MAILIMAP_BODY_TYPE_1PART_TEXT: 413 case MAILIMAP_BODY_TYPE_1PART_TEXT:
417 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 414 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
418 path.append(1); 415 path.append(1);
419 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 416 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
420 target_body.setBodytext(body_text); 417 target_body.setBodytext(body_text);
421 target_body.setDescription(singlePart); 418 target_body.setDescription(singlePart);
422 break; 419 break;
423 case MAILIMAP_BODY_TYPE_1PART_BASIC: 420 case MAILIMAP_BODY_TYPE_1PART_BASIC:
424 qDebug("Single attachment"); 421 qDebug("Single attachment");
425 target_body.setBodytext(""); 422 target_body.setBodytext("");
426 target_body.addPart(singlePart); 423 target_body.addPart(singlePart);
427 break; 424 break;
428 default: 425 default:
429 break; 426 break;
430 } 427 }
431 428
432 return; 429 return;
433} 430}
434 431
435QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 432QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
436{ 433{
437 QStringList l; 434 QStringList l;
438 QString from; 435 QString from;
439 bool named_from; 436 bool named_from;
440 clistcell *current = NULL; 437 clistcell *current = NULL;
441 mailimap_address * current_address=NULL; 438 mailimap_address * current_address=NULL;
442 if (!list) { 439 if (!list) {
443 return l; 440 return l;
444 } 441 }
445 unsigned int count = 0; 442 unsigned int count = 0;
446 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 443 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
447 from = ""; 444 from = "";
448 named_from = false; 445 named_from = false;
449 current_address=(mailimap_address*)current->data; 446 current_address=(mailimap_address*)current->data;
450 if (current_address->ad_personal_name){ 447 if (current_address->ad_personal_name){
451 from+=convert_String((const char*)current_address->ad_personal_name); 448 from+=convert_String((const char*)current_address->ad_personal_name);
452 //from+=QString(current_address->ad_personal_name); 449 //from+=QString(current_address->ad_personal_name);
453 from+=" "; 450 from+=" ";
454 named_from = true; 451 named_from = true;
455 } 452 }
456 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
457 from+="<"; 454 from+="<";
458 } 455 }
459 if (current_address->ad_mailbox_name) { 456 if (current_address->ad_mailbox_name) {
460 from+=QString(current_address->ad_mailbox_name); 457 from+=QString(current_address->ad_mailbox_name);
461 from+="@"; 458 from+="@";
462 } 459 }
463 if (current_address->ad_host_name) { 460 if (current_address->ad_host_name) {
464 from+=QString(current_address->ad_host_name); 461 from+=QString(current_address->ad_host_name);
465 } 462 }
466 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 463 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
467 from+=">"; 464 from+=">";
468 } 465 }
469 l.append(QString(from)); 466 l.append(QString(from));
470 if (++count > 99) { 467 if (++count > 99) {
471 break; 468 break;
472 } 469 }
473 } 470 }
474 return l; 471 return l;
475} 472}
476 473
477encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 474encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
478{ 475{
479 encodedString*res=new encodedString; 476 encodedString*res=new encodedString;
480 const char*mb; 477 const char*mb;
481 int err; 478 int err;
482 mailimap_fetch_type *fetchType; 479 mailimap_fetch_type *fetchType;
483 mailimap_set *set; 480 mailimap_set *set;
484 clistcell*current,*cur; 481 clistcell*current,*cur;
485 482
486 login(); 483 login();
487 if (!m_imap) { 484 if (!m_imap) {
488 return res; 485 return res;
489 } 486 }
490 if (!internal_call) { 487 if (!internal_call) {
491 mb = mail.getMbox().latin1(); 488 mb = mail.getMbox().latin1();
492 err = mailimap_select( m_imap, (char*)mb); 489 err = mailimap_select( m_imap, (char*)mb);
493 if ( err != MAILIMAP_NO_ERROR ) { 490 if ( err != MAILIMAP_NO_ERROR ) {
494 qDebug("error selecting mailbox: %s",m_imap->imap_response); 491 qDebug("error selecting mailbox: %s",m_imap->imap_response);
495 return res; 492 return res;
496 } 493 }
497 } 494 }
498 set = mailimap_set_new_single(mail.getNumber()); 495 set = mailimap_set_new_single(mail.getNumber());
499 clist*id_list=clist_new(); 496 clist*id_list=clist_new();
500 for (unsigned j=0; j < path.count();++j) { 497 for (unsigned j=0; j < path.count();++j) {
501 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 498 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
502 *p_id = path[j]; 499 *p_id = path[j];
503 clist_append(id_list,p_id); 500 clist_append(id_list,p_id);
504 } 501 }
505 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 502 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
506 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 503 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
507 mailimap_section * section = mailimap_section_new(section_spec); 504 mailimap_section * section = mailimap_section_new(section_spec);
508 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 505 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
509 506
510 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 507 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
511 508
512 clist*result = clist_new(); 509 clist*result = 0;
513 510
514 err = mailimap_fetch( m_imap, set, fetchType, &result ); 511 err = mailimap_fetch( m_imap, set, fetchType, &result );
515 mailimap_set_free( set ); 512 mailimap_set_free( set );
516 mailimap_fetch_type_free( fetchType ); 513 mailimap_fetch_type_free( fetchType );
517 514
518 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 515 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
519 mailimap_msg_att * msg_att; 516 mailimap_msg_att * msg_att;
520 msg_att = (mailimap_msg_att*)current->data; 517 msg_att = (mailimap_msg_att*)current->data;
521 mailimap_msg_att_item*msg_att_item; 518 mailimap_msg_att_item*msg_att_item;
522 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 519 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
523 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 520 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
524 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 521 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
525 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 522 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
526 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 523 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
527 /* detach - we take over the content */ 524 /* detach - we take over the content */
528 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 525 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
529 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 526 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
530 } 527 }
531 } 528 }
532 } 529 }
533 } else { 530 } else {
534 qDebug("error fetching text: %s",m_imap->imap_response); 531 qDebug("error fetching text: %s",m_imap->imap_response);
535 } 532 }
536 mailimap_fetch_list_free(result); 533 if (result) mailimap_fetch_list_free(result);
537 return res; 534 return res;
538} 535}
539 536
540void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 537void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
541{ 538{
542 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 539 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
543 if (!mailDescription||current_recursion==10) { 540 if (!mailDescription||current_recursion==10) {
544 return; 541 return;
545 } 542 }
546 clistcell*current; 543 clistcell*current;
547 mailimap_body*current_body; 544 mailimap_body*current_body;
548 unsigned int count = 0; 545 unsigned int count = 0;
549 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 546 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
550 /* the point in the message */ 547 /* the point in the message */
551 ++count; 548 ++count;
552 current_body = (mailimap_body*)current->data; 549 current_body = (mailimap_body*)current->data;
553 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 550 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
554 QValueList<int>countlist = recList; 551 QValueList<int>countlist = recList;
555 countlist.append(count); 552 countlist.append(count);
556 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); 553 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist);
557 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 554 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
558 RecPart currentPart; 555 RecPart currentPart;
559 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 556 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
560 QValueList<int>countlist = recList; 557 QValueList<int>countlist = recList;
561 countlist.append(count); 558 countlist.append(count);
562 /* important: Check for is NULL 'cause a body can be empty! */ 559 /* important: Check for is NULL 'cause a body can be empty! */
563 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 560 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
564 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 561 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
565 target_body.setDescription(currentPart); 562 target_body.setDescription(currentPart);
566 target_body.setBodytext(body_text); 563 target_body.setBodytext(body_text);
567 } else { 564 } else {
568 QString id(""); 565 QString id("");
569 for (unsigned int j = 0; j < countlist.count();++j) { 566 for (unsigned int j = 0; j < countlist.count();++j) {
570 id+=(j>0?" ":""); 567 id+=(j>0?" ":"");
571 id+=QString("%1").arg(countlist[j]); 568 id+=QString("%1").arg(countlist[j]);
572 } 569 }
573 qDebug("ID= %s",id.latin1()); 570 qDebug("ID= %s",id.latin1());
574 currentPart.setIdentifier(id); 571 currentPart.setIdentifier(id);
575 currentPart.setPositionlist(countlist); 572 currentPart.setPositionlist(countlist);
576 target_body.addPart(currentPart); 573 target_body.addPart(currentPart);
577 } 574 }
578 } 575 }
579 } 576 }
580} 577}
581 578
582void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 579void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
583{ 580{
584 if (!Description) { 581 if (!Description) {
585 return; 582 return;
586 } 583 }
587 switch (Description->bd_type) { 584 switch (Description->bd_type) {
588 case MAILIMAP_BODY_TYPE_1PART_TEXT: 585 case MAILIMAP_BODY_TYPE_1PART_TEXT:
589 target_part.setType("text"); 586 target_part.setType("text");
590 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 587 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
591 break; 588 break;
592 case MAILIMAP_BODY_TYPE_1PART_BASIC: 589 case MAILIMAP_BODY_TYPE_1PART_BASIC:
593 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 590 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
594 break; 591 break;
595 case MAILIMAP_BODY_TYPE_1PART_MSG: 592 case MAILIMAP_BODY_TYPE_1PART_MSG:
596 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 593 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
597 break; 594 break;
598 default: 595 default:
599 break; 596 break;
600 } 597 }
601} 598}
602 599
603void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 600void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
604{ 601{
605 if (!which) { 602 if (!which) {
606 return; 603 return;
607 } 604 }
608 QString sub; 605 QString sub;
609 sub = which->bd_media_text; 606 sub = which->bd_media_text;
610 target_part.setSubtype(sub.lower()); 607 target_part.setSubtype(sub.lower());
611 target_part.setLines(which->bd_lines); 608 target_part.setLines(which->bd_lines);
612 fillBodyFields(target_part,which->bd_fields); 609 fillBodyFields(target_part,which->bd_fields);
613} 610}
614 611
615void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 612void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
616{ 613{
617 if (!which) { 614 if (!which) {
618 return; 615 return;
619 } 616 }
620// QString sub; 617// QString sub;
621// sub = which->bd_media_text; 618// sub = which->bd_media_text;
622// target_part.setSubtype(sub.lower()); 619// target_part.setSubtype(sub.lower());
623 qDebug("Message part"); 620 qDebug("Message part");
624 /* we set this type to text/plain */ 621 /* we set this type to text/plain */
625 target_part.setType("text"); 622 target_part.setType("text");
626 target_part.setSubtype("plain"); 623 target_part.setSubtype("plain");
627 target_part.setLines(which->bd_lines); 624 target_part.setLines(which->bd_lines);
628 fillBodyFields(target_part,which->bd_fields); 625 fillBodyFields(target_part,which->bd_fields);
629} 626}
630 627
631void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 628void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
632{ 629{