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