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