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