summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp23
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp23
2 files changed, 22 insertions, 24 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 30eb678..853e4a2 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,821 +1,820 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include <libetpan/mailimap.h> 4#include <libetpan/libetpan.h>
5 5
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9 9
10IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 10IMAPwrapper::IMAPwrapper( IMAPaccount *a )
11 : AbstractMail() 11 : AbstractMail()
12{ 12{
13 account = a; 13 account = a;
14 m_imap = 0; 14 m_imap = 0;
15} 15}
16 16
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
18{ 18{
19 logout(); 19 logout();
20} 20}
21 21
22void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 22void IMAPwrapper::imap_progress( size_t current, size_t maximum )
23{ 23{
24 qDebug( "IMAP: %i of %i", current, maximum ); 24 qDebug( "IMAP: %i of %i", current, maximum );
25} 25}
26 26
27void IMAPwrapper::login() 27void IMAPwrapper::login()
28{ 28{
29 const char *server, *user, *pass; 29 const char *server, *user, *pass;
30 uint16_t port; 30 uint16_t port;
31 int err = MAILIMAP_NO_ERROR; 31 int err = MAILIMAP_NO_ERROR;
32 32
33 /* we are connected this moment */ 33 /* we are connected this moment */
34 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 34 /* TODO: setup a timer holding the line or if connection closed - delete the value */
35 if (m_imap) { 35 if (m_imap) {
36 mailstream_flush(m_imap->imap_stream); 36 mailstream_flush(m_imap->imap_stream);
37 return; 37 return;
38 } 38 }
39 server = account->getServer().latin1(); 39 server = account->getServer().latin1();
40 port = account->getPort().toUInt(); 40 port = account->getPort().toUInt();
41 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 41 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
42 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 42 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
43 login.show(); 43 login.show();
44 if ( QDialog::Accepted == login.exec() ) { 44 if ( QDialog::Accepted == login.exec() ) {
45 // ok 45 // ok
46 user = strdup( login.getUser().latin1() ); 46 user = strdup( login.getUser().latin1() );
47 pass = strdup( login.getPassword().latin1() ); 47 pass = strdup( login.getPassword().latin1() );
48 } else { 48 } else {
49 // cancel 49 // cancel
50 qDebug( "IMAP: Login canceled" ); 50 qDebug( "IMAP: Login canceled" );
51 return; 51 return;
52 } 52 }
53 } else { 53 } else {
54 user = account->getUser().latin1(); 54 user = account->getUser().latin1();
55 pass = account->getPassword().latin1(); 55 pass = account->getPassword().latin1();
56 } 56 }
57 57
58 m_imap = mailimap_new( 20, &imap_progress ); 58 m_imap = mailimap_new( 20, &imap_progress );
59 /* connect */ 59 /* connect */
60 if (account->getSSL()) { 60 if (account->getSSL()) {
61 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 61 err = mailimap_ssl_connect( m_imap, (char*)server, port );
62 } else { 62 } else {
63 err = mailimap_socket_connect( m_imap, (char*)server, port ); 63 err = mailimap_socket_connect( m_imap, (char*)server, port );
64 } 64 }
65 65
66 if ( err != MAILIMAP_NO_ERROR && 66 if ( err != MAILIMAP_NO_ERROR &&
67 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 67 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
69 qDebug("error connecting server: %s",m_imap->imap_response); 69 qDebug("error connecting server: %s",m_imap->imap_response);
70 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
71 m_imap = 0; 71 m_imap = 0;
72 return; 72 return;
73 } 73 }
74 74
75 /* login */ 75 /* login */
76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
77 if ( err != MAILIMAP_NO_ERROR ) { 77 if ( err != MAILIMAP_NO_ERROR ) {
78 qDebug("error logging in imap: %s",m_imap->imap_response); 78 qDebug("error logging in imap: %s",m_imap->imap_response);
79 err = mailimap_close( m_imap ); 79 err = mailimap_close( m_imap );
80 mailimap_free( m_imap ); 80 mailimap_free( m_imap );
81 m_imap = 0; 81 m_imap = 0;
82 } 82 }
83} 83}
84 84
85void IMAPwrapper::logout() 85void IMAPwrapper::logout()
86{ 86{
87 int err = MAILIMAP_NO_ERROR; 87 int err = MAILIMAP_NO_ERROR;
88 if (!m_imap) return; 88 if (!m_imap) return;
89 err = mailimap_logout( m_imap ); 89 err = mailimap_logout( m_imap );
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93} 93}
94 94
95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
96{ 96{
97 const char *mb; 97 const char *mb;
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 clist *result; 99 clist *result;
100 clistcell *current; 100 clistcell *current;
101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
102 mailimap_fetch_type *fetchType; 102 mailimap_fetch_type *fetchType;
103 mailimap_set *set; 103 mailimap_set *set;
104 104
105 mb = mailbox.latin1(); 105 mb = mailbox.latin1();
106 login(); 106 login();
107 if (!m_imap) { 107 if (!m_imap) {
108 return; 108 return;
109 } 109 }
110 /* select mailbox READONLY for operations */ 110 /* select mailbox READONLY for operations */
111 err = mailimap_examine( m_imap, (char*)mb); 111 err = mailimap_examine( m_imap, (char*)mb);
112 if ( err != MAILIMAP_NO_ERROR ) { 112 if ( err != MAILIMAP_NO_ERROR ) {
113 qDebug("error selecting mailbox: %s",m_imap->imap_response); 113 qDebug("error selecting mailbox: %s",m_imap->imap_response);
114 return; 114 return;
115 } 115 }
116 116
117 int last = m_imap->imap_selection_info->sel_exists; 117 int last = m_imap->imap_selection_info->sel_exists;
118 118
119 if (last == 0) { 119 if (last == 0) {
120 qDebug("mailbox has no mails"); 120 qDebug("mailbox has no mails");
121 return; 121 return;
122 } 122 }
123 123
124 result = clist_new(); 124 result = clist_new();
125 /* the range has to start at 1!!! not with 0!!!! */ 125 /* the range has to start at 1!!! not with 0!!!! */
126 set = mailimap_set_new_interval( 1, last ); 126 set = mailimap_set_new_interval( 1, last );
127 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 127 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
131 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 131 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
132 132
133 err = mailimap_fetch( m_imap, set, fetchType, &result ); 133 err = mailimap_fetch( m_imap, set, fetchType, &result );
134 mailimap_set_free( set ); 134 mailimap_set_free( set );
135 mailimap_fetch_type_free( fetchType ); 135 mailimap_fetch_type_free( fetchType );
136 136
137 QString date,subject,from; 137 QString date,subject,from;
138 138
139 if ( err == MAILIMAP_NO_ERROR ) { 139 if ( err == MAILIMAP_NO_ERROR ) {
140 140
141 mailimap_msg_att * msg_att; 141 mailimap_msg_att * msg_att;
142 int i = 0; 142 int i = 0;
143 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 143 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
144 ++i; 144 ++i;
145 msg_att = (mailimap_msg_att*)current->data; 145 msg_att = (mailimap_msg_att*)current->data;
146 RecMail*m = parse_list_result(msg_att); 146 RecMail*m = parse_list_result(msg_att);
147 if (m) { 147 if (m) {
148 m->setNumber(i); 148 m->setNumber(i);
149 m->setMbox(mailbox); 149 m->setMbox(mailbox);
150 m->setWrapper(this); 150 m->setWrapper(this);
151 target.append(m); 151 target.append(m);
152 } 152 }
153 } 153 }
154 } else { 154 } else {
155 qDebug("Error fetching headers: %s",m_imap->imap_response); 155 qDebug("Error fetching headers: %s",m_imap->imap_response);
156 } 156 }
157 mailimap_fetch_list_free(result); 157 mailimap_fetch_list_free(result);
158} 158}
159 159
160QList<Folder>* IMAPwrapper::listFolders() 160QList<Folder>* IMAPwrapper::listFolders()
161{ 161{
162 const char *path, *mask; 162 const char *path, *mask;
163 int err = MAILIMAP_NO_ERROR; 163 int err = MAILIMAP_NO_ERROR;
164 clist *result; 164 clist *result;
165 clistcell *current; 165 clistcell *current;
166 166
167 QList<Folder> * folders = new QList<Folder>(); 167 QList<Folder> * folders = new QList<Folder>();
168 folders->setAutoDelete( false ); 168 folders->setAutoDelete( false );
169 login(); 169 login();
170 if (!m_imap) { 170 if (!m_imap) {
171 return folders; 171 return folders;
172 } 172 }
173 173
174/* 174/*
175 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 175 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
176 * We must not forget to filter them out in next loop! 176 * We must not forget to filter them out in next loop!
177 * it seems like ugly code. and yes - it is ugly code. but the best way. 177 * it seems like ugly code. and yes - it is ugly code. but the best way.
178 */ 178 */
179 QString temp; 179 QString temp;
180 mask = "INBOX" ; 180 mask = "INBOX" ;
181 result = clist_new(); 181 result = clist_new();
182 mailimap_mailbox_list *list; 182 mailimap_mailbox_list *list;
183 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 183 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
184 QString del; 184 QString del;
185 if ( err == MAILIMAP_NO_ERROR ) { 185 if ( err == MAILIMAP_NO_ERROR ) {
186 current = result->first; 186 current = result->first;
187 for ( int i = result->count; i > 0; i-- ) { 187 for ( int i = result->count; i > 0; i-- ) {
188 list = (mailimap_mailbox_list *) current->data; 188 list = (mailimap_mailbox_list *) current->data;
189 // it is better use the deep copy mechanism of qt itself 189 // it is better use the deep copy mechanism of qt itself
190 // instead of using strdup! 190 // instead of using strdup!
191 temp = list->mb_name; 191 temp = list->mb_name;
192 del = list->mb_delimiter; 192 del = list->mb_delimiter;
193 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 193 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
194 current = current->next; 194 current = current->next;
195 } 195 }
196 } else { 196 } else {
197 qDebug("error fetching folders: %s",m_imap->imap_response); 197 qDebug("error fetching folders: %s",m_imap->imap_response);
198 } 198 }
199 mailimap_list_result_free( result ); 199 mailimap_list_result_free( result );
200 200
201/* 201/*
202 * second stage - get the other then inbox folders 202 * second stage - get the other then inbox folders
203 */ 203 */
204 mask = "*" ; 204 mask = "*" ;
205 path = account->getPrefix().latin1(); 205 path = account->getPrefix().latin1();
206 if (!path) path = ""; 206 if (!path) path = "";
207 result = clist_new(); 207 result = clist_new();
208 qDebug(path); 208 qDebug(path);
209 bool selectable = true; 209 bool selectable = true;
210 mailimap_mbx_list_flags*bflags; 210 mailimap_mbx_list_flags*bflags;
211 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 211 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
212 if ( err == MAILIMAP_NO_ERROR ) { 212 if ( err == MAILIMAP_NO_ERROR ) {
213 current = result->first; 213 current = result->first;
214 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 214 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
215 list = (mailimap_mailbox_list *) current->data; 215 list = (mailimap_mailbox_list *) current->data;
216 // it is better use the deep copy mechanism of qt itself 216 // it is better use the deep copy mechanism of qt itself
217 // instead of using strdup! 217 // instead of using strdup!
218 temp = list->mb_name; 218 temp = list->mb_name;
219 if (temp.lower()=="inbox") 219 if (temp.lower()=="inbox")
220 continue; 220 continue;
221 if (temp.lower()==account->getPrefix().lower()) 221 if (temp.lower()==account->getPrefix().lower())
222 continue; 222 continue;
223 if ( (bflags = list->mb_flag) ) { 223 if ( (bflags = list->mb_flag) ) {
224 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 224 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
225 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 225 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
226 } 226 }
227 del = list->mb_delimiter; 227 del = list->mb_delimiter;
228 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 228 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
229 } 229 }
230 } else { 230 } else {
231 qDebug("error fetching folders %s",m_imap->imap_response); 231 qDebug("error fetching folders %s",m_imap->imap_response);
232 } 232 }
233 mailimap_list_result_free( result ); 233 mailimap_list_result_free( result );
234 return folders; 234 return folders;
235} 235}
236 236
237RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 237RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
238{ 238{
239 RecMail * m = 0; 239 RecMail * m = 0;
240 mailimap_msg_att_item *item=0; 240 mailimap_msg_att_item *item=0;
241 clistcell *current,*c,*cf; 241 clistcell *current,*c,*cf;
242 mailimap_msg_att_dynamic*flist; 242 mailimap_msg_att_dynamic*flist;
243 mailimap_flag_fetch*cflag; 243 mailimap_flag_fetch*cflag;
244 int size; 244 int size;
245 QBitArray mFlags(7); 245 QBitArray mFlags(7);
246 QStringList addresslist; 246 QStringList addresslist;
247 247
248 if (!m_att) { 248 if (!m_att) {
249 return m; 249 return m;
250 } 250 }
251 m = new RecMail(); 251 m = new RecMail();
252 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 252 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
253 current = c; 253 current = c;
254 size = 0; 254 size = 0;
255 item = (mailimap_msg_att_item*)current->data; 255 item = (mailimap_msg_att_item*)current->data;
256 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 256 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
257 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 257 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
258 if (!flist->att_list) { 258 if (!flist->att_list) {
259 continue; 259 continue;
260 } 260 }
261 cf = flist->att_list->first; 261 cf = flist->att_list->first;
262 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 262 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
263 cflag = (mailimap_flag_fetch*)cf->data; 263 cflag = (mailimap_flag_fetch*)cf->data;
264 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 264 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
265 switch (cflag->fl_flag->fl_type) { 265 switch (cflag->fl_flag->fl_type) {
266 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 266 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
267 mFlags.setBit(FLAG_ANSWERED); 267 mFlags.setBit(FLAG_ANSWERED);
268 break; 268 break;
269 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 269 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
270 mFlags.setBit(FLAG_FLAGGED); 270 mFlags.setBit(FLAG_FLAGGED);
271 break; 271 break;
272 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 272 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
273 mFlags.setBit(FLAG_DELETED); 273 mFlags.setBit(FLAG_DELETED);
274 break; 274 break;
275 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 275 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
276 mFlags.setBit(FLAG_SEEN); 276 mFlags.setBit(FLAG_SEEN);
277 break; 277 break;
278 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 278 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
279 mFlags.setBit(FLAG_DRAFT); 279 mFlags.setBit(FLAG_DRAFT);
280 break; 280 break;
281 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 281 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
282 break; 282 break;
283 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 283 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
284 break; 284 break;
285 default: 285 default:
286 break; 286 break;
287 } 287 }
288 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 288 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
289 mFlags.setBit(FLAG_RECENT); 289 mFlags.setBit(FLAG_RECENT);
290 } 290 }
291 } 291 }
292 continue; 292 continue;
293 } 293 }
294 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 294 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
295 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 295 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
296 m->setDate(head->env_date); 296 m->setDate(head->env_date);
297 m->setSubject(convert_String((const char*)head->env_subject)); 297 m->setSubject(convert_String((const char*)head->env_subject));
298 //m->setSubject(head->env_subject); 298 //m->setSubject(head->env_subject);
299 if (head->env_from!=NULL) { 299 if (head->env_from!=NULL) {
300 addresslist = address_list_to_stringlist(head->env_from->frm_list); 300 addresslist = address_list_to_stringlist(head->env_from->frm_list);
301 if (addresslist.count()) { 301 if (addresslist.count()) {
302 m->setFrom(addresslist.first()); 302 m->setFrom(addresslist.first());
303 } 303 }
304 } 304 }
305 if (head->env_to!=NULL) { 305 if (head->env_to!=NULL) {
306 addresslist = address_list_to_stringlist(head->env_to->to_list); 306 addresslist = address_list_to_stringlist(head->env_to->to_list);
307 m->setTo(addresslist); 307 m->setTo(addresslist);
308 } 308 }
309 if (head->env_cc!=NULL) { 309 if (head->env_cc!=NULL) {
310 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 310 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
311 m->setCC(addresslist); 311 m->setCC(addresslist);
312 } 312 }
313 if (head->env_bcc!=NULL) { 313 if (head->env_bcc!=NULL) {
314 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 314 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
315 m->setBcc(addresslist); 315 m->setBcc(addresslist);
316 } 316 }
317 if (head->env_reply_to!=NULL) { 317 if (head->env_reply_to!=NULL) {
318 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 318 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
319 if (addresslist.count()) { 319 if (addresslist.count()) {
320 m->setReplyto(addresslist.first()); 320 m->setReplyto(addresslist.first());
321 } 321 }
322 } 322 }
323 m->setMsgid(QString(head->env_message_id)); 323 m->setMsgid(QString(head->env_message_id));
324 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 324 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
325#if 0 325#if 0
326
327 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 326 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
328 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 327 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
329 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); 328 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);
330 qDebug(da.toString()); 329 qDebug(da.toString());
331#endif 330#endif
332 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 331 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
333 size = item->att_data.att_static->att_data.att_rfc822_size; 332 size = item->att_data.att_static->att_data.att_rfc822_size;
334 } 333 }
335 } 334 }
336 /* msg is already deleted */ 335 /* msg is already deleted */
337 if (mFlags.testBit(FLAG_DELETED) && m) { 336 if (mFlags.testBit(FLAG_DELETED) && m) {
338 delete m; 337 delete m;
339 m = 0; 338 m = 0;
340 } 339 }
341 if (m) { 340 if (m) {
342 m->setFlags(mFlags); 341 m->setFlags(mFlags);
343 m->setMsgsize(size); 342 m->setMsgsize(size);
344 } 343 }
345 return m; 344 return m;
346} 345}
347 346
348RecBody IMAPwrapper::fetchBody(const RecMail&mail) 347RecBody IMAPwrapper::fetchBody(const RecMail&mail)
349{ 348{
350 RecBody body; 349 RecBody body;
351 const char *mb; 350 const char *mb;
352 int err = MAILIMAP_NO_ERROR; 351 int err = MAILIMAP_NO_ERROR;
353 clist *result; 352 clist *result;
354 clistcell *current; 353 clistcell *current;
355 mailimap_fetch_att *fetchAtt; 354 mailimap_fetch_att *fetchAtt;
356 mailimap_fetch_type *fetchType; 355 mailimap_fetch_type *fetchType;
357 mailimap_set *set; 356 mailimap_set *set;
358 mailimap_body*body_desc; 357 mailimap_body*body_desc;
359 358
360 mb = mail.getMbox().latin1(); 359 mb = mail.getMbox().latin1();
361 360
362 login(); 361 login();
363 if (!m_imap) { 362 if (!m_imap) {
364 return body; 363 return body;
365 } 364 }
366 365
367 err = mailimap_select( m_imap, (char*)mb); 366 err = mailimap_select( m_imap, (char*)mb);
368 if ( err != MAILIMAP_NO_ERROR ) { 367 if ( err != MAILIMAP_NO_ERROR ) {
369 qDebug("error selecting mailbox: %s",m_imap->imap_response); 368 qDebug("error selecting mailbox: %s",m_imap->imap_response);
370 return body; 369 return body;
371 } 370 }
372 371
373 result = clist_new(); 372 result = clist_new();
374 /* the range has to start at 1!!! not with 0!!!! */ 373 /* the range has to start at 1!!! not with 0!!!! */
375 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
376 fetchAtt = mailimap_fetch_att_new_bodystructure(); 375 fetchAtt = mailimap_fetch_att_new_bodystructure();
377 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
378 err = mailimap_fetch( m_imap, set, fetchType, &result ); 377 err = mailimap_fetch( m_imap, set, fetchType, &result );
379 mailimap_set_free( set ); 378 mailimap_set_free( set );
380 mailimap_fetch_type_free( fetchType ); 379 mailimap_fetch_type_free( fetchType );
381 380
382 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
383 mailimap_msg_att * msg_att; 382 mailimap_msg_att * msg_att;
384 msg_att = (mailimap_msg_att*)current->data; 383 msg_att = (mailimap_msg_att*)current->data;
385 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
386 body_desc = item->att_data.att_static->att_data.att_body; 385 body_desc = item->att_data.att_static->att_data.att_body;
387 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
388 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
389 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
390 qDebug("Mulitpart mail"); 389 qDebug("Mulitpart mail");
391 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
392 } 391 }
393 } else { 392 } else {
394 qDebug("error fetching body: %s",m_imap->imap_response); 393 qDebug("error fetching body: %s",m_imap->imap_response);
395 } 394 }
396 mailimap_fetch_list_free(result); 395 mailimap_fetch_list_free(result);
397 return body; 396 return body;
398} 397}
399 398
400/* this routine is just called when the mail has only ONE part. 399/* this routine is just called when the mail has only ONE part.
401 for filling the parts of a multi-part-message there are other 400 for filling the parts of a multi-part-message there are other
402 routines 'cause we can not simply fetch the whole body. */ 401 routines 'cause we can not simply fetch the whole body. */
403void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
404{ 403{
405 if (!mailDescription) { 404 if (!mailDescription) {
406 return; 405 return;
407 } 406 }
408 QString sub,body_text; 407 QString sub,body_text;
409 RecPart singlePart; 408 RecPart singlePart;
410 QValueList<int> path; 409 QValueList<int> path;
411 fillSinglePart(singlePart,mailDescription); 410 fillSinglePart(singlePart,mailDescription);
412 switch (mailDescription->bd_type) { 411 switch (mailDescription->bd_type) {
413 case MAILIMAP_BODY_TYPE_1PART_MSG: 412 case MAILIMAP_BODY_TYPE_1PART_MSG:
414 path.append(1); 413 path.append(1);
415 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
416 target_body.setBodytext(body_text); 415 target_body.setBodytext(body_text);
417 target_body.setDescription(singlePart); 416 target_body.setDescription(singlePart);
418 break; 417 break;
419 case MAILIMAP_BODY_TYPE_1PART_TEXT: 418 case MAILIMAP_BODY_TYPE_1PART_TEXT:
420 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
421 path.append(1); 420 path.append(1);
422 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
423 target_body.setBodytext(body_text); 422 target_body.setBodytext(body_text);
424 target_body.setDescription(singlePart); 423 target_body.setDescription(singlePart);
425 break; 424 break;
426 case MAILIMAP_BODY_TYPE_1PART_BASIC: 425 case MAILIMAP_BODY_TYPE_1PART_BASIC:
427 qDebug("Single attachment"); 426 qDebug("Single attachment");
428 target_body.setBodytext(""); 427 target_body.setBodytext("");
429 target_body.addPart(singlePart); 428 target_body.addPart(singlePart);
430 break; 429 break;
431 default: 430 default:
432 break; 431 break;
433 } 432 }
434 433
435 return; 434 return;
436} 435}
437 436
438QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 437QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
439{ 438{
440 QStringList l; 439 QStringList l;
441 QString from; 440 QString from;
442 bool named_from; 441 bool named_from;
443 clistcell *current = NULL; 442 clistcell *current = NULL;
444 mailimap_address * current_address=NULL; 443 mailimap_address * current_address=NULL;
445 if (!list) { 444 if (!list) {
446 return l; 445 return l;
447 } 446 }
448 unsigned int count = 0; 447 unsigned int count = 0;
449 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
450 from = ""; 449 from = "";
451 named_from = false; 450 named_from = false;
452 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
453 if (current_address->ad_personal_name){ 452 if (current_address->ad_personal_name){
454 from+=convert_String((const char*)current_address->ad_personal_name); 453 from+=convert_String((const char*)current_address->ad_personal_name);
455 //from+=QString(current_address->ad_personal_name); 454 //from+=QString(current_address->ad_personal_name);
456 from+=" "; 455 from+=" ";
457 named_from = true; 456 named_from = true;
458 } 457 }
459 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
460 from+="<"; 459 from+="<";
461 } 460 }
462 if (current_address->ad_mailbox_name) { 461 if (current_address->ad_mailbox_name) {
463 from+=QString(current_address->ad_mailbox_name); 462 from+=QString(current_address->ad_mailbox_name);
464 from+="@"; 463 from+="@";
465 } 464 }
466 if (current_address->ad_host_name) { 465 if (current_address->ad_host_name) {
467 from+=QString(current_address->ad_host_name); 466 from+=QString(current_address->ad_host_name);
468 } 467 }
469 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
470 from+=">"; 469 from+=">";
471 } 470 }
472 l.append(QString(from)); 471 l.append(QString(from));
473 if (++count > 99) { 472 if (++count > 99) {
474 break; 473 break;
475 } 474 }
476 } 475 }
477 return l; 476 return l;
478} 477}
479 478
480encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
481{ 480{
482 encodedString*res=new encodedString; 481 encodedString*res=new encodedString;
483 const char*mb; 482 const char*mb;
484 int err; 483 int err;
485 mailimap_fetch_type *fetchType; 484 mailimap_fetch_type *fetchType;
486 mailimap_set *set; 485 mailimap_set *set;
487 clistcell*current,*cur; 486 clistcell*current,*cur;
488 487
489 login(); 488 login();
490 if (!m_imap) { 489 if (!m_imap) {
491 return res; 490 return res;
492 } 491 }
493 if (!internal_call) { 492 if (!internal_call) {
494 mb = mail.getMbox().latin1(); 493 mb = mail.getMbox().latin1();
495 err = mailimap_select( m_imap, (char*)mb); 494 err = mailimap_select( m_imap, (char*)mb);
496 if ( err != MAILIMAP_NO_ERROR ) { 495 if ( err != MAILIMAP_NO_ERROR ) {
497 qDebug("error selecting mailbox: %s",m_imap->imap_response); 496 qDebug("error selecting mailbox: %s",m_imap->imap_response);
498 return res; 497 return res;
499 } 498 }
500 } 499 }
501 set = mailimap_set_new_single(mail.getNumber()); 500 set = mailimap_set_new_single(mail.getNumber());
502 clist*id_list=clist_new(); 501 clist*id_list=clist_new();
503 for (unsigned j=0; j < path.count();++j) { 502 for (unsigned j=0; j < path.count();++j) {
504 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 503 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
505 *p_id = path[j]; 504 *p_id = path[j];
506 clist_append(id_list,p_id); 505 clist_append(id_list,p_id);
507 } 506 }
508 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 507 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
509 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 508 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
510 mailimap_section * section = mailimap_section_new(section_spec); 509 mailimap_section * section = mailimap_section_new(section_spec);
511 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 510 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
512 511
513 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
514 513
515 clist*result = clist_new(); 514 clist*result = clist_new();
516 515
517 err = mailimap_fetch( m_imap, set, fetchType, &result ); 516 err = mailimap_fetch( m_imap, set, fetchType, &result );
518 mailimap_set_free( set ); 517 mailimap_set_free( set );
519 mailimap_fetch_type_free( fetchType ); 518 mailimap_fetch_type_free( fetchType );
520 519
521 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 520 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
522 mailimap_msg_att * msg_att; 521 mailimap_msg_att * msg_att;
523 msg_att = (mailimap_msg_att*)current->data; 522 msg_att = (mailimap_msg_att*)current->data;
524 mailimap_msg_att_item*msg_att_item; 523 mailimap_msg_att_item*msg_att_item;
525 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 524 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
526 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 525 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
527 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 526 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
528 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 527 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
529 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 528 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
530 /* detach - we take over the content */ 529 /* detach - we take over the content */
531 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 530 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
532 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 531 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
533 } 532 }
534 } 533 }
535 } 534 }
536 } else { 535 } else {
537 qDebug("error fetching text: %s",m_imap->imap_response); 536 qDebug("error fetching text: %s",m_imap->imap_response);
538 } 537 }
539 mailimap_fetch_list_free(result); 538 mailimap_fetch_list_free(result);
540 return res; 539 return res;
541} 540}
542 541
543void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 542void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
544{ 543{
545 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 544 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
546 if (!mailDescription||current_recursion==10) { 545 if (!mailDescription||current_recursion==10) {
547 return; 546 return;
548 } 547 }
549 clistcell*current; 548 clistcell*current;
550 mailimap_body*current_body; 549 mailimap_body*current_body;
551 unsigned int count = 0; 550 unsigned int count = 0;
552 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 551 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
553 /* the point in the message */ 552 /* the point in the message */
554 ++count; 553 ++count;
555 current_body = (mailimap_body*)current->data; 554 current_body = (mailimap_body*)current->data;
556 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 555 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
557 QValueList<int>clist = recList; 556 QValueList<int>countlist = recList;
558 clist.append(count); 557 countlist.append(count);
559 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 558 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist);
560 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 559 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
561 RecPart currentPart; 560 RecPart currentPart;
562 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 561 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
563 QValueList<int>clist = recList; 562 QValueList<int>countlist = recList;
564 clist.append(count); 563 countlist.append(count);
565 /* important: Check for is NULL 'cause a body can be empty! */ 564 /* important: Check for is NULL 'cause a body can be empty! */
566 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
567 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 566 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
568 target_body.setDescription(currentPart); 567 target_body.setDescription(currentPart);
569 target_body.setBodytext(body_text); 568 target_body.setBodytext(body_text);
570 } else { 569 } else {
571 QString id(""); 570 QString id("");
572 for (unsigned int j = 0; j < clist.count();++j) { 571 for (unsigned int j = 0; j < countlist.count();++j) {
573 id+=(j>0?" ":""); 572 id+=(j>0?" ":"");
574 id+=QString("%1").arg(clist[j]); 573 id+=QString("%1").arg(countlist[j]);
575 } 574 }
576 qDebug("ID= %s",id.latin1()); 575 qDebug("ID= %s",id.latin1());
577 currentPart.setIdentifier(id); 576 currentPart.setIdentifier(id);
578 currentPart.setPositionlist(clist); 577 currentPart.setPositionlist(countlist);
579 target_body.addPart(currentPart); 578 target_body.addPart(currentPart);
580 } 579 }
581 } 580 }
582 } 581 }
583} 582}
584 583
585void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
586{ 585{
587 if (!Description) { 586 if (!Description) {
588 return; 587 return;
589 } 588 }
590 switch (Description->bd_type) { 589 switch (Description->bd_type) {
591 case MAILIMAP_BODY_TYPE_1PART_TEXT: 590 case MAILIMAP_BODY_TYPE_1PART_TEXT:
592 target_part.setType("text"); 591 target_part.setType("text");
593 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
594 break; 593 break;
595 case MAILIMAP_BODY_TYPE_1PART_BASIC: 594 case MAILIMAP_BODY_TYPE_1PART_BASIC:
596 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
597 break; 596 break;
598 case MAILIMAP_BODY_TYPE_1PART_MSG: 597 case MAILIMAP_BODY_TYPE_1PART_MSG:
599 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
600 break; 599 break;
601 default: 600 default:
602 break; 601 break;
603 } 602 }
604} 603}
605 604
606void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
607{ 606{
608 if (!which) { 607 if (!which) {
609 return; 608 return;
610 } 609 }
611 QString sub; 610 QString sub;
612 sub = which->bd_media_text; 611 sub = which->bd_media_text;
613 target_part.setSubtype(sub.lower()); 612 target_part.setSubtype(sub.lower());
614 target_part.setLines(which->bd_lines); 613 target_part.setLines(which->bd_lines);
615 fillBodyFields(target_part,which->bd_fields); 614 fillBodyFields(target_part,which->bd_fields);
616} 615}
617 616
618void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
619{ 618{
620 if (!which) { 619 if (!which) {
621 return; 620 return;
622 } 621 }
623// QString sub; 622// QString sub;
624// sub = which->bd_media_text; 623// sub = which->bd_media_text;
625// target_part.setSubtype(sub.lower()); 624// target_part.setSubtype(sub.lower());
626 qDebug("Message part"); 625 qDebug("Message part");
627 /* we set this type to text/plain */ 626 /* we set this type to text/plain */
628 target_part.setType("text"); 627 target_part.setType("text");
629 target_part.setSubtype("plain"); 628 target_part.setSubtype("plain");
630 target_part.setLines(which->bd_lines); 629 target_part.setLines(which->bd_lines);
631 fillBodyFields(target_part,which->bd_fields); 630 fillBodyFields(target_part,which->bd_fields);
632} 631}
633 632
634void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
635{ 634{
636 if (!which) { 635 if (!which) {
637 return; 636 return;
638 } 637 }
639 QString type,sub; 638 QString type,sub;
640 switch (which->bd_media_basic->med_type) { 639 switch (which->bd_media_basic->med_type) {
641 case MAILIMAP_MEDIA_BASIC_APPLICATION: 640 case MAILIMAP_MEDIA_BASIC_APPLICATION:
642 type = "application"; 641 type = "application";
643 break; 642 break;
644 case MAILIMAP_MEDIA_BASIC_AUDIO: 643 case MAILIMAP_MEDIA_BASIC_AUDIO:
645 type = "audio"; 644 type = "audio";
646 break; 645 break;
647 case MAILIMAP_MEDIA_BASIC_IMAGE: 646 case MAILIMAP_MEDIA_BASIC_IMAGE:
648 type = "image"; 647 type = "image";
649 break; 648 break;
650 case MAILIMAP_MEDIA_BASIC_MESSAGE: 649 case MAILIMAP_MEDIA_BASIC_MESSAGE:
651 type = "message"; 650 type = "message";
652 break; 651 break;
653 case MAILIMAP_MEDIA_BASIC_VIDEO: 652 case MAILIMAP_MEDIA_BASIC_VIDEO:
654 type = "video"; 653 type = "video";
655 break; 654 break;
656 case MAILIMAP_MEDIA_BASIC_OTHER: 655 case MAILIMAP_MEDIA_BASIC_OTHER:
657 default: 656 default:
658 if (which->bd_media_basic->med_basic_type) { 657 if (which->bd_media_basic->med_basic_type) {
659 type = which->bd_media_basic->med_basic_type; 658 type = which->bd_media_basic->med_basic_type;
660 } else { 659 } else {
661 type = ""; 660 type = "";
662 } 661 }
663 break; 662 break;
664 } 663 }
665 if (which->bd_media_basic->med_subtype) { 664 if (which->bd_media_basic->med_subtype) {
666 sub = which->bd_media_basic->med_subtype; 665 sub = which->bd_media_basic->med_subtype;
667 } else { 666 } else {
668 sub = ""; 667 sub = "";
669 } 668 }
670 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 669 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
671 target_part.setType(type.lower()); 670 target_part.setType(type.lower());
672 target_part.setSubtype(sub.lower()); 671 target_part.setSubtype(sub.lower());
673 fillBodyFields(target_part,which->bd_fields); 672 fillBodyFields(target_part,which->bd_fields);
674} 673}
675 674
676void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
677{ 676{
678 if (!which) return; 677 if (!which) return;
679 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
680 clistcell*cur; 679 clistcell*cur;
681 mailimap_single_body_fld_param*param=0; 680 mailimap_single_body_fld_param*param=0;
682 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
683 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
684 if (param) { 683 if (param) {
685 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
686 } 685 }
687 } 686 }
688 } 687 }
689 mailimap_body_fld_enc*enc = which->bd_encoding; 688 mailimap_body_fld_enc*enc = which->bd_encoding;
690 QString encoding(""); 689 QString encoding("");
691 switch (enc->enc_type) { 690 switch (enc->enc_type) {
692 case MAILIMAP_BODY_FLD_ENC_7BIT: 691 case MAILIMAP_BODY_FLD_ENC_7BIT:
693 encoding = "7bit"; 692 encoding = "7bit";
694 break; 693 break;
695 case MAILIMAP_BODY_FLD_ENC_8BIT: 694 case MAILIMAP_BODY_FLD_ENC_8BIT:
696 encoding = "8bit"; 695 encoding = "8bit";
697 break; 696 break;
698 case MAILIMAP_BODY_FLD_ENC_BINARY: 697 case MAILIMAP_BODY_FLD_ENC_BINARY:
699 encoding="binary"; 698 encoding="binary";
700 break; 699 break;
701 case MAILIMAP_BODY_FLD_ENC_BASE64: 700 case MAILIMAP_BODY_FLD_ENC_BASE64:
702 encoding="base64"; 701 encoding="base64";
703 break; 702 break;
704 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
705 encoding="quoted-printable"; 704 encoding="quoted-printable";
706 break; 705 break;
707 case MAILIMAP_BODY_FLD_ENC_OTHER: 706 case MAILIMAP_BODY_FLD_ENC_OTHER:
708 default: 707 default:
709 if (enc->enc_value) { 708 if (enc->enc_value) {
710 char*t=enc->enc_value; 709 char*t=enc->enc_value;
711 encoding=QString(enc->enc_value); 710 encoding=QString(enc->enc_value);
712 enc->enc_value=0L; 711 enc->enc_value=0L;
713 free(t); 712 free(t);
714 } 713 }
715 } 714 }
716 if (which->bd_description) { 715 if (which->bd_description) {
717 target_part.setDescription(QString(which->bd_description)); 716 target_part.setDescription(QString(which->bd_description));
718 } 717 }
719 target_part.setEncoding(encoding); 718 target_part.setEncoding(encoding);
720 target_part.setSize(which->bd_size); 719 target_part.setSize(which->bd_size);
721} 720}
722 721
723void IMAPwrapper::deleteMail(const RecMail&mail) 722void IMAPwrapper::deleteMail(const RecMail&mail)
724{ 723{
725 mailimap_flag_list*flist; 724 mailimap_flag_list*flist;
726 mailimap_set *set; 725 mailimap_set *set;
727 mailimap_store_att_flags * store_flags; 726 mailimap_store_att_flags * store_flags;
728 int err; 727 int err;
729 login(); 728 login();
730 if (!m_imap) { 729 if (!m_imap) {
731 return; 730 return;
732 } 731 }
733 const char *mb = mail.getMbox().latin1(); 732 const char *mb = mail.getMbox().latin1();
734 err = mailimap_select( m_imap, (char*)mb); 733 err = mailimap_select( m_imap, (char*)mb);
735 if ( err != MAILIMAP_NO_ERROR ) { 734 if ( err != MAILIMAP_NO_ERROR ) {
736 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
737 return; 736 return;
738 } 737 }
739 flist = mailimap_flag_list_new_empty(); 738 flist = mailimap_flag_list_new_empty();
740 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
741 store_flags = mailimap_store_att_flags_new_set_flags(flist); 740 store_flags = mailimap_store_att_flags_new_set_flags(flist);
742 set = mailimap_set_new_single(mail.getNumber()); 741 set = mailimap_set_new_single(mail.getNumber());
743 err = mailimap_store(m_imap,set,store_flags); 742 err = mailimap_store(m_imap,set,store_flags);
744 mailimap_set_free( set ); 743 mailimap_set_free( set );
745 mailimap_store_att_flags_free(store_flags); 744 mailimap_store_att_flags_free(store_flags);
746 745
747 if (err != MAILIMAP_NO_ERROR) { 746 if (err != MAILIMAP_NO_ERROR) {
748 qDebug("error deleting mail: %s",m_imap->imap_response); 747 qDebug("error deleting mail: %s",m_imap->imap_response);
749 return; 748 return;
750 } 749 }
751 qDebug("deleting mail: %s",m_imap->imap_response); 750 qDebug("deleting mail: %s",m_imap->imap_response);
752 /* should we realy do that at this moment? */ 751 /* should we realy do that at this moment? */
753 err = mailimap_expunge(m_imap); 752 err = mailimap_expunge(m_imap);
754 if (err != MAILIMAP_NO_ERROR) { 753 if (err != MAILIMAP_NO_ERROR) {
755 qDebug("error deleting mail: %s",m_imap->imap_response); 754 qDebug("error deleting mail: %s",m_imap->imap_response);
756 } 755 }
757 qDebug("Delete successfull %s",m_imap->imap_response); 756 qDebug("Delete successfull %s",m_imap->imap_response);
758} 757}
759 758
760void IMAPwrapper::answeredMail(const RecMail&mail) 759void IMAPwrapper::answeredMail(const RecMail&mail)
761{ 760{
762 mailimap_flag_list*flist; 761 mailimap_flag_list*flist;
763 mailimap_set *set; 762 mailimap_set *set;
764 mailimap_store_att_flags * store_flags; 763 mailimap_store_att_flags * store_flags;
765 int err; 764 int err;
766 login(); 765 login();
767 if (!m_imap) { 766 if (!m_imap) {
768 return; 767 return;
769 } 768 }
770 const char *mb = mail.getMbox().latin1(); 769 const char *mb = mail.getMbox().latin1();
771 err = mailimap_select( m_imap, (char*)mb); 770 err = mailimap_select( m_imap, (char*)mb);
772 if ( err != MAILIMAP_NO_ERROR ) { 771 if ( err != MAILIMAP_NO_ERROR ) {
773 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
774 return; 773 return;
775 } 774 }
776 flist = mailimap_flag_list_new_empty(); 775 flist = mailimap_flag_list_new_empty();
777 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 776 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
778 store_flags = mailimap_store_att_flags_new_add_flags(flist); 777 store_flags = mailimap_store_att_flags_new_add_flags(flist);
779 set = mailimap_set_new_single(mail.getNumber()); 778 set = mailimap_set_new_single(mail.getNumber());
780 err = mailimap_store(m_imap,set,store_flags); 779 err = mailimap_store(m_imap,set,store_flags);
781 mailimap_set_free( set ); 780 mailimap_set_free( set );
782 mailimap_store_att_flags_free(store_flags); 781 mailimap_store_att_flags_free(store_flags);
783 782
784 if (err != MAILIMAP_NO_ERROR) { 783 if (err != MAILIMAP_NO_ERROR) {
785 qDebug("error marking mail: %s",m_imap->imap_response); 784 qDebug("error marking mail: %s",m_imap->imap_response);
786 return; 785 return;
787 } 786 }
788} 787}
789 788
790QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
791{ 790{
792 QString body(""); 791 QString body("");
793 encodedString*res = fetchRawPart(mail,path,internal_call); 792 encodedString*res = fetchRawPart(mail,path,internal_call);
794 encodedString*r = decode_String(res,enc); 793 encodedString*r = decode_String(res,enc);
795 delete res; 794 delete res;
796 if (r) { 795 if (r) {
797 if (r->Length()>0) { 796 if (r->Length()>0) {
798 body = r->Content(); 797 body = r->Content();
799 } 798 }
800 delete r; 799 delete r;
801 } 800 }
802 return body; 801 return body;
803} 802}
804 803
805QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
806{ 805{
807 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
808} 807}
809 808
810encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
811{ 810{
812 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
813 encodedString*r = decode_String(res,part.Encoding()); 812 encodedString*r = decode_String(res,part.Encoding());
814 delete res; 813 delete res;
815 return r; 814 return r;
816} 815}
817 816
818encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
819{ 818{
820 return fetchRawPart(mail,part.Positionlist(),false); 819 return fetchRawPart(mail,part.Positionlist(),false);
821} 820}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 30eb678..853e4a2 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,821 +1,820 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include <libetpan/mailimap.h> 4#include <libetpan/libetpan.h>
5 5
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9 9
10IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 10IMAPwrapper::IMAPwrapper( IMAPaccount *a )
11 : AbstractMail() 11 : AbstractMail()
12{ 12{
13 account = a; 13 account = a;
14 m_imap = 0; 14 m_imap = 0;
15} 15}
16 16
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
18{ 18{
19 logout(); 19 logout();
20} 20}
21 21
22void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 22void IMAPwrapper::imap_progress( size_t current, size_t maximum )
23{ 23{
24 qDebug( "IMAP: %i of %i", current, maximum ); 24 qDebug( "IMAP: %i of %i", current, maximum );
25} 25}
26 26
27void IMAPwrapper::login() 27void IMAPwrapper::login()
28{ 28{
29 const char *server, *user, *pass; 29 const char *server, *user, *pass;
30 uint16_t port; 30 uint16_t port;
31 int err = MAILIMAP_NO_ERROR; 31 int err = MAILIMAP_NO_ERROR;
32 32
33 /* we are connected this moment */ 33 /* we are connected this moment */
34 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 34 /* TODO: setup a timer holding the line or if connection closed - delete the value */
35 if (m_imap) { 35 if (m_imap) {
36 mailstream_flush(m_imap->imap_stream); 36 mailstream_flush(m_imap->imap_stream);
37 return; 37 return;
38 } 38 }
39 server = account->getServer().latin1(); 39 server = account->getServer().latin1();
40 port = account->getPort().toUInt(); 40 port = account->getPort().toUInt();
41 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 41 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
42 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 42 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
43 login.show(); 43 login.show();
44 if ( QDialog::Accepted == login.exec() ) { 44 if ( QDialog::Accepted == login.exec() ) {
45 // ok 45 // ok
46 user = strdup( login.getUser().latin1() ); 46 user = strdup( login.getUser().latin1() );
47 pass = strdup( login.getPassword().latin1() ); 47 pass = strdup( login.getPassword().latin1() );
48 } else { 48 } else {
49 // cancel 49 // cancel
50 qDebug( "IMAP: Login canceled" ); 50 qDebug( "IMAP: Login canceled" );
51 return; 51 return;
52 } 52 }
53 } else { 53 } else {
54 user = account->getUser().latin1(); 54 user = account->getUser().latin1();
55 pass = account->getPassword().latin1(); 55 pass = account->getPassword().latin1();
56 } 56 }
57 57
58 m_imap = mailimap_new( 20, &imap_progress ); 58 m_imap = mailimap_new( 20, &imap_progress );
59 /* connect */ 59 /* connect */
60 if (account->getSSL()) { 60 if (account->getSSL()) {
61 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 61 err = mailimap_ssl_connect( m_imap, (char*)server, port );
62 } else { 62 } else {
63 err = mailimap_socket_connect( m_imap, (char*)server, port ); 63 err = mailimap_socket_connect( m_imap, (char*)server, port );
64 } 64 }
65 65
66 if ( err != MAILIMAP_NO_ERROR && 66 if ( err != MAILIMAP_NO_ERROR &&
67 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 67 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 68 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
69 qDebug("error connecting server: %s",m_imap->imap_response); 69 qDebug("error connecting server: %s",m_imap->imap_response);
70 mailimap_free( m_imap ); 70 mailimap_free( m_imap );
71 m_imap = 0; 71 m_imap = 0;
72 return; 72 return;
73 } 73 }
74 74
75 /* login */ 75 /* login */
76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 76 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
77 if ( err != MAILIMAP_NO_ERROR ) { 77 if ( err != MAILIMAP_NO_ERROR ) {
78 qDebug("error logging in imap: %s",m_imap->imap_response); 78 qDebug("error logging in imap: %s",m_imap->imap_response);
79 err = mailimap_close( m_imap ); 79 err = mailimap_close( m_imap );
80 mailimap_free( m_imap ); 80 mailimap_free( m_imap );
81 m_imap = 0; 81 m_imap = 0;
82 } 82 }
83} 83}
84 84
85void IMAPwrapper::logout() 85void IMAPwrapper::logout()
86{ 86{
87 int err = MAILIMAP_NO_ERROR; 87 int err = MAILIMAP_NO_ERROR;
88 if (!m_imap) return; 88 if (!m_imap) return;
89 err = mailimap_logout( m_imap ); 89 err = mailimap_logout( m_imap );
90 err = mailimap_close( m_imap ); 90 err = mailimap_close( m_imap );
91 mailimap_free( m_imap ); 91 mailimap_free( m_imap );
92 m_imap = 0; 92 m_imap = 0;
93} 93}
94 94
95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 95void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
96{ 96{
97 const char *mb; 97 const char *mb;
98 int err = MAILIMAP_NO_ERROR; 98 int err = MAILIMAP_NO_ERROR;
99 clist *result; 99 clist *result;
100 clistcell *current; 100 clistcell *current;
101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 101// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
102 mailimap_fetch_type *fetchType; 102 mailimap_fetch_type *fetchType;
103 mailimap_set *set; 103 mailimap_set *set;
104 104
105 mb = mailbox.latin1(); 105 mb = mailbox.latin1();
106 login(); 106 login();
107 if (!m_imap) { 107 if (!m_imap) {
108 return; 108 return;
109 } 109 }
110 /* select mailbox READONLY for operations */ 110 /* select mailbox READONLY for operations */
111 err = mailimap_examine( m_imap, (char*)mb); 111 err = mailimap_examine( m_imap, (char*)mb);
112 if ( err != MAILIMAP_NO_ERROR ) { 112 if ( err != MAILIMAP_NO_ERROR ) {
113 qDebug("error selecting mailbox: %s",m_imap->imap_response); 113 qDebug("error selecting mailbox: %s",m_imap->imap_response);
114 return; 114 return;
115 } 115 }
116 116
117 int last = m_imap->imap_selection_info->sel_exists; 117 int last = m_imap->imap_selection_info->sel_exists;
118 118
119 if (last == 0) { 119 if (last == 0) {
120 qDebug("mailbox has no mails"); 120 qDebug("mailbox has no mails");
121 return; 121 return;
122 } 122 }
123 123
124 result = clist_new(); 124 result = clist_new();
125 /* the range has to start at 1!!! not with 0!!!! */ 125 /* the range has to start at 1!!! not with 0!!!! */
126 set = mailimap_set_new_interval( 1, last ); 126 set = mailimap_set_new_interval( 1, last );
127 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 127 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
131 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 131 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
132 132
133 err = mailimap_fetch( m_imap, set, fetchType, &result ); 133 err = mailimap_fetch( m_imap, set, fetchType, &result );
134 mailimap_set_free( set ); 134 mailimap_set_free( set );
135 mailimap_fetch_type_free( fetchType ); 135 mailimap_fetch_type_free( fetchType );
136 136
137 QString date,subject,from; 137 QString date,subject,from;
138 138
139 if ( err == MAILIMAP_NO_ERROR ) { 139 if ( err == MAILIMAP_NO_ERROR ) {
140 140
141 mailimap_msg_att * msg_att; 141 mailimap_msg_att * msg_att;
142 int i = 0; 142 int i = 0;
143 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 143 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
144 ++i; 144 ++i;
145 msg_att = (mailimap_msg_att*)current->data; 145 msg_att = (mailimap_msg_att*)current->data;
146 RecMail*m = parse_list_result(msg_att); 146 RecMail*m = parse_list_result(msg_att);
147 if (m) { 147 if (m) {
148 m->setNumber(i); 148 m->setNumber(i);
149 m->setMbox(mailbox); 149 m->setMbox(mailbox);
150 m->setWrapper(this); 150 m->setWrapper(this);
151 target.append(m); 151 target.append(m);
152 } 152 }
153 } 153 }
154 } else { 154 } else {
155 qDebug("Error fetching headers: %s",m_imap->imap_response); 155 qDebug("Error fetching headers: %s",m_imap->imap_response);
156 } 156 }
157 mailimap_fetch_list_free(result); 157 mailimap_fetch_list_free(result);
158} 158}
159 159
160QList<Folder>* IMAPwrapper::listFolders() 160QList<Folder>* IMAPwrapper::listFolders()
161{ 161{
162 const char *path, *mask; 162 const char *path, *mask;
163 int err = MAILIMAP_NO_ERROR; 163 int err = MAILIMAP_NO_ERROR;
164 clist *result; 164 clist *result;
165 clistcell *current; 165 clistcell *current;
166 166
167 QList<Folder> * folders = new QList<Folder>(); 167 QList<Folder> * folders = new QList<Folder>();
168 folders->setAutoDelete( false ); 168 folders->setAutoDelete( false );
169 login(); 169 login();
170 if (!m_imap) { 170 if (!m_imap) {
171 return folders; 171 return folders;
172 } 172 }
173 173
174/* 174/*
175 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 175 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
176 * We must not forget to filter them out in next loop! 176 * We must not forget to filter them out in next loop!
177 * it seems like ugly code. and yes - it is ugly code. but the best way. 177 * it seems like ugly code. and yes - it is ugly code. but the best way.
178 */ 178 */
179 QString temp; 179 QString temp;
180 mask = "INBOX" ; 180 mask = "INBOX" ;
181 result = clist_new(); 181 result = clist_new();
182 mailimap_mailbox_list *list; 182 mailimap_mailbox_list *list;
183 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 183 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
184 QString del; 184 QString del;
185 if ( err == MAILIMAP_NO_ERROR ) { 185 if ( err == MAILIMAP_NO_ERROR ) {
186 current = result->first; 186 current = result->first;
187 for ( int i = result->count; i > 0; i-- ) { 187 for ( int i = result->count; i > 0; i-- ) {
188 list = (mailimap_mailbox_list *) current->data; 188 list = (mailimap_mailbox_list *) current->data;
189 // it is better use the deep copy mechanism of qt itself 189 // it is better use the deep copy mechanism of qt itself
190 // instead of using strdup! 190 // instead of using strdup!
191 temp = list->mb_name; 191 temp = list->mb_name;
192 del = list->mb_delimiter; 192 del = list->mb_delimiter;
193 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 193 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
194 current = current->next; 194 current = current->next;
195 } 195 }
196 } else { 196 } else {
197 qDebug("error fetching folders: %s",m_imap->imap_response); 197 qDebug("error fetching folders: %s",m_imap->imap_response);
198 } 198 }
199 mailimap_list_result_free( result ); 199 mailimap_list_result_free( result );
200 200
201/* 201/*
202 * second stage - get the other then inbox folders 202 * second stage - get the other then inbox folders
203 */ 203 */
204 mask = "*" ; 204 mask = "*" ;
205 path = account->getPrefix().latin1(); 205 path = account->getPrefix().latin1();
206 if (!path) path = ""; 206 if (!path) path = "";
207 result = clist_new(); 207 result = clist_new();
208 qDebug(path); 208 qDebug(path);
209 bool selectable = true; 209 bool selectable = true;
210 mailimap_mbx_list_flags*bflags; 210 mailimap_mbx_list_flags*bflags;
211 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 211 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
212 if ( err == MAILIMAP_NO_ERROR ) { 212 if ( err == MAILIMAP_NO_ERROR ) {
213 current = result->first; 213 current = result->first;
214 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 214 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
215 list = (mailimap_mailbox_list *) current->data; 215 list = (mailimap_mailbox_list *) current->data;
216 // it is better use the deep copy mechanism of qt itself 216 // it is better use the deep copy mechanism of qt itself
217 // instead of using strdup! 217 // instead of using strdup!
218 temp = list->mb_name; 218 temp = list->mb_name;
219 if (temp.lower()=="inbox") 219 if (temp.lower()=="inbox")
220 continue; 220 continue;
221 if (temp.lower()==account->getPrefix().lower()) 221 if (temp.lower()==account->getPrefix().lower())
222 continue; 222 continue;
223 if ( (bflags = list->mb_flag) ) { 223 if ( (bflags = list->mb_flag) ) {
224 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 224 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
225 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 225 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
226 } 226 }
227 del = list->mb_delimiter; 227 del = list->mb_delimiter;
228 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 228 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
229 } 229 }
230 } else { 230 } else {
231 qDebug("error fetching folders %s",m_imap->imap_response); 231 qDebug("error fetching folders %s",m_imap->imap_response);
232 } 232 }
233 mailimap_list_result_free( result ); 233 mailimap_list_result_free( result );
234 return folders; 234 return folders;
235} 235}
236 236
237RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 237RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
238{ 238{
239 RecMail * m = 0; 239 RecMail * m = 0;
240 mailimap_msg_att_item *item=0; 240 mailimap_msg_att_item *item=0;
241 clistcell *current,*c,*cf; 241 clistcell *current,*c,*cf;
242 mailimap_msg_att_dynamic*flist; 242 mailimap_msg_att_dynamic*flist;
243 mailimap_flag_fetch*cflag; 243 mailimap_flag_fetch*cflag;
244 int size; 244 int size;
245 QBitArray mFlags(7); 245 QBitArray mFlags(7);
246 QStringList addresslist; 246 QStringList addresslist;
247 247
248 if (!m_att) { 248 if (!m_att) {
249 return m; 249 return m;
250 } 250 }
251 m = new RecMail(); 251 m = new RecMail();
252 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 252 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
253 current = c; 253 current = c;
254 size = 0; 254 size = 0;
255 item = (mailimap_msg_att_item*)current->data; 255 item = (mailimap_msg_att_item*)current->data;
256 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 256 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
257 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 257 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
258 if (!flist->att_list) { 258 if (!flist->att_list) {
259 continue; 259 continue;
260 } 260 }
261 cf = flist->att_list->first; 261 cf = flist->att_list->first;
262 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 262 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
263 cflag = (mailimap_flag_fetch*)cf->data; 263 cflag = (mailimap_flag_fetch*)cf->data;
264 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 264 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
265 switch (cflag->fl_flag->fl_type) { 265 switch (cflag->fl_flag->fl_type) {
266 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 266 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
267 mFlags.setBit(FLAG_ANSWERED); 267 mFlags.setBit(FLAG_ANSWERED);
268 break; 268 break;
269 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 269 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
270 mFlags.setBit(FLAG_FLAGGED); 270 mFlags.setBit(FLAG_FLAGGED);
271 break; 271 break;
272 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 272 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
273 mFlags.setBit(FLAG_DELETED); 273 mFlags.setBit(FLAG_DELETED);
274 break; 274 break;
275 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 275 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
276 mFlags.setBit(FLAG_SEEN); 276 mFlags.setBit(FLAG_SEEN);
277 break; 277 break;
278 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 278 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
279 mFlags.setBit(FLAG_DRAFT); 279 mFlags.setBit(FLAG_DRAFT);
280 break; 280 break;
281 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 281 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
282 break; 282 break;
283 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 283 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
284 break; 284 break;
285 default: 285 default:
286 break; 286 break;
287 } 287 }
288 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 288 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
289 mFlags.setBit(FLAG_RECENT); 289 mFlags.setBit(FLAG_RECENT);
290 } 290 }
291 } 291 }
292 continue; 292 continue;
293 } 293 }
294 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 294 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
295 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 295 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
296 m->setDate(head->env_date); 296 m->setDate(head->env_date);
297 m->setSubject(convert_String((const char*)head->env_subject)); 297 m->setSubject(convert_String((const char*)head->env_subject));
298 //m->setSubject(head->env_subject); 298 //m->setSubject(head->env_subject);
299 if (head->env_from!=NULL) { 299 if (head->env_from!=NULL) {
300 addresslist = address_list_to_stringlist(head->env_from->frm_list); 300 addresslist = address_list_to_stringlist(head->env_from->frm_list);
301 if (addresslist.count()) { 301 if (addresslist.count()) {
302 m->setFrom(addresslist.first()); 302 m->setFrom(addresslist.first());
303 } 303 }
304 } 304 }
305 if (head->env_to!=NULL) { 305 if (head->env_to!=NULL) {
306 addresslist = address_list_to_stringlist(head->env_to->to_list); 306 addresslist = address_list_to_stringlist(head->env_to->to_list);
307 m->setTo(addresslist); 307 m->setTo(addresslist);
308 } 308 }
309 if (head->env_cc!=NULL) { 309 if (head->env_cc!=NULL) {
310 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 310 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
311 m->setCC(addresslist); 311 m->setCC(addresslist);
312 } 312 }
313 if (head->env_bcc!=NULL) { 313 if (head->env_bcc!=NULL) {
314 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 314 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
315 m->setBcc(addresslist); 315 m->setBcc(addresslist);
316 } 316 }
317 if (head->env_reply_to!=NULL) { 317 if (head->env_reply_to!=NULL) {
318 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 318 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
319 if (addresslist.count()) { 319 if (addresslist.count()) {
320 m->setReplyto(addresslist.first()); 320 m->setReplyto(addresslist.first());
321 } 321 }
322 } 322 }
323 m->setMsgid(QString(head->env_message_id)); 323 m->setMsgid(QString(head->env_message_id));
324 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 324 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
325#if 0 325#if 0
326
327 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 326 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
328 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 327 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
329 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); 328 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);
330 qDebug(da.toString()); 329 qDebug(da.toString());
331#endif 330#endif
332 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 331 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
333 size = item->att_data.att_static->att_data.att_rfc822_size; 332 size = item->att_data.att_static->att_data.att_rfc822_size;
334 } 333 }
335 } 334 }
336 /* msg is already deleted */ 335 /* msg is already deleted */
337 if (mFlags.testBit(FLAG_DELETED) && m) { 336 if (mFlags.testBit(FLAG_DELETED) && m) {
338 delete m; 337 delete m;
339 m = 0; 338 m = 0;
340 } 339 }
341 if (m) { 340 if (m) {
342 m->setFlags(mFlags); 341 m->setFlags(mFlags);
343 m->setMsgsize(size); 342 m->setMsgsize(size);
344 } 343 }
345 return m; 344 return m;
346} 345}
347 346
348RecBody IMAPwrapper::fetchBody(const RecMail&mail) 347RecBody IMAPwrapper::fetchBody(const RecMail&mail)
349{ 348{
350 RecBody body; 349 RecBody body;
351 const char *mb; 350 const char *mb;
352 int err = MAILIMAP_NO_ERROR; 351 int err = MAILIMAP_NO_ERROR;
353 clist *result; 352 clist *result;
354 clistcell *current; 353 clistcell *current;
355 mailimap_fetch_att *fetchAtt; 354 mailimap_fetch_att *fetchAtt;
356 mailimap_fetch_type *fetchType; 355 mailimap_fetch_type *fetchType;
357 mailimap_set *set; 356 mailimap_set *set;
358 mailimap_body*body_desc; 357 mailimap_body*body_desc;
359 358
360 mb = mail.getMbox().latin1(); 359 mb = mail.getMbox().latin1();
361 360
362 login(); 361 login();
363 if (!m_imap) { 362 if (!m_imap) {
364 return body; 363 return body;
365 } 364 }
366 365
367 err = mailimap_select( m_imap, (char*)mb); 366 err = mailimap_select( m_imap, (char*)mb);
368 if ( err != MAILIMAP_NO_ERROR ) { 367 if ( err != MAILIMAP_NO_ERROR ) {
369 qDebug("error selecting mailbox: %s",m_imap->imap_response); 368 qDebug("error selecting mailbox: %s",m_imap->imap_response);
370 return body; 369 return body;
371 } 370 }
372 371
373 result = clist_new(); 372 result = clist_new();
374 /* the range has to start at 1!!! not with 0!!!! */ 373 /* the range has to start at 1!!! not with 0!!!! */
375 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
376 fetchAtt = mailimap_fetch_att_new_bodystructure(); 375 fetchAtt = mailimap_fetch_att_new_bodystructure();
377 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
378 err = mailimap_fetch( m_imap, set, fetchType, &result ); 377 err = mailimap_fetch( m_imap, set, fetchType, &result );
379 mailimap_set_free( set ); 378 mailimap_set_free( set );
380 mailimap_fetch_type_free( fetchType ); 379 mailimap_fetch_type_free( fetchType );
381 380
382 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
383 mailimap_msg_att * msg_att; 382 mailimap_msg_att * msg_att;
384 msg_att = (mailimap_msg_att*)current->data; 383 msg_att = (mailimap_msg_att*)current->data;
385 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
386 body_desc = item->att_data.att_static->att_data.att_body; 385 body_desc = item->att_data.att_static->att_data.att_body;
387 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
388 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
389 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
390 qDebug("Mulitpart mail"); 389 qDebug("Mulitpart mail");
391 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
392 } 391 }
393 } else { 392 } else {
394 qDebug("error fetching body: %s",m_imap->imap_response); 393 qDebug("error fetching body: %s",m_imap->imap_response);
395 } 394 }
396 mailimap_fetch_list_free(result); 395 mailimap_fetch_list_free(result);
397 return body; 396 return body;
398} 397}
399 398
400/* this routine is just called when the mail has only ONE part. 399/* this routine is just called when the mail has only ONE part.
401 for filling the parts of a multi-part-message there are other 400 for filling the parts of a multi-part-message there are other
402 routines 'cause we can not simply fetch the whole body. */ 401 routines 'cause we can not simply fetch the whole body. */
403void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
404{ 403{
405 if (!mailDescription) { 404 if (!mailDescription) {
406 return; 405 return;
407 } 406 }
408 QString sub,body_text; 407 QString sub,body_text;
409 RecPart singlePart; 408 RecPart singlePart;
410 QValueList<int> path; 409 QValueList<int> path;
411 fillSinglePart(singlePart,mailDescription); 410 fillSinglePart(singlePart,mailDescription);
412 switch (mailDescription->bd_type) { 411 switch (mailDescription->bd_type) {
413 case MAILIMAP_BODY_TYPE_1PART_MSG: 412 case MAILIMAP_BODY_TYPE_1PART_MSG:
414 path.append(1); 413 path.append(1);
415 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
416 target_body.setBodytext(body_text); 415 target_body.setBodytext(body_text);
417 target_body.setDescription(singlePart); 416 target_body.setDescription(singlePart);
418 break; 417 break;
419 case MAILIMAP_BODY_TYPE_1PART_TEXT: 418 case MAILIMAP_BODY_TYPE_1PART_TEXT:
420 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
421 path.append(1); 420 path.append(1);
422 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
423 target_body.setBodytext(body_text); 422 target_body.setBodytext(body_text);
424 target_body.setDescription(singlePart); 423 target_body.setDescription(singlePart);
425 break; 424 break;
426 case MAILIMAP_BODY_TYPE_1PART_BASIC: 425 case MAILIMAP_BODY_TYPE_1PART_BASIC:
427 qDebug("Single attachment"); 426 qDebug("Single attachment");
428 target_body.setBodytext(""); 427 target_body.setBodytext("");
429 target_body.addPart(singlePart); 428 target_body.addPart(singlePart);
430 break; 429 break;
431 default: 430 default:
432 break; 431 break;
433 } 432 }
434 433
435 return; 434 return;
436} 435}
437 436
438QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 437QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
439{ 438{
440 QStringList l; 439 QStringList l;
441 QString from; 440 QString from;
442 bool named_from; 441 bool named_from;
443 clistcell *current = NULL; 442 clistcell *current = NULL;
444 mailimap_address * current_address=NULL; 443 mailimap_address * current_address=NULL;
445 if (!list) { 444 if (!list) {
446 return l; 445 return l;
447 } 446 }
448 unsigned int count = 0; 447 unsigned int count = 0;
449 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
450 from = ""; 449 from = "";
451 named_from = false; 450 named_from = false;
452 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
453 if (current_address->ad_personal_name){ 452 if (current_address->ad_personal_name){
454 from+=convert_String((const char*)current_address->ad_personal_name); 453 from+=convert_String((const char*)current_address->ad_personal_name);
455 //from+=QString(current_address->ad_personal_name); 454 //from+=QString(current_address->ad_personal_name);
456 from+=" "; 455 from+=" ";
457 named_from = true; 456 named_from = true;
458 } 457 }
459 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
460 from+="<"; 459 from+="<";
461 } 460 }
462 if (current_address->ad_mailbox_name) { 461 if (current_address->ad_mailbox_name) {
463 from+=QString(current_address->ad_mailbox_name); 462 from+=QString(current_address->ad_mailbox_name);
464 from+="@"; 463 from+="@";
465 } 464 }
466 if (current_address->ad_host_name) { 465 if (current_address->ad_host_name) {
467 from+=QString(current_address->ad_host_name); 466 from+=QString(current_address->ad_host_name);
468 } 467 }
469 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
470 from+=">"; 469 from+=">";
471 } 470 }
472 l.append(QString(from)); 471 l.append(QString(from));
473 if (++count > 99) { 472 if (++count > 99) {
474 break; 473 break;
475 } 474 }
476 } 475 }
477 return l; 476 return l;
478} 477}
479 478
480encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
481{ 480{
482 encodedString*res=new encodedString; 481 encodedString*res=new encodedString;
483 const char*mb; 482 const char*mb;
484 int err; 483 int err;
485 mailimap_fetch_type *fetchType; 484 mailimap_fetch_type *fetchType;
486 mailimap_set *set; 485 mailimap_set *set;
487 clistcell*current,*cur; 486 clistcell*current,*cur;
488 487
489 login(); 488 login();
490 if (!m_imap) { 489 if (!m_imap) {
491 return res; 490 return res;
492 } 491 }
493 if (!internal_call) { 492 if (!internal_call) {
494 mb = mail.getMbox().latin1(); 493 mb = mail.getMbox().latin1();
495 err = mailimap_select( m_imap, (char*)mb); 494 err = mailimap_select( m_imap, (char*)mb);
496 if ( err != MAILIMAP_NO_ERROR ) { 495 if ( err != MAILIMAP_NO_ERROR ) {
497 qDebug("error selecting mailbox: %s",m_imap->imap_response); 496 qDebug("error selecting mailbox: %s",m_imap->imap_response);
498 return res; 497 return res;
499 } 498 }
500 } 499 }
501 set = mailimap_set_new_single(mail.getNumber()); 500 set = mailimap_set_new_single(mail.getNumber());
502 clist*id_list=clist_new(); 501 clist*id_list=clist_new();
503 for (unsigned j=0; j < path.count();++j) { 502 for (unsigned j=0; j < path.count();++j) {
504 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 503 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
505 *p_id = path[j]; 504 *p_id = path[j];
506 clist_append(id_list,p_id); 505 clist_append(id_list,p_id);
507 } 506 }
508 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 507 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
509 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 508 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
510 mailimap_section * section = mailimap_section_new(section_spec); 509 mailimap_section * section = mailimap_section_new(section_spec);
511 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 510 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
512 511
513 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
514 513
515 clist*result = clist_new(); 514 clist*result = clist_new();
516 515
517 err = mailimap_fetch( m_imap, set, fetchType, &result ); 516 err = mailimap_fetch( m_imap, set, fetchType, &result );
518 mailimap_set_free( set ); 517 mailimap_set_free( set );
519 mailimap_fetch_type_free( fetchType ); 518 mailimap_fetch_type_free( fetchType );
520 519
521 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 520 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
522 mailimap_msg_att * msg_att; 521 mailimap_msg_att * msg_att;
523 msg_att = (mailimap_msg_att*)current->data; 522 msg_att = (mailimap_msg_att*)current->data;
524 mailimap_msg_att_item*msg_att_item; 523 mailimap_msg_att_item*msg_att_item;
525 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 524 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
526 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 525 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
527 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 526 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
528 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 527 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
529 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 528 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
530 /* detach - we take over the content */ 529 /* detach - we take over the content */
531 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 530 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
532 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 531 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
533 } 532 }
534 } 533 }
535 } 534 }
536 } else { 535 } else {
537 qDebug("error fetching text: %s",m_imap->imap_response); 536 qDebug("error fetching text: %s",m_imap->imap_response);
538 } 537 }
539 mailimap_fetch_list_free(result); 538 mailimap_fetch_list_free(result);
540 return res; 539 return res;
541} 540}
542 541
543void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 542void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
544{ 543{
545 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 544 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
546 if (!mailDescription||current_recursion==10) { 545 if (!mailDescription||current_recursion==10) {
547 return; 546 return;
548 } 547 }
549 clistcell*current; 548 clistcell*current;
550 mailimap_body*current_body; 549 mailimap_body*current_body;
551 unsigned int count = 0; 550 unsigned int count = 0;
552 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 551 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
553 /* the point in the message */ 552 /* the point in the message */
554 ++count; 553 ++count;
555 current_body = (mailimap_body*)current->data; 554 current_body = (mailimap_body*)current->data;
556 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 555 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
557 QValueList<int>clist = recList; 556 QValueList<int>countlist = recList;
558 clist.append(count); 557 countlist.append(count);
559 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 558 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist);
560 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 559 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
561 RecPart currentPart; 560 RecPart currentPart;
562 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 561 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
563 QValueList<int>clist = recList; 562 QValueList<int>countlist = recList;
564 clist.append(count); 563 countlist.append(count);
565 /* important: Check for is NULL 'cause a body can be empty! */ 564 /* important: Check for is NULL 'cause a body can be empty! */
566 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
567 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 566 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
568 target_body.setDescription(currentPart); 567 target_body.setDescription(currentPart);
569 target_body.setBodytext(body_text); 568 target_body.setBodytext(body_text);
570 } else { 569 } else {
571 QString id(""); 570 QString id("");
572 for (unsigned int j = 0; j < clist.count();++j) { 571 for (unsigned int j = 0; j < countlist.count();++j) {
573 id+=(j>0?" ":""); 572 id+=(j>0?" ":"");
574 id+=QString("%1").arg(clist[j]); 573 id+=QString("%1").arg(countlist[j]);
575 } 574 }
576 qDebug("ID= %s",id.latin1()); 575 qDebug("ID= %s",id.latin1());
577 currentPart.setIdentifier(id); 576 currentPart.setIdentifier(id);
578 currentPart.setPositionlist(clist); 577 currentPart.setPositionlist(countlist);
579 target_body.addPart(currentPart); 578 target_body.addPart(currentPart);
580 } 579 }
581 } 580 }
582 } 581 }
583} 582}
584 583
585void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
586{ 585{
587 if (!Description) { 586 if (!Description) {
588 return; 587 return;
589 } 588 }
590 switch (Description->bd_type) { 589 switch (Description->bd_type) {
591 case MAILIMAP_BODY_TYPE_1PART_TEXT: 590 case MAILIMAP_BODY_TYPE_1PART_TEXT:
592 target_part.setType("text"); 591 target_part.setType("text");
593 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
594 break; 593 break;
595 case MAILIMAP_BODY_TYPE_1PART_BASIC: 594 case MAILIMAP_BODY_TYPE_1PART_BASIC:
596 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
597 break; 596 break;
598 case MAILIMAP_BODY_TYPE_1PART_MSG: 597 case MAILIMAP_BODY_TYPE_1PART_MSG:
599 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
600 break; 599 break;
601 default: 600 default:
602 break; 601 break;
603 } 602 }
604} 603}
605 604
606void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
607{ 606{
608 if (!which) { 607 if (!which) {
609 return; 608 return;
610 } 609 }
611 QString sub; 610 QString sub;
612 sub = which->bd_media_text; 611 sub = which->bd_media_text;
613 target_part.setSubtype(sub.lower()); 612 target_part.setSubtype(sub.lower());
614 target_part.setLines(which->bd_lines); 613 target_part.setLines(which->bd_lines);
615 fillBodyFields(target_part,which->bd_fields); 614 fillBodyFields(target_part,which->bd_fields);
616} 615}
617 616
618void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
619{ 618{
620 if (!which) { 619 if (!which) {
621 return; 620 return;
622 } 621 }
623// QString sub; 622// QString sub;
624// sub = which->bd_media_text; 623// sub = which->bd_media_text;
625// target_part.setSubtype(sub.lower()); 624// target_part.setSubtype(sub.lower());
626 qDebug("Message part"); 625 qDebug("Message part");
627 /* we set this type to text/plain */ 626 /* we set this type to text/plain */
628 target_part.setType("text"); 627 target_part.setType("text");
629 target_part.setSubtype("plain"); 628 target_part.setSubtype("plain");
630 target_part.setLines(which->bd_lines); 629 target_part.setLines(which->bd_lines);
631 fillBodyFields(target_part,which->bd_fields); 630 fillBodyFields(target_part,which->bd_fields);
632} 631}
633 632
634void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
635{ 634{
636 if (!which) { 635 if (!which) {
637 return; 636 return;
638 } 637 }
639 QString type,sub; 638 QString type,sub;
640 switch (which->bd_media_basic->med_type) { 639 switch (which->bd_media_basic->med_type) {
641 case MAILIMAP_MEDIA_BASIC_APPLICATION: 640 case MAILIMAP_MEDIA_BASIC_APPLICATION:
642 type = "application"; 641 type = "application";
643 break; 642 break;
644 case MAILIMAP_MEDIA_BASIC_AUDIO: 643 case MAILIMAP_MEDIA_BASIC_AUDIO:
645 type = "audio"; 644 type = "audio";
646 break; 645 break;
647 case MAILIMAP_MEDIA_BASIC_IMAGE: 646 case MAILIMAP_MEDIA_BASIC_IMAGE:
648 type = "image"; 647 type = "image";
649 break; 648 break;
650 case MAILIMAP_MEDIA_BASIC_MESSAGE: 649 case MAILIMAP_MEDIA_BASIC_MESSAGE:
651 type = "message"; 650 type = "message";
652 break; 651 break;
653 case MAILIMAP_MEDIA_BASIC_VIDEO: 652 case MAILIMAP_MEDIA_BASIC_VIDEO:
654 type = "video"; 653 type = "video";
655 break; 654 break;
656 case MAILIMAP_MEDIA_BASIC_OTHER: 655 case MAILIMAP_MEDIA_BASIC_OTHER:
657 default: 656 default:
658 if (which->bd_media_basic->med_basic_type) { 657 if (which->bd_media_basic->med_basic_type) {
659 type = which->bd_media_basic->med_basic_type; 658 type = which->bd_media_basic->med_basic_type;
660 } else { 659 } else {
661 type = ""; 660 type = "";
662 } 661 }
663 break; 662 break;
664 } 663 }
665 if (which->bd_media_basic->med_subtype) { 664 if (which->bd_media_basic->med_subtype) {
666 sub = which->bd_media_basic->med_subtype; 665 sub = which->bd_media_basic->med_subtype;
667 } else { 666 } else {
668 sub = ""; 667 sub = "";
669 } 668 }
670 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 669 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
671 target_part.setType(type.lower()); 670 target_part.setType(type.lower());
672 target_part.setSubtype(sub.lower()); 671 target_part.setSubtype(sub.lower());
673 fillBodyFields(target_part,which->bd_fields); 672 fillBodyFields(target_part,which->bd_fields);
674} 673}
675 674
676void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
677{ 676{
678 if (!which) return; 677 if (!which) return;
679 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
680 clistcell*cur; 679 clistcell*cur;
681 mailimap_single_body_fld_param*param=0; 680 mailimap_single_body_fld_param*param=0;
682 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
683 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
684 if (param) { 683 if (param) {
685 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
686 } 685 }
687 } 686 }
688 } 687 }
689 mailimap_body_fld_enc*enc = which->bd_encoding; 688 mailimap_body_fld_enc*enc = which->bd_encoding;
690 QString encoding(""); 689 QString encoding("");
691 switch (enc->enc_type) { 690 switch (enc->enc_type) {
692 case MAILIMAP_BODY_FLD_ENC_7BIT: 691 case MAILIMAP_BODY_FLD_ENC_7BIT:
693 encoding = "7bit"; 692 encoding = "7bit";
694 break; 693 break;
695 case MAILIMAP_BODY_FLD_ENC_8BIT: 694 case MAILIMAP_BODY_FLD_ENC_8BIT:
696 encoding = "8bit"; 695 encoding = "8bit";
697 break; 696 break;
698 case MAILIMAP_BODY_FLD_ENC_BINARY: 697 case MAILIMAP_BODY_FLD_ENC_BINARY:
699 encoding="binary"; 698 encoding="binary";
700 break; 699 break;
701 case MAILIMAP_BODY_FLD_ENC_BASE64: 700 case MAILIMAP_BODY_FLD_ENC_BASE64:
702 encoding="base64"; 701 encoding="base64";
703 break; 702 break;
704 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
705 encoding="quoted-printable"; 704 encoding="quoted-printable";
706 break; 705 break;
707 case MAILIMAP_BODY_FLD_ENC_OTHER: 706 case MAILIMAP_BODY_FLD_ENC_OTHER:
708 default: 707 default:
709 if (enc->enc_value) { 708 if (enc->enc_value) {
710 char*t=enc->enc_value; 709 char*t=enc->enc_value;
711 encoding=QString(enc->enc_value); 710 encoding=QString(enc->enc_value);
712 enc->enc_value=0L; 711 enc->enc_value=0L;
713 free(t); 712 free(t);
714 } 713 }
715 } 714 }
716 if (which->bd_description) { 715 if (which->bd_description) {
717 target_part.setDescription(QString(which->bd_description)); 716 target_part.setDescription(QString(which->bd_description));
718 } 717 }
719 target_part.setEncoding(encoding); 718 target_part.setEncoding(encoding);
720 target_part.setSize(which->bd_size); 719 target_part.setSize(which->bd_size);
721} 720}
722 721
723void IMAPwrapper::deleteMail(const RecMail&mail) 722void IMAPwrapper::deleteMail(const RecMail&mail)
724{ 723{
725 mailimap_flag_list*flist; 724 mailimap_flag_list*flist;
726 mailimap_set *set; 725 mailimap_set *set;
727 mailimap_store_att_flags * store_flags; 726 mailimap_store_att_flags * store_flags;
728 int err; 727 int err;
729 login(); 728 login();
730 if (!m_imap) { 729 if (!m_imap) {
731 return; 730 return;
732 } 731 }
733 const char *mb = mail.getMbox().latin1(); 732 const char *mb = mail.getMbox().latin1();
734 err = mailimap_select( m_imap, (char*)mb); 733 err = mailimap_select( m_imap, (char*)mb);
735 if ( err != MAILIMAP_NO_ERROR ) { 734 if ( err != MAILIMAP_NO_ERROR ) {
736 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
737 return; 736 return;
738 } 737 }
739 flist = mailimap_flag_list_new_empty(); 738 flist = mailimap_flag_list_new_empty();
740 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
741 store_flags = mailimap_store_att_flags_new_set_flags(flist); 740 store_flags = mailimap_store_att_flags_new_set_flags(flist);
742 set = mailimap_set_new_single(mail.getNumber()); 741 set = mailimap_set_new_single(mail.getNumber());
743 err = mailimap_store(m_imap,set,store_flags); 742 err = mailimap_store(m_imap,set,store_flags);
744 mailimap_set_free( set ); 743 mailimap_set_free( set );
745 mailimap_store_att_flags_free(store_flags); 744 mailimap_store_att_flags_free(store_flags);
746 745
747 if (err != MAILIMAP_NO_ERROR) { 746 if (err != MAILIMAP_NO_ERROR) {
748 qDebug("error deleting mail: %s",m_imap->imap_response); 747 qDebug("error deleting mail: %s",m_imap->imap_response);
749 return; 748 return;
750 } 749 }
751 qDebug("deleting mail: %s",m_imap->imap_response); 750 qDebug("deleting mail: %s",m_imap->imap_response);
752 /* should we realy do that at this moment? */ 751 /* should we realy do that at this moment? */
753 err = mailimap_expunge(m_imap); 752 err = mailimap_expunge(m_imap);
754 if (err != MAILIMAP_NO_ERROR) { 753 if (err != MAILIMAP_NO_ERROR) {
755 qDebug("error deleting mail: %s",m_imap->imap_response); 754 qDebug("error deleting mail: %s",m_imap->imap_response);
756 } 755 }
757 qDebug("Delete successfull %s",m_imap->imap_response); 756 qDebug("Delete successfull %s",m_imap->imap_response);
758} 757}
759 758
760void IMAPwrapper::answeredMail(const RecMail&mail) 759void IMAPwrapper::answeredMail(const RecMail&mail)
761{ 760{
762 mailimap_flag_list*flist; 761 mailimap_flag_list*flist;
763 mailimap_set *set; 762 mailimap_set *set;
764 mailimap_store_att_flags * store_flags; 763 mailimap_store_att_flags * store_flags;
765 int err; 764 int err;
766 login(); 765 login();
767 if (!m_imap) { 766 if (!m_imap) {
768 return; 767 return;
769 } 768 }
770 const char *mb = mail.getMbox().latin1(); 769 const char *mb = mail.getMbox().latin1();
771 err = mailimap_select( m_imap, (char*)mb); 770 err = mailimap_select( m_imap, (char*)mb);
772 if ( err != MAILIMAP_NO_ERROR ) { 771 if ( err != MAILIMAP_NO_ERROR ) {
773 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
774 return; 773 return;
775 } 774 }
776 flist = mailimap_flag_list_new_empty(); 775 flist = mailimap_flag_list_new_empty();
777 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 776 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
778 store_flags = mailimap_store_att_flags_new_add_flags(flist); 777 store_flags = mailimap_store_att_flags_new_add_flags(flist);
779 set = mailimap_set_new_single(mail.getNumber()); 778 set = mailimap_set_new_single(mail.getNumber());
780 err = mailimap_store(m_imap,set,store_flags); 779 err = mailimap_store(m_imap,set,store_flags);
781 mailimap_set_free( set ); 780 mailimap_set_free( set );
782 mailimap_store_att_flags_free(store_flags); 781 mailimap_store_att_flags_free(store_flags);
783 782
784 if (err != MAILIMAP_NO_ERROR) { 783 if (err != MAILIMAP_NO_ERROR) {
785 qDebug("error marking mail: %s",m_imap->imap_response); 784 qDebug("error marking mail: %s",m_imap->imap_response);
786 return; 785 return;
787 } 786 }
788} 787}
789 788
790QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
791{ 790{
792 QString body(""); 791 QString body("");
793 encodedString*res = fetchRawPart(mail,path,internal_call); 792 encodedString*res = fetchRawPart(mail,path,internal_call);
794 encodedString*r = decode_String(res,enc); 793 encodedString*r = decode_String(res,enc);
795 delete res; 794 delete res;
796 if (r) { 795 if (r) {
797 if (r->Length()>0) { 796 if (r->Length()>0) {
798 body = r->Content(); 797 body = r->Content();
799 } 798 }
800 delete r; 799 delete r;
801 } 800 }
802 return body; 801 return body;
803} 802}
804 803
805QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
806{ 805{
807 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
808} 807}
809 808
810encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
811{ 810{
812 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
813 encodedString*r = decode_String(res,part.Encoding()); 812 encodedString*r = decode_String(res,part.Encoding());
814 delete res; 813 delete res;
815 return r; 814 return r;
816} 815}
817 816
818encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
819{ 818{
820 return fetchRawPart(mail,part.Positionlist(),false); 819 return fetchRawPart(mail,part.Positionlist(),false);
821} 820}