author | alwin <alwin> | 2004-01-03 13:10:06 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-03 13:10:06 (UTC) |
commit | 45ace73de06a645d5876ad40a6d911f7ea24c69b (patch) (unidiff) | |
tree | 53a33b99444d0a7210c9c1b55d5a1fe3a7465b7c | |
parent | 622bddce6d0cd41c765225f4743b23bf1667f3db (diff) | |
download | opie-45ace73de06a645d5876ad40a6d911f7ea24c69b.zip opie-45ace73de06a645d5876ad40a6d911f7ea24c69b.tar.gz opie-45ace73de06a645d5876ad40a6d911f7ea24c69b.tar.bz2 |
multipart subtype will stored lower like in singleparts
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 3 |
2 files changed, 4 insertions, 2 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index ae196bb..b437df0 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -139,797 +139,798 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
139 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 139 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
140 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 140 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
141 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 141 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
142 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 142 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
143 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 143 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
144 | 144 | ||
145 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 145 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
146 | mailimap_set_free( set ); | 146 | mailimap_set_free( set ); |
147 | mailimap_fetch_type_free( fetchType ); | 147 | mailimap_fetch_type_free( fetchType ); |
148 | 148 | ||
149 | QString date,subject,from; | 149 | QString date,subject,from; |
150 | 150 | ||
151 | if ( err == MAILIMAP_NO_ERROR ) { | 151 | if ( err == MAILIMAP_NO_ERROR ) { |
152 | mailimap_msg_att * msg_att; | 152 | mailimap_msg_att * msg_att; |
153 | int i = 0; | 153 | int i = 0; |
154 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 154 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
155 | ++i; | 155 | ++i; |
156 | msg_att = (mailimap_msg_att*)current->data; | 156 | msg_att = (mailimap_msg_att*)current->data; |
157 | RecMail*m = parse_list_result(msg_att); | 157 | RecMail*m = parse_list_result(msg_att); |
158 | if (m) { | 158 | if (m) { |
159 | m->setNumber(i); | 159 | m->setNumber(i); |
160 | m->setMbox(mailbox); | 160 | m->setMbox(mailbox); |
161 | m->setWrapper(this); | 161 | m->setWrapper(this); |
162 | target.append(m); | 162 | target.append(m); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | } else { | 165 | } else { |
166 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 166 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
167 | } | 167 | } |
168 | if (result) mailimap_fetch_list_free(result); | 168 | if (result) mailimap_fetch_list_free(result); |
169 | } | 169 | } |
170 | 170 | ||
171 | QList<Folder>* IMAPwrapper::listFolders() | 171 | QList<Folder>* IMAPwrapper::listFolders() |
172 | { | 172 | { |
173 | const char *path, *mask; | 173 | const char *path, *mask; |
174 | int err = MAILIMAP_NO_ERROR; | 174 | int err = MAILIMAP_NO_ERROR; |
175 | clist *result = 0; | 175 | clist *result = 0; |
176 | clistcell *current = 0; | 176 | clistcell *current = 0; |
177 | clistcell*cur_flag = 0; | 177 | clistcell*cur_flag = 0; |
178 | mailimap_mbx_list_flags*bflags = 0; | 178 | mailimap_mbx_list_flags*bflags = 0; |
179 | 179 | ||
180 | QList<Folder> * folders = new QList<Folder>(); | 180 | QList<Folder> * folders = new QList<Folder>(); |
181 | folders->setAutoDelete( false ); | 181 | folders->setAutoDelete( false ); |
182 | login(); | 182 | login(); |
183 | if (!m_imap) { | 183 | if (!m_imap) { |
184 | return folders; | 184 | return folders; |
185 | } | 185 | } |
186 | 186 | ||
187 | /* | 187 | /* |
188 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 188 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
189 | * We must not forget to filter them out in next loop! | 189 | * We must not forget to filter them out in next loop! |
190 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 190 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
191 | */ | 191 | */ |
192 | QString temp; | 192 | QString temp; |
193 | mask = "INBOX" ; | 193 | mask = "INBOX" ; |
194 | mailimap_mailbox_list *list; | 194 | mailimap_mailbox_list *list; |
195 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 195 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
196 | QString del; | 196 | QString del; |
197 | bool selectable = true; | 197 | bool selectable = true; |
198 | bool no_inferiors = false; | 198 | bool no_inferiors = false; |
199 | if ( err == MAILIMAP_NO_ERROR ) { | 199 | if ( err == MAILIMAP_NO_ERROR ) { |
200 | current = result->first; | 200 | current = result->first; |
201 | for ( int i = result->count; i > 0; i-- ) { | 201 | for ( int i = result->count; i > 0; i-- ) { |
202 | list = (mailimap_mailbox_list *) current->data; | 202 | list = (mailimap_mailbox_list *) current->data; |
203 | // it is better use the deep copy mechanism of qt itself | 203 | // it is better use the deep copy mechanism of qt itself |
204 | // instead of using strdup! | 204 | // instead of using strdup! |
205 | temp = list->mb_name; | 205 | temp = list->mb_name; |
206 | del = list->mb_delimiter; | 206 | del = list->mb_delimiter; |
207 | current = current->next; | 207 | current = current->next; |
208 | if ( (bflags = list->mb_flag) ) { | 208 | if ( (bflags = list->mb_flag) ) { |
209 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 209 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
210 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 210 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
211 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 211 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
212 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 212 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
213 | no_inferiors = true; | 213 | no_inferiors = true; |
214 | } | 214 | } |
215 | } | 215 | } |
216 | } | 216 | } |
217 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 217 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
218 | } | 218 | } |
219 | } else { | 219 | } else { |
220 | qDebug("error fetching folders: %s",m_imap->imap_response); | 220 | qDebug("error fetching folders: %s",m_imap->imap_response); |
221 | } | 221 | } |
222 | mailimap_list_result_free( result ); | 222 | mailimap_list_result_free( result ); |
223 | 223 | ||
224 | /* | 224 | /* |
225 | * second stage - get the other then inbox folders | 225 | * second stage - get the other then inbox folders |
226 | */ | 226 | */ |
227 | mask = "*" ; | 227 | mask = "*" ; |
228 | path = account->getPrefix().latin1(); | 228 | path = account->getPrefix().latin1(); |
229 | if (!path) path = ""; | 229 | if (!path) path = ""; |
230 | qDebug(path); | 230 | qDebug(path); |
231 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 231 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
232 | if ( err == MAILIMAP_NO_ERROR ) { | 232 | if ( err == MAILIMAP_NO_ERROR ) { |
233 | current = result->first; | 233 | current = result->first; |
234 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 234 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
235 | no_inferiors = false; | 235 | no_inferiors = false; |
236 | list = (mailimap_mailbox_list *) current->data; | 236 | list = (mailimap_mailbox_list *) current->data; |
237 | // it is better use the deep copy mechanism of qt itself | 237 | // it is better use the deep copy mechanism of qt itself |
238 | // instead of using strdup! | 238 | // instead of using strdup! |
239 | temp = list->mb_name; | 239 | temp = list->mb_name; |
240 | if (temp.lower()=="inbox") | 240 | if (temp.lower()=="inbox") |
241 | continue; | 241 | continue; |
242 | if (temp.lower()==account->getPrefix().lower()) | 242 | if (temp.lower()==account->getPrefix().lower()) |
243 | continue; | 243 | continue; |
244 | if ( (bflags = list->mb_flag) ) { | 244 | if ( (bflags = list->mb_flag) ) { |
245 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 245 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
246 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 246 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
247 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 247 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
248 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 248 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
249 | no_inferiors = true; | 249 | no_inferiors = true; |
250 | } | 250 | } |
251 | } | 251 | } |
252 | } | 252 | } |
253 | del = list->mb_delimiter; | 253 | del = list->mb_delimiter; |
254 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 254 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
255 | } | 255 | } |
256 | } else { | 256 | } else { |
257 | qDebug("error fetching folders %s",m_imap->imap_response); | 257 | qDebug("error fetching folders %s",m_imap->imap_response); |
258 | } | 258 | } |
259 | if (result) mailimap_list_result_free( result ); | 259 | if (result) mailimap_list_result_free( result ); |
260 | return folders; | 260 | return folders; |
261 | } | 261 | } |
262 | 262 | ||
263 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 263 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
264 | { | 264 | { |
265 | RecMail * m = 0; | 265 | RecMail * m = 0; |
266 | mailimap_msg_att_item *item=0; | 266 | mailimap_msg_att_item *item=0; |
267 | clistcell *current,*c,*cf; | 267 | clistcell *current,*c,*cf; |
268 | mailimap_msg_att_dynamic*flist; | 268 | mailimap_msg_att_dynamic*flist; |
269 | mailimap_flag_fetch*cflag; | 269 | mailimap_flag_fetch*cflag; |
270 | int size; | 270 | int size; |
271 | QBitArray mFlags(7); | 271 | QBitArray mFlags(7); |
272 | QStringList addresslist; | 272 | QStringList addresslist; |
273 | 273 | ||
274 | if (!m_att) { | 274 | if (!m_att) { |
275 | return m; | 275 | return m; |
276 | } | 276 | } |
277 | m = new RecMail(); | 277 | m = new RecMail(); |
278 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 278 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
279 | current = c; | 279 | current = c; |
280 | size = 0; | 280 | size = 0; |
281 | item = (mailimap_msg_att_item*)current->data; | 281 | item = (mailimap_msg_att_item*)current->data; |
282 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 282 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
283 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 283 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
284 | if (!flist->att_list) { | 284 | if (!flist->att_list) { |
285 | continue; | 285 | continue; |
286 | } | 286 | } |
287 | cf = flist->att_list->first; | 287 | cf = flist->att_list->first; |
288 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 288 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
289 | cflag = (mailimap_flag_fetch*)cf->data; | 289 | cflag = (mailimap_flag_fetch*)cf->data; |
290 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 290 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
291 | switch (cflag->fl_flag->fl_type) { | 291 | switch (cflag->fl_flag->fl_type) { |
292 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 292 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
293 | mFlags.setBit(FLAG_ANSWERED); | 293 | mFlags.setBit(FLAG_ANSWERED); |
294 | break; | 294 | break; |
295 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 295 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
296 | mFlags.setBit(FLAG_FLAGGED); | 296 | mFlags.setBit(FLAG_FLAGGED); |
297 | break; | 297 | break; |
298 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 298 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
299 | mFlags.setBit(FLAG_DELETED); | 299 | mFlags.setBit(FLAG_DELETED); |
300 | break; | 300 | break; |
301 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 301 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
302 | mFlags.setBit(FLAG_SEEN); | 302 | mFlags.setBit(FLAG_SEEN); |
303 | break; | 303 | break; |
304 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 304 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
305 | mFlags.setBit(FLAG_DRAFT); | 305 | mFlags.setBit(FLAG_DRAFT); |
306 | break; | 306 | break; |
307 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 307 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
308 | break; | 308 | break; |
309 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 309 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
310 | break; | 310 | break; |
311 | default: | 311 | default: |
312 | break; | 312 | break; |
313 | } | 313 | } |
314 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 314 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
315 | mFlags.setBit(FLAG_RECENT); | 315 | mFlags.setBit(FLAG_RECENT); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | continue; | 318 | continue; |
319 | } | 319 | } |
320 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 320 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
321 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 321 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
322 | m->setDate(head->env_date); | 322 | m->setDate(head->env_date); |
323 | m->setSubject(convert_String((const char*)head->env_subject)); | 323 | m->setSubject(convert_String((const char*)head->env_subject)); |
324 | //m->setSubject(head->env_subject); | 324 | //m->setSubject(head->env_subject); |
325 | if (head->env_from!=NULL) { | 325 | if (head->env_from!=NULL) { |
326 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 326 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
327 | if (addresslist.count()) { | 327 | if (addresslist.count()) { |
328 | m->setFrom(addresslist.first()); | 328 | m->setFrom(addresslist.first()); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | if (head->env_to!=NULL) { | 331 | if (head->env_to!=NULL) { |
332 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 332 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
333 | m->setTo(addresslist); | 333 | m->setTo(addresslist); |
334 | } | 334 | } |
335 | if (head->env_cc!=NULL) { | 335 | if (head->env_cc!=NULL) { |
336 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 336 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
337 | m->setCC(addresslist); | 337 | m->setCC(addresslist); |
338 | } | 338 | } |
339 | if (head->env_bcc!=NULL) { | 339 | if (head->env_bcc!=NULL) { |
340 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 340 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
341 | m->setBcc(addresslist); | 341 | m->setBcc(addresslist); |
342 | } | 342 | } |
343 | if (head->env_reply_to!=NULL) { | 343 | if (head->env_reply_to!=NULL) { |
344 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 344 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
345 | if (addresslist.count()) { | 345 | if (addresslist.count()) { |
346 | m->setReplyto(addresslist.first()); | 346 | m->setReplyto(addresslist.first()); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | m->setMsgid(QString(head->env_message_id)); | 349 | m->setMsgid(QString(head->env_message_id)); |
350 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 350 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
351 | #if 0 | 351 | #if 0 |
352 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 352 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
353 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 353 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
354 | 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); | 354 | 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); |
355 | qDebug(da.toString()); | 355 | qDebug(da.toString()); |
356 | #endif | 356 | #endif |
357 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 357 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
358 | size = item->att_data.att_static->att_data.att_rfc822_size; | 358 | size = item->att_data.att_static->att_data.att_rfc822_size; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | /* msg is already deleted */ | 361 | /* msg is already deleted */ |
362 | if (mFlags.testBit(FLAG_DELETED) && m) { | 362 | if (mFlags.testBit(FLAG_DELETED) && m) { |
363 | delete m; | 363 | delete m; |
364 | m = 0; | 364 | m = 0; |
365 | } | 365 | } |
366 | if (m) { | 366 | if (m) { |
367 | m->setFlags(mFlags); | 367 | m->setFlags(mFlags); |
368 | m->setMsgsize(size); | 368 | m->setMsgsize(size); |
369 | } | 369 | } |
370 | return m; | 370 | return m; |
371 | } | 371 | } |
372 | 372 | ||
373 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 373 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
374 | { | 374 | { |
375 | RecBody body; | 375 | RecBody body; |
376 | const char *mb; | 376 | const char *mb; |
377 | int err = MAILIMAP_NO_ERROR; | 377 | int err = MAILIMAP_NO_ERROR; |
378 | clist *result = 0; | 378 | clist *result = 0; |
379 | clistcell *current; | 379 | clistcell *current; |
380 | mailimap_fetch_att *fetchAtt = 0; | 380 | mailimap_fetch_att *fetchAtt = 0; |
381 | mailimap_fetch_type *fetchType = 0; | 381 | mailimap_fetch_type *fetchType = 0; |
382 | mailimap_set *set = 0; | 382 | mailimap_set *set = 0; |
383 | mailimap_body*body_desc = 0; | 383 | mailimap_body*body_desc = 0; |
384 | 384 | ||
385 | mb = mail.getMbox().latin1(); | 385 | mb = mail.getMbox().latin1(); |
386 | 386 | ||
387 | login(); | 387 | login(); |
388 | if (!m_imap) { | 388 | if (!m_imap) { |
389 | return body; | 389 | return body; |
390 | } | 390 | } |
391 | 391 | ||
392 | err = mailimap_select( m_imap, (char*)mb); | 392 | err = mailimap_select( m_imap, (char*)mb); |
393 | if ( err != MAILIMAP_NO_ERROR ) { | 393 | if ( err != MAILIMAP_NO_ERROR ) { |
394 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 394 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
395 | return body; | 395 | return body; |
396 | } | 396 | } |
397 | 397 | ||
398 | /* the range has to start at 1!!! not with 0!!!! */ | 398 | /* the range has to start at 1!!! not with 0!!!! */ |
399 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 399 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
400 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 400 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
401 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 401 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
403 | mailimap_set_free( set ); | 403 | mailimap_set_free( set ); |
404 | mailimap_fetch_type_free( fetchType ); | 404 | mailimap_fetch_type_free( fetchType ); |
405 | 405 | ||
406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
407 | mailimap_msg_att * msg_att; | 407 | mailimap_msg_att * msg_att; |
408 | msg_att = (mailimap_msg_att*)current->data; | 408 | msg_att = (mailimap_msg_att*)current->data; |
409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
410 | QValueList<int> path; | 410 | QValueList<int> path; |
411 | body_desc = item->att_data.att_static->att_data.att_body; | 411 | body_desc = item->att_data.att_static->att_data.att_body; |
412 | traverseBody(mail,body_desc,body,0,path); | 412 | traverseBody(mail,body_desc,body,0,path); |
413 | } else { | 413 | } else { |
414 | qDebug("error fetching body: %s",m_imap->imap_response); | 414 | qDebug("error fetching body: %s",m_imap->imap_response); |
415 | } | 415 | } |
416 | if (result) mailimap_fetch_list_free(result); | 416 | if (result) mailimap_fetch_list_free(result); |
417 | return body; | 417 | return body; |
418 | } | 418 | } |
419 | 419 | ||
420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
421 | { | 421 | { |
422 | QStringList l; | 422 | QStringList l; |
423 | QString from; | 423 | QString from; |
424 | bool named_from; | 424 | bool named_from; |
425 | clistcell *current = NULL; | 425 | clistcell *current = NULL; |
426 | mailimap_address * current_address=NULL; | 426 | mailimap_address * current_address=NULL; |
427 | if (!list) { | 427 | if (!list) { |
428 | return l; | 428 | return l; |
429 | } | 429 | } |
430 | unsigned int count = 0; | 430 | unsigned int count = 0; |
431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
432 | from = ""; | 432 | from = ""; |
433 | named_from = false; | 433 | named_from = false; |
434 | current_address=(mailimap_address*)current->data; | 434 | current_address=(mailimap_address*)current->data; |
435 | if (current_address->ad_personal_name){ | 435 | if (current_address->ad_personal_name){ |
436 | from+=convert_String((const char*)current_address->ad_personal_name); | 436 | from+=convert_String((const char*)current_address->ad_personal_name); |
437 | from+=" "; | 437 | from+=" "; |
438 | named_from = true; | 438 | named_from = true; |
439 | } | 439 | } |
440 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 440 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
441 | from+="<"; | 441 | from+="<"; |
442 | } | 442 | } |
443 | if (current_address->ad_mailbox_name) { | 443 | if (current_address->ad_mailbox_name) { |
444 | from+=QString(current_address->ad_mailbox_name); | 444 | from+=QString(current_address->ad_mailbox_name); |
445 | from+="@"; | 445 | from+="@"; |
446 | } | 446 | } |
447 | if (current_address->ad_host_name) { | 447 | if (current_address->ad_host_name) { |
448 | from+=QString(current_address->ad_host_name); | 448 | from+=QString(current_address->ad_host_name); |
449 | } | 449 | } |
450 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 450 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
451 | from+=">"; | 451 | from+=">"; |
452 | } | 452 | } |
453 | l.append(QString(from)); | 453 | l.append(QString(from)); |
454 | if (++count > 99) { | 454 | if (++count > 99) { |
455 | break; | 455 | break; |
456 | } | 456 | } |
457 | } | 457 | } |
458 | return l; | 458 | return l; |
459 | } | 459 | } |
460 | 460 | ||
461 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 461 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
462 | { | 462 | { |
463 | encodedString*res=new encodedString; | 463 | encodedString*res=new encodedString; |
464 | const char*mb; | 464 | const char*mb; |
465 | int err; | 465 | int err; |
466 | mailimap_fetch_type *fetchType; | 466 | mailimap_fetch_type *fetchType; |
467 | mailimap_set *set; | 467 | mailimap_set *set; |
468 | clistcell*current,*cur; | 468 | clistcell*current,*cur; |
469 | 469 | ||
470 | login(); | 470 | login(); |
471 | if (!m_imap) { | 471 | if (!m_imap) { |
472 | return res; | 472 | return res; |
473 | } | 473 | } |
474 | if (!internal_call) { | 474 | if (!internal_call) { |
475 | mb = mail.getMbox().latin1(); | 475 | mb = mail.getMbox().latin1(); |
476 | err = mailimap_select( m_imap, (char*)mb); | 476 | err = mailimap_select( m_imap, (char*)mb); |
477 | if ( err != MAILIMAP_NO_ERROR ) { | 477 | if ( err != MAILIMAP_NO_ERROR ) { |
478 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 478 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
479 | return res; | 479 | return res; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | set = mailimap_set_new_single(mail.getNumber()); | 482 | set = mailimap_set_new_single(mail.getNumber()); |
483 | clist*id_list=clist_new(); | 483 | clist*id_list=clist_new(); |
484 | for (unsigned j=0; j < path.count();++j) { | 484 | for (unsigned j=0; j < path.count();++j) { |
485 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 485 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
486 | *p_id = path[j]; | 486 | *p_id = path[j]; |
487 | clist_append(id_list,p_id); | 487 | clist_append(id_list,p_id); |
488 | } | 488 | } |
489 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 489 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
490 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 490 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
491 | mailimap_section * section = mailimap_section_new(section_spec); | 491 | mailimap_section * section = mailimap_section_new(section_spec); |
492 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 492 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
493 | 493 | ||
494 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 494 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
495 | 495 | ||
496 | clist*result = 0; | 496 | clist*result = 0; |
497 | 497 | ||
498 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 498 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
499 | mailimap_set_free( set ); | 499 | mailimap_set_free( set ); |
500 | mailimap_fetch_type_free( fetchType ); | 500 | mailimap_fetch_type_free( fetchType ); |
501 | 501 | ||
502 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 502 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
503 | mailimap_msg_att * msg_att; | 503 | mailimap_msg_att * msg_att; |
504 | msg_att = (mailimap_msg_att*)current->data; | 504 | msg_att = (mailimap_msg_att*)current->data; |
505 | mailimap_msg_att_item*msg_att_item; | 505 | mailimap_msg_att_item*msg_att_item; |
506 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 506 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
507 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 507 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
508 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 508 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
509 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 509 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
510 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 510 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
511 | /* detach - we take over the content */ | 511 | /* detach - we take over the content */ |
512 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 512 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
513 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 513 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } else { | 517 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 519 | } |
520 | if (result) mailimap_fetch_list_free(result); | 520 | if (result) mailimap_fetch_list_free(result); |
521 | return res; | 521 | return res; |
522 | } | 522 | } |
523 | 523 | ||
524 | /* current_recursion is for recursive calls. | 524 | /* current_recursion is for recursive calls. |
525 | current_count means the position inside the internal loop! */ | 525 | current_count means the position inside the internal loop! */ |
526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | 526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, |
527 | int current_recursion,QValueList<int>recList,int current_count) | 527 | int current_recursion,QValueList<int>recList,int current_count) |
528 | { | 528 | { |
529 | if (!body || current_recursion>=10) { | 529 | if (!body || current_recursion>=10) { |
530 | return; | 530 | return; |
531 | } | 531 | } |
532 | switch (body->bd_type) { | 532 | switch (body->bd_type) { |
533 | case MAILIMAP_BODY_1PART: | 533 | case MAILIMAP_BODY_1PART: |
534 | { | 534 | { |
535 | QValueList<int>countlist = recList; | 535 | QValueList<int>countlist = recList; |
536 | countlist.append(current_count); | 536 | countlist.append(current_count); |
537 | RecPart currentPart; | 537 | RecPart currentPart; |
538 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 538 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
539 | QString id(""); | 539 | QString id(""); |
540 | currentPart.setPositionlist(countlist); | 540 | currentPart.setPositionlist(countlist); |
541 | for (unsigned int j = 0; j < countlist.count();++j) { | 541 | for (unsigned int j = 0; j < countlist.count();++j) { |
542 | id+=(j>0?" ":""); | 542 | id+=(j>0?" ":""); |
543 | id+=QString("%1").arg(countlist[j]); | 543 | id+=QString("%1").arg(countlist[j]); |
544 | } | 544 | } |
545 | qDebug("ID = %s",id.latin1()); | 545 | qDebug("ID = %s",id.latin1()); |
546 | currentPart.setIdentifier(id); | 546 | currentPart.setIdentifier(id); |
547 | fillSinglePart(currentPart,part1); | 547 | fillSinglePart(currentPart,part1); |
548 | /* important: Check for is NULL 'cause a body can be empty! | 548 | /* important: Check for is NULL 'cause a body can be empty! |
549 | And we put it only into the mail if it is the FIRST part */ | 549 | And we put it only into the mail if it is the FIRST part */ |
550 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { | 550 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
551 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 551 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
552 | target_body.setDescription(currentPart); | 552 | target_body.setDescription(currentPart); |
553 | target_body.setBodytext(body_text); | 553 | target_body.setBodytext(body_text); |
554 | if (countlist.count()>1) { | 554 | if (countlist.count()>1) { |
555 | target_body.addPart(currentPart); | 555 | target_body.addPart(currentPart); |
556 | } | 556 | } |
557 | } else { | 557 | } else { |
558 | target_body.addPart(currentPart); | 558 | target_body.addPart(currentPart); |
559 | } | 559 | } |
560 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 560 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
561 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 561 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
562 | } | 562 | } |
563 | } | 563 | } |
564 | break; | 564 | break; |
565 | case MAILIMAP_BODY_MPART: | 565 | case MAILIMAP_BODY_MPART: |
566 | { | 566 | { |
567 | QValueList<int>countlist = recList; | 567 | QValueList<int>countlist = recList; |
568 | clistcell*current=0; | 568 | clistcell*current=0; |
569 | mailimap_body*current_body=0; | 569 | mailimap_body*current_body=0; |
570 | unsigned int ccount = 1; | 570 | unsigned int ccount = 1; |
571 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 571 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
572 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 572 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
573 | current_body = (mailimap_body*)current->data; | 573 | current_body = (mailimap_body*)current->data; |
574 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 574 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
575 | RecPart targetPart; | 575 | RecPart targetPart; |
576 | targetPart.setType("multipart"); | 576 | targetPart.setType("multipart"); |
577 | fillMultiPart(targetPart,mailDescription); | 577 | fillMultiPart(targetPart,mailDescription); |
578 | countlist.append(current_count); | 578 | countlist.append(current_count); |
579 | targetPart.setPositionlist(countlist); | 579 | targetPart.setPositionlist(countlist); |
580 | target_body.addPart(targetPart); | 580 | target_body.addPart(targetPart); |
581 | QString id(""); | 581 | QString id(""); |
582 | for (unsigned int j = 0; j < countlist.count();++j) { | 582 | for (unsigned int j = 0; j < countlist.count();++j) { |
583 | id+=(j>0?" ":""); | 583 | id+=(j>0?" ":""); |
584 | id+=QString("%1").arg(countlist[j]); | 584 | id+=QString("%1").arg(countlist[j]); |
585 | } | 585 | } |
586 | qDebug("ID(mpart) = %s",id.latin1()); | 586 | qDebug("ID(mpart) = %s",id.latin1()); |
587 | } | 587 | } |
588 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 588 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
589 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 589 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
590 | countlist = recList; | 590 | countlist = recList; |
591 | } | 591 | } |
592 | ++ccount; | 592 | ++ccount; |
593 | } | 593 | } |
594 | } | 594 | } |
595 | break; | 595 | break; |
596 | default: | 596 | default: |
597 | break; | 597 | break; |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
602 | { | 602 | { |
603 | if (!Description) { | 603 | if (!Description) { |
604 | return; | 604 | return; |
605 | } | 605 | } |
606 | switch (Description->bd_type) { | 606 | switch (Description->bd_type) { |
607 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 607 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
608 | target_part.setType("text"); | 608 | target_part.setType("text"); |
609 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 609 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
610 | break; | 610 | break; |
611 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 611 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
612 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 612 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
613 | break; | 613 | break; |
614 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 614 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
615 | target_part.setType("message"); | 615 | target_part.setType("message"); |
616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
617 | break; | 617 | break; |
618 | default: | 618 | default: |
619 | break; | 619 | break; |
620 | } | 620 | } |
621 | } | 621 | } |
622 | 622 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
624 | { | 624 | { |
625 | if (!which) { | 625 | if (!which) { |
626 | return; | 626 | return; |
627 | } | 627 | } |
628 | QString sub; | 628 | QString sub; |
629 | sub = which->bd_media_text; | 629 | sub = which->bd_media_text; |
630 | qDebug("Type= text/%s",which->bd_media_text); | 630 | qDebug("Type= text/%s",which->bd_media_text); |
631 | target_part.setSubtype(sub.lower()); | 631 | target_part.setSubtype(sub.lower()); |
632 | target_part.setLines(which->bd_lines); | 632 | target_part.setLines(which->bd_lines); |
633 | fillBodyFields(target_part,which->bd_fields); | 633 | fillBodyFields(target_part,which->bd_fields); |
634 | } | 634 | } |
635 | 635 | ||
636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
637 | { | 637 | { |
638 | if (!which) { | 638 | if (!which) { |
639 | return; | 639 | return; |
640 | } | 640 | } |
641 | target_part.setSubtype("rfc822"); | 641 | target_part.setSubtype("rfc822"); |
642 | qDebug("Message part"); | 642 | qDebug("Message part"); |
643 | /* we set this type to text/plain */ | 643 | /* we set this type to text/plain */ |
644 | target_part.setLines(which->bd_lines); | 644 | target_part.setLines(which->bd_lines); |
645 | fillBodyFields(target_part,which->bd_fields); | 645 | fillBodyFields(target_part,which->bd_fields); |
646 | } | 646 | } |
647 | 647 | ||
648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) |
649 | { | 649 | { |
650 | if (!which) return; | 650 | if (!which) return; |
651 | target_part.setSubtype(which->bd_media_subtype); | 651 | QString sub = which->bd_media_subtype; |
652 | target_part.setSubtype(sub.lower()); | ||
652 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 653 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
653 | clistcell*cur = 0; | 654 | clistcell*cur = 0; |
654 | mailimap_single_body_fld_param*param=0; | 655 | mailimap_single_body_fld_param*param=0; |
655 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 656 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
656 | param = (mailimap_single_body_fld_param*)cur->data; | 657 | param = (mailimap_single_body_fld_param*)cur->data; |
657 | if (param) { | 658 | if (param) { |
658 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 659 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
659 | } | 660 | } |
660 | } | 661 | } |
661 | } | 662 | } |
662 | } | 663 | } |
663 | 664 | ||
664 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 665 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
665 | { | 666 | { |
666 | if (!which) { | 667 | if (!which) { |
667 | return; | 668 | return; |
668 | } | 669 | } |
669 | QString type,sub; | 670 | QString type,sub; |
670 | switch (which->bd_media_basic->med_type) { | 671 | switch (which->bd_media_basic->med_type) { |
671 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 672 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
672 | type = "application"; | 673 | type = "application"; |
673 | break; | 674 | break; |
674 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 675 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
675 | type = "audio"; | 676 | type = "audio"; |
676 | break; | 677 | break; |
677 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 678 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
678 | type = "image"; | 679 | type = "image"; |
679 | break; | 680 | break; |
680 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 681 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
681 | type = "message"; | 682 | type = "message"; |
682 | break; | 683 | break; |
683 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 684 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
684 | type = "video"; | 685 | type = "video"; |
685 | break; | 686 | break; |
686 | case MAILIMAP_MEDIA_BASIC_OTHER: | 687 | case MAILIMAP_MEDIA_BASIC_OTHER: |
687 | default: | 688 | default: |
688 | if (which->bd_media_basic->med_basic_type) { | 689 | if (which->bd_media_basic->med_basic_type) { |
689 | type = which->bd_media_basic->med_basic_type; | 690 | type = which->bd_media_basic->med_basic_type; |
690 | } else { | 691 | } else { |
691 | type = ""; | 692 | type = ""; |
692 | } | 693 | } |
693 | break; | 694 | break; |
694 | } | 695 | } |
695 | if (which->bd_media_basic->med_subtype) { | 696 | if (which->bd_media_basic->med_subtype) { |
696 | sub = which->bd_media_basic->med_subtype; | 697 | sub = which->bd_media_basic->med_subtype; |
697 | } else { | 698 | } else { |
698 | sub = ""; | 699 | sub = ""; |
699 | } | 700 | } |
700 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 701 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
701 | target_part.setType(type.lower()); | 702 | target_part.setType(type.lower()); |
702 | target_part.setSubtype(sub.lower()); | 703 | target_part.setSubtype(sub.lower()); |
703 | fillBodyFields(target_part,which->bd_fields); | 704 | fillBodyFields(target_part,which->bd_fields); |
704 | } | 705 | } |
705 | 706 | ||
706 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 707 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
707 | { | 708 | { |
708 | if (!which) return; | 709 | if (!which) return; |
709 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 710 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
710 | clistcell*cur; | 711 | clistcell*cur; |
711 | mailimap_single_body_fld_param*param=0; | 712 | mailimap_single_body_fld_param*param=0; |
712 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 713 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
713 | param = (mailimap_single_body_fld_param*)cur->data; | 714 | param = (mailimap_single_body_fld_param*)cur->data; |
714 | if (param) { | 715 | if (param) { |
715 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 716 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
716 | } | 717 | } |
717 | } | 718 | } |
718 | } | 719 | } |
719 | mailimap_body_fld_enc*enc = which->bd_encoding; | 720 | mailimap_body_fld_enc*enc = which->bd_encoding; |
720 | QString encoding(""); | 721 | QString encoding(""); |
721 | switch (enc->enc_type) { | 722 | switch (enc->enc_type) { |
722 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 723 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
723 | encoding = "7bit"; | 724 | encoding = "7bit"; |
724 | break; | 725 | break; |
725 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 726 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
726 | encoding = "8bit"; | 727 | encoding = "8bit"; |
727 | break; | 728 | break; |
728 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 729 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
729 | encoding="binary"; | 730 | encoding="binary"; |
730 | break; | 731 | break; |
731 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 732 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
732 | encoding="base64"; | 733 | encoding="base64"; |
733 | break; | 734 | break; |
734 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 735 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
735 | encoding="quoted-printable"; | 736 | encoding="quoted-printable"; |
736 | break; | 737 | break; |
737 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 738 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
738 | default: | 739 | default: |
739 | if (enc->enc_value) { | 740 | if (enc->enc_value) { |
740 | char*t=enc->enc_value; | 741 | char*t=enc->enc_value; |
741 | encoding=QString(enc->enc_value); | 742 | encoding=QString(enc->enc_value); |
742 | enc->enc_value=0L; | 743 | enc->enc_value=0L; |
743 | free(t); | 744 | free(t); |
744 | } | 745 | } |
745 | } | 746 | } |
746 | if (which->bd_description) { | 747 | if (which->bd_description) { |
747 | target_part.setDescription(QString(which->bd_description)); | 748 | target_part.setDescription(QString(which->bd_description)); |
748 | } | 749 | } |
749 | target_part.setEncoding(encoding); | 750 | target_part.setEncoding(encoding); |
750 | target_part.setSize(which->bd_size); | 751 | target_part.setSize(which->bd_size); |
751 | } | 752 | } |
752 | 753 | ||
753 | void IMAPwrapper::deleteMail(const RecMail&mail) | 754 | void IMAPwrapper::deleteMail(const RecMail&mail) |
754 | { | 755 | { |
755 | mailimap_flag_list*flist; | 756 | mailimap_flag_list*flist; |
756 | mailimap_set *set; | 757 | mailimap_set *set; |
757 | mailimap_store_att_flags * store_flags; | 758 | mailimap_store_att_flags * store_flags; |
758 | int err; | 759 | int err; |
759 | login(); | 760 | login(); |
760 | if (!m_imap) { | 761 | if (!m_imap) { |
761 | return; | 762 | return; |
762 | } | 763 | } |
763 | const char *mb = mail.getMbox().latin1(); | 764 | const char *mb = mail.getMbox().latin1(); |
764 | err = mailimap_select( m_imap, (char*)mb); | 765 | err = mailimap_select( m_imap, (char*)mb); |
765 | if ( err != MAILIMAP_NO_ERROR ) { | 766 | if ( err != MAILIMAP_NO_ERROR ) { |
766 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 767 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
767 | return; | 768 | return; |
768 | } | 769 | } |
769 | flist = mailimap_flag_list_new_empty(); | 770 | flist = mailimap_flag_list_new_empty(); |
770 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 771 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
771 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 772 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
772 | set = mailimap_set_new_single(mail.getNumber()); | 773 | set = mailimap_set_new_single(mail.getNumber()); |
773 | err = mailimap_store(m_imap,set,store_flags); | 774 | err = mailimap_store(m_imap,set,store_flags); |
774 | mailimap_set_free( set ); | 775 | mailimap_set_free( set ); |
775 | mailimap_store_att_flags_free(store_flags); | 776 | mailimap_store_att_flags_free(store_flags); |
776 | 777 | ||
777 | if (err != MAILIMAP_NO_ERROR) { | 778 | if (err != MAILIMAP_NO_ERROR) { |
778 | qDebug("error deleting mail: %s",m_imap->imap_response); | 779 | qDebug("error deleting mail: %s",m_imap->imap_response); |
779 | return; | 780 | return; |
780 | } | 781 | } |
781 | qDebug("deleting mail: %s",m_imap->imap_response); | 782 | qDebug("deleting mail: %s",m_imap->imap_response); |
782 | /* should we realy do that at this moment? */ | 783 | /* should we realy do that at this moment? */ |
783 | err = mailimap_expunge(m_imap); | 784 | err = mailimap_expunge(m_imap); |
784 | if (err != MAILIMAP_NO_ERROR) { | 785 | if (err != MAILIMAP_NO_ERROR) { |
785 | qDebug("error deleting mail: %s",m_imap->imap_response); | 786 | qDebug("error deleting mail: %s",m_imap->imap_response); |
786 | } | 787 | } |
787 | qDebug("Delete successfull %s",m_imap->imap_response); | 788 | qDebug("Delete successfull %s",m_imap->imap_response); |
788 | } | 789 | } |
789 | 790 | ||
790 | void IMAPwrapper::answeredMail(const RecMail&mail) | 791 | void IMAPwrapper::answeredMail(const RecMail&mail) |
791 | { | 792 | { |
792 | mailimap_flag_list*flist; | 793 | mailimap_flag_list*flist; |
793 | mailimap_set *set; | 794 | mailimap_set *set; |
794 | mailimap_store_att_flags * store_flags; | 795 | mailimap_store_att_flags * store_flags; |
795 | int err; | 796 | int err; |
796 | login(); | 797 | login(); |
797 | if (!m_imap) { | 798 | if (!m_imap) { |
798 | return; | 799 | return; |
799 | } | 800 | } |
800 | const char *mb = mail.getMbox().latin1(); | 801 | const char *mb = mail.getMbox().latin1(); |
801 | err = mailimap_select( m_imap, (char*)mb); | 802 | err = mailimap_select( m_imap, (char*)mb); |
802 | if ( err != MAILIMAP_NO_ERROR ) { | 803 | if ( err != MAILIMAP_NO_ERROR ) { |
803 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 804 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
804 | return; | 805 | return; |
805 | } | 806 | } |
806 | flist = mailimap_flag_list_new_empty(); | 807 | flist = mailimap_flag_list_new_empty(); |
807 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 808 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
808 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 809 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
809 | set = mailimap_set_new_single(mail.getNumber()); | 810 | set = mailimap_set_new_single(mail.getNumber()); |
810 | err = mailimap_store(m_imap,set,store_flags); | 811 | err = mailimap_store(m_imap,set,store_flags); |
811 | mailimap_set_free( set ); | 812 | mailimap_set_free( set ); |
812 | mailimap_store_att_flags_free(store_flags); | 813 | mailimap_store_att_flags_free(store_flags); |
813 | 814 | ||
814 | if (err != MAILIMAP_NO_ERROR) { | 815 | if (err != MAILIMAP_NO_ERROR) { |
815 | qDebug("error marking mail: %s",m_imap->imap_response); | 816 | qDebug("error marking mail: %s",m_imap->imap_response); |
816 | return; | 817 | return; |
817 | } | 818 | } |
818 | } | 819 | } |
819 | 820 | ||
820 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 821 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
821 | { | 822 | { |
822 | QString body(""); | 823 | QString body(""); |
823 | encodedString*res = fetchRawPart(mail,path,internal_call); | 824 | encodedString*res = fetchRawPart(mail,path,internal_call); |
824 | encodedString*r = decode_String(res,enc); | 825 | encodedString*r = decode_String(res,enc); |
825 | delete res; | 826 | delete res; |
826 | if (r) { | 827 | if (r) { |
827 | if (r->Length()>0) { | 828 | if (r->Length()>0) { |
828 | body = r->Content(); | 829 | body = r->Content(); |
829 | } | 830 | } |
830 | delete r; | 831 | delete r; |
831 | } | 832 | } |
832 | return body; | 833 | return body; |
833 | } | 834 | } |
834 | 835 | ||
835 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 836 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
836 | { | 837 | { |
837 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 838 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
838 | } | 839 | } |
839 | 840 | ||
840 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 841 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
841 | { | 842 | { |
842 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 843 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
843 | encodedString*r = decode_String(res,part.Encoding()); | 844 | encodedString*r = decode_String(res,part.Encoding()); |
844 | delete res; | 845 | delete res; |
845 | return r; | 846 | return r; |
846 | } | 847 | } |
847 | 848 | ||
848 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 849 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
849 | { | 850 | { |
850 | return fetchRawPart(mail,part.Positionlist(),false); | 851 | return fetchRawPart(mail,part.Positionlist(),false); |
851 | } | 852 | } |
852 | 853 | ||
853 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 854 | int IMAPwrapper::deleteAllMail(const Folder*folder) |
854 | { | 855 | { |
855 | login(); | 856 | login(); |
856 | if (!m_imap) { | 857 | if (!m_imap) { |
857 | return 0; | 858 | return 0; |
858 | } | 859 | } |
859 | mailimap_flag_list*flist; | 860 | mailimap_flag_list*flist; |
860 | mailimap_set *set; | 861 | mailimap_set *set; |
861 | mailimap_store_att_flags * store_flags; | 862 | mailimap_store_att_flags * store_flags; |
862 | int err = mailimap_select( m_imap, folder->getName().latin1()); | 863 | int err = mailimap_select( m_imap, folder->getName().latin1()); |
863 | if ( err != MAILIMAP_NO_ERROR ) { | 864 | if ( err != MAILIMAP_NO_ERROR ) { |
864 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | 865 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); |
865 | return 0; | 866 | return 0; |
866 | } | 867 | } |
867 | int last = m_imap->imap_selection_info->sel_exists; | 868 | int last = m_imap->imap_selection_info->sel_exists; |
868 | if (last == 0) { | 869 | if (last == 0) { |
869 | Global::statusMessage(tr("Mailbox has no mails!")); | 870 | Global::statusMessage(tr("Mailbox has no mails!")); |
870 | return 0; | 871 | return 0; |
871 | } | 872 | } |
872 | flist = mailimap_flag_list_new_empty(); | 873 | flist = mailimap_flag_list_new_empty(); |
873 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 874 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
874 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 875 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
875 | set = mailimap_set_new_interval( 1, last ); | 876 | set = mailimap_set_new_interval( 1, last ); |
876 | err = mailimap_store(m_imap,set,store_flags); | 877 | err = mailimap_store(m_imap,set,store_flags); |
877 | mailimap_set_free( set ); | 878 | mailimap_set_free( set ); |
878 | mailimap_store_att_flags_free(store_flags); | 879 | mailimap_store_att_flags_free(store_flags); |
879 | if (err != MAILIMAP_NO_ERROR) { | 880 | if (err != MAILIMAP_NO_ERROR) { |
880 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 881 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
881 | return 0; | 882 | return 0; |
882 | } | 883 | } |
883 | qDebug("deleting mail: %s",m_imap->imap_response); | 884 | qDebug("deleting mail: %s",m_imap->imap_response); |
884 | /* should we realy do that at this moment? */ | 885 | /* should we realy do that at this moment? */ |
885 | err = mailimap_expunge(m_imap); | 886 | err = mailimap_expunge(m_imap); |
886 | if (err != MAILIMAP_NO_ERROR) { | 887 | if (err != MAILIMAP_NO_ERROR) { |
887 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 888 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
888 | return 0; | 889 | return 0; |
889 | } | 890 | } |
890 | qDebug("Delete successfull %s",m_imap->imap_response); | 891 | qDebug("Delete successfull %s",m_imap->imap_response); |
891 | return 1; | 892 | return 1; |
892 | } | 893 | } |
893 | 894 | ||
894 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 895 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) |
895 | { | 896 | { |
896 | if (folder.length()==0) return 0; | 897 | if (folder.length()==0) return 0; |
897 | login(); | 898 | login(); |
898 | if (!m_imap) {return 0;} | 899 | if (!m_imap) {return 0;} |
899 | QString pre = account->getPrefix(); | 900 | QString pre = account->getPrefix(); |
900 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 901 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
901 | pre+=delemiter; | 902 | pre+=delemiter; |
902 | } | 903 | } |
903 | if (parentfolder) { | 904 | if (parentfolder) { |
904 | pre += parentfolder->getDisplayName()+delemiter; | 905 | pre += parentfolder->getDisplayName()+delemiter; |
905 | } | 906 | } |
906 | pre+=folder; | 907 | pre+=folder; |
907 | if (getsubfolder) { | 908 | if (getsubfolder) { |
908 | if (delemiter.length()>0) { | 909 | if (delemiter.length()>0) { |
909 | pre+=delemiter; | 910 | pre+=delemiter; |
910 | } else { | 911 | } else { |
911 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 912 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
912 | return 0; | 913 | return 0; |
913 | } | 914 | } |
914 | } | 915 | } |
915 | qDebug("Creating %s",pre.latin1()); | 916 | qDebug("Creating %s",pre.latin1()); |
916 | int res = mailimap_create(m_imap,pre.latin1()); | 917 | int res = mailimap_create(m_imap,pre.latin1()); |
917 | if (res != MAILIMAP_NO_ERROR) { | 918 | if (res != MAILIMAP_NO_ERROR) { |
918 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 919 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
919 | return 0; | 920 | return 0; |
920 | } | 921 | } |
921 | return 1; | 922 | return 1; |
922 | } | 923 | } |
923 | 924 | ||
924 | int IMAPwrapper::deleteMbox(const Folder*folder) | 925 | int IMAPwrapper::deleteMbox(const Folder*folder) |
925 | { | 926 | { |
926 | if (!folder) return 0; | 927 | if (!folder) return 0; |
927 | login(); | 928 | login(); |
928 | if (!m_imap) {return 0;} | 929 | if (!m_imap) {return 0;} |
929 | int res = mailimap_delete(m_imap,folder->getName()); | 930 | int res = mailimap_delete(m_imap,folder->getName()); |
930 | if (res != MAILIMAP_NO_ERROR) { | 931 | if (res != MAILIMAP_NO_ERROR) { |
931 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 932 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
932 | return 0; | 933 | return 0; |
933 | } | 934 | } |
934 | return 1; | 935 | return 1; |
935 | } | 936 | } |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index ae196bb..b437df0 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -139,797 +139,798 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
139 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); | 139 | fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); |
140 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); | 140 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); |
141 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); | 141 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); |
142 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); | 142 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); |
143 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); | 143 | mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); |
144 | 144 | ||
145 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 145 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
146 | mailimap_set_free( set ); | 146 | mailimap_set_free( set ); |
147 | mailimap_fetch_type_free( fetchType ); | 147 | mailimap_fetch_type_free( fetchType ); |
148 | 148 | ||
149 | QString date,subject,from; | 149 | QString date,subject,from; |
150 | 150 | ||
151 | if ( err == MAILIMAP_NO_ERROR ) { | 151 | if ( err == MAILIMAP_NO_ERROR ) { |
152 | mailimap_msg_att * msg_att; | 152 | mailimap_msg_att * msg_att; |
153 | int i = 0; | 153 | int i = 0; |
154 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { | 154 | for (current = clist_begin(result); current != 0; current=clist_next(current)) { |
155 | ++i; | 155 | ++i; |
156 | msg_att = (mailimap_msg_att*)current->data; | 156 | msg_att = (mailimap_msg_att*)current->data; |
157 | RecMail*m = parse_list_result(msg_att); | 157 | RecMail*m = parse_list_result(msg_att); |
158 | if (m) { | 158 | if (m) { |
159 | m->setNumber(i); | 159 | m->setNumber(i); |
160 | m->setMbox(mailbox); | 160 | m->setMbox(mailbox); |
161 | m->setWrapper(this); | 161 | m->setWrapper(this); |
162 | target.append(m); | 162 | target.append(m); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | } else { | 165 | } else { |
166 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); | 166 | Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); |
167 | } | 167 | } |
168 | if (result) mailimap_fetch_list_free(result); | 168 | if (result) mailimap_fetch_list_free(result); |
169 | } | 169 | } |
170 | 170 | ||
171 | QList<Folder>* IMAPwrapper::listFolders() | 171 | QList<Folder>* IMAPwrapper::listFolders() |
172 | { | 172 | { |
173 | const char *path, *mask; | 173 | const char *path, *mask; |
174 | int err = MAILIMAP_NO_ERROR; | 174 | int err = MAILIMAP_NO_ERROR; |
175 | clist *result = 0; | 175 | clist *result = 0; |
176 | clistcell *current = 0; | 176 | clistcell *current = 0; |
177 | clistcell*cur_flag = 0; | 177 | clistcell*cur_flag = 0; |
178 | mailimap_mbx_list_flags*bflags = 0; | 178 | mailimap_mbx_list_flags*bflags = 0; |
179 | 179 | ||
180 | QList<Folder> * folders = new QList<Folder>(); | 180 | QList<Folder> * folders = new QList<Folder>(); |
181 | folders->setAutoDelete( false ); | 181 | folders->setAutoDelete( false ); |
182 | login(); | 182 | login(); |
183 | if (!m_imap) { | 183 | if (!m_imap) { |
184 | return folders; | 184 | return folders; |
185 | } | 185 | } |
186 | 186 | ||
187 | /* | 187 | /* |
188 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 188 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
189 | * We must not forget to filter them out in next loop! | 189 | * We must not forget to filter them out in next loop! |
190 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 190 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
191 | */ | 191 | */ |
192 | QString temp; | 192 | QString temp; |
193 | mask = "INBOX" ; | 193 | mask = "INBOX" ; |
194 | mailimap_mailbox_list *list; | 194 | mailimap_mailbox_list *list; |
195 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 195 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
196 | QString del; | 196 | QString del; |
197 | bool selectable = true; | 197 | bool selectable = true; |
198 | bool no_inferiors = false; | 198 | bool no_inferiors = false; |
199 | if ( err == MAILIMAP_NO_ERROR ) { | 199 | if ( err == MAILIMAP_NO_ERROR ) { |
200 | current = result->first; | 200 | current = result->first; |
201 | for ( int i = result->count; i > 0; i-- ) { | 201 | for ( int i = result->count; i > 0; i-- ) { |
202 | list = (mailimap_mailbox_list *) current->data; | 202 | list = (mailimap_mailbox_list *) current->data; |
203 | // it is better use the deep copy mechanism of qt itself | 203 | // it is better use the deep copy mechanism of qt itself |
204 | // instead of using strdup! | 204 | // instead of using strdup! |
205 | temp = list->mb_name; | 205 | temp = list->mb_name; |
206 | del = list->mb_delimiter; | 206 | del = list->mb_delimiter; |
207 | current = current->next; | 207 | current = current->next; |
208 | if ( (bflags = list->mb_flag) ) { | 208 | if ( (bflags = list->mb_flag) ) { |
209 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 209 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
210 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 210 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
211 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 211 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
212 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 212 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
213 | no_inferiors = true; | 213 | no_inferiors = true; |
214 | } | 214 | } |
215 | } | 215 | } |
216 | } | 216 | } |
217 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 217 | folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
218 | } | 218 | } |
219 | } else { | 219 | } else { |
220 | qDebug("error fetching folders: %s",m_imap->imap_response); | 220 | qDebug("error fetching folders: %s",m_imap->imap_response); |
221 | } | 221 | } |
222 | mailimap_list_result_free( result ); | 222 | mailimap_list_result_free( result ); |
223 | 223 | ||
224 | /* | 224 | /* |
225 | * second stage - get the other then inbox folders | 225 | * second stage - get the other then inbox folders |
226 | */ | 226 | */ |
227 | mask = "*" ; | 227 | mask = "*" ; |
228 | path = account->getPrefix().latin1(); | 228 | path = account->getPrefix().latin1(); |
229 | if (!path) path = ""; | 229 | if (!path) path = ""; |
230 | qDebug(path); | 230 | qDebug(path); |
231 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 231 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
232 | if ( err == MAILIMAP_NO_ERROR ) { | 232 | if ( err == MAILIMAP_NO_ERROR ) { |
233 | current = result->first; | 233 | current = result->first; |
234 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 234 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
235 | no_inferiors = false; | 235 | no_inferiors = false; |
236 | list = (mailimap_mailbox_list *) current->data; | 236 | list = (mailimap_mailbox_list *) current->data; |
237 | // it is better use the deep copy mechanism of qt itself | 237 | // it is better use the deep copy mechanism of qt itself |
238 | // instead of using strdup! | 238 | // instead of using strdup! |
239 | temp = list->mb_name; | 239 | temp = list->mb_name; |
240 | if (temp.lower()=="inbox") | 240 | if (temp.lower()=="inbox") |
241 | continue; | 241 | continue; |
242 | if (temp.lower()==account->getPrefix().lower()) | 242 | if (temp.lower()==account->getPrefix().lower()) |
243 | continue; | 243 | continue; |
244 | if ( (bflags = list->mb_flag) ) { | 244 | if ( (bflags = list->mb_flag) ) { |
245 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 245 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
246 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 246 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
247 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { | 247 | for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { |
248 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { | 248 | if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { |
249 | no_inferiors = true; | 249 | no_inferiors = true; |
250 | } | 250 | } |
251 | } | 251 | } |
252 | } | 252 | } |
253 | del = list->mb_delimiter; | 253 | del = list->mb_delimiter; |
254 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); | 254 | folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); |
255 | } | 255 | } |
256 | } else { | 256 | } else { |
257 | qDebug("error fetching folders %s",m_imap->imap_response); | 257 | qDebug("error fetching folders %s",m_imap->imap_response); |
258 | } | 258 | } |
259 | if (result) mailimap_list_result_free( result ); | 259 | if (result) mailimap_list_result_free( result ); |
260 | return folders; | 260 | return folders; |
261 | } | 261 | } |
262 | 262 | ||
263 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 263 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
264 | { | 264 | { |
265 | RecMail * m = 0; | 265 | RecMail * m = 0; |
266 | mailimap_msg_att_item *item=0; | 266 | mailimap_msg_att_item *item=0; |
267 | clistcell *current,*c,*cf; | 267 | clistcell *current,*c,*cf; |
268 | mailimap_msg_att_dynamic*flist; | 268 | mailimap_msg_att_dynamic*flist; |
269 | mailimap_flag_fetch*cflag; | 269 | mailimap_flag_fetch*cflag; |
270 | int size; | 270 | int size; |
271 | QBitArray mFlags(7); | 271 | QBitArray mFlags(7); |
272 | QStringList addresslist; | 272 | QStringList addresslist; |
273 | 273 | ||
274 | if (!m_att) { | 274 | if (!m_att) { |
275 | return m; | 275 | return m; |
276 | } | 276 | } |
277 | m = new RecMail(); | 277 | m = new RecMail(); |
278 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { | 278 | for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { |
279 | current = c; | 279 | current = c; |
280 | size = 0; | 280 | size = 0; |
281 | item = (mailimap_msg_att_item*)current->data; | 281 | item = (mailimap_msg_att_item*)current->data; |
282 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { | 282 | if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { |
283 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; | 283 | flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; |
284 | if (!flist->att_list) { | 284 | if (!flist->att_list) { |
285 | continue; | 285 | continue; |
286 | } | 286 | } |
287 | cf = flist->att_list->first; | 287 | cf = flist->att_list->first; |
288 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { | 288 | for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { |
289 | cflag = (mailimap_flag_fetch*)cf->data; | 289 | cflag = (mailimap_flag_fetch*)cf->data; |
290 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { | 290 | if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { |
291 | switch (cflag->fl_flag->fl_type) { | 291 | switch (cflag->fl_flag->fl_type) { |
292 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ | 292 | case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ |
293 | mFlags.setBit(FLAG_ANSWERED); | 293 | mFlags.setBit(FLAG_ANSWERED); |
294 | break; | 294 | break; |
295 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ | 295 | case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ |
296 | mFlags.setBit(FLAG_FLAGGED); | 296 | mFlags.setBit(FLAG_FLAGGED); |
297 | break; | 297 | break; |
298 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ | 298 | case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ |
299 | mFlags.setBit(FLAG_DELETED); | 299 | mFlags.setBit(FLAG_DELETED); |
300 | break; | 300 | break; |
301 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ | 301 | case MAILIMAP_FLAG_SEEN: /* \Seen flag */ |
302 | mFlags.setBit(FLAG_SEEN); | 302 | mFlags.setBit(FLAG_SEEN); |
303 | break; | 303 | break; |
304 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ | 304 | case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ |
305 | mFlags.setBit(FLAG_DRAFT); | 305 | mFlags.setBit(FLAG_DRAFT); |
306 | break; | 306 | break; |
307 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ | 307 | case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ |
308 | break; | 308 | break; |
309 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ | 309 | case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ |
310 | break; | 310 | break; |
311 | default: | 311 | default: |
312 | break; | 312 | break; |
313 | } | 313 | } |
314 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { | 314 | } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { |
315 | mFlags.setBit(FLAG_RECENT); | 315 | mFlags.setBit(FLAG_RECENT); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | continue; | 318 | continue; |
319 | } | 319 | } |
320 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { | 320 | if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { |
321 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; | 321 | mailimap_envelope * head = item->att_data.att_static->att_data.att_env; |
322 | m->setDate(head->env_date); | 322 | m->setDate(head->env_date); |
323 | m->setSubject(convert_String((const char*)head->env_subject)); | 323 | m->setSubject(convert_String((const char*)head->env_subject)); |
324 | //m->setSubject(head->env_subject); | 324 | //m->setSubject(head->env_subject); |
325 | if (head->env_from!=NULL) { | 325 | if (head->env_from!=NULL) { |
326 | addresslist = address_list_to_stringlist(head->env_from->frm_list); | 326 | addresslist = address_list_to_stringlist(head->env_from->frm_list); |
327 | if (addresslist.count()) { | 327 | if (addresslist.count()) { |
328 | m->setFrom(addresslist.first()); | 328 | m->setFrom(addresslist.first()); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | if (head->env_to!=NULL) { | 331 | if (head->env_to!=NULL) { |
332 | addresslist = address_list_to_stringlist(head->env_to->to_list); | 332 | addresslist = address_list_to_stringlist(head->env_to->to_list); |
333 | m->setTo(addresslist); | 333 | m->setTo(addresslist); |
334 | } | 334 | } |
335 | if (head->env_cc!=NULL) { | 335 | if (head->env_cc!=NULL) { |
336 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); | 336 | addresslist = address_list_to_stringlist(head->env_cc->cc_list); |
337 | m->setCC(addresslist); | 337 | m->setCC(addresslist); |
338 | } | 338 | } |
339 | if (head->env_bcc!=NULL) { | 339 | if (head->env_bcc!=NULL) { |
340 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); | 340 | addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); |
341 | m->setBcc(addresslist); | 341 | m->setBcc(addresslist); |
342 | } | 342 | } |
343 | if (head->env_reply_to!=NULL) { | 343 | if (head->env_reply_to!=NULL) { |
344 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); | 344 | addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); |
345 | if (addresslist.count()) { | 345 | if (addresslist.count()) { |
346 | m->setReplyto(addresslist.first()); | 346 | m->setReplyto(addresslist.first()); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | m->setMsgid(QString(head->env_message_id)); | 349 | m->setMsgid(QString(head->env_message_id)); |
350 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 350 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
351 | #if 0 | 351 | #if 0 |
352 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | 352 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; |
353 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 353 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
354 | 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); | 354 | 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); |
355 | qDebug(da.toString()); | 355 | qDebug(da.toString()); |
356 | #endif | 356 | #endif |
357 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 357 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
358 | size = item->att_data.att_static->att_data.att_rfc822_size; | 358 | size = item->att_data.att_static->att_data.att_rfc822_size; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | /* msg is already deleted */ | 361 | /* msg is already deleted */ |
362 | if (mFlags.testBit(FLAG_DELETED) && m) { | 362 | if (mFlags.testBit(FLAG_DELETED) && m) { |
363 | delete m; | 363 | delete m; |
364 | m = 0; | 364 | m = 0; |
365 | } | 365 | } |
366 | if (m) { | 366 | if (m) { |
367 | m->setFlags(mFlags); | 367 | m->setFlags(mFlags); |
368 | m->setMsgsize(size); | 368 | m->setMsgsize(size); |
369 | } | 369 | } |
370 | return m; | 370 | return m; |
371 | } | 371 | } |
372 | 372 | ||
373 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 373 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
374 | { | 374 | { |
375 | RecBody body; | 375 | RecBody body; |
376 | const char *mb; | 376 | const char *mb; |
377 | int err = MAILIMAP_NO_ERROR; | 377 | int err = MAILIMAP_NO_ERROR; |
378 | clist *result = 0; | 378 | clist *result = 0; |
379 | clistcell *current; | 379 | clistcell *current; |
380 | mailimap_fetch_att *fetchAtt = 0; | 380 | mailimap_fetch_att *fetchAtt = 0; |
381 | mailimap_fetch_type *fetchType = 0; | 381 | mailimap_fetch_type *fetchType = 0; |
382 | mailimap_set *set = 0; | 382 | mailimap_set *set = 0; |
383 | mailimap_body*body_desc = 0; | 383 | mailimap_body*body_desc = 0; |
384 | 384 | ||
385 | mb = mail.getMbox().latin1(); | 385 | mb = mail.getMbox().latin1(); |
386 | 386 | ||
387 | login(); | 387 | login(); |
388 | if (!m_imap) { | 388 | if (!m_imap) { |
389 | return body; | 389 | return body; |
390 | } | 390 | } |
391 | 391 | ||
392 | err = mailimap_select( m_imap, (char*)mb); | 392 | err = mailimap_select( m_imap, (char*)mb); |
393 | if ( err != MAILIMAP_NO_ERROR ) { | 393 | if ( err != MAILIMAP_NO_ERROR ) { |
394 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 394 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
395 | return body; | 395 | return body; |
396 | } | 396 | } |
397 | 397 | ||
398 | /* the range has to start at 1!!! not with 0!!!! */ | 398 | /* the range has to start at 1!!! not with 0!!!! */ |
399 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 399 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
400 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 400 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
401 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 401 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
403 | mailimap_set_free( set ); | 403 | mailimap_set_free( set ); |
404 | mailimap_fetch_type_free( fetchType ); | 404 | mailimap_fetch_type_free( fetchType ); |
405 | 405 | ||
406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
407 | mailimap_msg_att * msg_att; | 407 | mailimap_msg_att * msg_att; |
408 | msg_att = (mailimap_msg_att*)current->data; | 408 | msg_att = (mailimap_msg_att*)current->data; |
409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
410 | QValueList<int> path; | 410 | QValueList<int> path; |
411 | body_desc = item->att_data.att_static->att_data.att_body; | 411 | body_desc = item->att_data.att_static->att_data.att_body; |
412 | traverseBody(mail,body_desc,body,0,path); | 412 | traverseBody(mail,body_desc,body,0,path); |
413 | } else { | 413 | } else { |
414 | qDebug("error fetching body: %s",m_imap->imap_response); | 414 | qDebug("error fetching body: %s",m_imap->imap_response); |
415 | } | 415 | } |
416 | if (result) mailimap_fetch_list_free(result); | 416 | if (result) mailimap_fetch_list_free(result); |
417 | return body; | 417 | return body; |
418 | } | 418 | } |
419 | 419 | ||
420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
421 | { | 421 | { |
422 | QStringList l; | 422 | QStringList l; |
423 | QString from; | 423 | QString from; |
424 | bool named_from; | 424 | bool named_from; |
425 | clistcell *current = NULL; | 425 | clistcell *current = NULL; |
426 | mailimap_address * current_address=NULL; | 426 | mailimap_address * current_address=NULL; |
427 | if (!list) { | 427 | if (!list) { |
428 | return l; | 428 | return l; |
429 | } | 429 | } |
430 | unsigned int count = 0; | 430 | unsigned int count = 0; |
431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
432 | from = ""; | 432 | from = ""; |
433 | named_from = false; | 433 | named_from = false; |
434 | current_address=(mailimap_address*)current->data; | 434 | current_address=(mailimap_address*)current->data; |
435 | if (current_address->ad_personal_name){ | 435 | if (current_address->ad_personal_name){ |
436 | from+=convert_String((const char*)current_address->ad_personal_name); | 436 | from+=convert_String((const char*)current_address->ad_personal_name); |
437 | from+=" "; | 437 | from+=" "; |
438 | named_from = true; | 438 | named_from = true; |
439 | } | 439 | } |
440 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 440 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
441 | from+="<"; | 441 | from+="<"; |
442 | } | 442 | } |
443 | if (current_address->ad_mailbox_name) { | 443 | if (current_address->ad_mailbox_name) { |
444 | from+=QString(current_address->ad_mailbox_name); | 444 | from+=QString(current_address->ad_mailbox_name); |
445 | from+="@"; | 445 | from+="@"; |
446 | } | 446 | } |
447 | if (current_address->ad_host_name) { | 447 | if (current_address->ad_host_name) { |
448 | from+=QString(current_address->ad_host_name); | 448 | from+=QString(current_address->ad_host_name); |
449 | } | 449 | } |
450 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { | 450 | if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { |
451 | from+=">"; | 451 | from+=">"; |
452 | } | 452 | } |
453 | l.append(QString(from)); | 453 | l.append(QString(from)); |
454 | if (++count > 99) { | 454 | if (++count > 99) { |
455 | break; | 455 | break; |
456 | } | 456 | } |
457 | } | 457 | } |
458 | return l; | 458 | return l; |
459 | } | 459 | } |
460 | 460 | ||
461 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) | 461 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
462 | { | 462 | { |
463 | encodedString*res=new encodedString; | 463 | encodedString*res=new encodedString; |
464 | const char*mb; | 464 | const char*mb; |
465 | int err; | 465 | int err; |
466 | mailimap_fetch_type *fetchType; | 466 | mailimap_fetch_type *fetchType; |
467 | mailimap_set *set; | 467 | mailimap_set *set; |
468 | clistcell*current,*cur; | 468 | clistcell*current,*cur; |
469 | 469 | ||
470 | login(); | 470 | login(); |
471 | if (!m_imap) { | 471 | if (!m_imap) { |
472 | return res; | 472 | return res; |
473 | } | 473 | } |
474 | if (!internal_call) { | 474 | if (!internal_call) { |
475 | mb = mail.getMbox().latin1(); | 475 | mb = mail.getMbox().latin1(); |
476 | err = mailimap_select( m_imap, (char*)mb); | 476 | err = mailimap_select( m_imap, (char*)mb); |
477 | if ( err != MAILIMAP_NO_ERROR ) { | 477 | if ( err != MAILIMAP_NO_ERROR ) { |
478 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 478 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
479 | return res; | 479 | return res; |
480 | } | 480 | } |
481 | } | 481 | } |
482 | set = mailimap_set_new_single(mail.getNumber()); | 482 | set = mailimap_set_new_single(mail.getNumber()); |
483 | clist*id_list=clist_new(); | 483 | clist*id_list=clist_new(); |
484 | for (unsigned j=0; j < path.count();++j) { | 484 | for (unsigned j=0; j < path.count();++j) { |
485 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 485 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
486 | *p_id = path[j]; | 486 | *p_id = path[j]; |
487 | clist_append(id_list,p_id); | 487 | clist_append(id_list,p_id); |
488 | } | 488 | } |
489 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 489 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
490 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 490 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
491 | mailimap_section * section = mailimap_section_new(section_spec); | 491 | mailimap_section * section = mailimap_section_new(section_spec); |
492 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 492 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
493 | 493 | ||
494 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 494 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
495 | 495 | ||
496 | clist*result = 0; | 496 | clist*result = 0; |
497 | 497 | ||
498 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 498 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
499 | mailimap_set_free( set ); | 499 | mailimap_set_free( set ); |
500 | mailimap_fetch_type_free( fetchType ); | 500 | mailimap_fetch_type_free( fetchType ); |
501 | 501 | ||
502 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 502 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
503 | mailimap_msg_att * msg_att; | 503 | mailimap_msg_att * msg_att; |
504 | msg_att = (mailimap_msg_att*)current->data; | 504 | msg_att = (mailimap_msg_att*)current->data; |
505 | mailimap_msg_att_item*msg_att_item; | 505 | mailimap_msg_att_item*msg_att_item; |
506 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 506 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
507 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 507 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
508 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 508 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
509 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 509 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
510 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 510 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
511 | /* detach - we take over the content */ | 511 | /* detach - we take over the content */ |
512 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 512 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
513 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 513 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } else { | 517 | } else { |
518 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
519 | } | 519 | } |
520 | if (result) mailimap_fetch_list_free(result); | 520 | if (result) mailimap_fetch_list_free(result); |
521 | return res; | 521 | return res; |
522 | } | 522 | } |
523 | 523 | ||
524 | /* current_recursion is for recursive calls. | 524 | /* current_recursion is for recursive calls. |
525 | current_count means the position inside the internal loop! */ | 525 | current_count means the position inside the internal loop! */ |
526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | 526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, |
527 | int current_recursion,QValueList<int>recList,int current_count) | 527 | int current_recursion,QValueList<int>recList,int current_count) |
528 | { | 528 | { |
529 | if (!body || current_recursion>=10) { | 529 | if (!body || current_recursion>=10) { |
530 | return; | 530 | return; |
531 | } | 531 | } |
532 | switch (body->bd_type) { | 532 | switch (body->bd_type) { |
533 | case MAILIMAP_BODY_1PART: | 533 | case MAILIMAP_BODY_1PART: |
534 | { | 534 | { |
535 | QValueList<int>countlist = recList; | 535 | QValueList<int>countlist = recList; |
536 | countlist.append(current_count); | 536 | countlist.append(current_count); |
537 | RecPart currentPart; | 537 | RecPart currentPart; |
538 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; | 538 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
539 | QString id(""); | 539 | QString id(""); |
540 | currentPart.setPositionlist(countlist); | 540 | currentPart.setPositionlist(countlist); |
541 | for (unsigned int j = 0; j < countlist.count();++j) { | 541 | for (unsigned int j = 0; j < countlist.count();++j) { |
542 | id+=(j>0?" ":""); | 542 | id+=(j>0?" ":""); |
543 | id+=QString("%1").arg(countlist[j]); | 543 | id+=QString("%1").arg(countlist[j]); |
544 | } | 544 | } |
545 | qDebug("ID = %s",id.latin1()); | 545 | qDebug("ID = %s",id.latin1()); |
546 | currentPart.setIdentifier(id); | 546 | currentPart.setIdentifier(id); |
547 | fillSinglePart(currentPart,part1); | 547 | fillSinglePart(currentPart,part1); |
548 | /* important: Check for is NULL 'cause a body can be empty! | 548 | /* important: Check for is NULL 'cause a body can be empty! |
549 | And we put it only into the mail if it is the FIRST part */ | 549 | And we put it only into the mail if it is the FIRST part */ |
550 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { | 550 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
551 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 551 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
552 | target_body.setDescription(currentPart); | 552 | target_body.setDescription(currentPart); |
553 | target_body.setBodytext(body_text); | 553 | target_body.setBodytext(body_text); |
554 | if (countlist.count()>1) { | 554 | if (countlist.count()>1) { |
555 | target_body.addPart(currentPart); | 555 | target_body.addPart(currentPart); |
556 | } | 556 | } |
557 | } else { | 557 | } else { |
558 | target_body.addPart(currentPart); | 558 | target_body.addPart(currentPart); |
559 | } | 559 | } |
560 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { | 560 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
561 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); | 561 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
562 | } | 562 | } |
563 | } | 563 | } |
564 | break; | 564 | break; |
565 | case MAILIMAP_BODY_MPART: | 565 | case MAILIMAP_BODY_MPART: |
566 | { | 566 | { |
567 | QValueList<int>countlist = recList; | 567 | QValueList<int>countlist = recList; |
568 | clistcell*current=0; | 568 | clistcell*current=0; |
569 | mailimap_body*current_body=0; | 569 | mailimap_body*current_body=0; |
570 | unsigned int ccount = 1; | 570 | unsigned int ccount = 1; |
571 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | 571 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; |
572 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 572 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { |
573 | current_body = (mailimap_body*)current->data; | 573 | current_body = (mailimap_body*)current->data; |
574 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 574 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
575 | RecPart targetPart; | 575 | RecPart targetPart; |
576 | targetPart.setType("multipart"); | 576 | targetPart.setType("multipart"); |
577 | fillMultiPart(targetPart,mailDescription); | 577 | fillMultiPart(targetPart,mailDescription); |
578 | countlist.append(current_count); | 578 | countlist.append(current_count); |
579 | targetPart.setPositionlist(countlist); | 579 | targetPart.setPositionlist(countlist); |
580 | target_body.addPart(targetPart); | 580 | target_body.addPart(targetPart); |
581 | QString id(""); | 581 | QString id(""); |
582 | for (unsigned int j = 0; j < countlist.count();++j) { | 582 | for (unsigned int j = 0; j < countlist.count();++j) { |
583 | id+=(j>0?" ":""); | 583 | id+=(j>0?" ":""); |
584 | id+=QString("%1").arg(countlist[j]); | 584 | id+=QString("%1").arg(countlist[j]); |
585 | } | 585 | } |
586 | qDebug("ID(mpart) = %s",id.latin1()); | 586 | qDebug("ID(mpart) = %s",id.latin1()); |
587 | } | 587 | } |
588 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); | 588 | traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); |
589 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 589 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { |
590 | countlist = recList; | 590 | countlist = recList; |
591 | } | 591 | } |
592 | ++ccount; | 592 | ++ccount; |
593 | } | 593 | } |
594 | } | 594 | } |
595 | break; | 595 | break; |
596 | default: | 596 | default: |
597 | break; | 597 | break; |
598 | } | 598 | } |
599 | } | 599 | } |
600 | 600 | ||
601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 601 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
602 | { | 602 | { |
603 | if (!Description) { | 603 | if (!Description) { |
604 | return; | 604 | return; |
605 | } | 605 | } |
606 | switch (Description->bd_type) { | 606 | switch (Description->bd_type) { |
607 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 607 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
608 | target_part.setType("text"); | 608 | target_part.setType("text"); |
609 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 609 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
610 | break; | 610 | break; |
611 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 611 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
612 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 612 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
613 | break; | 613 | break; |
614 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 614 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
615 | target_part.setType("message"); | 615 | target_part.setType("message"); |
616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
617 | break; | 617 | break; |
618 | default: | 618 | default: |
619 | break; | 619 | break; |
620 | } | 620 | } |
621 | } | 621 | } |
622 | 622 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
624 | { | 624 | { |
625 | if (!which) { | 625 | if (!which) { |
626 | return; | 626 | return; |
627 | } | 627 | } |
628 | QString sub; | 628 | QString sub; |
629 | sub = which->bd_media_text; | 629 | sub = which->bd_media_text; |
630 | qDebug("Type= text/%s",which->bd_media_text); | 630 | qDebug("Type= text/%s",which->bd_media_text); |
631 | target_part.setSubtype(sub.lower()); | 631 | target_part.setSubtype(sub.lower()); |
632 | target_part.setLines(which->bd_lines); | 632 | target_part.setLines(which->bd_lines); |
633 | fillBodyFields(target_part,which->bd_fields); | 633 | fillBodyFields(target_part,which->bd_fields); |
634 | } | 634 | } |
635 | 635 | ||
636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 636 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
637 | { | 637 | { |
638 | if (!which) { | 638 | if (!which) { |
639 | return; | 639 | return; |
640 | } | 640 | } |
641 | target_part.setSubtype("rfc822"); | 641 | target_part.setSubtype("rfc822"); |
642 | qDebug("Message part"); | 642 | qDebug("Message part"); |
643 | /* we set this type to text/plain */ | 643 | /* we set this type to text/plain */ |
644 | target_part.setLines(which->bd_lines); | 644 | target_part.setLines(which->bd_lines); |
645 | fillBodyFields(target_part,which->bd_fields); | 645 | fillBodyFields(target_part,which->bd_fields); |
646 | } | 646 | } |
647 | 647 | ||
648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) | 648 | void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) |
649 | { | 649 | { |
650 | if (!which) return; | 650 | if (!which) return; |
651 | target_part.setSubtype(which->bd_media_subtype); | 651 | QString sub = which->bd_media_subtype; |
652 | target_part.setSubtype(sub.lower()); | ||
652 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { | 653 | if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { |
653 | clistcell*cur = 0; | 654 | clistcell*cur = 0; |
654 | mailimap_single_body_fld_param*param=0; | 655 | mailimap_single_body_fld_param*param=0; |
655 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 656 | for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
656 | param = (mailimap_single_body_fld_param*)cur->data; | 657 | param = (mailimap_single_body_fld_param*)cur->data; |
657 | if (param) { | 658 | if (param) { |
658 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 659 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
659 | } | 660 | } |
660 | } | 661 | } |
661 | } | 662 | } |
662 | } | 663 | } |
663 | 664 | ||
664 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 665 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
665 | { | 666 | { |
666 | if (!which) { | 667 | if (!which) { |
667 | return; | 668 | return; |
668 | } | 669 | } |
669 | QString type,sub; | 670 | QString type,sub; |
670 | switch (which->bd_media_basic->med_type) { | 671 | switch (which->bd_media_basic->med_type) { |
671 | case MAILIMAP_MEDIA_BASIC_APPLICATION: | 672 | case MAILIMAP_MEDIA_BASIC_APPLICATION: |
672 | type = "application"; | 673 | type = "application"; |
673 | break; | 674 | break; |
674 | case MAILIMAP_MEDIA_BASIC_AUDIO: | 675 | case MAILIMAP_MEDIA_BASIC_AUDIO: |
675 | type = "audio"; | 676 | type = "audio"; |
676 | break; | 677 | break; |
677 | case MAILIMAP_MEDIA_BASIC_IMAGE: | 678 | case MAILIMAP_MEDIA_BASIC_IMAGE: |
678 | type = "image"; | 679 | type = "image"; |
679 | break; | 680 | break; |
680 | case MAILIMAP_MEDIA_BASIC_MESSAGE: | 681 | case MAILIMAP_MEDIA_BASIC_MESSAGE: |
681 | type = "message"; | 682 | type = "message"; |
682 | break; | 683 | break; |
683 | case MAILIMAP_MEDIA_BASIC_VIDEO: | 684 | case MAILIMAP_MEDIA_BASIC_VIDEO: |
684 | type = "video"; | 685 | type = "video"; |
685 | break; | 686 | break; |
686 | case MAILIMAP_MEDIA_BASIC_OTHER: | 687 | case MAILIMAP_MEDIA_BASIC_OTHER: |
687 | default: | 688 | default: |
688 | if (which->bd_media_basic->med_basic_type) { | 689 | if (which->bd_media_basic->med_basic_type) { |
689 | type = which->bd_media_basic->med_basic_type; | 690 | type = which->bd_media_basic->med_basic_type; |
690 | } else { | 691 | } else { |
691 | type = ""; | 692 | type = ""; |
692 | } | 693 | } |
693 | break; | 694 | break; |
694 | } | 695 | } |
695 | if (which->bd_media_basic->med_subtype) { | 696 | if (which->bd_media_basic->med_subtype) { |
696 | sub = which->bd_media_basic->med_subtype; | 697 | sub = which->bd_media_basic->med_subtype; |
697 | } else { | 698 | } else { |
698 | sub = ""; | 699 | sub = ""; |
699 | } | 700 | } |
700 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); | 701 | qDebug("Type = %s/%s",type.latin1(),sub.latin1()); |
701 | target_part.setType(type.lower()); | 702 | target_part.setType(type.lower()); |
702 | target_part.setSubtype(sub.lower()); | 703 | target_part.setSubtype(sub.lower()); |
703 | fillBodyFields(target_part,which->bd_fields); | 704 | fillBodyFields(target_part,which->bd_fields); |
704 | } | 705 | } |
705 | 706 | ||
706 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | 707 | void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) |
707 | { | 708 | { |
708 | if (!which) return; | 709 | if (!which) return; |
709 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { | 710 | if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { |
710 | clistcell*cur; | 711 | clistcell*cur; |
711 | mailimap_single_body_fld_param*param=0; | 712 | mailimap_single_body_fld_param*param=0; |
712 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { | 713 | for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { |
713 | param = (mailimap_single_body_fld_param*)cur->data; | 714 | param = (mailimap_single_body_fld_param*)cur->data; |
714 | if (param) { | 715 | if (param) { |
715 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); | 716 | target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); |
716 | } | 717 | } |
717 | } | 718 | } |
718 | } | 719 | } |
719 | mailimap_body_fld_enc*enc = which->bd_encoding; | 720 | mailimap_body_fld_enc*enc = which->bd_encoding; |
720 | QString encoding(""); | 721 | QString encoding(""); |
721 | switch (enc->enc_type) { | 722 | switch (enc->enc_type) { |
722 | case MAILIMAP_BODY_FLD_ENC_7BIT: | 723 | case MAILIMAP_BODY_FLD_ENC_7BIT: |
723 | encoding = "7bit"; | 724 | encoding = "7bit"; |
724 | break; | 725 | break; |
725 | case MAILIMAP_BODY_FLD_ENC_8BIT: | 726 | case MAILIMAP_BODY_FLD_ENC_8BIT: |
726 | encoding = "8bit"; | 727 | encoding = "8bit"; |
727 | break; | 728 | break; |
728 | case MAILIMAP_BODY_FLD_ENC_BINARY: | 729 | case MAILIMAP_BODY_FLD_ENC_BINARY: |
729 | encoding="binary"; | 730 | encoding="binary"; |
730 | break; | 731 | break; |
731 | case MAILIMAP_BODY_FLD_ENC_BASE64: | 732 | case MAILIMAP_BODY_FLD_ENC_BASE64: |
732 | encoding="base64"; | 733 | encoding="base64"; |
733 | break; | 734 | break; |
734 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: | 735 | case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: |
735 | encoding="quoted-printable"; | 736 | encoding="quoted-printable"; |
736 | break; | 737 | break; |
737 | case MAILIMAP_BODY_FLD_ENC_OTHER: | 738 | case MAILIMAP_BODY_FLD_ENC_OTHER: |
738 | default: | 739 | default: |
739 | if (enc->enc_value) { | 740 | if (enc->enc_value) { |
740 | char*t=enc->enc_value; | 741 | char*t=enc->enc_value; |
741 | encoding=QString(enc->enc_value); | 742 | encoding=QString(enc->enc_value); |
742 | enc->enc_value=0L; | 743 | enc->enc_value=0L; |
743 | free(t); | 744 | free(t); |
744 | } | 745 | } |
745 | } | 746 | } |
746 | if (which->bd_description) { | 747 | if (which->bd_description) { |
747 | target_part.setDescription(QString(which->bd_description)); | 748 | target_part.setDescription(QString(which->bd_description)); |
748 | } | 749 | } |
749 | target_part.setEncoding(encoding); | 750 | target_part.setEncoding(encoding); |
750 | target_part.setSize(which->bd_size); | 751 | target_part.setSize(which->bd_size); |
751 | } | 752 | } |
752 | 753 | ||
753 | void IMAPwrapper::deleteMail(const RecMail&mail) | 754 | void IMAPwrapper::deleteMail(const RecMail&mail) |
754 | { | 755 | { |
755 | mailimap_flag_list*flist; | 756 | mailimap_flag_list*flist; |
756 | mailimap_set *set; | 757 | mailimap_set *set; |
757 | mailimap_store_att_flags * store_flags; | 758 | mailimap_store_att_flags * store_flags; |
758 | int err; | 759 | int err; |
759 | login(); | 760 | login(); |
760 | if (!m_imap) { | 761 | if (!m_imap) { |
761 | return; | 762 | return; |
762 | } | 763 | } |
763 | const char *mb = mail.getMbox().latin1(); | 764 | const char *mb = mail.getMbox().latin1(); |
764 | err = mailimap_select( m_imap, (char*)mb); | 765 | err = mailimap_select( m_imap, (char*)mb); |
765 | if ( err != MAILIMAP_NO_ERROR ) { | 766 | if ( err != MAILIMAP_NO_ERROR ) { |
766 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); | 767 | qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); |
767 | return; | 768 | return; |
768 | } | 769 | } |
769 | flist = mailimap_flag_list_new_empty(); | 770 | flist = mailimap_flag_list_new_empty(); |
770 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 771 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
771 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 772 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
772 | set = mailimap_set_new_single(mail.getNumber()); | 773 | set = mailimap_set_new_single(mail.getNumber()); |
773 | err = mailimap_store(m_imap,set,store_flags); | 774 | err = mailimap_store(m_imap,set,store_flags); |
774 | mailimap_set_free( set ); | 775 | mailimap_set_free( set ); |
775 | mailimap_store_att_flags_free(store_flags); | 776 | mailimap_store_att_flags_free(store_flags); |
776 | 777 | ||
777 | if (err != MAILIMAP_NO_ERROR) { | 778 | if (err != MAILIMAP_NO_ERROR) { |
778 | qDebug("error deleting mail: %s",m_imap->imap_response); | 779 | qDebug("error deleting mail: %s",m_imap->imap_response); |
779 | return; | 780 | return; |
780 | } | 781 | } |
781 | qDebug("deleting mail: %s",m_imap->imap_response); | 782 | qDebug("deleting mail: %s",m_imap->imap_response); |
782 | /* should we realy do that at this moment? */ | 783 | /* should we realy do that at this moment? */ |
783 | err = mailimap_expunge(m_imap); | 784 | err = mailimap_expunge(m_imap); |
784 | if (err != MAILIMAP_NO_ERROR) { | 785 | if (err != MAILIMAP_NO_ERROR) { |
785 | qDebug("error deleting mail: %s",m_imap->imap_response); | 786 | qDebug("error deleting mail: %s",m_imap->imap_response); |
786 | } | 787 | } |
787 | qDebug("Delete successfull %s",m_imap->imap_response); | 788 | qDebug("Delete successfull %s",m_imap->imap_response); |
788 | } | 789 | } |
789 | 790 | ||
790 | void IMAPwrapper::answeredMail(const RecMail&mail) | 791 | void IMAPwrapper::answeredMail(const RecMail&mail) |
791 | { | 792 | { |
792 | mailimap_flag_list*flist; | 793 | mailimap_flag_list*flist; |
793 | mailimap_set *set; | 794 | mailimap_set *set; |
794 | mailimap_store_att_flags * store_flags; | 795 | mailimap_store_att_flags * store_flags; |
795 | int err; | 796 | int err; |
796 | login(); | 797 | login(); |
797 | if (!m_imap) { | 798 | if (!m_imap) { |
798 | return; | 799 | return; |
799 | } | 800 | } |
800 | const char *mb = mail.getMbox().latin1(); | 801 | const char *mb = mail.getMbox().latin1(); |
801 | err = mailimap_select( m_imap, (char*)mb); | 802 | err = mailimap_select( m_imap, (char*)mb); |
802 | if ( err != MAILIMAP_NO_ERROR ) { | 803 | if ( err != MAILIMAP_NO_ERROR ) { |
803 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); | 804 | qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); |
804 | return; | 805 | return; |
805 | } | 806 | } |
806 | flist = mailimap_flag_list_new_empty(); | 807 | flist = mailimap_flag_list_new_empty(); |
807 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); | 808 | mailimap_flag_list_add(flist,mailimap_flag_new_answered()); |
808 | store_flags = mailimap_store_att_flags_new_add_flags(flist); | 809 | store_flags = mailimap_store_att_flags_new_add_flags(flist); |
809 | set = mailimap_set_new_single(mail.getNumber()); | 810 | set = mailimap_set_new_single(mail.getNumber()); |
810 | err = mailimap_store(m_imap,set,store_flags); | 811 | err = mailimap_store(m_imap,set,store_flags); |
811 | mailimap_set_free( set ); | 812 | mailimap_set_free( set ); |
812 | mailimap_store_att_flags_free(store_flags); | 813 | mailimap_store_att_flags_free(store_flags); |
813 | 814 | ||
814 | if (err != MAILIMAP_NO_ERROR) { | 815 | if (err != MAILIMAP_NO_ERROR) { |
815 | qDebug("error marking mail: %s",m_imap->imap_response); | 816 | qDebug("error marking mail: %s",m_imap->imap_response); |
816 | return; | 817 | return; |
817 | } | 818 | } |
818 | } | 819 | } |
819 | 820 | ||
820 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 821 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) |
821 | { | 822 | { |
822 | QString body(""); | 823 | QString body(""); |
823 | encodedString*res = fetchRawPart(mail,path,internal_call); | 824 | encodedString*res = fetchRawPart(mail,path,internal_call); |
824 | encodedString*r = decode_String(res,enc); | 825 | encodedString*r = decode_String(res,enc); |
825 | delete res; | 826 | delete res; |
826 | if (r) { | 827 | if (r) { |
827 | if (r->Length()>0) { | 828 | if (r->Length()>0) { |
828 | body = r->Content(); | 829 | body = r->Content(); |
829 | } | 830 | } |
830 | delete r; | 831 | delete r; |
831 | } | 832 | } |
832 | return body; | 833 | return body; |
833 | } | 834 | } |
834 | 835 | ||
835 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | 836 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) |
836 | { | 837 | { |
837 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | 838 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); |
838 | } | 839 | } |
839 | 840 | ||
840 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | 841 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) |
841 | { | 842 | { |
842 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | 843 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); |
843 | encodedString*r = decode_String(res,part.Encoding()); | 844 | encodedString*r = decode_String(res,part.Encoding()); |
844 | delete res; | 845 | delete res; |
845 | return r; | 846 | return r; |
846 | } | 847 | } |
847 | 848 | ||
848 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | 849 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) |
849 | { | 850 | { |
850 | return fetchRawPart(mail,part.Positionlist(),false); | 851 | return fetchRawPart(mail,part.Positionlist(),false); |
851 | } | 852 | } |
852 | 853 | ||
853 | int IMAPwrapper::deleteAllMail(const Folder*folder) | 854 | int IMAPwrapper::deleteAllMail(const Folder*folder) |
854 | { | 855 | { |
855 | login(); | 856 | login(); |
856 | if (!m_imap) { | 857 | if (!m_imap) { |
857 | return 0; | 858 | return 0; |
858 | } | 859 | } |
859 | mailimap_flag_list*flist; | 860 | mailimap_flag_list*flist; |
860 | mailimap_set *set; | 861 | mailimap_set *set; |
861 | mailimap_store_att_flags * store_flags; | 862 | mailimap_store_att_flags * store_flags; |
862 | int err = mailimap_select( m_imap, folder->getName().latin1()); | 863 | int err = mailimap_select( m_imap, folder->getName().latin1()); |
863 | if ( err != MAILIMAP_NO_ERROR ) { | 864 | if ( err != MAILIMAP_NO_ERROR ) { |
864 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); | 865 | Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); |
865 | return 0; | 866 | return 0; |
866 | } | 867 | } |
867 | int last = m_imap->imap_selection_info->sel_exists; | 868 | int last = m_imap->imap_selection_info->sel_exists; |
868 | if (last == 0) { | 869 | if (last == 0) { |
869 | Global::statusMessage(tr("Mailbox has no mails!")); | 870 | Global::statusMessage(tr("Mailbox has no mails!")); |
870 | return 0; | 871 | return 0; |
871 | } | 872 | } |
872 | flist = mailimap_flag_list_new_empty(); | 873 | flist = mailimap_flag_list_new_empty(); |
873 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); | 874 | mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); |
874 | store_flags = mailimap_store_att_flags_new_set_flags(flist); | 875 | store_flags = mailimap_store_att_flags_new_set_flags(flist); |
875 | set = mailimap_set_new_interval( 1, last ); | 876 | set = mailimap_set_new_interval( 1, last ); |
876 | err = mailimap_store(m_imap,set,store_flags); | 877 | err = mailimap_store(m_imap,set,store_flags); |
877 | mailimap_set_free( set ); | 878 | mailimap_set_free( set ); |
878 | mailimap_store_att_flags_free(store_flags); | 879 | mailimap_store_att_flags_free(store_flags); |
879 | if (err != MAILIMAP_NO_ERROR) { | 880 | if (err != MAILIMAP_NO_ERROR) { |
880 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 881 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
881 | return 0; | 882 | return 0; |
882 | } | 883 | } |
883 | qDebug("deleting mail: %s",m_imap->imap_response); | 884 | qDebug("deleting mail: %s",m_imap->imap_response); |
884 | /* should we realy do that at this moment? */ | 885 | /* should we realy do that at this moment? */ |
885 | err = mailimap_expunge(m_imap); | 886 | err = mailimap_expunge(m_imap); |
886 | if (err != MAILIMAP_NO_ERROR) { | 887 | if (err != MAILIMAP_NO_ERROR) { |
887 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); | 888 | Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); |
888 | return 0; | 889 | return 0; |
889 | } | 890 | } |
890 | qDebug("Delete successfull %s",m_imap->imap_response); | 891 | qDebug("Delete successfull %s",m_imap->imap_response); |
891 | return 1; | 892 | return 1; |
892 | } | 893 | } |
893 | 894 | ||
894 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) | 895 | int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) |
895 | { | 896 | { |
896 | if (folder.length()==0) return 0; | 897 | if (folder.length()==0) return 0; |
897 | login(); | 898 | login(); |
898 | if (!m_imap) {return 0;} | 899 | if (!m_imap) {return 0;} |
899 | QString pre = account->getPrefix(); | 900 | QString pre = account->getPrefix(); |
900 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { | 901 | if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { |
901 | pre+=delemiter; | 902 | pre+=delemiter; |
902 | } | 903 | } |
903 | if (parentfolder) { | 904 | if (parentfolder) { |
904 | pre += parentfolder->getDisplayName()+delemiter; | 905 | pre += parentfolder->getDisplayName()+delemiter; |
905 | } | 906 | } |
906 | pre+=folder; | 907 | pre+=folder; |
907 | if (getsubfolder) { | 908 | if (getsubfolder) { |
908 | if (delemiter.length()>0) { | 909 | if (delemiter.length()>0) { |
909 | pre+=delemiter; | 910 | pre+=delemiter; |
910 | } else { | 911 | } else { |
911 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); | 912 | Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); |
912 | return 0; | 913 | return 0; |
913 | } | 914 | } |
914 | } | 915 | } |
915 | qDebug("Creating %s",pre.latin1()); | 916 | qDebug("Creating %s",pre.latin1()); |
916 | int res = mailimap_create(m_imap,pre.latin1()); | 917 | int res = mailimap_create(m_imap,pre.latin1()); |
917 | if (res != MAILIMAP_NO_ERROR) { | 918 | if (res != MAILIMAP_NO_ERROR) { |
918 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 919 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
919 | return 0; | 920 | return 0; |
920 | } | 921 | } |
921 | return 1; | 922 | return 1; |
922 | } | 923 | } |
923 | 924 | ||
924 | int IMAPwrapper::deleteMbox(const Folder*folder) | 925 | int IMAPwrapper::deleteMbox(const Folder*folder) |
925 | { | 926 | { |
926 | if (!folder) return 0; | 927 | if (!folder) return 0; |
927 | login(); | 928 | login(); |
928 | if (!m_imap) {return 0;} | 929 | if (!m_imap) {return 0;} |
929 | int res = mailimap_delete(m_imap,folder->getName()); | 930 | int res = mailimap_delete(m_imap,folder->getName()); |
930 | if (res != MAILIMAP_NO_ERROR) { | 931 | if (res != MAILIMAP_NO_ERROR) { |
931 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); | 932 | Global::statusMessage(tr("%1").arg(m_imap->imap_response)); |
932 | return 0; | 933 | return 0; |
933 | } | 934 | } |
934 | return 1; | 935 | return 1; |
935 | } | 936 | } |