summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp63
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h4
2 files changed, 38 insertions, 29 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 23c678b..98634a3 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,1051 +1,1058 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14 m_Lastmbox = "";
14} 15}
15 16
16IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
17{ 18{
18 logout(); 19 logout();
19} 20}
20 21
22/* to avoid to often select statements in loops etc.
23 we trust that we are logged in and connection is established!*/
24int IMAPwrapper::selectMbox(const QString&mbox)
25{
26 if (mbox == m_Lastmbox) {
27 return MAILIMAP_NO_ERROR;
28 }
29 int err = mailimap_select( m_imap, (char*)mbox.latin1());
30 if ( err != MAILIMAP_NO_ERROR ) {
31 qDebug("error selecting mailbox: %s",m_imap->imap_response);
32 m_Lastmbox = "";
33 return err;
34 }
35 m_Lastmbox = mbox;
36 return err;
37}
38
21void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void IMAPwrapper::imap_progress( size_t current, size_t maximum )
22{ 40{
23 qDebug( "IMAP: %i of %i", current, maximum ); 41 qDebug( "IMAP: %i of %i", current, maximum );
24} 42}
25 43
26void IMAPwrapper::login() 44void IMAPwrapper::login()
27{ 45{
28 const char *server, *user, *pass; 46 const char *server, *user, *pass;
29 uint16_t port; 47 uint16_t port;
30 int err = MAILIMAP_NO_ERROR; 48 int err = MAILIMAP_NO_ERROR;
31 49
32 if (account->getOffline()) return; 50 if (account->getOffline()) return;
33 /* we are connected this moment */ 51 /* we are connected this moment */
34 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 52 /* TODO: setup a timer holding the line or if connection closed - delete the value */
35 if (m_imap) { 53 if (m_imap) {
36 err = mailimap_noop(m_imap); 54 err = mailimap_noop(m_imap);
37 if (err!=MAILIMAP_NO_ERROR) { 55 if (err!=MAILIMAP_NO_ERROR) {
38 logout(); 56 logout();
39 } else { 57 } else {
40 mailstream_flush(m_imap->imap_stream); 58 mailstream_flush(m_imap->imap_stream);
41 return; 59 return;
42 } 60 }
43 } 61 }
44 server = account->getServer().latin1(); 62 server = account->getServer().latin1();
45 port = account->getPort().toUInt(); 63 port = account->getPort().toUInt();
46 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 64 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
47 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 65 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
48 login.show(); 66 login.show();
49 if ( QDialog::Accepted == login.exec() ) { 67 if ( QDialog::Accepted == login.exec() ) {
50 // ok 68 // ok
51 user = login.getUser().latin1(); 69 user = login.getUser().latin1();
52 pass = login.getPassword().latin1(); 70 pass = login.getPassword().latin1();
53 } else { 71 } else {
54 // cancel 72 // cancel
55 qDebug( "IMAP: Login canceled" ); 73 qDebug( "IMAP: Login canceled" );
56 return; 74 return;
57 } 75 }
58 } else { 76 } else {
59 user = account->getUser().latin1(); 77 user = account->getUser().latin1();
60 pass = account->getPassword().latin1(); 78 pass = account->getPassword().latin1();
61 } 79 }
62 80
63 m_imap = mailimap_new( 20, &imap_progress ); 81 m_imap = mailimap_new( 20, &imap_progress );
64 82
65 /* connect */ 83 /* connect */
66 if (account->getSSL()) { 84 if (account->getSSL()) {
67 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 85 err = mailimap_ssl_connect( m_imap, (char*)server, port );
68 } else { 86 } else {
69 err = mailimap_socket_connect( m_imap, (char*)server, port ); 87 err = mailimap_socket_connect( m_imap, (char*)server, port );
70 } 88 }
71 89
72 if ( err != MAILIMAP_NO_ERROR && 90 if ( err != MAILIMAP_NO_ERROR &&
73 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 91 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
74 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 92 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
75 QString failure = ""; 93 QString failure = "";
76 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 94 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
77 failure="Connection refused"; 95 failure="Connection refused";
78 } else { 96 } else {
79 failure="Unknown failure"; 97 failure="Unknown failure";
80 } 98 }
81 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 99 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
82 mailimap_free( m_imap ); 100 mailimap_free( m_imap );
83 m_imap = 0; 101 m_imap = 0;
84 return; 102 return;
85 } 103 }
86 104
87 /* login */ 105 /* login */
88 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 106 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
89 if ( err != MAILIMAP_NO_ERROR ) { 107 if ( err != MAILIMAP_NO_ERROR ) {
90 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 108 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
91 err = mailimap_close( m_imap ); 109 err = mailimap_close( m_imap );
92 mailimap_free( m_imap ); 110 mailimap_free( m_imap );
93 m_imap = 0; 111 m_imap = 0;
94 } 112 }
95} 113}
96 114
97void IMAPwrapper::logout() 115void IMAPwrapper::logout()
98{ 116{
99 int err = MAILIMAP_NO_ERROR; 117 int err = MAILIMAP_NO_ERROR;
100 if (!m_imap) return; 118 if (!m_imap) return;
101 err = mailimap_logout( m_imap ); 119 err = mailimap_logout( m_imap );
102 err = mailimap_close( m_imap ); 120 err = mailimap_close( m_imap );
103 mailimap_free( m_imap ); 121 mailimap_free( m_imap );
104 m_imap = 0; 122 m_imap = 0;
123 m_Lastmbox = "";
105} 124}
106 125
107void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 126void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
108{ 127{
109 const char *mb = 0;
110 int err = MAILIMAP_NO_ERROR; 128 int err = MAILIMAP_NO_ERROR;
111 clist *result = 0; 129 clist *result = 0;
112 clistcell *current; 130 clistcell *current;
113// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
114 mailimap_fetch_type *fetchType = 0; 131 mailimap_fetch_type *fetchType = 0;
115 mailimap_set *set = 0; 132 mailimap_set *set = 0;
116 133
117 mb = mailbox.latin1();
118 login(); 134 login();
119 if (!m_imap) { 135 if (!m_imap) {
120 return; 136 return;
121 } 137 }
122 /* select mailbox READONLY for operations */ 138 /* select mailbox READONLY for operations */
123 err = mailimap_examine( m_imap, (char*)mb); 139 err = selectMbox(mailbox);
124 if ( err != MAILIMAP_NO_ERROR ) { 140 if ( err != MAILIMAP_NO_ERROR ) {
125 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
126 return; 141 return;
127 } 142 }
128 143
129 int last = m_imap->imap_selection_info->sel_exists; 144 int last = m_imap->imap_selection_info->sel_exists;
130 145
131 if (last == 0) { 146 if (last == 0) {
132 Global::statusMessage(tr("Mailbox has no mails")); 147 Global::statusMessage(tr("Mailbox has no mails"));
133 return; 148 return;
134 } else { 149 } else {
135 Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); 150 Global::statusMessage(tr("Mailbox has %1 mails").arg(last));
136 } 151 }
137 152
138 /* the range has to start at 1!!! not with 0!!!! */ 153 /* the range has to start at 1!!! not with 0!!!! */
139 set = mailimap_set_new_interval( 1, last ); 154 set = mailimap_set_new_interval( 1, last );
140 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 155 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
141 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 156 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
142 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 157 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
143 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 158 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
144 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 159 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
145 160
146 err = mailimap_fetch( m_imap, set, fetchType, &result ); 161 err = mailimap_fetch( m_imap, set, fetchType, &result );
147 mailimap_set_free( set ); 162 mailimap_set_free( set );
148 mailimap_fetch_type_free( fetchType ); 163 mailimap_fetch_type_free( fetchType );
149 164
150 QString date,subject,from; 165 QString date,subject,from;
151 166
152 if ( err == MAILIMAP_NO_ERROR ) { 167 if ( err == MAILIMAP_NO_ERROR ) {
153 mailimap_msg_att * msg_att; 168 mailimap_msg_att * msg_att;
154 int i = 0; 169 int i = 0;
155 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 170 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
156 ++i; 171 ++i;
157 msg_att = (mailimap_msg_att*)current->data; 172 msg_att = (mailimap_msg_att*)current->data;
158 RecMail*m = parse_list_result(msg_att); 173 RecMail*m = parse_list_result(msg_att);
159 if (m) { 174 if (m) {
160 m->setNumber(i); 175 m->setNumber(i);
161 m->setMbox(mailbox); 176 m->setMbox(mailbox);
162 m->setWrapper(this); 177 m->setWrapper(this);
163 target.append(m); 178 target.append(m);
164 } 179 }
165 } 180 }
166 } else { 181 } else {
167 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 182 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
168 } 183 }
169 if (result) mailimap_fetch_list_free(result); 184 if (result) mailimap_fetch_list_free(result);
170} 185}
171 186
172QList<Folder>* IMAPwrapper::listFolders() 187QList<Folder>* IMAPwrapper::listFolders()
173{ 188{
174 const char *path, *mask; 189 const char *path, *mask;
175 int err = MAILIMAP_NO_ERROR; 190 int err = MAILIMAP_NO_ERROR;
176 clist *result = 0; 191 clist *result = 0;
177 clistcell *current = 0; 192 clistcell *current = 0;
178 clistcell*cur_flag = 0; 193 clistcell*cur_flag = 0;
179 mailimap_mbx_list_flags*bflags = 0; 194 mailimap_mbx_list_flags*bflags = 0;
180 195
181 QList<Folder> * folders = new QList<Folder>(); 196 QList<Folder> * folders = new QList<Folder>();
182 folders->setAutoDelete( false ); 197 folders->setAutoDelete( false );
183 login(); 198 login();
184 if (!m_imap) { 199 if (!m_imap) {
185 return folders; 200 return folders;
186 } 201 }
187 202
188/* 203/*
189 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 204 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
190 * We must not forget to filter them out in next loop! 205 * We must not forget to filter them out in next loop!
191 * it seems like ugly code. and yes - it is ugly code. but the best way. 206 * it seems like ugly code. and yes - it is ugly code. but the best way.
192 */ 207 */
193 QString temp; 208 QString temp;
194 mask = "INBOX" ; 209 mask = "INBOX" ;
195 mailimap_mailbox_list *list; 210 mailimap_mailbox_list *list;
196 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 211 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
197 QString del; 212 QString del;
198 bool selectable = true; 213 bool selectable = true;
199 bool no_inferiors = false; 214 bool no_inferiors = false;
200 if ( err == MAILIMAP_NO_ERROR ) { 215 if ( err == MAILIMAP_NO_ERROR ) {
201 current = result->first; 216 current = result->first;
202 for ( int i = result->count; i > 0; i-- ) { 217 for ( int i = result->count; i > 0; i-- ) {
203 list = (mailimap_mailbox_list *) current->data; 218 list = (mailimap_mailbox_list *) current->data;
204 // it is better use the deep copy mechanism of qt itself 219 // it is better use the deep copy mechanism of qt itself
205 // instead of using strdup! 220 // instead of using strdup!
206 temp = list->mb_name; 221 temp = list->mb_name;
207 del = list->mb_delimiter; 222 del = list->mb_delimiter;
208 current = current->next; 223 current = current->next;
209 if ( (bflags = list->mb_flag) ) { 224 if ( (bflags = list->mb_flag) ) {
210 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 225 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
211 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 226 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
212 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 227 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
213 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 228 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
214 no_inferiors = true; 229 no_inferiors = true;
215 } 230 }
216 } 231 }
217 } 232 }
218 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 233 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
219 } 234 }
220 } else { 235 } else {
221 qDebug("error fetching folders: %s",m_imap->imap_response); 236 qDebug("error fetching folders: %s",m_imap->imap_response);
222 } 237 }
223 mailimap_list_result_free( result ); 238 mailimap_list_result_free( result );
224 239
225/* 240/*
226 * second stage - get the other then inbox folders 241 * second stage - get the other then inbox folders
227 */ 242 */
228 mask = "*" ; 243 mask = "*" ;
229 path = account->getPrefix().latin1(); 244 path = account->getPrefix().latin1();
230 if (!path) path = ""; 245 if (!path) path = "";
231 qDebug(path); 246 qDebug(path);
232 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 247 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
233 if ( err == MAILIMAP_NO_ERROR ) { 248 if ( err == MAILIMAP_NO_ERROR ) {
234 current = result->first; 249 current = result->first;
235 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 250 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
236 no_inferiors = false; 251 no_inferiors = false;
237 list = (mailimap_mailbox_list *) current->data; 252 list = (mailimap_mailbox_list *) current->data;
238 // it is better use the deep copy mechanism of qt itself 253 // it is better use the deep copy mechanism of qt itself
239 // instead of using strdup! 254 // instead of using strdup!
240 temp = list->mb_name; 255 temp = list->mb_name;
241 if (temp.lower()=="inbox") 256 if (temp.lower()=="inbox")
242 continue; 257 continue;
243 if (temp.lower()==account->getPrefix().lower()) 258 if (temp.lower()==account->getPrefix().lower())
244 continue; 259 continue;
245 if ( (bflags = list->mb_flag) ) { 260 if ( (bflags = list->mb_flag) ) {
246 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 261 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
247 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 262 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
248 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 263 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
249 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 264 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
250 no_inferiors = true; 265 no_inferiors = true;
251 } 266 }
252 } 267 }
253 } 268 }
254 del = list->mb_delimiter; 269 del = list->mb_delimiter;
255 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 270 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
256 } 271 }
257 } else { 272 } else {
258 qDebug("error fetching folders %s",m_imap->imap_response); 273 qDebug("error fetching folders %s",m_imap->imap_response);
259 } 274 }
260 if (result) mailimap_list_result_free( result ); 275 if (result) mailimap_list_result_free( result );
261 return folders; 276 return folders;
262} 277}
263 278
264RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 279RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
265{ 280{
266 RecMail * m = 0; 281 RecMail * m = 0;
267 mailimap_msg_att_item *item=0; 282 mailimap_msg_att_item *item=0;
268 clistcell *current,*c,*cf; 283 clistcell *current,*c,*cf;
269 mailimap_msg_att_dynamic*flist; 284 mailimap_msg_att_dynamic*flist;
270 mailimap_flag_fetch*cflag; 285 mailimap_flag_fetch*cflag;
271 int size; 286 int size;
272 QBitArray mFlags(7); 287 QBitArray mFlags(7);
273 QStringList addresslist; 288 QStringList addresslist;
274 289
275 if (!m_att) { 290 if (!m_att) {
276 return m; 291 return m;
277 } 292 }
278 m = new RecMail(); 293 m = new RecMail();
279 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 294 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
280 current = c; 295 current = c;
281 size = 0; 296 size = 0;
282 item = (mailimap_msg_att_item*)current->data; 297 item = (mailimap_msg_att_item*)current->data;
283 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 298 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
284 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 299 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
285 if (!flist->att_list) { 300 if (!flist->att_list) {
286 continue; 301 continue;
287 } 302 }
288 cf = flist->att_list->first; 303 cf = flist->att_list->first;
289 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 304 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
290 cflag = (mailimap_flag_fetch*)cf->data; 305 cflag = (mailimap_flag_fetch*)cf->data;
291 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 306 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
292 switch (cflag->fl_flag->fl_type) { 307 switch (cflag->fl_flag->fl_type) {
293 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 308 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
294 mFlags.setBit(FLAG_ANSWERED); 309 mFlags.setBit(FLAG_ANSWERED);
295 break; 310 break;
296 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 311 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
297 mFlags.setBit(FLAG_FLAGGED); 312 mFlags.setBit(FLAG_FLAGGED);
298 break; 313 break;
299 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 314 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
300 mFlags.setBit(FLAG_DELETED); 315 mFlags.setBit(FLAG_DELETED);
301 break; 316 break;
302 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 317 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
303 mFlags.setBit(FLAG_SEEN); 318 mFlags.setBit(FLAG_SEEN);
304 break; 319 break;
305 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 320 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
306 mFlags.setBit(FLAG_DRAFT); 321 mFlags.setBit(FLAG_DRAFT);
307 break; 322 break;
308 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 323 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
309 break; 324 break;
310 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 325 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
311 break; 326 break;
312 default: 327 default:
313 break; 328 break;
314 } 329 }
315 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 330 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
316 mFlags.setBit(FLAG_RECENT); 331 mFlags.setBit(FLAG_RECENT);
317 } 332 }
318 } 333 }
319 continue; 334 continue;
320 } 335 }
321 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 336 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
322 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 337 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
323 m->setDate(head->env_date); 338 m->setDate(head->env_date);
324 m->setSubject(convert_String((const char*)head->env_subject)); 339 m->setSubject(convert_String((const char*)head->env_subject));
325 //m->setSubject(head->env_subject); 340 //m->setSubject(head->env_subject);
326 if (head->env_from!=NULL) { 341 if (head->env_from!=NULL) {
327 addresslist = address_list_to_stringlist(head->env_from->frm_list); 342 addresslist = address_list_to_stringlist(head->env_from->frm_list);
328 if (addresslist.count()) { 343 if (addresslist.count()) {
329 m->setFrom(addresslist.first()); 344 m->setFrom(addresslist.first());
330 } 345 }
331 } 346 }
332 if (head->env_to!=NULL) { 347 if (head->env_to!=NULL) {
333 addresslist = address_list_to_stringlist(head->env_to->to_list); 348 addresslist = address_list_to_stringlist(head->env_to->to_list);
334 m->setTo(addresslist); 349 m->setTo(addresslist);
335 } 350 }
336 if (head->env_cc!=NULL) { 351 if (head->env_cc!=NULL) {
337 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 352 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
338 m->setCC(addresslist); 353 m->setCC(addresslist);
339 } 354 }
340 if (head->env_bcc!=NULL) { 355 if (head->env_bcc!=NULL) {
341 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 356 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
342 m->setBcc(addresslist); 357 m->setBcc(addresslist);
343 } 358 }
344 if (head->env_reply_to!=NULL) { 359 if (head->env_reply_to!=NULL) {
345 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 360 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
346 if (addresslist.count()) { 361 if (addresslist.count()) {
347 m->setReplyto(addresslist.first()); 362 m->setReplyto(addresslist.first());
348 } 363 }
349 } 364 }
350 m->setMsgid(QString(head->env_message_id)); 365 m->setMsgid(QString(head->env_message_id));
351 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 366 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
352#if 0 367#if 0
353 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 368 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
354 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 369 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
355 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); 370 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);
356 qDebug(da.toString()); 371 qDebug(da.toString());
357#endif 372#endif
358 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 373 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
359 size = item->att_data.att_static->att_data.att_rfc822_size; 374 size = item->att_data.att_static->att_data.att_rfc822_size;
360 } 375 }
361 } 376 }
362 /* msg is already deleted */ 377 /* msg is already deleted */
363 if (mFlags.testBit(FLAG_DELETED) && m) { 378 if (mFlags.testBit(FLAG_DELETED) && m) {
364 delete m; 379 delete m;
365 m = 0; 380 m = 0;
366 } 381 }
367 if (m) { 382 if (m) {
368 m->setFlags(mFlags); 383 m->setFlags(mFlags);
369 m->setMsgsize(size); 384 m->setMsgsize(size);
370 } 385 }
371 return m; 386 return m;
372} 387}
373 388
374RecBody IMAPwrapper::fetchBody(const RecMail&mail) 389RecBody IMAPwrapper::fetchBody(const RecMail&mail)
375{ 390{
376 RecBody body; 391 RecBody body;
377 const char *mb; 392 const char *mb;
378 int err = MAILIMAP_NO_ERROR; 393 int err = MAILIMAP_NO_ERROR;
379 clist *result = 0; 394 clist *result = 0;
380 clistcell *current; 395 clistcell *current;
381 mailimap_fetch_att *fetchAtt = 0; 396 mailimap_fetch_att *fetchAtt = 0;
382 mailimap_fetch_type *fetchType = 0; 397 mailimap_fetch_type *fetchType = 0;
383 mailimap_set *set = 0; 398 mailimap_set *set = 0;
384 mailimap_body*body_desc = 0; 399 mailimap_body*body_desc = 0;
385 400
386 mb = mail.getMbox().latin1(); 401 mb = mail.getMbox().latin1();
387 402
388 login(); 403 login();
389 if (!m_imap) { 404 if (!m_imap) {
390 return body; 405 return body;
391 } 406 }
392 407 err = selectMbox(mail.getMbox());
393 err = mailimap_select( m_imap, (char*)mb);
394 if ( err != MAILIMAP_NO_ERROR ) { 408 if ( err != MAILIMAP_NO_ERROR ) {
395 qDebug("error selecting mailbox: %s",m_imap->imap_response);
396 return body; 409 return body;
397 } 410 }
398 411
399 /* the range has to start at 1!!! not with 0!!!! */ 412 /* the range has to start at 1!!! not with 0!!!! */
400 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 413 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
401 fetchAtt = mailimap_fetch_att_new_bodystructure(); 414 fetchAtt = mailimap_fetch_att_new_bodystructure();
402 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 415 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
403 err = mailimap_fetch( m_imap, set, fetchType, &result ); 416 err = mailimap_fetch( m_imap, set, fetchType, &result );
404 mailimap_set_free( set ); 417 mailimap_set_free( set );
405 mailimap_fetch_type_free( fetchType ); 418 mailimap_fetch_type_free( fetchType );
406 419
407 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 420 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
408 mailimap_msg_att * msg_att; 421 mailimap_msg_att * msg_att;
409 msg_att = (mailimap_msg_att*)current->data; 422 msg_att = (mailimap_msg_att*)current->data;
410 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 423 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
411 QValueList<int> path; 424 QValueList<int> path;
412 body_desc = item->att_data.att_static->att_data.att_body; 425 body_desc = item->att_data.att_static->att_data.att_body;
413 traverseBody(mail,body_desc,body,0,path); 426 traverseBody(mail,body_desc,body,0,path);
414 } else { 427 } else {
415 qDebug("error fetching body: %s",m_imap->imap_response); 428 qDebug("error fetching body: %s",m_imap->imap_response);
416 } 429 }
417 if (result) mailimap_fetch_list_free(result); 430 if (result) mailimap_fetch_list_free(result);
418 return body; 431 return body;
419} 432}
420 433
421QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 434QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
422{ 435{
423 QStringList l; 436 QStringList l;
424 QString from; 437 QString from;
425 bool named_from; 438 bool named_from;
426 clistcell *current = NULL; 439 clistcell *current = NULL;
427 mailimap_address * current_address=NULL; 440 mailimap_address * current_address=NULL;
428 if (!list) { 441 if (!list) {
429 return l; 442 return l;
430 } 443 }
431 unsigned int count = 0; 444 unsigned int count = 0;
432 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 445 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
433 from = ""; 446 from = "";
434 named_from = false; 447 named_from = false;
435 current_address=(mailimap_address*)current->data; 448 current_address=(mailimap_address*)current->data;
436 if (current_address->ad_personal_name){ 449 if (current_address->ad_personal_name){
437 from+=convert_String((const char*)current_address->ad_personal_name); 450 from+=convert_String((const char*)current_address->ad_personal_name);
438 from+=" "; 451 from+=" ";
439 named_from = true; 452 named_from = true;
440 } 453 }
441 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 454 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
442 from+="<"; 455 from+="<";
443 } 456 }
444 if (current_address->ad_mailbox_name) { 457 if (current_address->ad_mailbox_name) {
445 from+=QString(current_address->ad_mailbox_name); 458 from+=QString(current_address->ad_mailbox_name);
446 from+="@"; 459 from+="@";
447 } 460 }
448 if (current_address->ad_host_name) { 461 if (current_address->ad_host_name) {
449 from+=QString(current_address->ad_host_name); 462 from+=QString(current_address->ad_host_name);
450 } 463 }
451 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 464 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
452 from+=">"; 465 from+=">";
453 } 466 }
454 l.append(QString(from)); 467 l.append(QString(from));
455 if (++count > 99) { 468 if (++count > 99) {
456 break; 469 break;
457 } 470 }
458 } 471 }
459 return l; 472 return l;
460} 473}
461 474
462encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 475encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
463{ 476{
464 encodedString*res=new encodedString; 477 encodedString*res=new encodedString;
465 const char*mb;
466 int err; 478 int err;
467 mailimap_fetch_type *fetchType; 479 mailimap_fetch_type *fetchType;
468 mailimap_set *set; 480 mailimap_set *set;
469 clistcell*current,*cur; 481 clistcell*current,*cur;
470 mailimap_section_part * section_part = 0; 482 mailimap_section_part * section_part = 0;
471 mailimap_section_spec * section_spec = 0; 483 mailimap_section_spec * section_spec = 0;
472 mailimap_section * section = 0; 484 mailimap_section * section = 0;
473 mailimap_fetch_att * fetch_att = 0; 485 mailimap_fetch_att * fetch_att = 0;
474 486
475 login(); 487 login();
476 if (!m_imap) { 488 if (!m_imap) {
477 return res; 489 return res;
478 } 490 }
479 if (!internal_call) { 491 if (!internal_call) {
480 mb = mail.getMbox().latin1(); 492 err = selectMbox(mail.getMbox());
481 err = mailimap_select( m_imap, (char*)mb);
482 if ( err != MAILIMAP_NO_ERROR ) { 493 if ( err != MAILIMAP_NO_ERROR ) {
483 qDebug("error selecting mailbox: %s",m_imap->imap_response);
484 return res; 494 return res;
485 } 495 }
486 } 496 }
487 set = mailimap_set_new_single(mail.getNumber()); 497 set = mailimap_set_new_single(mail.getNumber());
488 498
489 clist*id_list = 0; 499 clist*id_list = 0;
490 500
491 /* if path == empty then its a request for the whole rfc822 mail and generates 501 /* if path == empty then its a request for the whole rfc822 mail and generates
492 a "fetch <id> (body[])" statement on imap server */ 502 a "fetch <id> (body[])" statement on imap server */
493 if (path.count()>0 ) { 503 if (path.count()>0 ) {
494 id_list = clist_new(); 504 id_list = clist_new();
495 for (unsigned j=0; j < path.count();++j) { 505 for (unsigned j=0; j < path.count();++j) {
496 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 506 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
497 *p_id = path[j]; 507 *p_id = path[j];
498 clist_append(id_list,p_id); 508 clist_append(id_list,p_id);
499 } 509 }
500 section_part = mailimap_section_part_new(id_list); 510 section_part = mailimap_section_part_new(id_list);
501 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 511 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
502 } 512 }
503 513
504 section = mailimap_section_new(section_spec); 514 section = mailimap_section_new(section_spec);
505 fetch_att = mailimap_fetch_att_new_body_section(section); 515 fetch_att = mailimap_fetch_att_new_body_section(section);
506 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 516 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
507 517
508 clist*result = 0; 518 clist*result = 0;
509 519
510 err = mailimap_fetch( m_imap, set, fetchType, &result ); 520 err = mailimap_fetch( m_imap, set, fetchType, &result );
511 mailimap_set_free( set ); 521 mailimap_set_free( set );
512 mailimap_fetch_type_free( fetchType ); 522 mailimap_fetch_type_free( fetchType );
513 523
514 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 524 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
515 mailimap_msg_att * msg_att; 525 mailimap_msg_att * msg_att;
516 msg_att = (mailimap_msg_att*)current->data; 526 msg_att = (mailimap_msg_att*)current->data;
517 mailimap_msg_att_item*msg_att_item; 527 mailimap_msg_att_item*msg_att_item;
518 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 528 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
519 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 529 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
520 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 530 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
521 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 531 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
522 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 532 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
523 /* detach - we take over the content */ 533 /* detach - we take over the content */
524 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 534 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
525 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 535 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
526 } 536 }
527 } 537 }
528 } 538 }
529 } else { 539 } else {
530 qDebug("error fetching text: %s",m_imap->imap_response); 540 qDebug("error fetching text: %s",m_imap->imap_response);
531 } 541 }
532 if (result) mailimap_fetch_list_free(result); 542 if (result) mailimap_fetch_list_free(result);
533 return res; 543 return res;
534} 544}
535 545
536/* current_recursion is for recursive calls. 546/* current_recursion is for recursive calls.
537 current_count means the position inside the internal loop! */ 547 current_count means the position inside the internal loop! */
538void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 548void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
539 int current_recursion,QValueList<int>recList,int current_count) 549 int current_recursion,QValueList<int>recList,int current_count)
540{ 550{
541 if (!body || current_recursion>=10) { 551 if (!body || current_recursion>=10) {
542 return; 552 return;
543 } 553 }
544 switch (body->bd_type) { 554 switch (body->bd_type) {
545 case MAILIMAP_BODY_1PART: 555 case MAILIMAP_BODY_1PART:
546 { 556 {
547 QValueList<int>countlist = recList; 557 QValueList<int>countlist = recList;
548 countlist.append(current_count); 558 countlist.append(current_count);
549 RecPart currentPart; 559 RecPart currentPart;
550 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 560 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
551 QString id(""); 561 QString id("");
552 currentPart.setPositionlist(countlist); 562 currentPart.setPositionlist(countlist);
553 for (unsigned int j = 0; j < countlist.count();++j) { 563 for (unsigned int j = 0; j < countlist.count();++j) {
554 id+=(j>0?" ":""); 564 id+=(j>0?" ":"");
555 id+=QString("%1").arg(countlist[j]); 565 id+=QString("%1").arg(countlist[j]);
556 } 566 }
557 qDebug("ID = %s",id.latin1()); 567 qDebug("ID = %s",id.latin1());
558 currentPart.setIdentifier(id); 568 currentPart.setIdentifier(id);
559 fillSinglePart(currentPart,part1); 569 fillSinglePart(currentPart,part1);
560 /* important: Check for is NULL 'cause a body can be empty! 570 /* important: Check for is NULL 'cause a body can be empty!
561 And we put it only into the mail if it is the FIRST part */ 571 And we put it only into the mail if it is the FIRST part */
562 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 572 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
563 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 573 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
564 target_body.setDescription(currentPart); 574 target_body.setDescription(currentPart);
565 target_body.setBodytext(body_text); 575 target_body.setBodytext(body_text);
566 if (countlist.count()>1) { 576 if (countlist.count()>1) {
567 target_body.addPart(currentPart); 577 target_body.addPart(currentPart);
568 } 578 }
569 } else { 579 } else {
570 target_body.addPart(currentPart); 580 target_body.addPart(currentPart);
571 } 581 }
572 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 582 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
573 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 583 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
574 } 584 }
575 } 585 }
576 break; 586 break;
577 case MAILIMAP_BODY_MPART: 587 case MAILIMAP_BODY_MPART:
578 { 588 {
579 QValueList<int>countlist = recList; 589 QValueList<int>countlist = recList;
580 clistcell*current=0; 590 clistcell*current=0;
581 mailimap_body*current_body=0; 591 mailimap_body*current_body=0;
582 unsigned int ccount = 1; 592 unsigned int ccount = 1;
583 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 593 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
584 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 594 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
585 current_body = (mailimap_body*)current->data; 595 current_body = (mailimap_body*)current->data;
586 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 596 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
587 RecPart targetPart; 597 RecPart targetPart;
588 targetPart.setType("multipart"); 598 targetPart.setType("multipart");
589 fillMultiPart(targetPart,mailDescription); 599 fillMultiPart(targetPart,mailDescription);
590 countlist.append(current_count); 600 countlist.append(current_count);
591 targetPart.setPositionlist(countlist); 601 targetPart.setPositionlist(countlist);
592 target_body.addPart(targetPart); 602 target_body.addPart(targetPart);
593 QString id(""); 603 QString id("");
594 for (unsigned int j = 0; j < countlist.count();++j) { 604 for (unsigned int j = 0; j < countlist.count();++j) {
595 id+=(j>0?" ":""); 605 id+=(j>0?" ":"");
596 id+=QString("%1").arg(countlist[j]); 606 id+=QString("%1").arg(countlist[j]);
597 } 607 }
598 qDebug("ID(mpart) = %s",id.latin1()); 608 qDebug("ID(mpart) = %s",id.latin1());
599 } 609 }
600 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 610 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
601 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 611 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
602 countlist = recList; 612 countlist = recList;
603 } 613 }
604 ++ccount; 614 ++ccount;
605 } 615 }
606 } 616 }
607 break; 617 break;
608 default: 618 default:
609 break; 619 break;
610 } 620 }
611} 621}
612 622
613void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 623void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
614{ 624{
615 if (!Description) { 625 if (!Description) {
616 return; 626 return;
617 } 627 }
618 switch (Description->bd_type) { 628 switch (Description->bd_type) {
619 case MAILIMAP_BODY_TYPE_1PART_TEXT: 629 case MAILIMAP_BODY_TYPE_1PART_TEXT:
620 target_part.setType("text"); 630 target_part.setType("text");
621 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 631 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
622 break; 632 break;
623 case MAILIMAP_BODY_TYPE_1PART_BASIC: 633 case MAILIMAP_BODY_TYPE_1PART_BASIC:
624 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 634 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
625 break; 635 break;
626 case MAILIMAP_BODY_TYPE_1PART_MSG: 636 case MAILIMAP_BODY_TYPE_1PART_MSG:
627 target_part.setType("message"); 637 target_part.setType("message");
628 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 638 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
629 break; 639 break;
630 default: 640 default:
631 break; 641 break;
632 } 642 }
633} 643}
634 644
635void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 645void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
636{ 646{
637 if (!which) { 647 if (!which) {
638 return; 648 return;
639 } 649 }
640 QString sub; 650 QString sub;
641 sub = which->bd_media_text; 651 sub = which->bd_media_text;
642 qDebug("Type= text/%s",which->bd_media_text); 652 qDebug("Type= text/%s",which->bd_media_text);
643 target_part.setSubtype(sub.lower()); 653 target_part.setSubtype(sub.lower());
644 target_part.setLines(which->bd_lines); 654 target_part.setLines(which->bd_lines);
645 fillBodyFields(target_part,which->bd_fields); 655 fillBodyFields(target_part,which->bd_fields);
646} 656}
647 657
648void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 658void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
649{ 659{
650 if (!which) { 660 if (!which) {
651 return; 661 return;
652 } 662 }
653 target_part.setSubtype("rfc822"); 663 target_part.setSubtype("rfc822");
654 qDebug("Message part"); 664 qDebug("Message part");
655 /* we set this type to text/plain */ 665 /* we set this type to text/plain */
656 target_part.setLines(which->bd_lines); 666 target_part.setLines(which->bd_lines);
657 fillBodyFields(target_part,which->bd_fields); 667 fillBodyFields(target_part,which->bd_fields);
658} 668}
659 669
660void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 670void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
661{ 671{
662 if (!which) return; 672 if (!which) return;
663 QString sub = which->bd_media_subtype; 673 QString sub = which->bd_media_subtype;
664 target_part.setSubtype(sub.lower()); 674 target_part.setSubtype(sub.lower());
665 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 675 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
666 clistcell*cur = 0; 676 clistcell*cur = 0;
667 mailimap_single_body_fld_param*param=0; 677 mailimap_single_body_fld_param*param=0;
668 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 678 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
669 param = (mailimap_single_body_fld_param*)cur->data; 679 param = (mailimap_single_body_fld_param*)cur->data;
670 if (param) { 680 if (param) {
671 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 681 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
672 } 682 }
673 } 683 }
674 } 684 }
675} 685}
676 686
677void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 687void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
678{ 688{
679 if (!which) { 689 if (!which) {
680 return; 690 return;
681 } 691 }
682 QString type,sub; 692 QString type,sub;
683 switch (which->bd_media_basic->med_type) { 693 switch (which->bd_media_basic->med_type) {
684 case MAILIMAP_MEDIA_BASIC_APPLICATION: 694 case MAILIMAP_MEDIA_BASIC_APPLICATION:
685 type = "application"; 695 type = "application";
686 break; 696 break;
687 case MAILIMAP_MEDIA_BASIC_AUDIO: 697 case MAILIMAP_MEDIA_BASIC_AUDIO:
688 type = "audio"; 698 type = "audio";
689 break; 699 break;
690 case MAILIMAP_MEDIA_BASIC_IMAGE: 700 case MAILIMAP_MEDIA_BASIC_IMAGE:
691 type = "image"; 701 type = "image";
692 break; 702 break;
693 case MAILIMAP_MEDIA_BASIC_MESSAGE: 703 case MAILIMAP_MEDIA_BASIC_MESSAGE:
694 type = "message"; 704 type = "message";
695 break; 705 break;
696 case MAILIMAP_MEDIA_BASIC_VIDEO: 706 case MAILIMAP_MEDIA_BASIC_VIDEO:
697 type = "video"; 707 type = "video";
698 break; 708 break;
699 case MAILIMAP_MEDIA_BASIC_OTHER: 709 case MAILIMAP_MEDIA_BASIC_OTHER:
700 default: 710 default:
701 if (which->bd_media_basic->med_basic_type) { 711 if (which->bd_media_basic->med_basic_type) {
702 type = which->bd_media_basic->med_basic_type; 712 type = which->bd_media_basic->med_basic_type;
703 } else { 713 } else {
704 type = ""; 714 type = "";
705 } 715 }
706 break; 716 break;
707 } 717 }
708 if (which->bd_media_basic->med_subtype) { 718 if (which->bd_media_basic->med_subtype) {
709 sub = which->bd_media_basic->med_subtype; 719 sub = which->bd_media_basic->med_subtype;
710 } else { 720 } else {
711 sub = ""; 721 sub = "";
712 } 722 }
713 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 723 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
714 target_part.setType(type.lower()); 724 target_part.setType(type.lower());
715 target_part.setSubtype(sub.lower()); 725 target_part.setSubtype(sub.lower());
716 fillBodyFields(target_part,which->bd_fields); 726 fillBodyFields(target_part,which->bd_fields);
717} 727}
718 728
719void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 729void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
720{ 730{
721 if (!which) return; 731 if (!which) return;
722 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 732 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
723 clistcell*cur; 733 clistcell*cur;
724 mailimap_single_body_fld_param*param=0; 734 mailimap_single_body_fld_param*param=0;
725 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 735 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
726 param = (mailimap_single_body_fld_param*)cur->data; 736 param = (mailimap_single_body_fld_param*)cur->data;
727 if (param) { 737 if (param) {
728 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 738 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
729 } 739 }
730 } 740 }
731 } 741 }
732 mailimap_body_fld_enc*enc = which->bd_encoding; 742 mailimap_body_fld_enc*enc = which->bd_encoding;
733 QString encoding(""); 743 QString encoding("");
734 switch (enc->enc_type) { 744 switch (enc->enc_type) {
735 case MAILIMAP_BODY_FLD_ENC_7BIT: 745 case MAILIMAP_BODY_FLD_ENC_7BIT:
736 encoding = "7bit"; 746 encoding = "7bit";
737 break; 747 break;
738 case MAILIMAP_BODY_FLD_ENC_8BIT: 748 case MAILIMAP_BODY_FLD_ENC_8BIT:
739 encoding = "8bit"; 749 encoding = "8bit";
740 break; 750 break;
741 case MAILIMAP_BODY_FLD_ENC_BINARY: 751 case MAILIMAP_BODY_FLD_ENC_BINARY:
742 encoding="binary"; 752 encoding="binary";
743 break; 753 break;
744 case MAILIMAP_BODY_FLD_ENC_BASE64: 754 case MAILIMAP_BODY_FLD_ENC_BASE64:
745 encoding="base64"; 755 encoding="base64";
746 break; 756 break;
747 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 757 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
748 encoding="quoted-printable"; 758 encoding="quoted-printable";
749 break; 759 break;
750 case MAILIMAP_BODY_FLD_ENC_OTHER: 760 case MAILIMAP_BODY_FLD_ENC_OTHER:
751 default: 761 default:
752 if (enc->enc_value) { 762 if (enc->enc_value) {
753 char*t=enc->enc_value; 763 char*t=enc->enc_value;
754 encoding=QString(enc->enc_value); 764 encoding=QString(enc->enc_value);
755 enc->enc_value=0L; 765 enc->enc_value=0L;
756 free(t); 766 free(t);
757 } 767 }
758 } 768 }
759 if (which->bd_description) { 769 if (which->bd_description) {
760 target_part.setDescription(QString(which->bd_description)); 770 target_part.setDescription(QString(which->bd_description));
761 } 771 }
762 target_part.setEncoding(encoding); 772 target_part.setEncoding(encoding);
763 target_part.setSize(which->bd_size); 773 target_part.setSize(which->bd_size);
764} 774}
765 775
766void IMAPwrapper::deleteMail(const RecMail&mail) 776void IMAPwrapper::deleteMail(const RecMail&mail)
767{ 777{
768 mailimap_flag_list*flist; 778 mailimap_flag_list*flist;
769 mailimap_set *set; 779 mailimap_set *set;
770 mailimap_store_att_flags * store_flags; 780 mailimap_store_att_flags * store_flags;
771 int err; 781 int err;
772 login(); 782 login();
773 if (!m_imap) { 783 if (!m_imap) {
774 return; 784 return;
775 } 785 }
776 const char *mb = mail.getMbox().latin1(); 786 err = selectMbox(mail.getMbox());
777 err = mailimap_select( m_imap, (char*)mb);
778 if ( err != MAILIMAP_NO_ERROR ) { 787 if ( err != MAILIMAP_NO_ERROR ) {
779 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
780 return; 788 return;
781 } 789 }
782 flist = mailimap_flag_list_new_empty(); 790 flist = mailimap_flag_list_new_empty();
783 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 791 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
784 store_flags = mailimap_store_att_flags_new_set_flags(flist); 792 store_flags = mailimap_store_att_flags_new_set_flags(flist);
785 set = mailimap_set_new_single(mail.getNumber()); 793 set = mailimap_set_new_single(mail.getNumber());
786 err = mailimap_store(m_imap,set,store_flags); 794 err = mailimap_store(m_imap,set,store_flags);
787 mailimap_set_free( set ); 795 mailimap_set_free( set );
788 mailimap_store_att_flags_free(store_flags); 796 mailimap_store_att_flags_free(store_flags);
789 797
790 if (err != MAILIMAP_NO_ERROR) { 798 if (err != MAILIMAP_NO_ERROR) {
791 qDebug("error deleting mail: %s",m_imap->imap_response); 799 qDebug("error deleting mail: %s",m_imap->imap_response);
792 return; 800 return;
793 } 801 }
794 qDebug("deleting mail: %s",m_imap->imap_response); 802 qDebug("deleting mail: %s",m_imap->imap_response);
795 /* should we realy do that at this moment? */ 803 /* should we realy do that at this moment? */
796 err = mailimap_expunge(m_imap); 804 err = mailimap_expunge(m_imap);
797 if (err != MAILIMAP_NO_ERROR) { 805 if (err != MAILIMAP_NO_ERROR) {
798 qDebug("error deleting mail: %s",m_imap->imap_response); 806 qDebug("error deleting mail: %s",m_imap->imap_response);
799 } 807 }
800 qDebug("Delete successfull %s",m_imap->imap_response); 808 qDebug("Delete successfull %s",m_imap->imap_response);
801} 809}
802 810
803void IMAPwrapper::answeredMail(const RecMail&mail) 811void IMAPwrapper::answeredMail(const RecMail&mail)
804{ 812{
805 mailimap_flag_list*flist; 813 mailimap_flag_list*flist;
806 mailimap_set *set; 814 mailimap_set *set;
807 mailimap_store_att_flags * store_flags; 815 mailimap_store_att_flags * store_flags;
808 int err; 816 int err;
809 login(); 817 login();
810 if (!m_imap) { 818 if (!m_imap) {
811 return; 819 return;
812 } 820 }
813 const char *mb = mail.getMbox().latin1(); 821 err = selectMbox(mail.getMbox());
814 err = mailimap_select( m_imap, (char*)mb);
815 if ( err != MAILIMAP_NO_ERROR ) { 822 if ( err != MAILIMAP_NO_ERROR ) {
816 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
817 return; 823 return;
818 } 824 }
819 flist = mailimap_flag_list_new_empty(); 825 flist = mailimap_flag_list_new_empty();
820 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 826 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
821 store_flags = mailimap_store_att_flags_new_add_flags(flist); 827 store_flags = mailimap_store_att_flags_new_add_flags(flist);
822 set = mailimap_set_new_single(mail.getNumber()); 828 set = mailimap_set_new_single(mail.getNumber());
823 err = mailimap_store(m_imap,set,store_flags); 829 err = mailimap_store(m_imap,set,store_flags);
824 mailimap_set_free( set ); 830 mailimap_set_free( set );
825 mailimap_store_att_flags_free(store_flags); 831 mailimap_store_att_flags_free(store_flags);
826 832
827 if (err != MAILIMAP_NO_ERROR) { 833 if (err != MAILIMAP_NO_ERROR) {
828 qDebug("error marking mail: %s",m_imap->imap_response); 834 qDebug("error marking mail: %s",m_imap->imap_response);
829 return; 835 return;
830 } 836 }
831} 837}
832 838
833QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 839QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
834{ 840{
835 QString body(""); 841 QString body("");
836 encodedString*res = fetchRawPart(mail,path,internal_call); 842 encodedString*res = fetchRawPart(mail,path,internal_call);
837 encodedString*r = decode_String(res,enc); 843 encodedString*r = decode_String(res,enc);
838 delete res; 844 delete res;
839 if (r) { 845 if (r) {
840 if (r->Length()>0) { 846 if (r->Length()>0) {
841 body = r->Content(); 847 body = r->Content();
842 } 848 }
843 delete r; 849 delete r;
844 } 850 }
845 return body; 851 return body;
846} 852}
847 853
848QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 854QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
849{ 855{
850 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 856 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
851} 857}
852 858
853encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 859encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
854{ 860{
855 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 861 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
856 encodedString*r = decode_String(res,part.Encoding()); 862 encodedString*r = decode_String(res,part.Encoding());
857 delete res; 863 delete res;
858 return r; 864 return r;
859} 865}
860 866
861encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 867encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
862{ 868{
863 return fetchRawPart(mail,part.Positionlist(),false); 869 return fetchRawPart(mail,part.Positionlist(),false);
864} 870}
865 871
866int IMAPwrapper::deleteAllMail(const Folder*folder) 872int IMAPwrapper::deleteAllMail(const Folder*folder)
867{ 873{
868 login(); 874 login();
869 if (!m_imap) { 875 if (!m_imap) {
870 return 0; 876 return 0;
871 } 877 }
872 mailimap_flag_list*flist; 878 mailimap_flag_list*flist;
873 mailimap_set *set; 879 mailimap_set *set;
874 mailimap_store_att_flags * store_flags; 880 mailimap_store_att_flags * store_flags;
875 int err = mailimap_select( m_imap, folder->getName().latin1()); 881 int err = selectMbox(folder->getName());
876 if ( err != MAILIMAP_NO_ERROR ) { 882 if ( err != MAILIMAP_NO_ERROR ) {
877 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
878 return 0; 883 return 0;
879 } 884 }
885
880 int last = m_imap->imap_selection_info->sel_exists; 886 int last = m_imap->imap_selection_info->sel_exists;
881 if (last == 0) { 887 if (last == 0) {
882 Global::statusMessage(tr("Mailbox has no mails!")); 888 Global::statusMessage(tr("Mailbox has no mails!"));
883 return 0; 889 return 0;
884 } 890 }
885 flist = mailimap_flag_list_new_empty(); 891 flist = mailimap_flag_list_new_empty();
886 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 892 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
887 store_flags = mailimap_store_att_flags_new_set_flags(flist); 893 store_flags = mailimap_store_att_flags_new_set_flags(flist);
888 set = mailimap_set_new_interval( 1, last ); 894 set = mailimap_set_new_interval( 1, last );
889 err = mailimap_store(m_imap,set,store_flags); 895 err = mailimap_store(m_imap,set,store_flags);
890 mailimap_set_free( set ); 896 mailimap_set_free( set );
891 mailimap_store_att_flags_free(store_flags); 897 mailimap_store_att_flags_free(store_flags);
892 if (err != MAILIMAP_NO_ERROR) { 898 if (err != MAILIMAP_NO_ERROR) {
893 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 899 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
894 return 0; 900 return 0;
895 } 901 }
896 qDebug("deleting mail: %s",m_imap->imap_response); 902 qDebug("deleting mail: %s",m_imap->imap_response);
897 /* should we realy do that at this moment? */ 903 /* should we realy do that at this moment? */
898 err = mailimap_expunge(m_imap); 904 err = mailimap_expunge(m_imap);
899 if (err != MAILIMAP_NO_ERROR) { 905 if (err != MAILIMAP_NO_ERROR) {
900 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 906 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
901 return 0; 907 return 0;
902 } 908 }
903 qDebug("Delete successfull %s",m_imap->imap_response); 909 qDebug("Delete successfull %s",m_imap->imap_response);
904 return 1; 910 return 1;
905} 911}
906 912
907int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 913int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
908{ 914{
909 if (folder.length()==0) return 0; 915 if (folder.length()==0) return 0;
910 login(); 916 login();
911 if (!m_imap) {return 0;} 917 if (!m_imap) {return 0;}
912 QString pre = account->getPrefix(); 918 QString pre = account->getPrefix();
913 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 919 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
914 pre+=delemiter; 920 pre+=delemiter;
915 } 921 }
916 if (parentfolder) { 922 if (parentfolder) {
917 pre += parentfolder->getDisplayName()+delemiter; 923 pre += parentfolder->getDisplayName()+delemiter;
918 } 924 }
919 pre+=folder; 925 pre+=folder;
920 if (getsubfolder) { 926 if (getsubfolder) {
921 if (delemiter.length()>0) { 927 if (delemiter.length()>0) {
922 pre+=delemiter; 928 pre+=delemiter;
923 } else { 929 } else {
924 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 930 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
925 return 0; 931 return 0;
926 } 932 }
927 } 933 }
928 qDebug("Creating %s",pre.latin1()); 934 qDebug("Creating %s",pre.latin1());
929 int res = mailimap_create(m_imap,pre.latin1()); 935 int res = mailimap_create(m_imap,pre.latin1());
930 if (res != MAILIMAP_NO_ERROR) { 936 if (res != MAILIMAP_NO_ERROR) {
931 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 937 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
932 return 0; 938 return 0;
933 } 939 }
934 return 1; 940 return 1;
935} 941}
936 942
937int IMAPwrapper::deleteMbox(const Folder*folder) 943int IMAPwrapper::deleteMbox(const Folder*folder)
938{ 944{
939 if (!folder) return 0; 945 if (!folder) return 0;
940 login(); 946 login();
941 if (!m_imap) {return 0;} 947 if (!m_imap) {return 0;}
942 int res = mailimap_delete(m_imap,folder->getName()); 948 int res = mailimap_delete(m_imap,folder->getName());
943 if (res != MAILIMAP_NO_ERROR) { 949 if (res != MAILIMAP_NO_ERROR) {
944 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 950 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
945 return 0; 951 return 0;
946 } 952 }
947 return 1; 953 return 1;
948} 954}
949 955
950void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 956void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
951{ 957{
952 mailimap_status_att_list * att_list =0; 958 mailimap_status_att_list * att_list =0;
953 mailimap_mailbox_data_status * status=0; 959 mailimap_mailbox_data_status * status=0;
954 clistiter * cur = 0; 960 clistiter * cur = 0;
955 int r = 0; 961 int r = 0;
956 int res = 0; 962 int res = 0;
957 target_stat.message_count = 0; 963 target_stat.message_count = 0;
958 target_stat.message_unseen = 0; 964 target_stat.message_unseen = 0;
959 target_stat.message_recent = 0; 965 target_stat.message_recent = 0;
960 login(); 966 login();
961 if (!m_imap) { 967 if (!m_imap) {
962 return; 968 return;
963 } 969 }
964 att_list = mailimap_status_att_list_new_empty(); 970 att_list = mailimap_status_att_list_new_empty();
965 if (!att_list) return; 971 if (!att_list) return;
966 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 972 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
967 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 973 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
968 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 974 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
969 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 975 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
970 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 976 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
971 for (cur = clist_begin(status->st_info_list); 977 for (cur = clist_begin(status->st_info_list);
972 cur != NULL ; cur = clist_next(cur)) { 978 cur != NULL ; cur = clist_next(cur)) {
973 mailimap_status_info * status_info; 979 mailimap_status_info * status_info;
974 status_info = (mailimap_status_info *)clist_content(cur); 980 status_info = (mailimap_status_info *)clist_content(cur);
975 switch (status_info->st_att) { 981 switch (status_info->st_att) {
976 case MAILIMAP_STATUS_ATT_MESSAGES: 982 case MAILIMAP_STATUS_ATT_MESSAGES:
977 target_stat.message_count = status_info->st_value; 983 target_stat.message_count = status_info->st_value;
978 break; 984 break;
979 case MAILIMAP_STATUS_ATT_RECENT: 985 case MAILIMAP_STATUS_ATT_RECENT:
980 target_stat.message_recent = status_info->st_value; 986 target_stat.message_recent = status_info->st_value;
981 break; 987 break;
982 case MAILIMAP_STATUS_ATT_UNSEEN: 988 case MAILIMAP_STATUS_ATT_UNSEEN:
983 target_stat.message_unseen = status_info->st_value; 989 target_stat.message_unseen = status_info->st_value;
984 break; 990 break;
985 } 991 }
986 } 992 }
987 } else { 993 } else {
988 qDebug("Error retrieving status"); 994 qDebug("Error retrieving status");
989 } 995 }
990 if (status) mailimap_mailbox_data_status_free(status); 996 if (status) mailimap_mailbox_data_status_free(status);
991 if (att_list) mailimap_status_att_list_free(att_list); 997 if (att_list) mailimap_status_att_list_free(att_list);
992} 998}
993 999
994void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1000void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
995{ 1001{
996 login(); 1002 login();
997 if (!m_imap) return; 1003 if (!m_imap) return;
998 if (!msg) return; 1004 if (!msg) return;
999 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1005 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1000 if (r != MAILIMAP_NO_ERROR) { 1006 if (r != MAILIMAP_NO_ERROR) {
1001 Global::statusMessage("Error storing mail!"); 1007 Global::statusMessage("Error storing mail!");
1002 } 1008 }
1003} 1009}
1004 1010
1005const QString&IMAPwrapper::getType()const 1011const QString&IMAPwrapper::getType()const
1006{ 1012{
1007 return account->getType(); 1013 return account->getType();
1008} 1014}
1009 1015
1010const QString&IMAPwrapper::getName()const 1016const QString&IMAPwrapper::getName()const
1011{ 1017{
1012 qDebug("Get name: %s",account->getAccountName().latin1()); 1018 qDebug("Get name: %s",account->getAccountName().latin1());
1013 return account->getAccountName(); 1019 return account->getAccountName();
1014} 1020}
1015 1021
1016encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) 1022encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
1017{ 1023{
1018 // dummy 1024 // dummy
1019 QValueList<int> path; 1025 QValueList<int> path;
1020 return fetchRawPart(mail,path,false); 1026 return fetchRawPart(mail,path,false);
1021} 1027}
1022 1028
1023void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1029void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1024{ 1030{
1025 qDebug("mvcp mail imap");
1026 if (targetWrapper != this) { 1031 if (targetWrapper != this) {
1027 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 1032 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
1028 qDebug("Using generic"); 1033 qDebug("Using generic");
1029 return; 1034 return;
1030 } 1035 }
1031 qDebug("Using internal");
1032 mailimap_set *set = 0; 1036 mailimap_set *set = 0;
1033 1037 login();
1034 int err = mailimap_select( m_imap, fromFolder->getName().latin1()); 1038 if (!m_imap) {
1039 return;
1040 }
1041 int err = selectMbox(fromFolder->getName());
1035 if ( err != MAILIMAP_NO_ERROR ) { 1042 if ( err != MAILIMAP_NO_ERROR ) {
1036 Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response));
1037 return; 1043 return;
1038 } 1044 }
1039
1040 int last = m_imap->imap_selection_info->sel_exists; 1045 int last = m_imap->imap_selection_info->sel_exists;
1041 set = mailimap_set_new_interval( 1, last ); 1046 set = mailimap_set_new_interval( 1, last );
1042 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1047 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1048 mailimap_set_free( set );
1043 if ( err != MAILIMAP_NO_ERROR ) { 1049 if ( err != MAILIMAP_NO_ERROR ) {
1044 Global::statusMessage(tr("error copy mails: %1").arg(m_imap->imap_response)); 1050 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
1051 Global::statusMessage(error_msg);
1052 qDebug(error_msg);
1045 return; 1053 return;
1046 } 1054 }
1047 mailimap_set_free( set );
1048 if (moveit) { 1055 if (moveit) {
1049 deleteAllMail(fromFolder); 1056 deleteAllMail(fromFolder);
1050 } 1057 }
1051} 1058}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 07c6210..99986c2 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,74 +1,76 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder); 32 virtual int deleteAllMail(const Folder*folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 34 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
35 35
36 virtual RecBody fetchBody(const RecMail&mail); 36 virtual RecBody fetchBody(const RecMail&mail);
37 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 37 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
38 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 38 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
39 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 39 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
40 virtual encodedString* fetchRawBody(const RecMail&mail); 40 virtual encodedString* fetchRawBody(const RecMail&mail);
41 41
42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 42 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
43 virtual int deleteMbox(const Folder*folder); 43 virtual int deleteMbox(const Folder*folder);
44 44
45 static void imap_progress( size_t current, size_t maximum ); 45 static void imap_progress( size_t current, size_t maximum );
46 46
47 virtual void logout(); 47 virtual void logout();
48 virtual const QString&getType()const; 48 virtual const QString&getType()const;
49 virtual const QString&getName()const; 49 virtual const QString&getName()const;
50 50
51protected: 51protected:
52 RecMail*parse_list_result(mailimap_msg_att*); 52 RecMail*parse_list_result(mailimap_msg_att*);
53 void login(); 53 void login();
54 54
55 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 55 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
56 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 56 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
57 57 int selectMbox(const QString&mbox);
58
58 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 59 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
59 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 60 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
60 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 61 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
61 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 62 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
62 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 63 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
63 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 64 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
64 65
65 /* just helpers */ 66 /* just helpers */
66 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 67 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
67 static QStringList address_list_to_stringlist(clist*list); 68 static QStringList address_list_to_stringlist(clist*list);
68 69
69 70
70 IMAPaccount *account; 71 IMAPaccount *account;
71 mailimap *m_imap; 72 mailimap *m_imap;
73 QString m_Lastmbox;
72}; 74};
73 75
74#endif 76#endif