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