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