-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index be825ef..ca1c7f1 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -150,593 +150,604 @@ void IMAPwrapper::login() | |||
150 | // cancel | 150 | // cancel |
151 | return; | 151 | return; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | user = account->getUser(); | 154 | user = account->getUser(); |
155 | pass = account->getPassword(); | 155 | pass = account->getPassword(); |
156 | } | 156 | } |
157 | 157 | ||
158 | m_imap = mailimap_new( 20, &imap_progress ); | 158 | m_imap = mailimap_new( 20, &imap_progress ); |
159 | 159 | ||
160 | /* connect */ | 160 | /* connect */ |
161 | bool ssl = false; | 161 | bool ssl = false; |
162 | bool try_tls = false; | 162 | bool try_tls = false; |
163 | bool force_tls = false; | 163 | bool force_tls = false; |
164 | 164 | ||
165 | if ( account->ConnectionType() == 2 ) { | 165 | if ( account->ConnectionType() == 2 ) { |
166 | ssl = true; | 166 | ssl = true; |
167 | } | 167 | } |
168 | if (account->ConnectionType()==1) { | 168 | if (account->ConnectionType()==1) { |
169 | force_tls = true; | 169 | force_tls = true; |
170 | } | 170 | } |
171 | 171 | ||
172 | if ( ssl ) { | 172 | if ( ssl ) { |
173 | qDebug("using ssl "); | 173 | qDebug("using ssl "); |
174 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 174 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
175 | } else { | 175 | } else { |
176 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 176 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
177 | } | 177 | } |
178 | 178 | ||
179 | if ( err != MAILIMAP_NO_ERROR && | 179 | if ( err != MAILIMAP_NO_ERROR && |
180 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 180 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
181 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 181 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
182 | QString failure = ""; | 182 | QString failure = ""; |
183 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 183 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
184 | failure="Connection refused"; | 184 | failure="Connection refused"; |
185 | } else { | 185 | } else { |
186 | failure="Unknown failure"; | 186 | failure="Unknown failure"; |
187 | } | 187 | } |
188 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 188 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
189 | mailimap_free( m_imap ); | 189 | mailimap_free( m_imap ); |
190 | m_imap = 0; | 190 | m_imap = 0; |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | 193 | ||
194 | if (!ssl) { | 194 | if (!ssl) { |
195 | try_tls = start_tls(force_tls); | 195 | try_tls = start_tls(force_tls); |
196 | } | 196 | } |
197 | 197 | ||
198 | bool ok = true; | 198 | bool ok = true; |
199 | if (force_tls && !try_tls) { | 199 | if (force_tls && !try_tls) { |
200 | Global::statusMessage(tr("Server has no TLS support!")); | 200 | Global::statusMessage(tr("Server has no TLS support!")); |
201 | ok = false; | 201 | ok = false; |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | /* login */ | 205 | /* login */ |
206 | 206 | ||
207 | if (ok) { | 207 | if (ok) { |
208 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 208 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
209 | if ( err != MAILIMAP_NO_ERROR ) { | 209 | if ( err != MAILIMAP_NO_ERROR ) { |
210 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 210 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
211 | ok = false; | 211 | ok = false; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | if (!ok) { | 214 | if (!ok) { |
215 | err = mailimap_close( m_imap ); | 215 | err = mailimap_close( m_imap ); |
216 | mailimap_free( m_imap ); | 216 | mailimap_free( m_imap ); |
217 | m_imap = 0; | 217 | m_imap = 0; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | 220 | ||
221 | void IMAPwrapper::logout() | 221 | void IMAPwrapper::logout() |
222 | { | 222 | { |
223 | int err = MAILIMAP_NO_ERROR; | 223 | int err = MAILIMAP_NO_ERROR; |
224 | if (!m_imap) return; | 224 | if (!m_imap) return; |
225 | err = mailimap_logout( m_imap ); | 225 | err = mailimap_logout( m_imap ); |
226 | err = mailimap_close( m_imap ); | 226 | err = mailimap_close( m_imap ); |
227 | mailimap_free( m_imap ); | 227 | mailimap_free( m_imap ); |
228 | m_imap = 0; | 228 | m_imap = 0; |
229 | m_Lastmbox = ""; | 229 | m_Lastmbox = ""; |
230 | } | 230 | } |
231 | 231 | ||
232 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) | 232 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) |
233 | { | 233 | { |
234 | int err = MAILIMAP_NO_ERROR; | 234 | int err = MAILIMAP_NO_ERROR; |
235 | clist *result = 0; | 235 | clist *result = 0; |
236 | clistcell *current; | 236 | clistcell *current; |
237 | mailimap_fetch_type *fetchType = 0; | 237 | mailimap_fetch_type *fetchType = 0; |
238 | mailimap_set *set = 0; | 238 | mailimap_set *set = 0; |
239 | 239 | ||
240 | login(); | 240 | login(); |
241 | if (!m_imap) { | 241 | if (!m_imap) { |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | /* select mailbox READONLY for operations */ | 244 | /* select mailbox READONLY for operations */ |
245 | err = selectMbox(mailbox); | 245 | err = selectMbox(mailbox); |
246 | if ( err != MAILIMAP_NO_ERROR ) { | 246 | if ( err != MAILIMAP_NO_ERROR ) { |
247 | return; | 247 | return; |
248 | } | 248 | } |
249 | 249 | ||
250 | int last = m_imap->imap_selection_info->sel_exists; | 250 | int last = m_imap->imap_selection_info->sel_exists; |
251 | 251 | ||
252 | if (last == 0) { | 252 | if (last == 0) { |
253 | Global::statusMessage(tr("Mailbox has no mails")); | 253 | Global::statusMessage(tr("Mailbox has no mails")); |
254 | return; | 254 | return; |
255 | } else { | 255 | } else { |
256 | } | 256 | } |
257 | 257 | ||
258 | /* the range has to start at 1!!! not with 0!!!! */ | 258 | /* the range has to start at 1!!! not with 0!!!! */ |
259 | set = mailimap_set_new_interval( 1, last ); | 259 | set = mailimap_set_new_interval( 1, last ); |
260 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 260 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
261 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 261 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
262 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 262 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
263 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 263 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
264 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 264 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
265 | 265 | ||
266 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 266 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
267 | mailimap_set_free( set ); | 267 | mailimap_set_free( set ); |
268 | mailimap_fetch_type_free( fetchType ); | 268 | mailimap_fetch_type_free( fetchType ); |
269 | 269 | ||
270 | QString date,subject,from; | 270 | QString date,subject,from; |
271 | 271 | ||
272 | if ( err == MAILIMAP_NO_ERROR ) { | 272 | if ( err == MAILIMAP_NO_ERROR ) { |
273 | mailimap_msg_att * msg_att; | 273 | mailimap_msg_att * msg_att; |
274 | int i = 0; | 274 | int i = 0; |
275 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 275 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
276 | ++i; | 276 | ++i; |
277 | msg_att = (mailimap_msg_att*)current->data; | 277 | msg_att = (mailimap_msg_att*)current->data; |
278 | RecMail*m = parse_list_result(msg_att); | 278 | RecMail*m = parse_list_result(msg_att); |
279 | if (m) { | 279 | if (m) { |
280 | if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { | 280 | if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { |
281 | m->setNumber(i); | 281 | m->setNumber(i); |
282 | m->setMbox(mailbox); | 282 | m->setMbox(mailbox); |
283 | m->setWrapper(this); | 283 | m->setWrapper(this); |
284 | target.append(m); | 284 | target.append(m); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | } | 287 | } |
288 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); | 288 | Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); |
289 | } else { | 289 | } else { |
290 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 290 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
291 | } | 291 | } |
292 | if (result) mailimap_fetch_list_free(result); | 292 | if (result) mailimap_fetch_list_free(result); |
293 | } | 293 | } |
294 | 294 | ||
295 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() | 295 | QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() |
296 | { | 296 | { |
297 | const char *path, *mask; | 297 | const char *path, *mask; |
298 | int err = MAILIMAP_NO_ERROR; | 298 | int err = MAILIMAP_NO_ERROR; |
299 | clist *result = 0; | 299 | clist *result = 0; |
300 | clistcell *current = 0; | 300 | clistcell *current = 0; |
301 | clistcell*cur_flag = 0; | 301 | clistcell*cur_flag = 0; |
302 | mailimap_mbx_list_flags*bflags = 0; | 302 | mailimap_mbx_list_flags*bflags = 0; |
303 | 303 | ||
304 | QValueList<FolderP>* folders = new QValueList<FolderP>(); | 304 | QValueList<FolderP>* folders = new QValueList<FolderP>(); |
305 | login(); | 305 | login(); |
306 | if (!m_imap) { | 306 | if (!m_imap) { |
307 | return folders; | 307 | return folders; |
308 | } | 308 | } |
309 | 309 | ||
310 | /* | 310 | /* |
311 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 311 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
312 | * We must not forget to filter them out in next loop! | 312 | * We must not forget to filter them out in next loop! |
313 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 313 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
314 | */ | 314 | */ |
315 | QString temp; | 315 | QString temp; |
316 | mask = "INBOX" ; | 316 | mask = "INBOX" ; |
317 | mailimap_mailbox_list *list; | 317 | mailimap_mailbox_list *list; |
318 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 318 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
319 | QString del; | 319 | QString del; |
320 | bool selectable = true; | 320 | bool selectable = true; |
321 | bool no_inferiors = false; | 321 | bool no_inferiors = false; |
322 | if ( err == MAILIMAP_NO_ERROR ) { | 322 | if ( err == MAILIMAP_NO_ERROR ) { |
323 | current = result->first; | 323 | current = result->first; |
324 | for ( int i = result->count; i > 0; i-- ) { | 324 | for ( int i = result->count; i > 0; i-- ) { |
325 | list = (mailimap_mailbox_list *) current->data; | 325 | list = (mailimap_mailbox_list *) current->data; |
326 | // it is better use the deep copy mechanism of qt itself | 326 | // it is better use the deep copy mechanism of qt itself |
327 | // instead of using strdup! | 327 | // instead of using strdup! |
328 | temp = list->mb_name; | 328 | temp = list->mb_name; |
329 | del = list->mb_delimiter; | 329 | del = list->mb_delimiter; |
330 | current = current->next; | 330 | current = current->next; |
331 | if ( (bflags = list->mb_flag) ) { | 331 | if ( (bflags = list->mb_flag) ) { |
332 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 332 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
333 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 333 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
334 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 334 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
335 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 335 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
336 | no_inferiors = true; | 336 | no_inferiors = true; |
337 | } | 337 | } |
338 | } | 338 | } |
339 | } | 339 | } |
340 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 340 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
341 | } | 341 | } |
342 | } else { | 342 | } else { |
343 | qDebug("error fetching folders: "); | 343 | qDebug("error fetching folders: "); |
344 | 344 | ||
345 | } | 345 | } |
346 | mailimap_list_result_free( result ); | 346 | mailimap_list_result_free( result ); |
347 | 347 | ||
348 | /* | 348 | /* |
349 | * second stage - get the other then inbox folders | 349 | * second stage - get the other then inbox folders |
350 | */ | 350 | */ |
351 | mask = "*" ; | 351 | mask = "*" ; |
352 | path = account->getPrefix().latin1(); | 352 | path = account->getPrefix().latin1(); |
353 | if (!path) path = ""; | 353 | if (!path) path = ""; |
354 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 354 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
355 | if ( err == MAILIMAP_NO_ERROR ) { | 355 | if ( err == MAILIMAP_NO_ERROR ) { |
356 | current = result->first; | 356 | current = result->first; |
357 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 357 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
358 | no_inferiors = false; | 358 | no_inferiors = false; |
359 | list = (mailimap_mailbox_list *) current->data; | 359 | list = (mailimap_mailbox_list *) current->data; |
360 | // it is better use the deep copy mechanism of qt itself | 360 | // it is better use the deep copy mechanism of qt itself |
361 | // instead of using strdup! | 361 | // instead of using strdup! |
362 | temp = list->mb_name; | 362 | temp = list->mb_name; |
363 | if (temp.lower()=="inbox") | 363 | if (temp.lower()=="inbox") |
364 | continue; | 364 | continue; |
365 | if (temp.lower()==account->getPrefix().lower()) | 365 | if (temp.lower()==account->getPrefix().lower()) |
366 | continue; | 366 | continue; |
367 | if ( (bflags = list->mb_flag) ) { | 367 | if ( (bflags = list->mb_flag) ) { |
368 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 368 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
369 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 369 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
370 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 370 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
371 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 371 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
372 | no_inferiors = true; | 372 | no_inferiors = true; |
373 | } | 373 | } |
374 | } | 374 | } |
375 | } | 375 | } |
376 | del = list->mb_delimiter; | 376 | del = list->mb_delimiter; |
377 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 377 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
378 | } | 378 | } |
379 | } else { | 379 | } else { |
380 | qDebug("error fetching folders "); | 380 | qDebug("error fetching folders "); |
381 | 381 | ||
382 | } | 382 | } |
383 | if (result) mailimap_list_result_free( result ); | 383 | if (result) mailimap_list_result_free( result ); |
384 | return folders; | 384 | return folders; |
385 | } | 385 | } |
386 | 386 | ||
387 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 387 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
388 | { | 388 | { |
389 | RecMail * m = 0; | 389 | RecMail * m = 0; |
390 | mailimap_msg_att_item *item=0; | 390 | mailimap_msg_att_item *item=0; |
391 | clistcell *current,*c,*cf; | 391 | clistcell *current,*c,*cf; |
392 | mailimap_msg_att_dynamic*flist; | 392 | mailimap_msg_att_dynamic*flist; |
393 | mailimap_flag_fetch*cflag; | 393 | mailimap_flag_fetch*cflag; |
394 | int size; | 394 | int size; |
395 | QBitArray mFlags(7); | 395 | QBitArray mFlags(7); |
396 | QStringList addresslist; | 396 | QStringList addresslist; |
397 | 397 | ||
398 | if (!m_att) { | 398 | if (!m_att) { |
399 | return m; | 399 | return m; |
400 | } | 400 | } |
401 | m = new RecMail(); | 401 | m = new RecMail(); |
402 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 402 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
403 | current = c; | 403 | current = c; |
404 | size = 0; | 404 | size = 0; |
405 | item = (mailimap_msg_att_item*)current->data; | 405 | item = (mailimap_msg_att_item*)current->data; |
406 | if ( !item ) | ||
407 | continue; | ||
406 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 408 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
407 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 409 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
408 | if (!flist->att_list) { | 410 | if (!flist || !flist->att_list) { |
409 | continue; | 411 | continue; |
410 | } | 412 | } |
411 | cf = flist->att_list->first; | 413 | cf = flist->att_list->first; |
414 | if( ! cf ) | ||
412 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 415 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
413 | cflag = (mailimap_flag_fetch*)cf->data; | 416 | cflag = (mailimap_flag_fetch*)cf->data; |
417 | if( ! cflag ) | ||
418 | qDebug("imap:not cflag "); | ||
414 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 419 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
415 | switch (cflag->fl_flag->fl_type) { | 420 | switch (cflag->fl_flag->fl_type) { |
416 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 421 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
417 | mFlags.setBit(FLAG_ANSWERED); | 422 | mFlags.setBit(FLAG_ANSWERED); |
418 | break; | 423 | break; |
419 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 424 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
420 | mFlags.setBit(FLAG_FLAGGED); | 425 | mFlags.setBit(FLAG_FLAGGED); |
421 | break; | 426 | break; |
422 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 427 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
423 | mFlags.setBit(FLAG_DELETED); | 428 | mFlags.setBit(FLAG_DELETED); |
424 | break; | 429 | break; |
425 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 430 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
426 | mFlags.setBit(FLAG_SEEN); | 431 | mFlags.setBit(FLAG_SEEN); |
427 | break; | 432 | break; |
428 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 433 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
429 | mFlags.setBit(FLAG_DRAFT); | 434 | mFlags.setBit(FLAG_DRAFT); |
430 | break; | 435 | break; |
431 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 436 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
432 | break; | 437 | break; |
433 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 438 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
434 | break; | 439 | break; |
435 | default: | 440 | default: |
436 | break; | 441 | break; |
437 | } | 442 | } |
438 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 443 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
439 | mFlags.setBit(FLAG_RECENT); | 444 | mFlags.setBit(FLAG_RECENT); |
440 | } | 445 | } |
441 | } | 446 | } |
442 | continue; | 447 | continue; |
443 | } | 448 | } |
449 | if ( item->att_data.att_static == NULL ) | ||
450 | continue; | ||
444 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 451 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
445 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 452 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
446 | m->setDate(head->env_date); | 453 | if ( head == NULL ) |
447 | m->setSubject(convert_String((const char*)head->env_subject)); | 454 | continue; |
455 | if ( head->env_date != NULL ) | ||
456 | m->setDate(head->env_date); | ||
457 | if ( head->env_subject != NULL ) | ||
458 | m->setSubject(convert_String((const char*)head->env_subject)); | ||
448 | //m->setSubject(head->env_subject); | 459 | //m->setSubject(head->env_subject); |
449 | if (head->env_from!=NULL) { | 460 | if (head->env_from!=NULL) { |
450 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 461 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
451 | if (addresslist.count()) { | 462 | if (addresslist.count()) { |
452 | m->setFrom(addresslist.first()); | 463 | m->setFrom(addresslist.first()); |
453 | } | 464 | } |
454 | } | 465 | } |
455 | if (head->env_to!=NULL) { | 466 | if (head->env_to!=NULL) { |
456 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 467 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
457 | m->setTo(addresslist); | 468 | m->setTo(addresslist); |
458 | } | 469 | } |
459 | if (head->env_cc!=NULL) { | 470 | if (head->env_cc!=NULL) { |
460 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 471 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
461 | m->setCC(addresslist); | 472 | m->setCC(addresslist); |
462 | } | 473 | } |
463 | if (head->env_bcc!=NULL) { | 474 | if (head->env_bcc!=NULL) { |
464 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 475 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
465 | m->setBcc(addresslist); | 476 | m->setBcc(addresslist); |
466 | } | 477 | } |
467 | /* reply to address, eg. email. */ | 478 | /* reply to address, eg. email. */ |
468 | if (head->env_reply_to!=NULL) { | 479 | if (head->env_reply_to!=NULL) { |
469 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 480 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
470 | if (addresslist.count()) { | 481 | if (addresslist.count()) { |
471 | m->setReplyto(addresslist.first()); | 482 | m->setReplyto(addresslist.first()); |
472 | } | 483 | } |
473 | } | 484 | } |
474 | if (head->env_in_reply_to!=NULL) { | 485 | if (head->env_in_reply_to!=NULL) { |
475 | QString h(head->env_in_reply_to); | 486 | QString h(head->env_in_reply_to); |
476 | while (h.length()>0 && h[0]=='<') { | 487 | while (h.length()>0 && h[0]=='<') { |
477 | h.remove(0,1); | 488 | h.remove(0,1); |
478 | } | 489 | } |
479 | while (h.length()>0 && h[h.length()-1]=='>') { | 490 | while (h.length()>0 && h[h.length()-1]=='>') { |
480 | h.remove(h.length()-1,1); | 491 | h.remove(h.length()-1,1); |
481 | } | 492 | } |
482 | if (h.length()>0) { | 493 | if (h.length()>0) { |
483 | m->setInreply(QStringList(h)); | 494 | m->setInreply(QStringList(h)); |
484 | } | 495 | } |
485 | } | 496 | } |
486 | if (head->env_message_id) { | 497 | if (head->env_message_id != NULL) { |
487 | m->setMsgid(QString(head->env_message_id)); | 498 | m->setMsgid(QString(head->env_message_id)); |
488 | } | 499 | } |
489 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 500 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
490 | #if 0 | 501 | #if 0 |
491 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 502 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
492 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 503 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
493 | qDebug("time %s ",da.toString().latin1() ); | 504 | qDebug("time %s ",da.toString().latin1() ); |
494 | #endif | 505 | #endif |
495 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 506 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
496 | size = item->att_data.att_static->att_data.att_rfc822_size; | 507 | size = item->att_data.att_static->att_data.att_rfc822_size; |
497 | } | 508 | } |
498 | } | 509 | } |
499 | /* msg is already deleted */ | 510 | /* msg is already deleted */ |
500 | if (mFlags.testBit(FLAG_DELETED) && m) { | 511 | if (mFlags.testBit(FLAG_DELETED) && m) { |
501 | delete m; | 512 | delete m; |
502 | m = 0; | 513 | m = 0; |
503 | } | 514 | } |
504 | if (m) { | 515 | if (m) { |
505 | m->setFlags(mFlags); | 516 | m->setFlags(mFlags); |
506 | m->setMsgsize(size); | 517 | m->setMsgsize(size); |
507 | } | 518 | } |
508 | return m; | 519 | return m; |
509 | } | 520 | } |
510 | 521 | ||
511 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) | 522 | RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) |
512 | { | 523 | { |
513 | RecBodyP body = new RecBody(); | 524 | RecBodyP body = new RecBody(); |
514 | const char *mb; | 525 | const char *mb; |
515 | int err = MAILIMAP_NO_ERROR; | 526 | int err = MAILIMAP_NO_ERROR; |
516 | clist *result = 0; | 527 | clist *result = 0; |
517 | clistcell *current; | 528 | clistcell *current; |
518 | mailimap_fetch_att *fetchAtt = 0; | 529 | mailimap_fetch_att *fetchAtt = 0; |
519 | mailimap_fetch_type *fetchType = 0; | 530 | mailimap_fetch_type *fetchType = 0; |
520 | mailimap_set *set = 0; | 531 | mailimap_set *set = 0; |
521 | mailimap_body*body_desc = 0; | 532 | mailimap_body*body_desc = 0; |
522 | 533 | ||
523 | mb = mail->getMbox().latin1(); | 534 | mb = mail->getMbox().latin1(); |
524 | 535 | ||
525 | login(); | 536 | login(); |
526 | if (!m_imap) { | 537 | if (!m_imap) { |
527 | return body; | 538 | return body; |
528 | } | 539 | } |
529 | err = selectMbox(mail->getMbox()); | 540 | err = selectMbox(mail->getMbox()); |
530 | if ( err != MAILIMAP_NO_ERROR ) { | 541 | if ( err != MAILIMAP_NO_ERROR ) { |
531 | return body; | 542 | return body; |
532 | } | 543 | } |
533 | 544 | ||
534 | /* the range has to start at 1!!! not with 0!!!! */ | 545 | /* the range has to start at 1!!! not with 0!!!! */ |
535 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); | 546 | set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); |
536 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 547 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
537 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 548 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
538 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 549 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
539 | mailimap_set_free( set ); | 550 | mailimap_set_free( set ); |
540 | mailimap_fetch_type_free( fetchType ); | 551 | mailimap_fetch_type_free( fetchType ); |
541 | 552 | ||
542 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 553 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
543 | mailimap_msg_att * msg_att; | 554 | mailimap_msg_att * msg_att; |
544 | msg_att = (mailimap_msg_att*)current->data; | 555 | msg_att = (mailimap_msg_att*)current->data; |
545 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 556 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
546 | QValueList<int> path; | 557 | QValueList<int> path; |
547 | body_desc = item->att_data.att_static->att_data.att_body; | 558 | body_desc = item->att_data.att_static->att_data.att_body; |
548 | traverseBody(mail,body_desc,body,0,path); | 559 | traverseBody(mail,body_desc,body,0,path); |
549 | } else { | 560 | } else { |
550 | //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; | 561 | //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; |
551 | } | 562 | } |
552 | if (result) mailimap_fetch_list_free(result); | 563 | if (result) mailimap_fetch_list_free(result); |
553 | return body; | 564 | return body; |
554 | } | 565 | } |
555 | 566 | ||
556 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 567 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
557 | { | 568 | { |
558 | QStringList l; | 569 | QStringList l; |
559 | QString from; | 570 | QString from; |
560 | bool named_from; | 571 | bool named_from; |
561 | clistcell *current = NULL; | 572 | clistcell *current = NULL; |
562 | mailimap_address * current_address=NULL; | 573 | mailimap_address * current_address=NULL; |
563 | if (!list) { | 574 | if (!list) { |
564 | return l; | 575 | return l; |
565 | } | 576 | } |
566 | unsigned int count = 0; | 577 | unsigned int count = 0; |
567 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 578 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
568 | from = ""; | 579 | from = ""; |
569 | named_from = false; | 580 | named_from = false; |
570 | current_address=(mailimap_address*)current->data; | 581 | current_address=(mailimap_address*)current->data; |
571 | if (current_address->ad_personal_name){ | 582 | if (current_address->ad_personal_name){ |
572 | from+=convert_String((const char*)current_address->ad_personal_name); | 583 | from+=convert_String((const char*)current_address->ad_personal_name); |
573 | from+=" "; | 584 | from+=" "; |
574 | named_from = true; | 585 | named_from = true; |
575 | } | 586 | } |
576 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 587 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
577 | from+="<"; | 588 | from+="<"; |
578 | } | 589 | } |
579 | if (current_address->ad_mailbox_name) { | 590 | if (current_address->ad_mailbox_name) { |
580 | from+=QString(current_address->ad_mailbox_name); | 591 | from+=QString(current_address->ad_mailbox_name); |
581 | from+="@"; | 592 | from+="@"; |
582 | } | 593 | } |
583 | if (current_address->ad_host_name) { | 594 | if (current_address->ad_host_name) { |
584 | from+=QString(current_address->ad_host_name); | 595 | from+=QString(current_address->ad_host_name); |
585 | } | 596 | } |
586 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 597 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
587 | from+=">"; | 598 | from+=">"; |
588 | } | 599 | } |
589 | l.append(QString(from)); | 600 | l.append(QString(from)); |
590 | if (++count > 99) { | 601 | if (++count > 99) { |
591 | break; | 602 | break; |
592 | } | 603 | } |
593 | } | 604 | } |
594 | return l; | 605 | return l; |
595 | } | 606 | } |
596 | 607 | ||
597 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) | 608 | encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) |
598 | { | 609 | { |
599 | encodedString*res=new encodedString; | 610 | encodedString*res=new encodedString; |
600 | int err; | 611 | int err; |
601 | mailimap_fetch_type *fetchType; | 612 | mailimap_fetch_type *fetchType; |
602 | mailimap_set *set; | 613 | mailimap_set *set; |
603 | clistcell*current,*cur; | 614 | clistcell*current,*cur; |
604 | mailimap_section_part * section_part = 0; | 615 | mailimap_section_part * section_part = 0; |
605 | mailimap_section_spec * section_spec = 0; | 616 | mailimap_section_spec * section_spec = 0; |
606 | mailimap_section * section = 0; | 617 | mailimap_section * section = 0; |
607 | mailimap_fetch_att * fetch_att = 0; | 618 | mailimap_fetch_att * fetch_att = 0; |
608 | 619 | ||
609 | login(); | 620 | login(); |
610 | if (!m_imap) { | 621 | if (!m_imap) { |
611 | return res; | 622 | return res; |
612 | } | 623 | } |
613 | if (!internal_call) { | 624 | if (!internal_call) { |
614 | err = selectMbox(mail->getMbox()); | 625 | err = selectMbox(mail->getMbox()); |
615 | if ( err != MAILIMAP_NO_ERROR ) { | 626 | if ( err != MAILIMAP_NO_ERROR ) { |
616 | return res; | 627 | return res; |
617 | } | 628 | } |
618 | } | 629 | } |
619 | set = mailimap_set_new_single(mail->getNumber()); | 630 | set = mailimap_set_new_single(mail->getNumber()); |
620 | 631 | ||
621 | clist*id_list = 0; | 632 | clist*id_list = 0; |
622 | 633 | ||
623 | /* if path == empty then its a request for the whole rfc822 mail and generates | 634 | /* if path == empty then its a request for the whole rfc822 mail and generates |
624 | a "fetch <id> (body[])" statement on imap server */ | 635 | a "fetch <id> (body[])" statement on imap server */ |
625 | if (path.count()>0 ) { | 636 | if (path.count()>0 ) { |
626 | id_list = clist_new(); | 637 | id_list = clist_new(); |
627 | for (unsigned j=0; j < path.count();++j) { | 638 | for (unsigned j=0; j < path.count();++j) { |
628 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 639 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
629 | *p_id = path[j]; | 640 | *p_id = path[j]; |
630 | clist_append(id_list,p_id); | 641 | clist_append(id_list,p_id); |
631 | } | 642 | } |
632 | section_part = mailimap_section_part_new(id_list); | 643 | section_part = mailimap_section_part_new(id_list); |
633 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 644 | section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
634 | } | 645 | } |
635 | 646 | ||
636 | section = mailimap_section_new(section_spec); | 647 | section = mailimap_section_new(section_spec); |
637 | fetch_att = mailimap_fetch_att_new_body_section(section); | 648 | fetch_att = mailimap_fetch_att_new_body_section(section); |
638 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 649 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
639 | 650 | ||
640 | clist*result = 0; | 651 | clist*result = 0; |
641 | 652 | ||
642 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 653 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
643 | mailimap_set_free( set ); | 654 | mailimap_set_free( set ); |
644 | mailimap_fetch_type_free( fetchType ); | 655 | mailimap_fetch_type_free( fetchType ); |
645 | 656 | ||
646 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 657 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
647 | mailimap_msg_att * msg_att; | 658 | mailimap_msg_att * msg_att; |
648 | msg_att = (mailimap_msg_att*)current->data; | 659 | msg_att = (mailimap_msg_att*)current->data; |
649 | mailimap_msg_att_item*msg_att_item; | 660 | mailimap_msg_att_item*msg_att_item; |
650 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 661 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
651 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 662 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
652 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 663 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
653 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 664 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
654 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 665 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
655 | /* detach - we take over the content */ | 666 | /* detach - we take over the content */ |
656 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 667 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
657 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 668 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
658 | } | 669 | } |
659 | } | 670 | } |
660 | } | 671 | } |
661 | } else { | 672 | } else { |
662 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; | 673 | ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; |
663 | } | 674 | } |
664 | if (result) mailimap_fetch_list_free(result); | 675 | if (result) mailimap_fetch_list_free(result); |
665 | return res; | 676 | return res; |
666 | } | 677 | } |
667 | 678 | ||
668 | /* current_recursion is for recursive calls. | 679 | /* current_recursion is for recursive calls. |
669 | current_count means the position inside the internal loop! */ | 680 | current_count means the position inside the internal loop! */ |
670 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, | 681 | void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, |
671 | int current_recursion,QValueList<int>recList,int current_count) | 682 | int current_recursion,QValueList<int>recList,int current_count) |
672 | { | 683 | { |
673 | if (!body || current_recursion>=10) { | 684 | if (!body || current_recursion>=10) { |
674 | return; | 685 | return; |
675 | } | 686 | } |
676 | switch (body->bd_type) { | 687 | switch (body->bd_type) { |
677 | case MAILIMAP_BODY_1PART: | 688 | case MAILIMAP_BODY_1PART: |
678 | { | 689 | { |
679 | QValueList<int>countlist = recList; | 690 | QValueList<int>countlist = recList; |
680 | countlist.append(current_count); | 691 | countlist.append(current_count); |
681 | RecPartP currentPart = new RecPart(); | 692 | RecPartP currentPart = new RecPart(); |
682 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 693 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
683 | QString id(""); | 694 | QString id(""); |
684 | currentPart->setPositionlist(countlist); | 695 | currentPart->setPositionlist(countlist); |
685 | for (unsigned int j = 0; j < countlist.count();++j) { | 696 | for (unsigned int j = 0; j < countlist.count();++j) { |
686 | id+=(j>0?" ":""); | 697 | id+=(j>0?" ":""); |
687 | id+=QString("%1").arg(countlist[j]); | 698 | id+=QString("%1").arg(countlist[j]); |
688 | } | 699 | } |
689 | //odebug << "ID = " << id.latin1() << "" << oendl; | 700 | //odebug << "ID = " << id.latin1() << "" << oendl; |
690 | currentPart->setIdentifier(id); | 701 | currentPart->setIdentifier(id); |
691 | fillSinglePart(currentPart,part1); | 702 | fillSinglePart(currentPart,part1); |
692 | /* important: Check for is NULL 'cause a body can be empty! | 703 | /* important: Check for is NULL 'cause a body can be empty! |
693 | And we put it only into the mail if it is the FIRST part */ | 704 | And we put it only into the mail if it is the FIRST part */ |
694 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { | 705 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { |
695 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); | 706 | QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); |
696 | target_body->setDescription(currentPart); | 707 | target_body->setDescription(currentPart); |
697 | target_body->setBodytext(body_text); | 708 | target_body->setBodytext(body_text); |
698 | if (countlist.count()>1) { | 709 | if (countlist.count()>1) { |
699 | target_body->addPart(currentPart); | 710 | target_body->addPart(currentPart); |
700 | } | 711 | } |
701 | } else { | 712 | } else { |
702 | target_body->addPart(currentPart); | 713 | target_body->addPart(currentPart); |
703 | } | 714 | } |
704 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 715 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
705 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 716 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
706 | } | 717 | } |
707 | } | 718 | } |
708 | break; | 719 | break; |
709 | case MAILIMAP_BODY_MPART: | 720 | case MAILIMAP_BODY_MPART: |
710 | { | 721 | { |
711 | QValueList<int>countlist = recList; | 722 | QValueList<int>countlist = recList; |
712 | clistcell*current=0; | 723 | clistcell*current=0; |
713 | mailimap_body*current_body=0; | 724 | mailimap_body*current_body=0; |
714 | unsigned int ccount = 1; | 725 | unsigned int ccount = 1; |
715 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 726 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
716 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 727 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
717 | current_body = (mailimap_body*)current->data; | 728 | current_body = (mailimap_body*)current->data; |
718 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 729 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
719 | RecPartP targetPart = new RecPart(); | 730 | RecPartP targetPart = new RecPart(); |
720 | targetPart->setType("multipart"); | 731 | targetPart->setType("multipart"); |
721 | fillMultiPart(targetPart,mailDescription); | 732 | fillMultiPart(targetPart,mailDescription); |
722 | countlist.append(current_count); | 733 | countlist.append(current_count); |
723 | targetPart->setPositionlist(countlist); | 734 | targetPart->setPositionlist(countlist); |
724 | target_body->addPart(targetPart); | 735 | target_body->addPart(targetPart); |
725 | QString id(""); | 736 | QString id(""); |
726 | for (unsigned int j = 0; j < countlist.count();++j) { | 737 | for (unsigned int j = 0; j < countlist.count();++j) { |
727 | id+=(j>0?" ":""); | 738 | id+=(j>0?" ":""); |
728 | id+=QString("%1").arg(countlist[j]); | 739 | id+=QString("%1").arg(countlist[j]); |
729 | } | 740 | } |
730 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; | 741 | // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; |
731 | } | 742 | } |
732 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 743 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
733 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 744 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
734 | countlist = recList; | 745 | countlist = recList; |
735 | } | 746 | } |
736 | ++ccount; | 747 | ++ccount; |
737 | } | 748 | } |
738 | } | 749 | } |
739 | break; | 750 | break; |
740 | default: | 751 | default: |
741 | break; | 752 | break; |
742 | } | 753 | } |