summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp144
-rw-r--r--noncore/net/mail/imapwrapper.h1
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp144
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
4 files changed, 156 insertions, 134 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index dc02780..e6e9fc9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -36,34 +36,34 @@ void IMAPwrapper::login()
36 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 37 /* connect */
38 // err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 // err = mailimap_socket_connect( m_imap, (char*)server, port );
39 if (account->getSSL()) { 39 if (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 40 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else { 41 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port ); 42 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 } 43 }
44 44
45 if ( err != MAILIMAP_NO_ERROR && 45 if ( err != MAILIMAP_NO_ERROR &&
46 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 46 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
48 qDebug("error connecting server: %s",m_imap->response); 48 qDebug("error connecting server: %s",m_imap->imap_response);
49 mailimap_free( m_imap ); 49 mailimap_free( m_imap );
50 m_imap = 0; 50 m_imap = 0;
51 return; 51 return;
52 } 52 }
53 53
54 /* login */ 54 /* login */
55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
56 if ( err != MAILIMAP_NO_ERROR ) { 56 if ( err != MAILIMAP_NO_ERROR ) {
57 qDebug("error logging in imap: %s",m_imap->response); 57 qDebug("error logging in imap: %s",m_imap->imap_response);
58 err = mailimap_close( m_imap ); 58 err = mailimap_close( m_imap );
59 mailimap_free( m_imap ); 59 mailimap_free( m_imap );
60 m_imap = 0; 60 m_imap = 0;
61 } 61 }
62} 62}
63 63
64void IMAPwrapper::logout() 64void IMAPwrapper::logout()
65{ 65{
66 int err = MAILIMAP_NO_ERROR; 66 int err = MAILIMAP_NO_ERROR;
67 if (!m_imap) return; 67 if (!m_imap) return;
68 err = mailimap_logout( m_imap ); 68 err = mailimap_logout( m_imap );
69 err = mailimap_close( m_imap ); 69 err = mailimap_close( m_imap );
@@ -80,30 +80,30 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
81 mailimap_fetch_type *fetchType; 81 mailimap_fetch_type *fetchType;
82 mailimap_set *set; 82 mailimap_set *set;
83 83
84 mb = mailbox.latin1(); 84 mb = mailbox.latin1();
85 login(); 85 login();
86 if (!m_imap) { 86 if (!m_imap) {
87 return; 87 return;
88 } 88 }
89 /* select mailbox READONLY for operations */ 89 /* select mailbox READONLY for operations */
90 err = mailimap_examine( m_imap, (char*)mb); 90 err = mailimap_examine( m_imap, (char*)mb);
91 if ( err != MAILIMAP_NO_ERROR ) { 91 if ( err != MAILIMAP_NO_ERROR ) {
92 qDebug("error selecting mailbox: %s",m_imap->response); 92 qDebug("error selecting mailbox: %s",m_imap->imap_response);
93 logout(); 93 logout();
94 return; 94 return;
95 } 95 }
96 96
97 int last = m_imap->selection_info->exists; 97 int last = m_imap->imap_selection_info->sel_exists;
98 98
99 if (last == 0) { 99 if (last == 0) {
100 qDebug("mailbox has no mails"); 100 qDebug("mailbox has no mails");
101 logout(); 101 logout();
102 return; 102 return;
103 } 103 }
104 104
105 result = clist_new(); 105 result = clist_new();
106 /* the range has to start at 1!!! not with 0!!!! */ 106 /* the range has to start at 1!!! not with 0!!!! */
107 set = mailimap_set_new_interval( 1, last ); 107 set = mailimap_set_new_interval( 1, last );
108 fetchAtt = mailimap_fetch_att_new_envelope(); 108 fetchAtt = mailimap_fetch_att_new_envelope();
109 fetchAttFlags = mailimap_fetch_att_new_flags(); 109 fetchAttFlags = mailimap_fetch_att_new_flags();
@@ -129,25 +129,25 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
129 while ( current != 0 ) { 129 while ( current != 0 ) {
130 ++i; 130 ++i;
131 msg_att = (mailimap_msg_att*)current->data; 131 msg_att = (mailimap_msg_att*)current->data;
132 RecMail*m = parse_list_result(msg_att); 132 RecMail*m = parse_list_result(msg_att);
133 if (m) { 133 if (m) {
134 m->setNumber(i); 134 m->setNumber(i);
135 m->setMbox(mailbox); 135 m->setMbox(mailbox);
136 target.append(m); 136 target.append(m);
137 } 137 }
138 current = current->next; 138 current = current->next;
139 } 139 }
140 } else { 140 } else {
141 qDebug("Error fetching headers: %s",m_imap->response); 141 qDebug("Error fetching headers: %s",m_imap->imap_response);
142 } 142 }
143 logout(); 143 logout();
144 clist_free(result); 144 clist_free(result);
145} 145}
146 146
147QList<IMAPFolder>* IMAPwrapper::listFolders() 147QList<IMAPFolder>* IMAPwrapper::listFolders()
148{ 148{
149 const char *path, *mask; 149 const char *path, *mask;
150 int err = MAILIMAP_NO_ERROR; 150 int err = MAILIMAP_NO_ERROR;
151 clist *result; 151 clist *result;
152 clistcell *current; 152 clistcell *current;
153 153
@@ -165,158 +165,156 @@ QList<IMAPFolder>* IMAPwrapper::listFolders()
165 */ 165 */
166 QString temp; 166 QString temp;
167 mask = "INBOX" ; 167 mask = "INBOX" ;
168 result = clist_new(); 168 result = clist_new();
169 mailimap_mailbox_list *list; 169 mailimap_mailbox_list *list;
170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 171 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 172 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 173 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 174 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 175 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 176 // instead of using strdup!
177 temp = list->mb; 177 temp = list->mb_name;
178 folders->append( new IMAPFolder(temp)); 178 folders->append( new IMAPFolder(temp));
179 current = current->next; 179 current = current->next;
180 } 180 }
181 } else { 181 } else {
182 qDebug("error fetching folders: %s",m_imap->response); 182 qDebug("error fetching folders: %s",m_imap->imap_response);
183 } 183 }
184 mailimap_list_result_free( result ); 184 mailimap_list_result_free( result );
185 185
186/* 186/*
187 * second stage - get the other then inbox folders 187 * second stage - get the other then inbox folders
188 */ 188 */
189 mask = "*" ; 189 mask = "*" ;
190 path = account->getPrefix().latin1(); 190 path = account->getPrefix().latin1();
191 if (!path) path = "";
191 result = clist_new(); 192 result = clist_new();
192 qDebug(path); 193 qDebug(path);
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 194 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 195 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 196 current = result->first;
196 for ( int i = result->count; i > 0; i-- ) { 197 for ( int i = result->count; i > 0; i-- ) {
197 list = (mailimap_mailbox_list *) current->data; 198 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 199 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 200 // instead of using strdup!
200 temp = list->mb; 201 temp = list->mb_name;
201 current = current->next; 202 current = current->next;
202 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
203 continue; 204 continue;
204 folders->append(new IMAPFolder(temp)); 205 folders->append(new IMAPFolder(temp));
205 206
206 } 207 }
207 } else { 208 } else {
208 qDebug("error fetching folders %s",m_imap->response); 209 qDebug("error fetching folders %s",m_imap->imap_response);
209 } 210 }
210 mailimap_list_result_free( result ); 211 mailimap_list_result_free( result );
211 return folders; 212 return folders;
212} 213}
213 214
214RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
215{ 216{
216 RecMail * m = 0; 217 RecMail * m = 0;
217 mailimap_msg_att_item *item=0; 218 mailimap_msg_att_item *item=0;
218 clistcell *current,*c,*cf; 219 clistcell *current,*c,*cf;
219 mailimap_msg_att_dynamic*flist; 220 mailimap_msg_att_dynamic*flist;
220 mailimap_flag_fetch*cflag; 221 mailimap_flag_fetch*cflag;
221 QBitArray mFlags(7); 222 QBitArray mFlags(7);
222 QStringList addresslist; 223 QStringList addresslist;
223 224
224 if (!m_att) { 225 if (!m_att) {
225 return m; 226 return m;
226 } 227 }
227 228
228 c = clist_begin(m_att->list); 229 c = clist_begin(m_att->att_list);
229 while ( c ) { 230 while ( c ) {
230 current = c; 231 current = c;
231 c = c->next; 232 c = c->next;
232 item = (mailimap_msg_att_item*)current->data; 233 item = (mailimap_msg_att_item*)current->data;
233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 234 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 235 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
235 if (!flist->list) { 236 if (!flist->att_list) {
236 continue; 237 continue;
237 } 238 }
238 cf = flist->list->first; 239 cf = flist->att_list->first;
239 while (cf) { 240 while (cf) {
240 cflag = (mailimap_flag_fetch*)cf->data; 241 cflag = (mailimap_flag_fetch*)cf->data;
241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 242 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
242 switch (cflag->flag->type) { 243 switch (cflag->fl_flag->fl_type) {
243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
244 mFlags.setBit(FLAG_ANSWERED); 245 mFlags.setBit(FLAG_ANSWERED);
245 break; 246 break;
246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
247 mFlags.setBit(FLAG_FLAGGED); 248 mFlags.setBit(FLAG_FLAGGED);
248 break; 249 break;
249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
250 mFlags.setBit(FLAG_DELETED); 251 mFlags.setBit(FLAG_DELETED);
251 break; 252 break;
252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
253 mFlags.setBit(FLAG_SEEN); 254 mFlags.setBit(FLAG_SEEN);
254 break; 255 break;
255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
256 mFlags.setBit(FLAG_DRAFT); 257 mFlags.setBit(FLAG_DRAFT);
257 break; 258 break;
258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
259 break; 260 break;
260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
261 break; 262 break;
262 default: 263 default:
263 break; 264 break;
264 } 265 }
265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 266 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
266 mFlags.setBit(FLAG_RECENT); 267 mFlags.setBit(FLAG_RECENT);
267 } 268 }
268 cf = cf->next; 269 cf = cf->next;
269 } 270 }
270 continue; 271 continue;
271 } 272 }
272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 273 if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 274 qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
275 mailimap_envelope * head = item->msg_att_static->env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
276 m = new RecMail(); 277 m = new RecMail();
277 m->setDate(head->date); 278 m->setDate(head->env_date);
278 m->setSubject(head->subject); 279 m->setSubject(head->env_subject);
279 if (head->from!=NULL) { 280 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->from->list); 281 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 282 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 283 m->setFrom(addresslist.first());
283 } 284 }
284 } 285 }
285 if (head->to!=NULL) { 286 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->to->list); 287 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 288 m->setTo(addresslist);
288 } 289 }
289 if (head->cc!=NULL) { 290 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->cc->list); 291 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 292 m->setCC(addresslist);
292 } 293 }
293 if (head->bcc!=NULL) { 294 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->bcc->list); 295 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 296 m->setBcc(addresslist);
296 } 297 }
297 if (head->reply_to!=NULL) { 298 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->bcc->list); 299 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 300 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 301 m->setReplyto(addresslist.first());
301 } 302 }
302 } 303 }
303 m->setMsgid(QString(head->message_id)); 304 m->setMsgid(QString(head->env_message_id));
304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 305 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 m->getFrom().latin1(), 306 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1()); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
307 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
308 mailimap_date_time*d = item->msg_att_static->internal_date;
309 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
310 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
311 qDebug(da.toString()); 309 qDebug(da.toString());
312 } else { 310 } else {
313 qDebug("Another type"); 311 qDebug("Another type");
314 } 312 }
315 } 313 }
316 /* msg is already deleted */ 314 /* msg is already deleted */
317 if (mFlags.testBit(FLAG_DELETED) && m) { 315 if (mFlags.testBit(FLAG_DELETED) && m) {
318 delete m; 316 delete m;
319 m = 0; 317 m = 0;
320 } 318 }
321 if (m) { 319 if (m) {
322 m->setFlags(mFlags); 320 m->setFlags(mFlags);
@@ -336,142 +334,154 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
336 mailimap_set *set; 334 mailimap_set *set;
337 mailimap_body*body_desc; 335 mailimap_body*body_desc;
338 336
339 mb = mail.getMbox().latin1(); 337 mb = mail.getMbox().latin1();
340 338
341 login(); 339 login();
342 if (!m_imap) { 340 if (!m_imap) {
343 return body; 341 return body;
344 } 342 }
345 /* select mailbox READONLY for operations */ 343 /* select mailbox READONLY for operations */
346 err = mailimap_examine( m_imap, (char*)mb); 344 err = mailimap_examine( m_imap, (char*)mb);
347 if ( err != MAILIMAP_NO_ERROR ) { 345 if ( err != MAILIMAP_NO_ERROR ) {
348 qDebug("error selecting mailbox: %s",m_imap->response); 346 qDebug("error selecting mailbox: %s",m_imap->imap_response);
349 logout(); 347 logout();
350 return body; 348 return body;
351 } 349 }
352 result = clist_new(); 350 result = clist_new();
353 /* the range has to start at 1!!! not with 0!!!! */ 351 /* the range has to start at 1!!! not with 0!!!! */
354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
355 fetchAtt = mailimap_fetch_att_new_body(); 353 fetchAtt = mailimap_fetch_att_new_body();
356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
357 err = mailimap_fetch( m_imap, set, fetchType, &result ); 355 err = mailimap_fetch( m_imap, set, fetchType, &result );
358 mailimap_set_free( set ); 356 mailimap_set_free( set );
359 mailimap_fetch_type_free( fetchType ); 357 mailimap_fetch_type_free( fetchType );
360 358
361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
362 mailimap_msg_att * msg_att; 360 mailimap_msg_att * msg_att;
363 msg_att = (mailimap_msg_att*)current->data; 361 msg_att = (mailimap_msg_att*)current->data;
364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 362 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
365 body_desc = item->msg_att_static->body; 363 body_desc = item->att_data.att_static->att_data.att_body;
366 if (body_desc->type==MAILIMAP_BODY_1PART) { 364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
367 searchBodyText(mail,body_desc->body_1part,body); 365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
368 } else { 366 } else {
369 } 367 }
370 368
371 } else { 369 } else {
372 qDebug("error fetching body: %s",m_imap->response); 370 qDebug("error fetching body: %s",m_imap->imap_response);
373 } 371 }
374 372
375 clist_free(result); 373 clist_free(result);
376 logout(); 374 logout();
377 return body; 375 return body;
378} 376}
379 377
380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 378void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
381{ 379{
382 if (!mailDescription) { 380 if (!mailDescription) {
383 return; 381 return;
384 } 382 }
385 switch (mailDescription->type) { 383 switch (mailDescription->bd_type) {
386 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
387 fillPlainBody(mail,target_body,mailDescription->body_type_text); 385 fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text);
388 break; 386 break;
389 default: 387 default:
390 break; 388 break;
391 } 389 }
392 return; 390 return;
393} 391}
394 392
395void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 393void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd)
396{ 394{
397 const char *mb; 395 const char *mb;
398 QString body=""; 396 QString body="";
399 int err = MAILIMAP_NO_ERROR; 397 int err = MAILIMAP_NO_ERROR;
400 clist *result; 398 clist *result;
401 clistcell *current; 399 clistcell *current,*cur;
402 mailimap_fetch_att *fetchAtt; 400 mailimap_fetch_att *fetchAtt;
403 mailimap_fetch_type *fetchType; 401 mailimap_fetch_type *fetchType;
404 mailimap_set *set; 402 mailimap_set *set;
405 403
406 mb = mail.getMbox().latin1(); 404 mb = mail.getMbox().latin1();
407 405
408 if (!m_imap) { 406 if (!m_imap) {
409 return; 407 return;
410 } 408 }
411 409
412 result = clist_new(); 410 result = clist_new();
413 /* the range has to start at 1!!! not with 0!!!! */ 411 set = set = mailimap_set_new_single(mail.getNumber());
414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 412 mailimap_section * section = mailimap_section_new_text();
415 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 413 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 414 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
417 err = mailimap_fetch( m_imap, set, fetchType, &result ); 415 err = mailimap_fetch( m_imap, set, fetchType, &result );
418 mailimap_set_free( set ); 416 mailimap_set_free( set );
419 mailimap_fetch_type_free( fetchType ); 417 mailimap_fetch_type_free( fetchType );
420 418
419
421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
422 mailimap_msg_att * msg_att; 421 mailimap_msg_att * msg_att;
423 msg_att = (mailimap_msg_att*)current->data; 422 msg_att = (mailimap_msg_att*)current->data;
424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 423 mailimap_msg_att_item*msg_att_item;
425 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 424 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
426 body = item->msg_att_static->rfc822_text; 425 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
426 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
427 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
428 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
429 int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
430 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
431 body = QString(text);
432 free(text);
433 }
434 }
427 } 435 }
436
428 } else { 437 } else {
429 qDebug("error fetching text: %s",m_imap->response); 438 qDebug("error fetching text: %s",m_imap->imap_response);
430 } 439 }
431 clist_free(result); 440 //clist_free(result);
441 mailimap_fetch_list_free(result);
432 target_body.setBodytext(body); 442 target_body.setBodytext(body);
433 return; 443 return;
434} 444}
435 445
436QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 446QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
437{ 447{
438 QStringList l; 448 QStringList l;
439 QString from; 449 QString from;
440 bool named_from; 450 bool named_from;
441 clistcell *current = NULL; 451 clistcell *current = NULL;
442 mailimap_address * current_address=NULL; 452 mailimap_address * current_address=NULL;
443 if (!list) { 453 if (!list) {
444 return l; 454 return l;
445 } 455 }
446 current = clist_begin(list); 456 current = clist_begin(list);
447 unsigned int count = 0; 457 unsigned int count = 0;
448 while (current!= NULL) { 458 while (current!= NULL) {
449 from = ""; 459 from = "";
450 named_from = false; 460 named_from = false;
451 current_address=(mailimap_address*)current->data; 461 current_address=(mailimap_address*)current->data;
452 current = current->next; 462 current = current->next;
453 if (current_address->personal_name){ 463 if (current_address->ad_personal_name){
454 from+=QString(current_address->personal_name); 464 from+=QString(current_address->ad_personal_name);
455 from+=" "; 465 from+=" ";
456 named_from = true; 466 named_from = true;
457 } 467 }
458 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
459 from+="<"; 469 from+="<";
460 } 470 }
461 if (current_address->mailbox_name) { 471 if (current_address->ad_mailbox_name) {
462 from+=QString(current_address->mailbox_name); 472 from+=QString(current_address->ad_mailbox_name);
463 from+="@"; 473 from+="@";
464 } 474 }
465 if (current_address->host_name) { 475 if (current_address->ad_host_name) {
466 from+=QString(current_address->host_name); 476 from+=QString(current_address->ad_host_name);
467 } 477 }
468 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 478 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+=">"; 479 from+=">";
470 } 480 }
471 l.append(QString(from)); 481 l.append(QString(from));
472 if (++count > 99) { 482 if (++count > 99) {
473 break; 483 break;
474 } 484 }
475 } 485 }
476 return l; 486 return l;
477} 487}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index faab43c..90f3004 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,21 +1,22 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_msg_att;
10class RecMail; 11class RecMail;
11class RecBody; 12class RecBody;
12 13
13class IMAPwrapper : public QObject 14class IMAPwrapper : public QObject
14{ 15{
15 Q_OBJECT 16 Q_OBJECT
16 17
17public: 18public:
18 IMAPwrapper( IMAPaccount *a ); 19 IMAPwrapper( IMAPaccount *a );
19 virtual ~IMAPwrapper(); 20 virtual ~IMAPwrapper();
20 QList<IMAPFolder>* listFolders(); 21 QList<IMAPFolder>* listFolders();
21 void listMessages(const QString & mailbox,QList<RecMail>&target ); 22 void listMessages(const QString & mailbox,QList<RecMail>&target );
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index dc02780..e6e9fc9 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -36,34 +36,34 @@ void IMAPwrapper::login()
36 m_imap = mailimap_new( 20, &imap_progress ); 36 m_imap = mailimap_new( 20, &imap_progress );
37 /* connect */ 37 /* connect */
38 // err = mailimap_socket_connect( m_imap, (char*)server, port ); 38 // err = mailimap_socket_connect( m_imap, (char*)server, port );
39 if (account->getSSL()) { 39 if (account->getSSL()) {
40 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 40 err = mailimap_ssl_connect( m_imap, (char*)server, port );
41 } else { 41 } else {
42 err = mailimap_socket_connect( m_imap, (char*)server, port ); 42 err = mailimap_socket_connect( m_imap, (char*)server, port );
43 } 43 }
44 44
45 if ( err != MAILIMAP_NO_ERROR && 45 if ( err != MAILIMAP_NO_ERROR &&
46 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 46 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 47 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
48 qDebug("error connecting server: %s",m_imap->response); 48 qDebug("error connecting server: %s",m_imap->imap_response);
49 mailimap_free( m_imap ); 49 mailimap_free( m_imap );
50 m_imap = 0; 50 m_imap = 0;
51 return; 51 return;
52 } 52 }
53 53
54 /* login */ 54 /* login */
55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 55 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
56 if ( err != MAILIMAP_NO_ERROR ) { 56 if ( err != MAILIMAP_NO_ERROR ) {
57 qDebug("error logging in imap: %s",m_imap->response); 57 qDebug("error logging in imap: %s",m_imap->imap_response);
58 err = mailimap_close( m_imap ); 58 err = mailimap_close( m_imap );
59 mailimap_free( m_imap ); 59 mailimap_free( m_imap );
60 m_imap = 0; 60 m_imap = 0;
61 } 61 }
62} 62}
63 63
64void IMAPwrapper::logout() 64void IMAPwrapper::logout()
65{ 65{
66 int err = MAILIMAP_NO_ERROR; 66 int err = MAILIMAP_NO_ERROR;
67 if (!m_imap) return; 67 if (!m_imap) return;
68 err = mailimap_logout( m_imap ); 68 err = mailimap_logout( m_imap );
69 err = mailimap_close( m_imap ); 69 err = mailimap_close( m_imap );
@@ -80,30 +80,30 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate; 80 mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
81 mailimap_fetch_type *fetchType; 81 mailimap_fetch_type *fetchType;
82 mailimap_set *set; 82 mailimap_set *set;
83 83
84 mb = mailbox.latin1(); 84 mb = mailbox.latin1();
85 login(); 85 login();
86 if (!m_imap) { 86 if (!m_imap) {
87 return; 87 return;
88 } 88 }
89 /* select mailbox READONLY for operations */ 89 /* select mailbox READONLY for operations */
90 err = mailimap_examine( m_imap, (char*)mb); 90 err = mailimap_examine( m_imap, (char*)mb);
91 if ( err != MAILIMAP_NO_ERROR ) { 91 if ( err != MAILIMAP_NO_ERROR ) {
92 qDebug("error selecting mailbox: %s",m_imap->response); 92 qDebug("error selecting mailbox: %s",m_imap->imap_response);
93 logout(); 93 logout();
94 return; 94 return;
95 } 95 }
96 96
97 int last = m_imap->selection_info->exists; 97 int last = m_imap->imap_selection_info->sel_exists;
98 98
99 if (last == 0) { 99 if (last == 0) {
100 qDebug("mailbox has no mails"); 100 qDebug("mailbox has no mails");
101 logout(); 101 logout();
102 return; 102 return;
103 } 103 }
104 104
105 result = clist_new(); 105 result = clist_new();
106 /* the range has to start at 1!!! not with 0!!!! */ 106 /* the range has to start at 1!!! not with 0!!!! */
107 set = mailimap_set_new_interval( 1, last ); 107 set = mailimap_set_new_interval( 1, last );
108 fetchAtt = mailimap_fetch_att_new_envelope(); 108 fetchAtt = mailimap_fetch_att_new_envelope();
109 fetchAttFlags = mailimap_fetch_att_new_flags(); 109 fetchAttFlags = mailimap_fetch_att_new_flags();
@@ -129,25 +129,25 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
129 while ( current != 0 ) { 129 while ( current != 0 ) {
130 ++i; 130 ++i;
131 msg_att = (mailimap_msg_att*)current->data; 131 msg_att = (mailimap_msg_att*)current->data;
132 RecMail*m = parse_list_result(msg_att); 132 RecMail*m = parse_list_result(msg_att);
133 if (m) { 133 if (m) {
134 m->setNumber(i); 134 m->setNumber(i);
135 m->setMbox(mailbox); 135 m->setMbox(mailbox);
136 target.append(m); 136 target.append(m);
137 } 137 }
138 current = current->next; 138 current = current->next;
139 } 139 }
140 } else { 140 } else {
141 qDebug("Error fetching headers: %s",m_imap->response); 141 qDebug("Error fetching headers: %s",m_imap->imap_response);
142 } 142 }
143 logout(); 143 logout();
144 clist_free(result); 144 clist_free(result);
145} 145}
146 146
147QList<IMAPFolder>* IMAPwrapper::listFolders() 147QList<IMAPFolder>* IMAPwrapper::listFolders()
148{ 148{
149 const char *path, *mask; 149 const char *path, *mask;
150 int err = MAILIMAP_NO_ERROR; 150 int err = MAILIMAP_NO_ERROR;
151 clist *result; 151 clist *result;
152 clistcell *current; 152 clistcell *current;
153 153
@@ -165,158 +165,156 @@ QList<IMAPFolder>* IMAPwrapper::listFolders()
165 */ 165 */
166 QString temp; 166 QString temp;
167 mask = "INBOX" ; 167 mask = "INBOX" ;
168 result = clist_new(); 168 result = clist_new();
169 mailimap_mailbox_list *list; 169 mailimap_mailbox_list *list;
170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 170 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
171 if ( err == MAILIMAP_NO_ERROR ) { 171 if ( err == MAILIMAP_NO_ERROR ) {
172 current = result->first; 172 current = result->first;
173 for ( int i = result->count; i > 0; i-- ) { 173 for ( int i = result->count; i > 0; i-- ) {
174 list = (mailimap_mailbox_list *) current->data; 174 list = (mailimap_mailbox_list *) current->data;
175 // it is better use the deep copy mechanism of qt itself 175 // it is better use the deep copy mechanism of qt itself
176 // instead of using strdup! 176 // instead of using strdup!
177 temp = list->mb; 177 temp = list->mb_name;
178 folders->append( new IMAPFolder(temp)); 178 folders->append( new IMAPFolder(temp));
179 current = current->next; 179 current = current->next;
180 } 180 }
181 } else { 181 } else {
182 qDebug("error fetching folders: %s",m_imap->response); 182 qDebug("error fetching folders: %s",m_imap->imap_response);
183 } 183 }
184 mailimap_list_result_free( result ); 184 mailimap_list_result_free( result );
185 185
186/* 186/*
187 * second stage - get the other then inbox folders 187 * second stage - get the other then inbox folders
188 */ 188 */
189 mask = "*" ; 189 mask = "*" ;
190 path = account->getPrefix().latin1(); 190 path = account->getPrefix().latin1();
191 if (!path) path = "";
191 result = clist_new(); 192 result = clist_new();
192 qDebug(path); 193 qDebug(path);
193 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 194 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
194 if ( err == MAILIMAP_NO_ERROR ) { 195 if ( err == MAILIMAP_NO_ERROR ) {
195 current = result->first; 196 current = result->first;
196 for ( int i = result->count; i > 0; i-- ) { 197 for ( int i = result->count; i > 0; i-- ) {
197 list = (mailimap_mailbox_list *) current->data; 198 list = (mailimap_mailbox_list *) current->data;
198 // it is better use the deep copy mechanism of qt itself 199 // it is better use the deep copy mechanism of qt itself
199 // instead of using strdup! 200 // instead of using strdup!
200 temp = list->mb; 201 temp = list->mb_name;
201 current = current->next; 202 current = current->next;
202 if (temp.lower()=="inbox") 203 if (temp.lower()=="inbox")
203 continue; 204 continue;
204 folders->append(new IMAPFolder(temp)); 205 folders->append(new IMAPFolder(temp));
205 206
206 } 207 }
207 } else { 208 } else {
208 qDebug("error fetching folders %s",m_imap->response); 209 qDebug("error fetching folders %s",m_imap->imap_response);
209 } 210 }
210 mailimap_list_result_free( result ); 211 mailimap_list_result_free( result );
211 return folders; 212 return folders;
212} 213}
213 214
214RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 215RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
215{ 216{
216 RecMail * m = 0; 217 RecMail * m = 0;
217 mailimap_msg_att_item *item=0; 218 mailimap_msg_att_item *item=0;
218 clistcell *current,*c,*cf; 219 clistcell *current,*c,*cf;
219 mailimap_msg_att_dynamic*flist; 220 mailimap_msg_att_dynamic*flist;
220 mailimap_flag_fetch*cflag; 221 mailimap_flag_fetch*cflag;
221 QBitArray mFlags(7); 222 QBitArray mFlags(7);
222 QStringList addresslist; 223 QStringList addresslist;
223 224
224 if (!m_att) { 225 if (!m_att) {
225 return m; 226 return m;
226 } 227 }
227 228
228 c = clist_begin(m_att->list); 229 c = clist_begin(m_att->att_list);
229 while ( c ) { 230 while ( c ) {
230 current = c; 231 current = c;
231 c = c->next; 232 c = c->next;
232 item = (mailimap_msg_att_item*)current->data; 233 item = (mailimap_msg_att_item*)current->data;
233 if (item->type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 234 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
234 flist = (mailimap_msg_att_dynamic*)item->msg_att_dyn; 235 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
235 if (!flist->list) { 236 if (!flist->att_list) {
236 continue; 237 continue;
237 } 238 }
238 cf = flist->list->first; 239 cf = flist->att_list->first;
239 while (cf) { 240 while (cf) {
240 cflag = (mailimap_flag_fetch*)cf->data; 241 cflag = (mailimap_flag_fetch*)cf->data;
241 if (cflag->type==MAILIMAP_FLAG_FETCH_OTHER && cflag->flag!=0) { 242 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
242 switch (cflag->flag->type) { 243 switch (cflag->fl_flag->fl_type) {
243 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 244 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
244 mFlags.setBit(FLAG_ANSWERED); 245 mFlags.setBit(FLAG_ANSWERED);
245 break; 246 break;
246 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 247 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
247 mFlags.setBit(FLAG_FLAGGED); 248 mFlags.setBit(FLAG_FLAGGED);
248 break; 249 break;
249 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 250 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
250 mFlags.setBit(FLAG_DELETED); 251 mFlags.setBit(FLAG_DELETED);
251 break; 252 break;
252 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 253 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
253 mFlags.setBit(FLAG_SEEN); 254 mFlags.setBit(FLAG_SEEN);
254 break; 255 break;
255 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 256 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
256 mFlags.setBit(FLAG_DRAFT); 257 mFlags.setBit(FLAG_DRAFT);
257 break; 258 break;
258 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 259 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
259 break; 260 break;
260 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 261 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
261 break; 262 break;
262 default: 263 default:
263 break; 264 break;
264 } 265 }
265 } else if (cflag->type==MAILIMAP_FLAG_FETCH_RECENT) { 266 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
266 mFlags.setBit(FLAG_RECENT); 267 mFlags.setBit(FLAG_RECENT);
267 } 268 }
268 cf = cf->next; 269 cf = cf->next;
269 } 270 }
270 continue; 271 continue;
271 } 272 }
272 if ( item->msg_att_static->type == MAILIMAP_MSG_ATT_RFC822_HEADER ) { 273 if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
273 qDebug( "header: \n%s", item->msg_att_static->rfc822_header ); 274 qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
274 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_ENVELOPE) { 275 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
275 mailimap_envelope * head = item->msg_att_static->env; 276 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
276 m = new RecMail(); 277 m = new RecMail();
277 m->setDate(head->date); 278 m->setDate(head->env_date);
278 m->setSubject(head->subject); 279 m->setSubject(head->env_subject);
279 if (head->from!=NULL) { 280 if (head->env_from!=NULL) {
280 addresslist = address_list_to_stringlist(head->from->list); 281 addresslist = address_list_to_stringlist(head->env_from->frm_list);
281 if (addresslist.count()) { 282 if (addresslist.count()) {
282 m->setFrom(addresslist.first()); 283 m->setFrom(addresslist.first());
283 } 284 }
284 } 285 }
285 if (head->to!=NULL) { 286 if (head->env_to!=NULL) {
286 addresslist = address_list_to_stringlist(head->to->list); 287 addresslist = address_list_to_stringlist(head->env_to->to_list);
287 m->setTo(addresslist); 288 m->setTo(addresslist);
288 } 289 }
289 if (head->cc!=NULL) { 290 if (head->env_cc!=NULL) {
290 addresslist = address_list_to_stringlist(head->cc->list); 291 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
291 m->setCC(addresslist); 292 m->setCC(addresslist);
292 } 293 }
293 if (head->bcc!=NULL) { 294 if (head->env_bcc!=NULL) {
294 addresslist = address_list_to_stringlist(head->bcc->list); 295 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
295 m->setBcc(addresslist); 296 m->setBcc(addresslist);
296 } 297 }
297 if (head->reply_to!=NULL) { 298 if (head->env_reply_to!=NULL) {
298 addresslist = address_list_to_stringlist(head->bcc->list); 299 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
299 if (addresslist.count()) { 300 if (addresslist.count()) {
300 m->setReplyto(addresslist.first()); 301 m->setReplyto(addresslist.first());
301 } 302 }
302 } 303 }
303 m->setMsgid(QString(head->message_id)); 304 m->setMsgid(QString(head->env_message_id));
304 qDebug("header: \nFrom: %s\nSubject: %s\nDate: %s\nMsgid: %s", 305 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
305 m->getFrom().latin1(), 306 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
306 m->getSubject().latin1(),m->getDate().latin1(),m->Msgid().latin1()); 307 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
307 } else if (item->msg_att_static->type==MAILIMAP_MSG_ATT_INTERNALDATE) { 308 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
308 mailimap_date_time*d = item->msg_att_static->internal_date;
309 QDateTime da(QDate(d->year,d->month,d->day),QTime(d->hour,d->min,d->sec));
310 qDebug("%i %i %i - %i %i %i",d->year,d->month,d->day,d->hour,d->min,d->sec);
311 qDebug(da.toString()); 309 qDebug(da.toString());
312 } else { 310 } else {
313 qDebug("Another type"); 311 qDebug("Another type");
314 } 312 }
315 } 313 }
316 /* msg is already deleted */ 314 /* msg is already deleted */
317 if (mFlags.testBit(FLAG_DELETED) && m) { 315 if (mFlags.testBit(FLAG_DELETED) && m) {
318 delete m; 316 delete m;
319 m = 0; 317 m = 0;
320 } 318 }
321 if (m) { 319 if (m) {
322 m->setFlags(mFlags); 320 m->setFlags(mFlags);
@@ -336,142 +334,154 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
336 mailimap_set *set; 334 mailimap_set *set;
337 mailimap_body*body_desc; 335 mailimap_body*body_desc;
338 336
339 mb = mail.getMbox().latin1(); 337 mb = mail.getMbox().latin1();
340 338
341 login(); 339 login();
342 if (!m_imap) { 340 if (!m_imap) {
343 return body; 341 return body;
344 } 342 }
345 /* select mailbox READONLY for operations */ 343 /* select mailbox READONLY for operations */
346 err = mailimap_examine( m_imap, (char*)mb); 344 err = mailimap_examine( m_imap, (char*)mb);
347 if ( err != MAILIMAP_NO_ERROR ) { 345 if ( err != MAILIMAP_NO_ERROR ) {
348 qDebug("error selecting mailbox: %s",m_imap->response); 346 qDebug("error selecting mailbox: %s",m_imap->imap_response);
349 logout(); 347 logout();
350 return body; 348 return body;
351 } 349 }
352 result = clist_new(); 350 result = clist_new();
353 /* the range has to start at 1!!! not with 0!!!! */ 351 /* the range has to start at 1!!! not with 0!!!! */
354 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 352 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
355 fetchAtt = mailimap_fetch_att_new_body(); 353 fetchAtt = mailimap_fetch_att_new_body();
356 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 354 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
357 err = mailimap_fetch( m_imap, set, fetchType, &result ); 355 err = mailimap_fetch( m_imap, set, fetchType, &result );
358 mailimap_set_free( set ); 356 mailimap_set_free( set );
359 mailimap_fetch_type_free( fetchType ); 357 mailimap_fetch_type_free( fetchType );
360 358
361 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 359 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
362 mailimap_msg_att * msg_att; 360 mailimap_msg_att * msg_att;
363 msg_att = (mailimap_msg_att*)current->data; 361 msg_att = (mailimap_msg_att*)current->data;
364 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 362 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
365 body_desc = item->msg_att_static->body; 363 body_desc = item->att_data.att_static->att_data.att_body;
366 if (body_desc->type==MAILIMAP_BODY_1PART) { 364 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
367 searchBodyText(mail,body_desc->body_1part,body); 365 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
368 } else { 366 } else {
369 } 367 }
370 368
371 } else { 369 } else {
372 qDebug("error fetching body: %s",m_imap->response); 370 qDebug("error fetching body: %s",m_imap->imap_response);
373 } 371 }
374 372
375 clist_free(result); 373 clist_free(result);
376 logout(); 374 logout();
377 return body; 375 return body;
378} 376}
379 377
380void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 378void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
381{ 379{
382 if (!mailDescription) { 380 if (!mailDescription) {
383 return; 381 return;
384 } 382 }
385 switch (mailDescription->type) { 383 switch (mailDescription->bd_type) {
386 case MAILIMAP_BODY_TYPE_1PART_TEXT: 384 case MAILIMAP_BODY_TYPE_1PART_TEXT:
387 fillPlainBody(mail,target_body,mailDescription->body_type_text); 385 fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text);
388 break; 386 break;
389 default: 387 default:
390 break; 388 break;
391 } 389 }
392 return; 390 return;
393} 391}
394 392
395void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body) 393void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd)
396{ 394{
397 const char *mb; 395 const char *mb;
398 QString body=""; 396 QString body="";
399 int err = MAILIMAP_NO_ERROR; 397 int err = MAILIMAP_NO_ERROR;
400 clist *result; 398 clist *result;
401 clistcell *current; 399 clistcell *current,*cur;
402 mailimap_fetch_att *fetchAtt; 400 mailimap_fetch_att *fetchAtt;
403 mailimap_fetch_type *fetchType; 401 mailimap_fetch_type *fetchType;
404 mailimap_set *set; 402 mailimap_set *set;
405 403
406 mb = mail.getMbox().latin1(); 404 mb = mail.getMbox().latin1();
407 405
408 if (!m_imap) { 406 if (!m_imap) {
409 return; 407 return;
410 } 408 }
411 409
412 result = clist_new(); 410 result = clist_new();
413 /* the range has to start at 1!!! not with 0!!!! */ 411 set = set = mailimap_set_new_single(mail.getNumber());
414 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 412 mailimap_section * section = mailimap_section_new_text();
415 fetchAtt = mailimap_fetch_att_new_rfc822_text(); 413 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
416 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 414 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
417 err = mailimap_fetch( m_imap, set, fetchType, &result ); 415 err = mailimap_fetch( m_imap, set, fetchType, &result );
418 mailimap_set_free( set ); 416 mailimap_set_free( set );
419 mailimap_fetch_type_free( fetchType ); 417 mailimap_fetch_type_free( fetchType );
420 418
419
421 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
422 mailimap_msg_att * msg_att; 421 mailimap_msg_att * msg_att;
423 msg_att = (mailimap_msg_att*)current->data; 422 msg_att = (mailimap_msg_att*)current->data;
424 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->list->first->data; 423 mailimap_msg_att_item*msg_att_item;
425 if (item->msg_att_static && item->msg_att_static->rfc822_text) { 424 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
426 body = item->msg_att_static->rfc822_text; 425 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
426 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
427 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
428 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
429 int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
430 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
431 body = QString(text);
432 free(text);
433 }
434 }
427 } 435 }
436
428 } else { 437 } else {
429 qDebug("error fetching text: %s",m_imap->response); 438 qDebug("error fetching text: %s",m_imap->imap_response);
430 } 439 }
431 clist_free(result); 440 //clist_free(result);
441 mailimap_fetch_list_free(result);
432 target_body.setBodytext(body); 442 target_body.setBodytext(body);
433 return; 443 return;
434} 444}
435 445
436QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 446QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
437{ 447{
438 QStringList l; 448 QStringList l;
439 QString from; 449 QString from;
440 bool named_from; 450 bool named_from;
441 clistcell *current = NULL; 451 clistcell *current = NULL;
442 mailimap_address * current_address=NULL; 452 mailimap_address * current_address=NULL;
443 if (!list) { 453 if (!list) {
444 return l; 454 return l;
445 } 455 }
446 current = clist_begin(list); 456 current = clist_begin(list);
447 unsigned int count = 0; 457 unsigned int count = 0;
448 while (current!= NULL) { 458 while (current!= NULL) {
449 from = ""; 459 from = "";
450 named_from = false; 460 named_from = false;
451 current_address=(mailimap_address*)current->data; 461 current_address=(mailimap_address*)current->data;
452 current = current->next; 462 current = current->next;
453 if (current_address->personal_name){ 463 if (current_address->ad_personal_name){
454 from+=QString(current_address->personal_name); 464 from+=QString(current_address->ad_personal_name);
455 from+=" "; 465 from+=" ";
456 named_from = true; 466 named_from = true;
457 } 467 }
458 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
459 from+="<"; 469 from+="<";
460 } 470 }
461 if (current_address->mailbox_name) { 471 if (current_address->ad_mailbox_name) {
462 from+=QString(current_address->mailbox_name); 472 from+=QString(current_address->ad_mailbox_name);
463 from+="@"; 473 from+="@";
464 } 474 }
465 if (current_address->host_name) { 475 if (current_address->ad_host_name) {
466 from+=QString(current_address->host_name); 476 from+=QString(current_address->ad_host_name);
467 } 477 }
468 if (named_from && (current_address->mailbox_name || current_address->host_name)) { 478 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
469 from+=">"; 479 from+=">";
470 } 480 }
471 l.append(QString(from)); 481 l.append(QString(from));
472 if (++count > 99) { 482 if (++count > 99) {
473 break; 483 break;
474 } 484 }
475 } 485 }
476 return l; 486 return l;
477} 487}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index faab43c..90f3004 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,21 +1,22 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6 6
7struct mailimap; 7struct mailimap;
8struct mailimap_body_type_1part; 8struct mailimap_body_type_1part;
9struct mailimap_body_type_text; 9struct mailimap_body_type_text;
10struct mailimap_msg_att;
10class RecMail; 11class RecMail;
11class RecBody; 12class RecBody;
12 13
13class IMAPwrapper : public QObject 14class IMAPwrapper : public QObject
14{ 15{
15 Q_OBJECT 16 Q_OBJECT
16 17
17public: 18public:
18 IMAPwrapper( IMAPaccount *a ); 19 IMAPwrapper( IMAPaccount *a );
19 virtual ~IMAPwrapper(); 20 virtual ~IMAPwrapper();
20 QList<IMAPFolder>* listFolders(); 21 QList<IMAPFolder>* listFolders();
21 void listMessages(const QString & mailbox,QList<RecMail>&target ); 22 void listMessages(const QString & mailbox,QList<RecMail>&target );