summaryrefslogtreecommitdiff
authorjgf <jgf>2003-12-18 16:02:47 (UTC)
committer jgf <jgf>2003-12-18 16:02:47 (UTC)
commit5b88f5d05b2f3f5d106b58b07bc7018f757cfc03 (patch) (unidiff)
tree27f8a7ccb9dd659ea8484cb12c0e3dc3c3c99252
parent5cb08b0c69ffc7216405b552e17ff0541578bda0 (diff)
downloadopie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.zip
opie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.tar.gz
opie-5b88f5d05b2f3f5d106b58b07bc7018f757cfc03.tar.bz2
ask for user/password if field is empty
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp20
-rw-r--r--noncore/net/mail/pop3wrapper.cpp20
4 files changed, 70 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 838300a..cce3d34 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -1,805 +1,820 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "logindialog.h"
6#include <libetpan/mailimap.h> 7#include <libetpan/mailimap.h>
7 8
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 10 : AbstractMail()
10{ 11{
11 account = a; 12 account = a;
12 m_imap = 0; 13 m_imap = 0;
13} 14}
14 15
15IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
16{ 17{
17 logout(); 18 logout();
18} 19}
19 20
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 22{
22 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
23} 24}
24 25
25void IMAPwrapper::login() 26void IMAPwrapper::login()
26{ 27{
27 const char *server, *user, *pass; 28 const char *server, *user, *pass;
28 uint16_t port; 29 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
30 31
31 /* we are connected this moment */ 32 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 34 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 35 mailstream_flush(m_imap->imap_stream);
35 return; 36 return;
36 } 37 }
37 server = account->getServer().latin1(); 38 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 39 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 40 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
40 pass = account->getPassword().latin1(); 41 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
42 login.show();
43 if ( QDialog::Accepted == login.exec() ) {
44 // ok
45 user = strdup( login.getUser().latin1() );
46 pass = strdup( login.getPassword().latin1() );
47 } else {
48 // cancel
49 qDebug( "IMAP: Login canceled" );
50 return;
51 }
52 } else {
53 user = account->getUser().latin1();
54 pass = account->getPassword().latin1();
55 }
41 56
42 m_imap = mailimap_new( 20, &imap_progress ); 57 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 58 /* connect */
44 if (account->getSSL()) { 59 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 60 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 61 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 62 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 63 }
49 64
50 if ( err != MAILIMAP_NO_ERROR && 65 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 66 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 67 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 68 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 69 mailimap_free( m_imap );
55 m_imap = 0; 70 m_imap = 0;
56 return; 71 return;
57 } 72 }
58 73
59 /* login */ 74 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 75 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 76 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 77 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 78 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 79 mailimap_free( m_imap );
65 m_imap = 0; 80 m_imap = 0;
66 } 81 }
67} 82}
68 83
69void IMAPwrapper::logout() 84void IMAPwrapper::logout()
70{ 85{
71 int err = MAILIMAP_NO_ERROR; 86 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 87 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 88 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 89 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 90 mailimap_free( m_imap );
76 m_imap = 0; 91 m_imap = 0;
77} 92}
78 93
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 94void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 95{
81 const char *mb; 96 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 97 int err = MAILIMAP_NO_ERROR;
83 clist *result; 98 clist *result;
84 clistcell *current; 99 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 100// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 101 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 102 mailimap_set *set;
88 103
89 mb = mailbox.latin1(); 104 mb = mailbox.latin1();
90 login(); 105 login();
91 if (!m_imap) { 106 if (!m_imap) {
92 return; 107 return;
93 } 108 }
94 /* select mailbox READONLY for operations */ 109 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 110 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 111 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 112 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 113 return;
99 } 114 }
100 115
101 int last = m_imap->imap_selection_info->sel_exists; 116 int last = m_imap->imap_selection_info->sel_exists;
102 117
103 if (last == 0) { 118 if (last == 0) {
104 qDebug("mailbox has no mails"); 119 qDebug("mailbox has no mails");
105 return; 120 return;
106 } 121 }
107 122
108 result = clist_new(); 123 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 131
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 133 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
120 135
121 QString date,subject,from; 136 QString date,subject,from;
122 137
123 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
124 139
125 mailimap_msg_att * msg_att; 140 mailimap_msg_att * msg_att;
126 int i = 0; 141 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 142 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 143 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 144 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 145 RecMail*m = parse_list_result(msg_att);
131 if (m) { 146 if (m) {
132 m->setNumber(i); 147 m->setNumber(i);
133 m->setMbox(mailbox); 148 m->setMbox(mailbox);
134 m->setWrapper(this); 149 m->setWrapper(this);
135 target.append(m); 150 target.append(m);
136 } 151 }
137 } 152 }
138 } else { 153 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 154 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 155 }
141 mailimap_fetch_list_free(result); 156 mailimap_fetch_list_free(result);
142} 157}
143 158
144QList<Folder>* IMAPwrapper::listFolders() 159QList<Folder>* IMAPwrapper::listFolders()
145{ 160{
146 const char *path, *mask; 161 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 162 int err = MAILIMAP_NO_ERROR;
148 clist *result; 163 clist *result;
149 clistcell *current; 164 clistcell *current;
150 165
151 QList<Folder> * folders = new QList<Folder>(); 166 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 167 folders->setAutoDelete( false );
153 login(); 168 login();
154 if (!m_imap) { 169 if (!m_imap) {
155 return folders; 170 return folders;
156 } 171 }
157 172
158/* 173/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 174 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 175 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 176 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 177 */
163 QString temp; 178 QString temp;
164 mask = "INBOX" ; 179 mask = "INBOX" ;
165 result = clist_new(); 180 result = clist_new();
166 mailimap_mailbox_list *list; 181 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 182 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 QString del; 183 QString del;
169 if ( err == MAILIMAP_NO_ERROR ) { 184 if ( err == MAILIMAP_NO_ERROR ) {
170 current = result->first; 185 current = result->first;
171 for ( int i = result->count; i > 0; i-- ) { 186 for ( int i = result->count; i > 0; i-- ) {
172 list = (mailimap_mailbox_list *) current->data; 187 list = (mailimap_mailbox_list *) current->data;
173 // it is better use the deep copy mechanism of qt itself 188 // it is better use the deep copy mechanism of qt itself
174 // instead of using strdup! 189 // instead of using strdup!
175 temp = list->mb_name; 190 temp = list->mb_name;
176 del = list->mb_delimiter; 191 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 192 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
178 current = current->next; 193 current = current->next;
179 } 194 }
180 } else { 195 } else {
181 qDebug("error fetching folders: %s",m_imap->imap_response); 196 qDebug("error fetching folders: %s",m_imap->imap_response);
182 } 197 }
183 mailimap_list_result_free( result ); 198 mailimap_list_result_free( result );
184 199
185/* 200/*
186 * second stage - get the other then inbox folders 201 * second stage - get the other then inbox folders
187 */ 202 */
188 mask = "*" ; 203 mask = "*" ;
189 path = account->getPrefix().latin1(); 204 path = account->getPrefix().latin1();
190 if (!path) path = ""; 205 if (!path) path = "";
191 result = clist_new(); 206 result = clist_new();
192 qDebug(path); 207 qDebug(path);
193 bool selectable = true; 208 bool selectable = true;
194 mailimap_mbx_list_flags*bflags; 209 mailimap_mbx_list_flags*bflags;
195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 210 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
196 if ( err == MAILIMAP_NO_ERROR ) { 211 if ( err == MAILIMAP_NO_ERROR ) {
197 current = result->first; 212 current = result->first;
198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 213 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
199 list = (mailimap_mailbox_list *) current->data; 214 list = (mailimap_mailbox_list *) current->data;
200 // it is better use the deep copy mechanism of qt itself 215 // it is better use the deep copy mechanism of qt itself
201 // instead of using strdup! 216 // instead of using strdup!
202 temp = list->mb_name; 217 temp = list->mb_name;
203 if (temp.lower()=="inbox") 218 if (temp.lower()=="inbox")
204 continue; 219 continue;
205 if (temp.lower()==account->getPrefix().lower()) 220 if (temp.lower()==account->getPrefix().lower())
206 continue; 221 continue;
207 if ( (bflags = list->mb_flag) ) { 222 if ( (bflags = list->mb_flag) ) {
208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 223 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 224 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
210 } 225 }
211 del = list->mb_delimiter; 226 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 227 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
213 } 228 }
214 } else { 229 } else {
215 qDebug("error fetching folders %s",m_imap->imap_response); 230 qDebug("error fetching folders %s",m_imap->imap_response);
216 } 231 }
217 mailimap_list_result_free( result ); 232 mailimap_list_result_free( result );
218 return folders; 233 return folders;
219} 234}
220 235
221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 236RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
222{ 237{
223 RecMail * m = 0; 238 RecMail * m = 0;
224 mailimap_msg_att_item *item=0; 239 mailimap_msg_att_item *item=0;
225 clistcell *current,*c,*cf; 240 clistcell *current,*c,*cf;
226 mailimap_msg_att_dynamic*flist; 241 mailimap_msg_att_dynamic*flist;
227 mailimap_flag_fetch*cflag; 242 mailimap_flag_fetch*cflag;
228 int size; 243 int size;
229 QBitArray mFlags(7); 244 QBitArray mFlags(7);
230 QStringList addresslist; 245 QStringList addresslist;
231 246
232 if (!m_att) { 247 if (!m_att) {
233 return m; 248 return m;
234 } 249 }
235 m = new RecMail(); 250 m = new RecMail();
236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 251 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
237 current = c; 252 current = c;
238 size = 0; 253 size = 0;
239 item = (mailimap_msg_att_item*)current->data; 254 item = (mailimap_msg_att_item*)current->data;
240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 255 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 256 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
242 if (!flist->att_list) { 257 if (!flist->att_list) {
243 continue; 258 continue;
244 } 259 }
245 cf = flist->att_list->first; 260 cf = flist->att_list->first;
246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 261 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
247 cflag = (mailimap_flag_fetch*)cf->data; 262 cflag = (mailimap_flag_fetch*)cf->data;
248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 263 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
249 switch (cflag->fl_flag->fl_type) { 264 switch (cflag->fl_flag->fl_type) {
250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 265 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
251 mFlags.setBit(FLAG_ANSWERED); 266 mFlags.setBit(FLAG_ANSWERED);
252 break; 267 break;
253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 268 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
254 mFlags.setBit(FLAG_FLAGGED); 269 mFlags.setBit(FLAG_FLAGGED);
255 break; 270 break;
256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 271 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
257 mFlags.setBit(FLAG_DELETED); 272 mFlags.setBit(FLAG_DELETED);
258 break; 273 break;
259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 274 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
260 mFlags.setBit(FLAG_SEEN); 275 mFlags.setBit(FLAG_SEEN);
261 break; 276 break;
262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 277 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
263 mFlags.setBit(FLAG_DRAFT); 278 mFlags.setBit(FLAG_DRAFT);
264 break; 279 break;
265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 280 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
266 break; 281 break;
267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 282 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
268 break; 283 break;
269 default: 284 default:
270 break; 285 break;
271 } 286 }
272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 287 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
273 mFlags.setBit(FLAG_RECENT); 288 mFlags.setBit(FLAG_RECENT);
274 } 289 }
275 } 290 }
276 continue; 291 continue;
277 } 292 }
278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 293 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 294 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
280 m->setDate(head->env_date); 295 m->setDate(head->env_date);
281 m->setSubject(convert_String((const char*)head->env_subject)); 296 m->setSubject(convert_String((const char*)head->env_subject));
282 //m->setSubject(head->env_subject); 297 //m->setSubject(head->env_subject);
283 if (head->env_from!=NULL) { 298 if (head->env_from!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_from->frm_list); 299 addresslist = address_list_to_stringlist(head->env_from->frm_list);
285 if (addresslist.count()) { 300 if (addresslist.count()) {
286 m->setFrom(addresslist.first()); 301 m->setFrom(addresslist.first());
287 } 302 }
288 } 303 }
289 if (head->env_to!=NULL) { 304 if (head->env_to!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_to->to_list); 305 addresslist = address_list_to_stringlist(head->env_to->to_list);
291 m->setTo(addresslist); 306 m->setTo(addresslist);
292 } 307 }
293 if (head->env_cc!=NULL) { 308 if (head->env_cc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 309 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
295 m->setCC(addresslist); 310 m->setCC(addresslist);
296 } 311 }
297 if (head->env_bcc!=NULL) { 312 if (head->env_bcc!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 313 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
299 m->setBcc(addresslist); 314 m->setBcc(addresslist);
300 } 315 }
301 if (head->env_reply_to!=NULL) { 316 if (head->env_reply_to!=NULL) {
302 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 317 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
303 if (addresslist.count()) { 318 if (addresslist.count()) {
304 m->setReplyto(addresslist.first()); 319 m->setReplyto(addresslist.first());
305 } 320 }
306 } 321 }
307 m->setMsgid(QString(head->env_message_id)); 322 m->setMsgid(QString(head->env_message_id));
308 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 323 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
309#if 0 324#if 0
310 325
311 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 326 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
312 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 327 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
313 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); 328 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);
314 qDebug(da.toString()); 329 qDebug(da.toString());
315#endif 330#endif
316 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 331 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
317 size = item->att_data.att_static->att_data.att_rfc822_size; 332 size = item->att_data.att_static->att_data.att_rfc822_size;
318 } 333 }
319 } 334 }
320 /* msg is already deleted */ 335 /* msg is already deleted */
321 if (mFlags.testBit(FLAG_DELETED) && m) { 336 if (mFlags.testBit(FLAG_DELETED) && m) {
322 delete m; 337 delete m;
323 m = 0; 338 m = 0;
324 } 339 }
325 if (m) { 340 if (m) {
326 m->setFlags(mFlags); 341 m->setFlags(mFlags);
327 m->setMsgsize(size); 342 m->setMsgsize(size);
328 } 343 }
329 return m; 344 return m;
330} 345}
331 346
332RecBody IMAPwrapper::fetchBody(const RecMail&mail) 347RecBody IMAPwrapper::fetchBody(const RecMail&mail)
333{ 348{
334 RecBody body; 349 RecBody body;
335 const char *mb; 350 const char *mb;
336 int err = MAILIMAP_NO_ERROR; 351 int err = MAILIMAP_NO_ERROR;
337 clist *result; 352 clist *result;
338 clistcell *current; 353 clistcell *current;
339 mailimap_fetch_att *fetchAtt; 354 mailimap_fetch_att *fetchAtt;
340 mailimap_fetch_type *fetchType; 355 mailimap_fetch_type *fetchType;
341 mailimap_set *set; 356 mailimap_set *set;
342 mailimap_body*body_desc; 357 mailimap_body*body_desc;
343 358
344 mb = mail.getMbox().latin1(); 359 mb = mail.getMbox().latin1();
345 360
346 login(); 361 login();
347 if (!m_imap) { 362 if (!m_imap) {
348 return body; 363 return body;
349 } 364 }
350 365
351 err = mailimap_select( m_imap, (char*)mb); 366 err = mailimap_select( m_imap, (char*)mb);
352 if ( err != MAILIMAP_NO_ERROR ) { 367 if ( err != MAILIMAP_NO_ERROR ) {
353 qDebug("error selecting mailbox: %s",m_imap->imap_response); 368 qDebug("error selecting mailbox: %s",m_imap->imap_response);
354 return body; 369 return body;
355 } 370 }
356 371
357 result = clist_new(); 372 result = clist_new();
358 /* the range has to start at 1!!! not with 0!!!! */ 373 /* the range has to start at 1!!! not with 0!!!! */
359 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
360 fetchAtt = mailimap_fetch_att_new_bodystructure(); 375 fetchAtt = mailimap_fetch_att_new_bodystructure();
361 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
362 err = mailimap_fetch( m_imap, set, fetchType, &result ); 377 err = mailimap_fetch( m_imap, set, fetchType, &result );
363 mailimap_set_free( set ); 378 mailimap_set_free( set );
364 mailimap_fetch_type_free( fetchType ); 379 mailimap_fetch_type_free( fetchType );
365 380
366 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
367 mailimap_msg_att * msg_att; 382 mailimap_msg_att * msg_att;
368 msg_att = (mailimap_msg_att*)current->data; 383 msg_att = (mailimap_msg_att*)current->data;
369 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
370 body_desc = item->att_data.att_static->att_data.att_body; 385 body_desc = item->att_data.att_static->att_data.att_body;
371 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
372 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
373 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
374 qDebug("Mulitpart mail"); 389 qDebug("Mulitpart mail");
375 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
376 } 391 }
377 } else { 392 } else {
378 qDebug("error fetching body: %s",m_imap->imap_response); 393 qDebug("error fetching body: %s",m_imap->imap_response);
379 } 394 }
380 mailimap_fetch_list_free(result); 395 mailimap_fetch_list_free(result);
381 return body; 396 return body;
382} 397}
383 398
384/* this routine is just called when the mail has only ONE part. 399/* this routine is just called when the mail has only ONE part.
385 for filling the parts of a multi-part-message there are other 400 for filling the parts of a multi-part-message there are other
386 routines 'cause we can not simply fetch the whole body. */ 401 routines 'cause we can not simply fetch the whole body. */
387void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
388{ 403{
389 if (!mailDescription) { 404 if (!mailDescription) {
390 return; 405 return;
391 } 406 }
392 QString sub,body_text; 407 QString sub,body_text;
393 RecPart singlePart; 408 RecPart singlePart;
394 QValueList<int> path; 409 QValueList<int> path;
395 fillSinglePart(singlePart,mailDescription); 410 fillSinglePart(singlePart,mailDescription);
396 switch (mailDescription->bd_type) { 411 switch (mailDescription->bd_type) {
397 case MAILIMAP_BODY_TYPE_1PART_MSG: 412 case MAILIMAP_BODY_TYPE_1PART_MSG:
398 path.append(1); 413 path.append(1);
399 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
400 target_body.setBodytext(body_text); 415 target_body.setBodytext(body_text);
401 target_body.setDescription(singlePart); 416 target_body.setDescription(singlePart);
402 break; 417 break;
403 case MAILIMAP_BODY_TYPE_1PART_TEXT: 418 case MAILIMAP_BODY_TYPE_1PART_TEXT:
404 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
405 path.append(1); 420 path.append(1);
406 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
407 target_body.setBodytext(body_text); 422 target_body.setBodytext(body_text);
408 target_body.setDescription(singlePart); 423 target_body.setDescription(singlePart);
409 break; 424 break;
410 case MAILIMAP_BODY_TYPE_1PART_BASIC: 425 case MAILIMAP_BODY_TYPE_1PART_BASIC:
411 qDebug("Single attachment"); 426 qDebug("Single attachment");
412 target_body.setBodytext(""); 427 target_body.setBodytext("");
413 target_body.addPart(singlePart); 428 target_body.addPart(singlePart);
414 break; 429 break;
415 default: 430 default:
416 break; 431 break;
417 } 432 }
418 433
419 return; 434 return;
420} 435}
421 436
422QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 437QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
423{ 438{
424 QStringList l; 439 QStringList l;
425 QString from; 440 QString from;
426 bool named_from; 441 bool named_from;
427 clistcell *current = NULL; 442 clistcell *current = NULL;
428 mailimap_address * current_address=NULL; 443 mailimap_address * current_address=NULL;
429 if (!list) { 444 if (!list) {
430 return l; 445 return l;
431 } 446 }
432 unsigned int count = 0; 447 unsigned int count = 0;
433 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
434 from = ""; 449 from = "";
435 named_from = false; 450 named_from = false;
436 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
437 if (current_address->ad_personal_name){ 452 if (current_address->ad_personal_name){
438 from+=convert_String((const char*)current_address->ad_personal_name); 453 from+=convert_String((const char*)current_address->ad_personal_name);
439 //from+=QString(current_address->ad_personal_name); 454 //from+=QString(current_address->ad_personal_name);
440 from+=" "; 455 from+=" ";
441 named_from = true; 456 named_from = true;
442 } 457 }
443 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
444 from+="<"; 459 from+="<";
445 } 460 }
446 if (current_address->ad_mailbox_name) { 461 if (current_address->ad_mailbox_name) {
447 from+=QString(current_address->ad_mailbox_name); 462 from+=QString(current_address->ad_mailbox_name);
448 from+="@"; 463 from+="@";
449 } 464 }
450 if (current_address->ad_host_name) { 465 if (current_address->ad_host_name) {
451 from+=QString(current_address->ad_host_name); 466 from+=QString(current_address->ad_host_name);
452 } 467 }
453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
454 from+=">"; 469 from+=">";
455 } 470 }
456 l.append(QString(from)); 471 l.append(QString(from));
457 if (++count > 99) { 472 if (++count > 99) {
458 break; 473 break;
459 } 474 }
460 } 475 }
461 return l; 476 return l;
462} 477}
463 478
464encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
465{ 480{
466 encodedString*res=new encodedString; 481 encodedString*res=new encodedString;
467 const char*mb; 482 const char*mb;
468 int err; 483 int err;
469 mailimap_fetch_type *fetchType; 484 mailimap_fetch_type *fetchType;
470 mailimap_set *set; 485 mailimap_set *set;
471 clistcell*current,*cur; 486 clistcell*current,*cur;
472 487
473 login(); 488 login();
474 if (!m_imap) { 489 if (!m_imap) {
475 return res; 490 return res;
476 } 491 }
477 if (!internal_call) { 492 if (!internal_call) {
478 mb = mail.getMbox().latin1(); 493 mb = mail.getMbox().latin1();
479 err = mailimap_select( m_imap, (char*)mb); 494 err = mailimap_select( m_imap, (char*)mb);
480 if ( err != MAILIMAP_NO_ERROR ) { 495 if ( err != MAILIMAP_NO_ERROR ) {
481 qDebug("error selecting mailbox: %s",m_imap->imap_response); 496 qDebug("error selecting mailbox: %s",m_imap->imap_response);
482 return res; 497 return res;
483 } 498 }
484 } 499 }
485 set = mailimap_set_new_single(mail.getNumber()); 500 set = mailimap_set_new_single(mail.getNumber());
486 clist*id_list=clist_new(); 501 clist*id_list=clist_new();
487 for (unsigned j=0; j < path.count();++j) { 502 for (unsigned j=0; j < path.count();++j) {
488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 503 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
489 *p_id = path[j]; 504 *p_id = path[j];
490 clist_append(id_list,p_id); 505 clist_append(id_list,p_id);
491 } 506 }
492 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 507 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 508 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
494 mailimap_section * section = mailimap_section_new(section_spec); 509 mailimap_section * section = mailimap_section_new(section_spec);
495 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 510 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
496 511
497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
498 513
499 clist*result = clist_new(); 514 clist*result = clist_new();
500 515
501 err = mailimap_fetch( m_imap, set, fetchType, &result ); 516 err = mailimap_fetch( m_imap, set, fetchType, &result );
502 mailimap_set_free( set ); 517 mailimap_set_free( set );
503 mailimap_fetch_type_free( fetchType ); 518 mailimap_fetch_type_free( fetchType );
504 519
505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 520 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
506 mailimap_msg_att * msg_att; 521 mailimap_msg_att * msg_att;
507 msg_att = (mailimap_msg_att*)current->data; 522 msg_att = (mailimap_msg_att*)current->data;
508 mailimap_msg_att_item*msg_att_item; 523 mailimap_msg_att_item*msg_att_item;
509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 524 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 525 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 526 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 527 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 528 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
514 /* detach - we take over the content */ 529 /* detach - we take over the content */
515 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 530 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
516 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 531 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
517 } 532 }
518 } 533 }
519 } 534 }
520 } else { 535 } else {
521 qDebug("error fetching text: %s",m_imap->imap_response); 536 qDebug("error fetching text: %s",m_imap->imap_response);
522 } 537 }
523 mailimap_fetch_list_free(result); 538 mailimap_fetch_list_free(result);
524 return res; 539 return res;
525} 540}
526 541
527void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 542void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
528{ 543{
529 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 544 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
530 if (!mailDescription||current_recursion==10) { 545 if (!mailDescription||current_recursion==10) {
531 return; 546 return;
532 } 547 }
533 clistcell*current; 548 clistcell*current;
534 mailimap_body*current_body; 549 mailimap_body*current_body;
535 unsigned int count = 0; 550 unsigned int count = 0;
536 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 551 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
537 /* the point in the message */ 552 /* the point in the message */
538 ++count; 553 ++count;
539 current_body = (mailimap_body*)current->data; 554 current_body = (mailimap_body*)current->data;
540 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 555 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
541 QValueList<int>clist = recList; 556 QValueList<int>clist = recList;
542 clist.append(count); 557 clist.append(count);
543 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 558 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
544 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 559 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
545 RecPart currentPart; 560 RecPart currentPart;
546 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 561 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
547 QValueList<int>clist = recList; 562 QValueList<int>clist = recList;
548 clist.append(count); 563 clist.append(count);
549 /* important: Check for is NULL 'cause a body can be empty! */ 564 /* important: Check for is NULL 'cause a body can be empty! */
550 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
551 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 566 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
552 target_body.setDescription(currentPart); 567 target_body.setDescription(currentPart);
553 target_body.setBodytext(body_text); 568 target_body.setBodytext(body_text);
554 } else { 569 } else {
555 QString id(""); 570 QString id("");
556 for (unsigned int j = 0; j < clist.count();++j) { 571 for (unsigned int j = 0; j < clist.count();++j) {
557 id+=(j>0?" ":""); 572 id+=(j>0?" ":"");
558 id+=QString("%1").arg(clist[j]); 573 id+=QString("%1").arg(clist[j]);
559 } 574 }
560 qDebug("ID= %s",id.latin1()); 575 qDebug("ID= %s",id.latin1());
561 currentPart.setIdentifier(id); 576 currentPart.setIdentifier(id);
562 currentPart.setPositionlist(clist); 577 currentPart.setPositionlist(clist);
563 target_body.addPart(currentPart); 578 target_body.addPart(currentPart);
564 } 579 }
565 } 580 }
566 } 581 }
567} 582}
568 583
569void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
570{ 585{
571 if (!Description) { 586 if (!Description) {
572 return; 587 return;
573 } 588 }
574 switch (Description->bd_type) { 589 switch (Description->bd_type) {
575 case MAILIMAP_BODY_TYPE_1PART_TEXT: 590 case MAILIMAP_BODY_TYPE_1PART_TEXT:
576 target_part.setType("text"); 591 target_part.setType("text");
577 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
578 break; 593 break;
579 case MAILIMAP_BODY_TYPE_1PART_BASIC: 594 case MAILIMAP_BODY_TYPE_1PART_BASIC:
580 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
581 break; 596 break;
582 case MAILIMAP_BODY_TYPE_1PART_MSG: 597 case MAILIMAP_BODY_TYPE_1PART_MSG:
583 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
584 break; 599 break;
585 default: 600 default:
586 break; 601 break;
587 } 602 }
588} 603}
589 604
590void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
591{ 606{
592 if (!which) { 607 if (!which) {
593 return; 608 return;
594 } 609 }
595 QString sub; 610 QString sub;
596 sub = which->bd_media_text; 611 sub = which->bd_media_text;
597 target_part.setSubtype(sub.lower()); 612 target_part.setSubtype(sub.lower());
598 target_part.setLines(which->bd_lines); 613 target_part.setLines(which->bd_lines);
599 fillBodyFields(target_part,which->bd_fields); 614 fillBodyFields(target_part,which->bd_fields);
600} 615}
601 616
602void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
603{ 618{
604 if (!which) { 619 if (!which) {
605 return; 620 return;
606 } 621 }
607// QString sub; 622// QString sub;
608// sub = which->bd_media_text; 623// sub = which->bd_media_text;
609// target_part.setSubtype(sub.lower()); 624// target_part.setSubtype(sub.lower());
610 qDebug("Message part"); 625 qDebug("Message part");
611 /* we set this type to text/plain */ 626 /* we set this type to text/plain */
612 target_part.setType("text"); 627 target_part.setType("text");
613 target_part.setSubtype("plain"); 628 target_part.setSubtype("plain");
614 target_part.setLines(which->bd_lines); 629 target_part.setLines(which->bd_lines);
615 fillBodyFields(target_part,which->bd_fields); 630 fillBodyFields(target_part,which->bd_fields);
616} 631}
617 632
618void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
619{ 634{
620 if (!which) { 635 if (!which) {
621 return; 636 return;
622 } 637 }
623 QString type,sub; 638 QString type,sub;
624 switch (which->bd_media_basic->med_type) { 639 switch (which->bd_media_basic->med_type) {
625 case MAILIMAP_MEDIA_BASIC_APPLICATION: 640 case MAILIMAP_MEDIA_BASIC_APPLICATION:
626 type = "application"; 641 type = "application";
627 break; 642 break;
628 case MAILIMAP_MEDIA_BASIC_AUDIO: 643 case MAILIMAP_MEDIA_BASIC_AUDIO:
629 type = "audio"; 644 type = "audio";
630 break; 645 break;
631 case MAILIMAP_MEDIA_BASIC_IMAGE: 646 case MAILIMAP_MEDIA_BASIC_IMAGE:
632 type = "image"; 647 type = "image";
633 break; 648 break;
634 case MAILIMAP_MEDIA_BASIC_MESSAGE: 649 case MAILIMAP_MEDIA_BASIC_MESSAGE:
635 type = "message"; 650 type = "message";
636 break; 651 break;
637 case MAILIMAP_MEDIA_BASIC_VIDEO: 652 case MAILIMAP_MEDIA_BASIC_VIDEO:
638 type = "video"; 653 type = "video";
639 break; 654 break;
640 case MAILIMAP_MEDIA_BASIC_OTHER: 655 case MAILIMAP_MEDIA_BASIC_OTHER:
641 default: 656 default:
642 if (which->bd_media_basic->med_basic_type) { 657 if (which->bd_media_basic->med_basic_type) {
643 type = which->bd_media_basic->med_basic_type; 658 type = which->bd_media_basic->med_basic_type;
644 } else { 659 } else {
645 type = ""; 660 type = "";
646 } 661 }
647 break; 662 break;
648 } 663 }
649 if (which->bd_media_basic->med_subtype) { 664 if (which->bd_media_basic->med_subtype) {
650 sub = which->bd_media_basic->med_subtype; 665 sub = which->bd_media_basic->med_subtype;
651 } else { 666 } else {
652 sub = ""; 667 sub = "";
653 } 668 }
654 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 669 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
655 target_part.setType(type.lower()); 670 target_part.setType(type.lower());
656 target_part.setSubtype(sub.lower()); 671 target_part.setSubtype(sub.lower());
657 fillBodyFields(target_part,which->bd_fields); 672 fillBodyFields(target_part,which->bd_fields);
658} 673}
659 674
660void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
661{ 676{
662 if (!which) return; 677 if (!which) return;
663 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
664 clistcell*cur; 679 clistcell*cur;
665 mailimap_single_body_fld_param*param=0; 680 mailimap_single_body_fld_param*param=0;
666 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
667 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
668 if (param) { 683 if (param) {
669 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
670 } 685 }
671 } 686 }
672 } 687 }
673 mailimap_body_fld_enc*enc = which->bd_encoding; 688 mailimap_body_fld_enc*enc = which->bd_encoding;
674 QString encoding(""); 689 QString encoding("");
675 switch (enc->enc_type) { 690 switch (enc->enc_type) {
676 case MAILIMAP_BODY_FLD_ENC_7BIT: 691 case MAILIMAP_BODY_FLD_ENC_7BIT:
677 encoding = "7bit"; 692 encoding = "7bit";
678 break; 693 break;
679 case MAILIMAP_BODY_FLD_ENC_8BIT: 694 case MAILIMAP_BODY_FLD_ENC_8BIT:
680 encoding = "8bit"; 695 encoding = "8bit";
681 break; 696 break;
682 case MAILIMAP_BODY_FLD_ENC_BINARY: 697 case MAILIMAP_BODY_FLD_ENC_BINARY:
683 encoding="binary"; 698 encoding="binary";
684 break; 699 break;
685 case MAILIMAP_BODY_FLD_ENC_BASE64: 700 case MAILIMAP_BODY_FLD_ENC_BASE64:
686 encoding="base64"; 701 encoding="base64";
687 break; 702 break;
688 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
689 encoding="quoted-printable"; 704 encoding="quoted-printable";
690 break; 705 break;
691 case MAILIMAP_BODY_FLD_ENC_OTHER: 706 case MAILIMAP_BODY_FLD_ENC_OTHER:
692 default: 707 default:
693 if (enc->enc_value) { 708 if (enc->enc_value) {
694 char*t=enc->enc_value; 709 char*t=enc->enc_value;
695 encoding=QString(enc->enc_value); 710 encoding=QString(enc->enc_value);
696 enc->enc_value=0L; 711 enc->enc_value=0L;
697 free(t); 712 free(t);
698 } 713 }
699 } 714 }
700 if (which->bd_description) { 715 if (which->bd_description) {
701 target_part.setDescription(QString(which->bd_description)); 716 target_part.setDescription(QString(which->bd_description));
702 } 717 }
703 target_part.setEncoding(encoding); 718 target_part.setEncoding(encoding);
704 target_part.setSize(which->bd_size); 719 target_part.setSize(which->bd_size);
705} 720}
706 721
707void IMAPwrapper::deleteMail(const RecMail&mail) 722void IMAPwrapper::deleteMail(const RecMail&mail)
708{ 723{
709 mailimap_flag_list*flist; 724 mailimap_flag_list*flist;
710 mailimap_set *set; 725 mailimap_set *set;
711 mailimap_store_att_flags * store_flags; 726 mailimap_store_att_flags * store_flags;
712 int err; 727 int err;
713 login(); 728 login();
714 if (!m_imap) { 729 if (!m_imap) {
715 return; 730 return;
716 } 731 }
717 const char *mb = mail.getMbox().latin1(); 732 const char *mb = mail.getMbox().latin1();
718 err = mailimap_select( m_imap, (char*)mb); 733 err = mailimap_select( m_imap, (char*)mb);
719 if ( err != MAILIMAP_NO_ERROR ) { 734 if ( err != MAILIMAP_NO_ERROR ) {
720 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
721 return; 736 return;
722 } 737 }
723 flist = mailimap_flag_list_new_empty(); 738 flist = mailimap_flag_list_new_empty();
724 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
725 store_flags = mailimap_store_att_flags_new_set_flags(flist); 740 store_flags = mailimap_store_att_flags_new_set_flags(flist);
726 set = mailimap_set_new_single(mail.getNumber()); 741 set = mailimap_set_new_single(mail.getNumber());
727 err = mailimap_store(m_imap,set,store_flags); 742 err = mailimap_store(m_imap,set,store_flags);
728 mailimap_set_free( set ); 743 mailimap_set_free( set );
729 mailimap_store_att_flags_free(store_flags); 744 mailimap_store_att_flags_free(store_flags);
730 745
731 if (err != MAILIMAP_NO_ERROR) { 746 if (err != MAILIMAP_NO_ERROR) {
732 qDebug("error deleting mail: %s",m_imap->imap_response); 747 qDebug("error deleting mail: %s",m_imap->imap_response);
733 return; 748 return;
734 } 749 }
735 qDebug("deleting mail: %s",m_imap->imap_response); 750 qDebug("deleting mail: %s",m_imap->imap_response);
736 /* should we realy do that at this moment? */ 751 /* should we realy do that at this moment? */
737 err = mailimap_expunge(m_imap); 752 err = mailimap_expunge(m_imap);
738 if (err != MAILIMAP_NO_ERROR) { 753 if (err != MAILIMAP_NO_ERROR) {
739 qDebug("error deleting mail: %s",m_imap->imap_response); 754 qDebug("error deleting mail: %s",m_imap->imap_response);
740 } 755 }
741 qDebug("Delete successfull %s",m_imap->imap_response); 756 qDebug("Delete successfull %s",m_imap->imap_response);
742} 757}
743 758
744void IMAPwrapper::answeredMail(const RecMail&mail) 759void IMAPwrapper::answeredMail(const RecMail&mail)
745{ 760{
746 mailimap_flag_list*flist; 761 mailimap_flag_list*flist;
747 mailimap_set *set; 762 mailimap_set *set;
748 mailimap_store_att_flags * store_flags; 763 mailimap_store_att_flags * store_flags;
749 int err; 764 int err;
750 login(); 765 login();
751 if (!m_imap) { 766 if (!m_imap) {
752 return; 767 return;
753 } 768 }
754 const char *mb = mail.getMbox().latin1(); 769 const char *mb = mail.getMbox().latin1();
755 err = mailimap_select( m_imap, (char*)mb); 770 err = mailimap_select( m_imap, (char*)mb);
756 if ( err != MAILIMAP_NO_ERROR ) { 771 if ( err != MAILIMAP_NO_ERROR ) {
757 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
758 return; 773 return;
759 } 774 }
760 flist = mailimap_flag_list_new_empty(); 775 flist = mailimap_flag_list_new_empty();
761 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 776 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
762 store_flags = mailimap_store_att_flags_new_add_flags(flist); 777 store_flags = mailimap_store_att_flags_new_add_flags(flist);
763 set = mailimap_set_new_single(mail.getNumber()); 778 set = mailimap_set_new_single(mail.getNumber());
764 err = mailimap_store(m_imap,set,store_flags); 779 err = mailimap_store(m_imap,set,store_flags);
765 mailimap_set_free( set ); 780 mailimap_set_free( set );
766 mailimap_store_att_flags_free(store_flags); 781 mailimap_store_att_flags_free(store_flags);
767 782
768 if (err != MAILIMAP_NO_ERROR) { 783 if (err != MAILIMAP_NO_ERROR) {
769 qDebug("error marking mail: %s",m_imap->imap_response); 784 qDebug("error marking mail: %s",m_imap->imap_response);
770 return; 785 return;
771 } 786 }
772} 787}
773 788
774QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
775{ 790{
776 QString body(""); 791 QString body("");
777 encodedString*res = fetchRawPart(mail,path,internal_call); 792 encodedString*res = fetchRawPart(mail,path,internal_call);
778 encodedString*r = decode_String(res,enc); 793 encodedString*r = decode_String(res,enc);
779 delete res; 794 delete res;
780 if (r) { 795 if (r) {
781 if (r->Length()>0) { 796 if (r->Length()>0) {
782 body = r->Content(); 797 body = r->Content();
783 } 798 }
784 delete r; 799 delete r;
785 } 800 }
786 return body; 801 return body;
787} 802}
788 803
789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
790{ 805{
791 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
792} 807}
793 808
794encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
795{ 810{
796 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
797 encodedString*r = decode_String(res,part.Encoding()); 812 encodedString*r = decode_String(res,part.Encoding());
798 delete res; 813 delete res;
799 return r; 814 return r;
800} 815}
801 816
802encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
803{ 818{
804 return fetchRawPart(mail,part.Positionlist(),false); 819 return fetchRawPart(mail,part.Positionlist(),false);
805} 820}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 838300a..cce3d34 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,805 +1,820 @@
1 1
2#include <stdlib.h> 2#include <stdlib.h>
3 3
4#include "imapwrapper.h" 4#include "imapwrapper.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "logindialog.h"
6#include <libetpan/mailimap.h> 7#include <libetpan/mailimap.h>
7 8
8IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
9 : AbstractMail() 10 : AbstractMail()
10{ 11{
11 account = a; 12 account = a;
12 m_imap = 0; 13 m_imap = 0;
13} 14}
14 15
15IMAPwrapper::~IMAPwrapper() 16IMAPwrapper::~IMAPwrapper()
16{ 17{
17 logout(); 18 logout();
18} 19}
19 20
20void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 21void IMAPwrapper::imap_progress( size_t current, size_t maximum )
21{ 22{
22 qDebug( "IMAP: %i of %i", current, maximum ); 23 qDebug( "IMAP: %i of %i", current, maximum );
23} 24}
24 25
25void IMAPwrapper::login() 26void IMAPwrapper::login()
26{ 27{
27 const char *server, *user, *pass; 28 const char *server, *user, *pass;
28 uint16_t port; 29 uint16_t port;
29 int err = MAILIMAP_NO_ERROR; 30 int err = MAILIMAP_NO_ERROR;
30 31
31 /* we are connected this moment */ 32 /* we are connected this moment */
32 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 33 /* TODO: setup a timer holding the line or if connection closed - delete the value */
33 if (m_imap) { 34 if (m_imap) {
34 mailstream_flush(m_imap->imap_stream); 35 mailstream_flush(m_imap->imap_stream);
35 return; 36 return;
36 } 37 }
37 server = account->getServer().latin1(); 38 server = account->getServer().latin1();
38 port = account->getPort().toUInt(); 39 port = account->getPort().toUInt();
39 user = account->getUser().latin1(); 40 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
40 pass = account->getPassword().latin1(); 41 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
42 login.show();
43 if ( QDialog::Accepted == login.exec() ) {
44 // ok
45 user = strdup( login.getUser().latin1() );
46 pass = strdup( login.getPassword().latin1() );
47 } else {
48 // cancel
49 qDebug( "IMAP: Login canceled" );
50 return;
51 }
52 } else {
53 user = account->getUser().latin1();
54 pass = account->getPassword().latin1();
55 }
41 56
42 m_imap = mailimap_new( 20, &imap_progress ); 57 m_imap = mailimap_new( 20, &imap_progress );
43 /* connect */ 58 /* connect */
44 if (account->getSSL()) { 59 if (account->getSSL()) {
45 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 60 err = mailimap_ssl_connect( m_imap, (char*)server, port );
46 } else { 61 } else {
47 err = mailimap_socket_connect( m_imap, (char*)server, port ); 62 err = mailimap_socket_connect( m_imap, (char*)server, port );
48 } 63 }
49 64
50 if ( err != MAILIMAP_NO_ERROR && 65 if ( err != MAILIMAP_NO_ERROR &&
51 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 66 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
52 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 67 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
53 qDebug("error connecting server: %s",m_imap->imap_response); 68 qDebug("error connecting server: %s",m_imap->imap_response);
54 mailimap_free( m_imap ); 69 mailimap_free( m_imap );
55 m_imap = 0; 70 m_imap = 0;
56 return; 71 return;
57 } 72 }
58 73
59 /* login */ 74 /* login */
60 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 75 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
61 if ( err != MAILIMAP_NO_ERROR ) { 76 if ( err != MAILIMAP_NO_ERROR ) {
62 qDebug("error logging in imap: %s",m_imap->imap_response); 77 qDebug("error logging in imap: %s",m_imap->imap_response);
63 err = mailimap_close( m_imap ); 78 err = mailimap_close( m_imap );
64 mailimap_free( m_imap ); 79 mailimap_free( m_imap );
65 m_imap = 0; 80 m_imap = 0;
66 } 81 }
67} 82}
68 83
69void IMAPwrapper::logout() 84void IMAPwrapper::logout()
70{ 85{
71 int err = MAILIMAP_NO_ERROR; 86 int err = MAILIMAP_NO_ERROR;
72 if (!m_imap) return; 87 if (!m_imap) return;
73 err = mailimap_logout( m_imap ); 88 err = mailimap_logout( m_imap );
74 err = mailimap_close( m_imap ); 89 err = mailimap_close( m_imap );
75 mailimap_free( m_imap ); 90 mailimap_free( m_imap );
76 m_imap = 0; 91 m_imap = 0;
77} 92}
78 93
79void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 94void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
80{ 95{
81 const char *mb; 96 const char *mb;
82 int err = MAILIMAP_NO_ERROR; 97 int err = MAILIMAP_NO_ERROR;
83 clist *result; 98 clist *result;
84 clistcell *current; 99 clistcell *current;
85// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize; 100// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
86 mailimap_fetch_type *fetchType; 101 mailimap_fetch_type *fetchType;
87 mailimap_set *set; 102 mailimap_set *set;
88 103
89 mb = mailbox.latin1(); 104 mb = mailbox.latin1();
90 login(); 105 login();
91 if (!m_imap) { 106 if (!m_imap) {
92 return; 107 return;
93 } 108 }
94 /* select mailbox READONLY for operations */ 109 /* select mailbox READONLY for operations */
95 err = mailimap_examine( m_imap, (char*)mb); 110 err = mailimap_examine( m_imap, (char*)mb);
96 if ( err != MAILIMAP_NO_ERROR ) { 111 if ( err != MAILIMAP_NO_ERROR ) {
97 qDebug("error selecting mailbox: %s",m_imap->imap_response); 112 qDebug("error selecting mailbox: %s",m_imap->imap_response);
98 return; 113 return;
99 } 114 }
100 115
101 int last = m_imap->imap_selection_info->sel_exists; 116 int last = m_imap->imap_selection_info->sel_exists;
102 117
103 if (last == 0) { 118 if (last == 0) {
104 qDebug("mailbox has no mails"); 119 qDebug("mailbox has no mails");
105 return; 120 return;
106 } 121 }
107 122
108 result = clist_new(); 123 result = clist_new();
109 /* the range has to start at 1!!! not with 0!!!! */ 124 /* the range has to start at 1!!! not with 0!!!! */
110 set = mailimap_set_new_interval( 1, last ); 125 set = mailimap_set_new_interval( 1, last );
111 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 126 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
112 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 127 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
113 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 128 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
114 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 129 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
115 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 130 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
116 131
117 err = mailimap_fetch( m_imap, set, fetchType, &result ); 132 err = mailimap_fetch( m_imap, set, fetchType, &result );
118 mailimap_set_free( set ); 133 mailimap_set_free( set );
119 mailimap_fetch_type_free( fetchType ); 134 mailimap_fetch_type_free( fetchType );
120 135
121 QString date,subject,from; 136 QString date,subject,from;
122 137
123 if ( err == MAILIMAP_NO_ERROR ) { 138 if ( err == MAILIMAP_NO_ERROR ) {
124 139
125 mailimap_msg_att * msg_att; 140 mailimap_msg_att * msg_att;
126 int i = 0; 141 int i = 0;
127 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 142 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
128 ++i; 143 ++i;
129 msg_att = (mailimap_msg_att*)current->data; 144 msg_att = (mailimap_msg_att*)current->data;
130 RecMail*m = parse_list_result(msg_att); 145 RecMail*m = parse_list_result(msg_att);
131 if (m) { 146 if (m) {
132 m->setNumber(i); 147 m->setNumber(i);
133 m->setMbox(mailbox); 148 m->setMbox(mailbox);
134 m->setWrapper(this); 149 m->setWrapper(this);
135 target.append(m); 150 target.append(m);
136 } 151 }
137 } 152 }
138 } else { 153 } else {
139 qDebug("Error fetching headers: %s",m_imap->imap_response); 154 qDebug("Error fetching headers: %s",m_imap->imap_response);
140 } 155 }
141 mailimap_fetch_list_free(result); 156 mailimap_fetch_list_free(result);
142} 157}
143 158
144QList<Folder>* IMAPwrapper::listFolders() 159QList<Folder>* IMAPwrapper::listFolders()
145{ 160{
146 const char *path, *mask; 161 const char *path, *mask;
147 int err = MAILIMAP_NO_ERROR; 162 int err = MAILIMAP_NO_ERROR;
148 clist *result; 163 clist *result;
149 clistcell *current; 164 clistcell *current;
150 165
151 QList<Folder> * folders = new QList<Folder>(); 166 QList<Folder> * folders = new QList<Folder>();
152 folders->setAutoDelete( false ); 167 folders->setAutoDelete( false );
153 login(); 168 login();
154 if (!m_imap) { 169 if (!m_imap) {
155 return folders; 170 return folders;
156 } 171 }
157 172
158/* 173/*
159 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 174 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
160 * We must not forget to filter them out in next loop! 175 * We must not forget to filter them out in next loop!
161 * it seems like ugly code. and yes - it is ugly code. but the best way. 176 * it seems like ugly code. and yes - it is ugly code. but the best way.
162 */ 177 */
163 QString temp; 178 QString temp;
164 mask = "INBOX" ; 179 mask = "INBOX" ;
165 result = clist_new(); 180 result = clist_new();
166 mailimap_mailbox_list *list; 181 mailimap_mailbox_list *list;
167 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 182 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
168 QString del; 183 QString del;
169 if ( err == MAILIMAP_NO_ERROR ) { 184 if ( err == MAILIMAP_NO_ERROR ) {
170 current = result->first; 185 current = result->first;
171 for ( int i = result->count; i > 0; i-- ) { 186 for ( int i = result->count; i > 0; i-- ) {
172 list = (mailimap_mailbox_list *) current->data; 187 list = (mailimap_mailbox_list *) current->data;
173 // it is better use the deep copy mechanism of qt itself 188 // it is better use the deep copy mechanism of qt itself
174 // instead of using strdup! 189 // instead of using strdup!
175 temp = list->mb_name; 190 temp = list->mb_name;
176 del = list->mb_delimiter; 191 del = list->mb_delimiter;
177 folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); 192 folders->append( new IMAPFolder(temp,del,true,account->getPrefix()));
178 current = current->next; 193 current = current->next;
179 } 194 }
180 } else { 195 } else {
181 qDebug("error fetching folders: %s",m_imap->imap_response); 196 qDebug("error fetching folders: %s",m_imap->imap_response);
182 } 197 }
183 mailimap_list_result_free( result ); 198 mailimap_list_result_free( result );
184 199
185/* 200/*
186 * second stage - get the other then inbox folders 201 * second stage - get the other then inbox folders
187 */ 202 */
188 mask = "*" ; 203 mask = "*" ;
189 path = account->getPrefix().latin1(); 204 path = account->getPrefix().latin1();
190 if (!path) path = ""; 205 if (!path) path = "";
191 result = clist_new(); 206 result = clist_new();
192 qDebug(path); 207 qDebug(path);
193 bool selectable = true; 208 bool selectable = true;
194 mailimap_mbx_list_flags*bflags; 209 mailimap_mbx_list_flags*bflags;
195 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 210 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
196 if ( err == MAILIMAP_NO_ERROR ) { 211 if ( err == MAILIMAP_NO_ERROR ) {
197 current = result->first; 212 current = result->first;
198 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 213 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
199 list = (mailimap_mailbox_list *) current->data; 214 list = (mailimap_mailbox_list *) current->data;
200 // it is better use the deep copy mechanism of qt itself 215 // it is better use the deep copy mechanism of qt itself
201 // instead of using strdup! 216 // instead of using strdup!
202 temp = list->mb_name; 217 temp = list->mb_name;
203 if (temp.lower()=="inbox") 218 if (temp.lower()=="inbox")
204 continue; 219 continue;
205 if (temp.lower()==account->getPrefix().lower()) 220 if (temp.lower()==account->getPrefix().lower())
206 continue; 221 continue;
207 if ( (bflags = list->mb_flag) ) { 222 if ( (bflags = list->mb_flag) ) {
208 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 223 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
209 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 224 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
210 } 225 }
211 del = list->mb_delimiter; 226 del = list->mb_delimiter;
212 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); 227 folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix()));
213 } 228 }
214 } else { 229 } else {
215 qDebug("error fetching folders %s",m_imap->imap_response); 230 qDebug("error fetching folders %s",m_imap->imap_response);
216 } 231 }
217 mailimap_list_result_free( result ); 232 mailimap_list_result_free( result );
218 return folders; 233 return folders;
219} 234}
220 235
221RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 236RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
222{ 237{
223 RecMail * m = 0; 238 RecMail * m = 0;
224 mailimap_msg_att_item *item=0; 239 mailimap_msg_att_item *item=0;
225 clistcell *current,*c,*cf; 240 clistcell *current,*c,*cf;
226 mailimap_msg_att_dynamic*flist; 241 mailimap_msg_att_dynamic*flist;
227 mailimap_flag_fetch*cflag; 242 mailimap_flag_fetch*cflag;
228 int size; 243 int size;
229 QBitArray mFlags(7); 244 QBitArray mFlags(7);
230 QStringList addresslist; 245 QStringList addresslist;
231 246
232 if (!m_att) { 247 if (!m_att) {
233 return m; 248 return m;
234 } 249 }
235 m = new RecMail(); 250 m = new RecMail();
236 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 251 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
237 current = c; 252 current = c;
238 size = 0; 253 size = 0;
239 item = (mailimap_msg_att_item*)current->data; 254 item = (mailimap_msg_att_item*)current->data;
240 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 255 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
241 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 256 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
242 if (!flist->att_list) { 257 if (!flist->att_list) {
243 continue; 258 continue;
244 } 259 }
245 cf = flist->att_list->first; 260 cf = flist->att_list->first;
246 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 261 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
247 cflag = (mailimap_flag_fetch*)cf->data; 262 cflag = (mailimap_flag_fetch*)cf->data;
248 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 263 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
249 switch (cflag->fl_flag->fl_type) { 264 switch (cflag->fl_flag->fl_type) {
250 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 265 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
251 mFlags.setBit(FLAG_ANSWERED); 266 mFlags.setBit(FLAG_ANSWERED);
252 break; 267 break;
253 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 268 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
254 mFlags.setBit(FLAG_FLAGGED); 269 mFlags.setBit(FLAG_FLAGGED);
255 break; 270 break;
256 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 271 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
257 mFlags.setBit(FLAG_DELETED); 272 mFlags.setBit(FLAG_DELETED);
258 break; 273 break;
259 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 274 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
260 mFlags.setBit(FLAG_SEEN); 275 mFlags.setBit(FLAG_SEEN);
261 break; 276 break;
262 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 277 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
263 mFlags.setBit(FLAG_DRAFT); 278 mFlags.setBit(FLAG_DRAFT);
264 break; 279 break;
265 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 280 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
266 break; 281 break;
267 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 282 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
268 break; 283 break;
269 default: 284 default:
270 break; 285 break;
271 } 286 }
272 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 287 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
273 mFlags.setBit(FLAG_RECENT); 288 mFlags.setBit(FLAG_RECENT);
274 } 289 }
275 } 290 }
276 continue; 291 continue;
277 } 292 }
278 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 293 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
279 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 294 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
280 m->setDate(head->env_date); 295 m->setDate(head->env_date);
281 m->setSubject(convert_String((const char*)head->env_subject)); 296 m->setSubject(convert_String((const char*)head->env_subject));
282 //m->setSubject(head->env_subject); 297 //m->setSubject(head->env_subject);
283 if (head->env_from!=NULL) { 298 if (head->env_from!=NULL) {
284 addresslist = address_list_to_stringlist(head->env_from->frm_list); 299 addresslist = address_list_to_stringlist(head->env_from->frm_list);
285 if (addresslist.count()) { 300 if (addresslist.count()) {
286 m->setFrom(addresslist.first()); 301 m->setFrom(addresslist.first());
287 } 302 }
288 } 303 }
289 if (head->env_to!=NULL) { 304 if (head->env_to!=NULL) {
290 addresslist = address_list_to_stringlist(head->env_to->to_list); 305 addresslist = address_list_to_stringlist(head->env_to->to_list);
291 m->setTo(addresslist); 306 m->setTo(addresslist);
292 } 307 }
293 if (head->env_cc!=NULL) { 308 if (head->env_cc!=NULL) {
294 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 309 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
295 m->setCC(addresslist); 310 m->setCC(addresslist);
296 } 311 }
297 if (head->env_bcc!=NULL) { 312 if (head->env_bcc!=NULL) {
298 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 313 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
299 m->setBcc(addresslist); 314 m->setBcc(addresslist);
300 } 315 }
301 if (head->env_reply_to!=NULL) { 316 if (head->env_reply_to!=NULL) {
302 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 317 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
303 if (addresslist.count()) { 318 if (addresslist.count()) {
304 m->setReplyto(addresslist.first()); 319 m->setReplyto(addresslist.first());
305 } 320 }
306 } 321 }
307 m->setMsgid(QString(head->env_message_id)); 322 m->setMsgid(QString(head->env_message_id));
308 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 323 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
309#if 0 324#if 0
310 325
311 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 326 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
312 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 327 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
313 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); 328 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);
314 qDebug(da.toString()); 329 qDebug(da.toString());
315#endif 330#endif
316 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 331 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
317 size = item->att_data.att_static->att_data.att_rfc822_size; 332 size = item->att_data.att_static->att_data.att_rfc822_size;
318 } 333 }
319 } 334 }
320 /* msg is already deleted */ 335 /* msg is already deleted */
321 if (mFlags.testBit(FLAG_DELETED) && m) { 336 if (mFlags.testBit(FLAG_DELETED) && m) {
322 delete m; 337 delete m;
323 m = 0; 338 m = 0;
324 } 339 }
325 if (m) { 340 if (m) {
326 m->setFlags(mFlags); 341 m->setFlags(mFlags);
327 m->setMsgsize(size); 342 m->setMsgsize(size);
328 } 343 }
329 return m; 344 return m;
330} 345}
331 346
332RecBody IMAPwrapper::fetchBody(const RecMail&mail) 347RecBody IMAPwrapper::fetchBody(const RecMail&mail)
333{ 348{
334 RecBody body; 349 RecBody body;
335 const char *mb; 350 const char *mb;
336 int err = MAILIMAP_NO_ERROR; 351 int err = MAILIMAP_NO_ERROR;
337 clist *result; 352 clist *result;
338 clistcell *current; 353 clistcell *current;
339 mailimap_fetch_att *fetchAtt; 354 mailimap_fetch_att *fetchAtt;
340 mailimap_fetch_type *fetchType; 355 mailimap_fetch_type *fetchType;
341 mailimap_set *set; 356 mailimap_set *set;
342 mailimap_body*body_desc; 357 mailimap_body*body_desc;
343 358
344 mb = mail.getMbox().latin1(); 359 mb = mail.getMbox().latin1();
345 360
346 login(); 361 login();
347 if (!m_imap) { 362 if (!m_imap) {
348 return body; 363 return body;
349 } 364 }
350 365
351 err = mailimap_select( m_imap, (char*)mb); 366 err = mailimap_select( m_imap, (char*)mb);
352 if ( err != MAILIMAP_NO_ERROR ) { 367 if ( err != MAILIMAP_NO_ERROR ) {
353 qDebug("error selecting mailbox: %s",m_imap->imap_response); 368 qDebug("error selecting mailbox: %s",m_imap->imap_response);
354 return body; 369 return body;
355 } 370 }
356 371
357 result = clist_new(); 372 result = clist_new();
358 /* the range has to start at 1!!! not with 0!!!! */ 373 /* the range has to start at 1!!! not with 0!!!! */
359 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 374 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
360 fetchAtt = mailimap_fetch_att_new_bodystructure(); 375 fetchAtt = mailimap_fetch_att_new_bodystructure();
361 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 376 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
362 err = mailimap_fetch( m_imap, set, fetchType, &result ); 377 err = mailimap_fetch( m_imap, set, fetchType, &result );
363 mailimap_set_free( set ); 378 mailimap_set_free( set );
364 mailimap_fetch_type_free( fetchType ); 379 mailimap_fetch_type_free( fetchType );
365 380
366 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 381 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
367 mailimap_msg_att * msg_att; 382 mailimap_msg_att * msg_att;
368 msg_att = (mailimap_msg_att*)current->data; 383 msg_att = (mailimap_msg_att*)current->data;
369 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 384 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
370 body_desc = item->att_data.att_static->att_data.att_body; 385 body_desc = item->att_data.att_static->att_data.att_body;
371 if (body_desc->bd_type==MAILIMAP_BODY_1PART) { 386 if (body_desc->bd_type==MAILIMAP_BODY_1PART) {
372 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); 387 searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
373 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { 388 } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
374 qDebug("Mulitpart mail"); 389 qDebug("Mulitpart mail");
375 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); 390 searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body);
376 } 391 }
377 } else { 392 } else {
378 qDebug("error fetching body: %s",m_imap->imap_response); 393 qDebug("error fetching body: %s",m_imap->imap_response);
379 } 394 }
380 mailimap_fetch_list_free(result); 395 mailimap_fetch_list_free(result);
381 return body; 396 return body;
382} 397}
383 398
384/* this routine is just called when the mail has only ONE part. 399/* this routine is just called when the mail has only ONE part.
385 for filling the parts of a multi-part-message there are other 400 for filling the parts of a multi-part-message there are other
386 routines 'cause we can not simply fetch the whole body. */ 401 routines 'cause we can not simply fetch the whole body. */
387void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) 402void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
388{ 403{
389 if (!mailDescription) { 404 if (!mailDescription) {
390 return; 405 return;
391 } 406 }
392 QString sub,body_text; 407 QString sub,body_text;
393 RecPart singlePart; 408 RecPart singlePart;
394 QValueList<int> path; 409 QValueList<int> path;
395 fillSinglePart(singlePart,mailDescription); 410 fillSinglePart(singlePart,mailDescription);
396 switch (mailDescription->bd_type) { 411 switch (mailDescription->bd_type) {
397 case MAILIMAP_BODY_TYPE_1PART_MSG: 412 case MAILIMAP_BODY_TYPE_1PART_MSG:
398 path.append(1); 413 path.append(1);
399 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 414 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
400 target_body.setBodytext(body_text); 415 target_body.setBodytext(body_text);
401 target_body.setDescription(singlePart); 416 target_body.setDescription(singlePart);
402 break; 417 break;
403 case MAILIMAP_BODY_TYPE_1PART_TEXT: 418 case MAILIMAP_BODY_TYPE_1PART_TEXT:
404 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 419 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
405 path.append(1); 420 path.append(1);
406 body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); 421 body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
407 target_body.setBodytext(body_text); 422 target_body.setBodytext(body_text);
408 target_body.setDescription(singlePart); 423 target_body.setDescription(singlePart);
409 break; 424 break;
410 case MAILIMAP_BODY_TYPE_1PART_BASIC: 425 case MAILIMAP_BODY_TYPE_1PART_BASIC:
411 qDebug("Single attachment"); 426 qDebug("Single attachment");
412 target_body.setBodytext(""); 427 target_body.setBodytext("");
413 target_body.addPart(singlePart); 428 target_body.addPart(singlePart);
414 break; 429 break;
415 default: 430 default:
416 break; 431 break;
417 } 432 }
418 433
419 return; 434 return;
420} 435}
421 436
422QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 437QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
423{ 438{
424 QStringList l; 439 QStringList l;
425 QString from; 440 QString from;
426 bool named_from; 441 bool named_from;
427 clistcell *current = NULL; 442 clistcell *current = NULL;
428 mailimap_address * current_address=NULL; 443 mailimap_address * current_address=NULL;
429 if (!list) { 444 if (!list) {
430 return l; 445 return l;
431 } 446 }
432 unsigned int count = 0; 447 unsigned int count = 0;
433 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 448 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
434 from = ""; 449 from = "";
435 named_from = false; 450 named_from = false;
436 current_address=(mailimap_address*)current->data; 451 current_address=(mailimap_address*)current->data;
437 if (current_address->ad_personal_name){ 452 if (current_address->ad_personal_name){
438 from+=convert_String((const char*)current_address->ad_personal_name); 453 from+=convert_String((const char*)current_address->ad_personal_name);
439 //from+=QString(current_address->ad_personal_name); 454 //from+=QString(current_address->ad_personal_name);
440 from+=" "; 455 from+=" ";
441 named_from = true; 456 named_from = true;
442 } 457 }
443 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 458 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
444 from+="<"; 459 from+="<";
445 } 460 }
446 if (current_address->ad_mailbox_name) { 461 if (current_address->ad_mailbox_name) {
447 from+=QString(current_address->ad_mailbox_name); 462 from+=QString(current_address->ad_mailbox_name);
448 from+="@"; 463 from+="@";
449 } 464 }
450 if (current_address->ad_host_name) { 465 if (current_address->ad_host_name) {
451 from+=QString(current_address->ad_host_name); 466 from+=QString(current_address->ad_host_name);
452 } 467 }
453 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 468 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
454 from+=">"; 469 from+=">";
455 } 470 }
456 l.append(QString(from)); 471 l.append(QString(from));
457 if (++count > 99) { 472 if (++count > 99) {
458 break; 473 break;
459 } 474 }
460 } 475 }
461 return l; 476 return l;
462} 477}
463 478
464encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 479encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
465{ 480{
466 encodedString*res=new encodedString; 481 encodedString*res=new encodedString;
467 const char*mb; 482 const char*mb;
468 int err; 483 int err;
469 mailimap_fetch_type *fetchType; 484 mailimap_fetch_type *fetchType;
470 mailimap_set *set; 485 mailimap_set *set;
471 clistcell*current,*cur; 486 clistcell*current,*cur;
472 487
473 login(); 488 login();
474 if (!m_imap) { 489 if (!m_imap) {
475 return res; 490 return res;
476 } 491 }
477 if (!internal_call) { 492 if (!internal_call) {
478 mb = mail.getMbox().latin1(); 493 mb = mail.getMbox().latin1();
479 err = mailimap_select( m_imap, (char*)mb); 494 err = mailimap_select( m_imap, (char*)mb);
480 if ( err != MAILIMAP_NO_ERROR ) { 495 if ( err != MAILIMAP_NO_ERROR ) {
481 qDebug("error selecting mailbox: %s",m_imap->imap_response); 496 qDebug("error selecting mailbox: %s",m_imap->imap_response);
482 return res; 497 return res;
483 } 498 }
484 } 499 }
485 set = mailimap_set_new_single(mail.getNumber()); 500 set = mailimap_set_new_single(mail.getNumber());
486 clist*id_list=clist_new(); 501 clist*id_list=clist_new();
487 for (unsigned j=0; j < path.count();++j) { 502 for (unsigned j=0; j < path.count();++j) {
488 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 503 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
489 *p_id = path[j]; 504 *p_id = path[j];
490 clist_append(id_list,p_id); 505 clist_append(id_list,p_id);
491 } 506 }
492 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 507 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
493 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 508 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
494 mailimap_section * section = mailimap_section_new(section_spec); 509 mailimap_section * section = mailimap_section_new(section_spec);
495 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 510 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
496 511
497 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 512 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
498 513
499 clist*result = clist_new(); 514 clist*result = clist_new();
500 515
501 err = mailimap_fetch( m_imap, set, fetchType, &result ); 516 err = mailimap_fetch( m_imap, set, fetchType, &result );
502 mailimap_set_free( set ); 517 mailimap_set_free( set );
503 mailimap_fetch_type_free( fetchType ); 518 mailimap_fetch_type_free( fetchType );
504 519
505 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 520 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
506 mailimap_msg_att * msg_att; 521 mailimap_msg_att * msg_att;
507 msg_att = (mailimap_msg_att*)current->data; 522 msg_att = (mailimap_msg_att*)current->data;
508 mailimap_msg_att_item*msg_att_item; 523 mailimap_msg_att_item*msg_att_item;
509 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 524 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
510 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 525 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
511 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 526 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
512 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 527 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
513 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 528 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
514 /* detach - we take over the content */ 529 /* detach - we take over the content */
515 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 530 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
516 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 531 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
517 } 532 }
518 } 533 }
519 } 534 }
520 } else { 535 } else {
521 qDebug("error fetching text: %s",m_imap->imap_response); 536 qDebug("error fetching text: %s",m_imap->imap_response);
522 } 537 }
523 mailimap_fetch_list_free(result); 538 mailimap_fetch_list_free(result);
524 return res; 539 return res;
525} 540}
526 541
527void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 542void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
528{ 543{
529 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 544 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
530 if (!mailDescription||current_recursion==10) { 545 if (!mailDescription||current_recursion==10) {
531 return; 546 return;
532 } 547 }
533 clistcell*current; 548 clistcell*current;
534 mailimap_body*current_body; 549 mailimap_body*current_body;
535 unsigned int count = 0; 550 unsigned int count = 0;
536 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 551 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
537 /* the point in the message */ 552 /* the point in the message */
538 ++count; 553 ++count;
539 current_body = (mailimap_body*)current->data; 554 current_body = (mailimap_body*)current->data;
540 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 555 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
541 QValueList<int>clist = recList; 556 QValueList<int>clist = recList;
542 clist.append(count); 557 clist.append(count);
543 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 558 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
544 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 559 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
545 RecPart currentPart; 560 RecPart currentPart;
546 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 561 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
547 QValueList<int>clist = recList; 562 QValueList<int>clist = recList;
548 clist.append(count); 563 clist.append(count);
549 /* important: Check for is NULL 'cause a body can be empty! */ 564 /* important: Check for is NULL 'cause a body can be empty! */
550 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 565 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
551 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); 566 QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
552 target_body.setDescription(currentPart); 567 target_body.setDescription(currentPart);
553 target_body.setBodytext(body_text); 568 target_body.setBodytext(body_text);
554 } else { 569 } else {
555 QString id(""); 570 QString id("");
556 for (unsigned int j = 0; j < clist.count();++j) { 571 for (unsigned int j = 0; j < clist.count();++j) {
557 id+=(j>0?" ":""); 572 id+=(j>0?" ":"");
558 id+=QString("%1").arg(clist[j]); 573 id+=QString("%1").arg(clist[j]);
559 } 574 }
560 qDebug("ID= %s",id.latin1()); 575 qDebug("ID= %s",id.latin1());
561 currentPart.setIdentifier(id); 576 currentPart.setIdentifier(id);
562 currentPart.setPositionlist(clist); 577 currentPart.setPositionlist(clist);
563 target_body.addPart(currentPart); 578 target_body.addPart(currentPart);
564 } 579 }
565 } 580 }
566 } 581 }
567} 582}
568 583
569void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 584void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
570{ 585{
571 if (!Description) { 586 if (!Description) {
572 return; 587 return;
573 } 588 }
574 switch (Description->bd_type) { 589 switch (Description->bd_type) {
575 case MAILIMAP_BODY_TYPE_1PART_TEXT: 590 case MAILIMAP_BODY_TYPE_1PART_TEXT:
576 target_part.setType("text"); 591 target_part.setType("text");
577 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 592 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
578 break; 593 break;
579 case MAILIMAP_BODY_TYPE_1PART_BASIC: 594 case MAILIMAP_BODY_TYPE_1PART_BASIC:
580 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 595 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
581 break; 596 break;
582 case MAILIMAP_BODY_TYPE_1PART_MSG: 597 case MAILIMAP_BODY_TYPE_1PART_MSG:
583 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 598 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
584 break; 599 break;
585 default: 600 default:
586 break; 601 break;
587 } 602 }
588} 603}
589 604
590void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 605void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
591{ 606{
592 if (!which) { 607 if (!which) {
593 return; 608 return;
594 } 609 }
595 QString sub; 610 QString sub;
596 sub = which->bd_media_text; 611 sub = which->bd_media_text;
597 target_part.setSubtype(sub.lower()); 612 target_part.setSubtype(sub.lower());
598 target_part.setLines(which->bd_lines); 613 target_part.setLines(which->bd_lines);
599 fillBodyFields(target_part,which->bd_fields); 614 fillBodyFields(target_part,which->bd_fields);
600} 615}
601 616
602void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 617void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
603{ 618{
604 if (!which) { 619 if (!which) {
605 return; 620 return;
606 } 621 }
607// QString sub; 622// QString sub;
608// sub = which->bd_media_text; 623// sub = which->bd_media_text;
609// target_part.setSubtype(sub.lower()); 624// target_part.setSubtype(sub.lower());
610 qDebug("Message part"); 625 qDebug("Message part");
611 /* we set this type to text/plain */ 626 /* we set this type to text/plain */
612 target_part.setType("text"); 627 target_part.setType("text");
613 target_part.setSubtype("plain"); 628 target_part.setSubtype("plain");
614 target_part.setLines(which->bd_lines); 629 target_part.setLines(which->bd_lines);
615 fillBodyFields(target_part,which->bd_fields); 630 fillBodyFields(target_part,which->bd_fields);
616} 631}
617 632
618void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 633void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
619{ 634{
620 if (!which) { 635 if (!which) {
621 return; 636 return;
622 } 637 }
623 QString type,sub; 638 QString type,sub;
624 switch (which->bd_media_basic->med_type) { 639 switch (which->bd_media_basic->med_type) {
625 case MAILIMAP_MEDIA_BASIC_APPLICATION: 640 case MAILIMAP_MEDIA_BASIC_APPLICATION:
626 type = "application"; 641 type = "application";
627 break; 642 break;
628 case MAILIMAP_MEDIA_BASIC_AUDIO: 643 case MAILIMAP_MEDIA_BASIC_AUDIO:
629 type = "audio"; 644 type = "audio";
630 break; 645 break;
631 case MAILIMAP_MEDIA_BASIC_IMAGE: 646 case MAILIMAP_MEDIA_BASIC_IMAGE:
632 type = "image"; 647 type = "image";
633 break; 648 break;
634 case MAILIMAP_MEDIA_BASIC_MESSAGE: 649 case MAILIMAP_MEDIA_BASIC_MESSAGE:
635 type = "message"; 650 type = "message";
636 break; 651 break;
637 case MAILIMAP_MEDIA_BASIC_VIDEO: 652 case MAILIMAP_MEDIA_BASIC_VIDEO:
638 type = "video"; 653 type = "video";
639 break; 654 break;
640 case MAILIMAP_MEDIA_BASIC_OTHER: 655 case MAILIMAP_MEDIA_BASIC_OTHER:
641 default: 656 default:
642 if (which->bd_media_basic->med_basic_type) { 657 if (which->bd_media_basic->med_basic_type) {
643 type = which->bd_media_basic->med_basic_type; 658 type = which->bd_media_basic->med_basic_type;
644 } else { 659 } else {
645 type = ""; 660 type = "";
646 } 661 }
647 break; 662 break;
648 } 663 }
649 if (which->bd_media_basic->med_subtype) { 664 if (which->bd_media_basic->med_subtype) {
650 sub = which->bd_media_basic->med_subtype; 665 sub = which->bd_media_basic->med_subtype;
651 } else { 666 } else {
652 sub = ""; 667 sub = "";
653 } 668 }
654 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 669 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
655 target_part.setType(type.lower()); 670 target_part.setType(type.lower());
656 target_part.setSubtype(sub.lower()); 671 target_part.setSubtype(sub.lower());
657 fillBodyFields(target_part,which->bd_fields); 672 fillBodyFields(target_part,which->bd_fields);
658} 673}
659 674
660void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 675void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
661{ 676{
662 if (!which) return; 677 if (!which) return;
663 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 678 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
664 clistcell*cur; 679 clistcell*cur;
665 mailimap_single_body_fld_param*param=0; 680 mailimap_single_body_fld_param*param=0;
666 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 681 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
667 param = (mailimap_single_body_fld_param*)cur->data; 682 param = (mailimap_single_body_fld_param*)cur->data;
668 if (param) { 683 if (param) {
669 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 684 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
670 } 685 }
671 } 686 }
672 } 687 }
673 mailimap_body_fld_enc*enc = which->bd_encoding; 688 mailimap_body_fld_enc*enc = which->bd_encoding;
674 QString encoding(""); 689 QString encoding("");
675 switch (enc->enc_type) { 690 switch (enc->enc_type) {
676 case MAILIMAP_BODY_FLD_ENC_7BIT: 691 case MAILIMAP_BODY_FLD_ENC_7BIT:
677 encoding = "7bit"; 692 encoding = "7bit";
678 break; 693 break;
679 case MAILIMAP_BODY_FLD_ENC_8BIT: 694 case MAILIMAP_BODY_FLD_ENC_8BIT:
680 encoding = "8bit"; 695 encoding = "8bit";
681 break; 696 break;
682 case MAILIMAP_BODY_FLD_ENC_BINARY: 697 case MAILIMAP_BODY_FLD_ENC_BINARY:
683 encoding="binary"; 698 encoding="binary";
684 break; 699 break;
685 case MAILIMAP_BODY_FLD_ENC_BASE64: 700 case MAILIMAP_BODY_FLD_ENC_BASE64:
686 encoding="base64"; 701 encoding="base64";
687 break; 702 break;
688 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 703 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
689 encoding="quoted-printable"; 704 encoding="quoted-printable";
690 break; 705 break;
691 case MAILIMAP_BODY_FLD_ENC_OTHER: 706 case MAILIMAP_BODY_FLD_ENC_OTHER:
692 default: 707 default:
693 if (enc->enc_value) { 708 if (enc->enc_value) {
694 char*t=enc->enc_value; 709 char*t=enc->enc_value;
695 encoding=QString(enc->enc_value); 710 encoding=QString(enc->enc_value);
696 enc->enc_value=0L; 711 enc->enc_value=0L;
697 free(t); 712 free(t);
698 } 713 }
699 } 714 }
700 if (which->bd_description) { 715 if (which->bd_description) {
701 target_part.setDescription(QString(which->bd_description)); 716 target_part.setDescription(QString(which->bd_description));
702 } 717 }
703 target_part.setEncoding(encoding); 718 target_part.setEncoding(encoding);
704 target_part.setSize(which->bd_size); 719 target_part.setSize(which->bd_size);
705} 720}
706 721
707void IMAPwrapper::deleteMail(const RecMail&mail) 722void IMAPwrapper::deleteMail(const RecMail&mail)
708{ 723{
709 mailimap_flag_list*flist; 724 mailimap_flag_list*flist;
710 mailimap_set *set; 725 mailimap_set *set;
711 mailimap_store_att_flags * store_flags; 726 mailimap_store_att_flags * store_flags;
712 int err; 727 int err;
713 login(); 728 login();
714 if (!m_imap) { 729 if (!m_imap) {
715 return; 730 return;
716 } 731 }
717 const char *mb = mail.getMbox().latin1(); 732 const char *mb = mail.getMbox().latin1();
718 err = mailimap_select( m_imap, (char*)mb); 733 err = mailimap_select( m_imap, (char*)mb);
719 if ( err != MAILIMAP_NO_ERROR ) { 734 if ( err != MAILIMAP_NO_ERROR ) {
720 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 735 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
721 return; 736 return;
722 } 737 }
723 flist = mailimap_flag_list_new_empty(); 738 flist = mailimap_flag_list_new_empty();
724 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 739 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
725 store_flags = mailimap_store_att_flags_new_set_flags(flist); 740 store_flags = mailimap_store_att_flags_new_set_flags(flist);
726 set = mailimap_set_new_single(mail.getNumber()); 741 set = mailimap_set_new_single(mail.getNumber());
727 err = mailimap_store(m_imap,set,store_flags); 742 err = mailimap_store(m_imap,set,store_flags);
728 mailimap_set_free( set ); 743 mailimap_set_free( set );
729 mailimap_store_att_flags_free(store_flags); 744 mailimap_store_att_flags_free(store_flags);
730 745
731 if (err != MAILIMAP_NO_ERROR) { 746 if (err != MAILIMAP_NO_ERROR) {
732 qDebug("error deleting mail: %s",m_imap->imap_response); 747 qDebug("error deleting mail: %s",m_imap->imap_response);
733 return; 748 return;
734 } 749 }
735 qDebug("deleting mail: %s",m_imap->imap_response); 750 qDebug("deleting mail: %s",m_imap->imap_response);
736 /* should we realy do that at this moment? */ 751 /* should we realy do that at this moment? */
737 err = mailimap_expunge(m_imap); 752 err = mailimap_expunge(m_imap);
738 if (err != MAILIMAP_NO_ERROR) { 753 if (err != MAILIMAP_NO_ERROR) {
739 qDebug("error deleting mail: %s",m_imap->imap_response); 754 qDebug("error deleting mail: %s",m_imap->imap_response);
740 } 755 }
741 qDebug("Delete successfull %s",m_imap->imap_response); 756 qDebug("Delete successfull %s",m_imap->imap_response);
742} 757}
743 758
744void IMAPwrapper::answeredMail(const RecMail&mail) 759void IMAPwrapper::answeredMail(const RecMail&mail)
745{ 760{
746 mailimap_flag_list*flist; 761 mailimap_flag_list*flist;
747 mailimap_set *set; 762 mailimap_set *set;
748 mailimap_store_att_flags * store_flags; 763 mailimap_store_att_flags * store_flags;
749 int err; 764 int err;
750 login(); 765 login();
751 if (!m_imap) { 766 if (!m_imap) {
752 return; 767 return;
753 } 768 }
754 const char *mb = mail.getMbox().latin1(); 769 const char *mb = mail.getMbox().latin1();
755 err = mailimap_select( m_imap, (char*)mb); 770 err = mailimap_select( m_imap, (char*)mb);
756 if ( err != MAILIMAP_NO_ERROR ) { 771 if ( err != MAILIMAP_NO_ERROR ) {
757 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response); 772 qDebug("error selecting mailbox for mark: %s",m_imap->imap_response);
758 return; 773 return;
759 } 774 }
760 flist = mailimap_flag_list_new_empty(); 775 flist = mailimap_flag_list_new_empty();
761 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 776 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
762 store_flags = mailimap_store_att_flags_new_add_flags(flist); 777 store_flags = mailimap_store_att_flags_new_add_flags(flist);
763 set = mailimap_set_new_single(mail.getNumber()); 778 set = mailimap_set_new_single(mail.getNumber());
764 err = mailimap_store(m_imap,set,store_flags); 779 err = mailimap_store(m_imap,set,store_flags);
765 mailimap_set_free( set ); 780 mailimap_set_free( set );
766 mailimap_store_att_flags_free(store_flags); 781 mailimap_store_att_flags_free(store_flags);
767 782
768 if (err != MAILIMAP_NO_ERROR) { 783 if (err != MAILIMAP_NO_ERROR) {
769 qDebug("error marking mail: %s",m_imap->imap_response); 784 qDebug("error marking mail: %s",m_imap->imap_response);
770 return; 785 return;
771 } 786 }
772} 787}
773 788
774QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
775{ 790{
776 QString body(""); 791 QString body("");
777 encodedString*res = fetchRawPart(mail,path,internal_call); 792 encodedString*res = fetchRawPart(mail,path,internal_call);
778 encodedString*r = decode_String(res,enc); 793 encodedString*r = decode_String(res,enc);
779 delete res; 794 delete res;
780 if (r) { 795 if (r) {
781 if (r->Length()>0) { 796 if (r->Length()>0) {
782 body = r->Content(); 797 body = r->Content();
783 } 798 }
784 delete r; 799 delete r;
785 } 800 }
786 return body; 801 return body;
787} 802}
788 803
789QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 804QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
790{ 805{
791 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 806 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
792} 807}
793 808
794encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 809encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
795{ 810{
796 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 811 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
797 encodedString*r = decode_String(res,part.Encoding()); 812 encodedString*r = decode_String(res,part.Encoding());
798 delete res; 813 delete res;
799 return r; 814 return r;
800} 815}
801 816
802encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 817encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
803{ 818{
804 return fetchRawPart(mail,part.Positionlist(),false); 819 return fetchRawPart(mail,part.Positionlist(),false);
805} 820}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 22a4c70..b0b985c 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,442 +1,458 @@
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 <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
7#include <qfile.h> 8#include <qfile.h>
8 9
9/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
11 12
12POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
13{ 14{
14 account = a; 15 account = a;
15 m_pop3 = NULL; 16 m_pop3 = NULL;
16 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
17 last_msg_id = 0; 18 last_msg_id = 0;
18} 19}
19 20
20POP3wrapper::~POP3wrapper() 21POP3wrapper::~POP3wrapper()
21{ 22{
22 logout(); 23 logout();
23 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
24 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
25 msg_cache.remove(); 26 msg_cache.remove();
26 } 27 }
27} 28}
28 29
29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 30void POP3wrapper::pop3_progress( size_t current, size_t maximum )
30{ 31{
31 //qDebug( "POP3: %i of %i", current, maximum ); 32 //qDebug( "POP3: %i of %i", current, maximum );
32} 33}
33 34
34RecBody POP3wrapper::fetchBody( const RecMail &mail ) 35RecBody POP3wrapper::fetchBody( const RecMail &mail )
35{ 36{
36 int err = MAILPOP3_NO_ERROR; 37 int err = MAILPOP3_NO_ERROR;
37 char *message; 38 char *message;
38 size_t length = 0; 39 size_t length = 0;
39 40
40 login(); 41 login();
41 if ( !m_pop3 ) { 42 if ( !m_pop3 ) {
42 return RecBody(); 43 return RecBody();
43 } 44 }
44 45
45 RecBody body; 46 RecBody body;
46 47
47 QFile msg_cache(msgTempName); 48 QFile msg_cache(msgTempName);
48 49
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
51 return body; 52 return body;
52 } 53 }
53 if (mail.getNumber()!=last_msg_id) { 54 if (mail.getNumber()!=last_msg_id) {
54 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
55 msg_cache.remove(); 56 msg_cache.remove();
56 } 57 }
57 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
58 last_msg_id = mail.getNumber(); 59 last_msg_id = mail.getNumber();
59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 60 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
60 if ( err != MAILPOP3_NO_ERROR ) { 61 if ( err != MAILPOP3_NO_ERROR ) {
61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 62 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
62 last_msg_id = 0; 63 last_msg_id = 0;
63 return RecBody(); 64 return RecBody();
64 } 65 }
65 msg_cache.writeBlock(message,length); 66 msg_cache.writeBlock(message,length);
66 } else { 67 } else {
67 QString msg=""; 68 QString msg="";
68 msg_cache.open(IO_ReadOnly); 69 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 70 message = new char[4096];
70 memset(message,0,4096); 71 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 72 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 73 msg+=message;
73 memset(message,0,4096); 74 memset(message,0,4096);
74 } 75 }
75 delete message; 76 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 77 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 78 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 79 memcpy(message,msg.latin1(),msg.length());
79 } 80 }
80 body = parseMail(message); 81 body = parseMail(message);
81 free(message); 82 free(message);
82 return body; 83 return body;
83} 84}
84 85
85RecBody POP3wrapper::parseMail( char *message ) 86RecBody POP3wrapper::parseMail( char *message )
86{ 87{
87 int err = MAILIMF_NO_ERROR; 88 int err = MAILIMF_NO_ERROR;
88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 89 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
89 size_t curTok = 0; 90 size_t curTok = 0;
90 mailimf_message *result = 0; 91 mailimf_message *result = 0;
91 mailmessage * msg=0; 92 mailmessage * msg=0;
92 struct mailmime * mime=0; 93 struct mailmime * mime=0;
93 struct mailmime_single_fields fields; 94 struct mailmime_single_fields fields;
94 95
95 RecBody body; 96 RecBody body;
96 97
97 98
98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 99 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
99 if ( err != MAILIMF_NO_ERROR ) { 100 if ( err != MAILIMF_NO_ERROR ) {
100 if (result) mailimf_message_free(result); 101 if (result) mailimf_message_free(result);
101 return body; 102 return body;
102 } 103 }
103 104
104#if 0 105#if 0
105 char*body_msg = message; 106 char*body_msg = message;
106 if ( result && result->msg_body && result->msg_body->bd_text ) { 107 if ( result && result->msg_body && result->msg_body->bd_text ) {
107 body_msg = (char*)result->msg_body->bd_text; 108 body_msg = (char*)result->msg_body->bd_text;
108 result->msg_body->bd_text = 0; 109 result->msg_body->bd_text = 0;
109 } 110 }
110 111
111 msg = mailmessage_new(); 112 msg = mailmessage_new();
112 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); 113 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg));
113 generic_message_t * msg_data; 114 generic_message_t * msg_data;
114 msg_data = (generic_message_t *)msg->msg_data; 115 msg_data = (generic_message_t *)msg->msg_data;
115 msg_data->msg_fetched = 1; 116 msg_data->msg_fetched = 1;
116 msg_data->msg_message = body_msg; 117 msg_data->msg_message = body_msg;
117 msg_data->msg_length = strlen(body_msg); 118 msg_data->msg_length = strlen(body_msg);
118 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 119 memset(&fields, 0, sizeof(struct mailmime_single_fields));
119 err = mailmessage_get_bodystructure(msg,&mime); 120 err = mailmessage_get_bodystructure(msg,&mime);
120 121
121 if (mime->mm_mime_fields != NULL) { 122 if (mime->mm_mime_fields != NULL) {
122 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 123 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
123 mime->mm_content_type); 124 mime->mm_content_type);
124 } 125 }
125#endif 126#endif
126 127
127#if 1 128#if 1
128 if ( result && result->msg_body && result->msg_body->bd_text ) { 129 if ( result && result->msg_body && result->msg_body->bd_text ) {
129 qDebug( "POP3: bodytext found" ); 130 qDebug( "POP3: bodytext found" );
130 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 131 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
131 body.setBodytext( QString( result->msg_body->bd_text ) ); 132 body.setBodytext( QString( result->msg_body->bd_text ) );
132#if 0 133#if 0
133 curTok = 0; 134 curTok = 0;
134 mailmime_content*mresult = 0; 135 mailmime_content*mresult = 0;
135 size_t index = 0; 136 size_t index = 0;
136 mailmime_content_parse(result->msg_body->bd_text, 137 mailmime_content_parse(result->msg_body->bd_text,
137 strlen(result->msg_body->bd_text),&index,&mresult); 138 strlen(result->msg_body->bd_text),&index,&mresult);
138 if (mresult) { 139 if (mresult) {
139 mailmime_content_free(mresult); 140 mailmime_content_free(mresult);
140 } 141 }
141#endif 142#endif
142 mailimf_message_free(result); 143 mailimf_message_free(result);
143 } 144 }
144#endif 145#endif
145 return body; 146 return body;
146} 147}
147 148
148void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 149void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
149{ 150{
150 int err = MAILPOP3_NO_ERROR; 151 int err = MAILPOP3_NO_ERROR;
151 char * header = 0; 152 char * header = 0;
152 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 153 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
153 size_t length = 0; 154 size_t length = 0;
154 carray * messages = 0; 155 carray * messages = 0;
155 156
156 login(); 157 login();
157 if (!m_pop3) return; 158 if (!m_pop3) return;
158 mailpop3_list( m_pop3, &messages ); 159 mailpop3_list( m_pop3, &messages );
159 160
160 for (unsigned int i = 0; i < carray_count(messages);++i) { 161 for (unsigned int i = 0; i < carray_count(messages);++i) {
161 mailpop3_msg_info *info; 162 mailpop3_msg_info *info;
162 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 163 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
163 if (info->msg_deleted) 164 if (info->msg_deleted)
164 continue; 165 continue;
165 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 166 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
166 if ( err != MAILPOP3_NO_ERROR ) { 167 if ( err != MAILPOP3_NO_ERROR ) {
167 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 168 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
168 free(header); 169 free(header);
169 return; 170 return;
170 } 171 }
171 RecMail *mail = parseHeader( header ); 172 RecMail *mail = parseHeader( header );
172 mail->setNumber( info->msg_index ); 173 mail->setNumber( info->msg_index );
173 mail->setWrapper(this); 174 mail->setWrapper(this);
174 mail->setMsgsize(info->msg_size); 175 mail->setMsgsize(info->msg_size);
175 target.append( mail ); 176 target.append( mail );
176 free(header); 177 free(header);
177 } 178 }
178} 179}
179 180
180RecMail *POP3wrapper::parseHeader( const char *header ) 181RecMail *POP3wrapper::parseHeader( const char *header )
181{ 182{
182 int err = MAILIMF_NO_ERROR; 183 int err = MAILIMF_NO_ERROR;
183 size_t curTok = 0; 184 size_t curTok = 0;
184 RecMail *mail = new RecMail(); 185 RecMail *mail = new RecMail();
185 mailimf_fields *fields; 186 mailimf_fields *fields;
186 mailimf_references * refs; 187 mailimf_references * refs;
187 mailimf_keywords*keys; 188 mailimf_keywords*keys;
188 QString status; 189 QString status;
189 QString value; 190 QString value;
190 QBitArray mFlags(7); 191 QBitArray mFlags(7);
191 192
192 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 193 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
193 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 194 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
194 mailimf_field *field = (mailimf_field *) current->data; 195 mailimf_field *field = (mailimf_field *) current->data;
195 switch ( field->fld_type ) { 196 switch ( field->fld_type ) {
196 case MAILIMF_FIELD_FROM: 197 case MAILIMF_FIELD_FROM:
197 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 198 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
198 break; 199 break;
199 case MAILIMF_FIELD_TO: 200 case MAILIMF_FIELD_TO:
200 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 201 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
201 break; 202 break;
202 case MAILIMF_FIELD_CC: 203 case MAILIMF_FIELD_CC:
203 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 204 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
204 break; 205 break;
205 case MAILIMF_FIELD_BCC: 206 case MAILIMF_FIELD_BCC:
206 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 207 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
207 break; 208 break;
208 case MAILIMF_FIELD_SUBJECT: 209 case MAILIMF_FIELD_SUBJECT:
209 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 210 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
210 break; 211 break;
211 case MAILIMF_FIELD_ORIG_DATE: 212 case MAILIMF_FIELD_ORIG_DATE:
212 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 213 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
213 break; 214 break;
214 case MAILIMF_FIELD_MESSAGE_ID: 215 case MAILIMF_FIELD_MESSAGE_ID:
215 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 216 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
216 break; 217 break;
217 case MAILIMF_FIELD_REFERENCES: 218 case MAILIMF_FIELD_REFERENCES:
218 refs = field->fld_data.fld_references; 219 refs = field->fld_data.fld_references;
219 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 220 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
220 char * text = (char*)refs->mid_list->first->data; 221 char * text = (char*)refs->mid_list->first->data;
221 mail->setReplyto(QString(text)); 222 mail->setReplyto(QString(text));
222 } 223 }
223 break; 224 break;
224 case MAILIMF_FIELD_KEYWORDS: 225 case MAILIMF_FIELD_KEYWORDS:
225 keys = field->fld_data.fld_keywords; 226 keys = field->fld_data.fld_keywords;
226 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 227 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
227 qDebug("Keyword: %s",(char*)cur->data); 228 qDebug("Keyword: %s",(char*)cur->data);
228 } 229 }
229 break; 230 break;
230 case MAILIMF_FIELD_OPTIONAL_FIELD: 231 case MAILIMF_FIELD_OPTIONAL_FIELD:
231 status = field->fld_data.fld_optional_field->fld_name; 232 status = field->fld_data.fld_optional_field->fld_name;
232 value = field->fld_data.fld_optional_field->fld_value; 233 value = field->fld_data.fld_optional_field->fld_value;
233 if (status.lower()=="status") { 234 if (status.lower()=="status") {
234 if (value.lower()=="ro") { 235 if (value.lower()=="ro") {
235 mFlags.setBit(FLAG_SEEN); 236 mFlags.setBit(FLAG_SEEN);
236 } 237 }
237 } else if (status.lower()=="x-status") { 238 } else if (status.lower()=="x-status") {
238 qDebug("X-Status: %s",value.latin1()); 239 qDebug("X-Status: %s",value.latin1());
239 if (value.lower()=="a") { 240 if (value.lower()=="a") {
240 mFlags.setBit(FLAG_ANSWERED); 241 mFlags.setBit(FLAG_ANSWERED);
241 } 242 }
242 } else { 243 } else {
243// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 244// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
244// field->fld_data.fld_optional_field->fld_value); 245// field->fld_data.fld_optional_field->fld_value);
245 } 246 }
246 break; 247 break;
247 default: 248 default:
248 qDebug("Non parsed field"); 249 qDebug("Non parsed field");
249 break; 250 break;
250 } 251 }
251 } 252 }
252 if (fields) mailimf_fields_free(fields); 253 if (fields) mailimf_fields_free(fields);
253 mail->setFlags(mFlags); 254 mail->setFlags(mFlags);
254 return mail; 255 return mail;
255} 256}
256 257
257QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 258QString POP3wrapper::parseDateTime( mailimf_date_time *date )
258{ 259{
259 char tmp[23]; 260 char tmp[23];
260 261
261 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 262 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
262 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 263 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
263 264
264 return QString( tmp ); 265 return QString( tmp );
265} 266}
266 267
267QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 268QString POP3wrapper::parseAddressList( mailimf_address_list *list )
268{ 269{
269 QString result( "" ); 270 QString result( "" );
270 271
271 bool first = true; 272 bool first = true;
272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 273 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
273 mailimf_address *addr = (mailimf_address *) current->data; 274 mailimf_address *addr = (mailimf_address *) current->data;
274 275
275 if ( !first ) { 276 if ( !first ) {
276 result.append( "," ); 277 result.append( "," );
277 } else { 278 } else {
278 first = false; 279 first = false;
279 } 280 }
280 281
281 switch ( addr->ad_type ) { 282 switch ( addr->ad_type ) {
282 case MAILIMF_ADDRESS_MAILBOX: 283 case MAILIMF_ADDRESS_MAILBOX:
283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 284 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
284 break; 285 break;
285 case MAILIMF_ADDRESS_GROUP: 286 case MAILIMF_ADDRESS_GROUP:
286 result.append( parseGroup( addr->ad_data.ad_group ) ); 287 result.append( parseGroup( addr->ad_data.ad_group ) );
287 break; 288 break;
288 default: 289 default:
289 qDebug( "POP3: unkown mailimf address type" ); 290 qDebug( "POP3: unkown mailimf address type" );
290 break; 291 break;
291 } 292 }
292 } 293 }
293 294
294 return result; 295 return result;
295} 296}
296 297
297QString POP3wrapper::parseGroup( mailimf_group *group ) 298QString POP3wrapper::parseGroup( mailimf_group *group )
298{ 299{
299 QString result( "" ); 300 QString result( "" );
300 301
301 result.append( group->grp_display_name ); 302 result.append( group->grp_display_name );
302 result.append( ": " ); 303 result.append( ": " );
303 304
304 if ( group->grp_mb_list != NULL ) { 305 if ( group->grp_mb_list != NULL ) {
305 result.append( parseMailboxList( group->grp_mb_list ) ); 306 result.append( parseMailboxList( group->grp_mb_list ) );
306 } 307 }
307 308
308 result.append( ";" ); 309 result.append( ";" );
309 310
310 return result; 311 return result;
311} 312}
312 313
313QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 314QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
314{ 315{
315 QString result( "" ); 316 QString result( "" );
316 317
317 if ( box->mb_display_name == NULL ) { 318 if ( box->mb_display_name == NULL ) {
318 result.append( box->mb_addr_spec ); 319 result.append( box->mb_addr_spec );
319 } else { 320 } else {
320 result.append( convert_String(box->mb_display_name).latin1() ); 321 result.append( convert_String(box->mb_display_name).latin1() );
321 result.append( " <" ); 322 result.append( " <" );
322 result.append( box->mb_addr_spec ); 323 result.append( box->mb_addr_spec );
323 result.append( ">" ); 324 result.append( ">" );
324 } 325 }
325 326
326 return result; 327 return result;
327} 328}
328 329
329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 330QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
330{ 331{
331 QString result( "" ); 332 QString result( "" );
332 333
333 bool first = true; 334 bool first = true;
334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 335 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
335 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 336 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
336 337
337 if ( !first ) { 338 if ( !first ) {
338 result.append( "," ); 339 result.append( "," );
339 } else { 340 } else {
340 first = false; 341 first = false;
341 } 342 }
342 343
343 result.append( parseMailbox( box ) ); 344 result.append( parseMailbox( box ) );
344 } 345 }
345 346
346 return result; 347 return result;
347} 348}
348 349
349void POP3wrapper::login() 350void POP3wrapper::login()
350{ 351{
351 /* we'll hold the line */ 352 /* we'll hold the line */
352 if ( m_pop3 != NULL ) return; 353 if ( m_pop3 != NULL ) return;
353 354
354 const char *server, *user, *pass; 355 const char *server, *user, *pass;
355 uint16_t port; 356 uint16_t port;
356 int err = MAILPOP3_NO_ERROR; 357 int err = MAILPOP3_NO_ERROR;
357 358
358 server = account->getServer().latin1(); 359 server = account->getServer().latin1();
359 port = account->getPort().toUInt(); 360 port = account->getPort().toUInt();
360 user = account->getUser().latin1(); 361
361 pass = account->getPassword().latin1(); 362 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
363 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
364 login.show();
365 if ( QDialog::Accepted == login.exec() ) {
366 // ok
367 user = strdup( login.getUser().latin1() );
368 pass = strdup( login.getPassword().latin1() );
369 } else {
370 // cancel
371 qDebug( "POP3: Login canceled" );
372 return;
373 }
374 } else {
375 user = account->getUser().latin1();
376 pass = account->getPassword().latin1();
377 }
362 378
363 m_pop3 = mailpop3_new( 200, &pop3_progress ); 379 m_pop3 = mailpop3_new( 200, &pop3_progress );
364 380
365 // connect 381 // connect
366 if (account->getSSL()) { 382 if (account->getSSL()) {
367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 383 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
368 } else { 384 } else {
369 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 385 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
370 } 386 }
371 387
372 if ( err != MAILPOP3_NO_ERROR ) { 388 if ( err != MAILPOP3_NO_ERROR ) {
373 qDebug( "pop3: error connecting to %s\n reason: %s", server, 389 qDebug( "pop3: error connecting to %s\n reason: %s", server,
374 m_pop3->pop3_response ); 390 m_pop3->pop3_response );
375 mailpop3_free( m_pop3 ); 391 mailpop3_free( m_pop3 );
376 m_pop3 = NULL; 392 m_pop3 = NULL;
377 return; 393 return;
378 } 394 }
379 qDebug( "POP3: connected!" ); 395 qDebug( "POP3: connected!" );
380 396
381 // login 397 // login
382 // TODO: decide if apop or plain login should be used 398 // TODO: decide if apop or plain login should be used
383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 399 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
384 if ( err != MAILPOP3_NO_ERROR ) { 400 if ( err != MAILPOP3_NO_ERROR ) {
385 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 401 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
386 logout(); 402 logout();
387 return; 403 return;
388 } 404 }
389 405
390 qDebug( "POP3: logged in!" ); 406 qDebug( "POP3: logged in!" );
391} 407}
392 408
393void POP3wrapper::logout() 409void POP3wrapper::logout()
394{ 410{
395 int err = MAILPOP3_NO_ERROR; 411 int err = MAILPOP3_NO_ERROR;
396 if ( m_pop3 == NULL ) return; 412 if ( m_pop3 == NULL ) return;
397 err = mailpop3_quit( m_pop3 ); 413 err = mailpop3_quit( m_pop3 );
398 mailpop3_free( m_pop3 ); 414 mailpop3_free( m_pop3 );
399 m_pop3 = NULL; 415 m_pop3 = NULL;
400} 416}
401 417
402 418
403QList<Folder>* POP3wrapper::listFolders() 419QList<Folder>* POP3wrapper::listFolders()
404{ 420{
405 /* TODO: integrate MH directories 421 /* TODO: integrate MH directories
406 but not before version 0.1 ;) 422 but not before version 0.1 ;)
407 */ 423 */
408 QList<Folder> * folders = new QList<Folder>(); 424 QList<Folder> * folders = new QList<Folder>();
409 folders->setAutoDelete( false ); 425 folders->setAutoDelete( false );
410 Folder*inb=new Folder("INBOX","/"); 426 Folder*inb=new Folder("INBOX","/");
411 folders->append(inb); 427 folders->append(inb);
412 return folders; 428 return folders;
413} 429}
414 430
415QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 431QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
416{ 432{
417 return ""; 433 return "";
418} 434}
419 435
420void POP3wrapper::deleteMail(const RecMail&mail) 436void POP3wrapper::deleteMail(const RecMail&mail)
421{ 437{
422 login(); 438 login();
423 if (!m_pop3) return; 439 if (!m_pop3) return;
424 int err = mailpop3_dele(m_pop3,mail.getNumber()); 440 int err = mailpop3_dele(m_pop3,mail.getNumber());
425 if (err != MAILPOP3_NO_ERROR) { 441 if (err != MAILPOP3_NO_ERROR) {
426 qDebug("error deleting mail"); 442 qDebug("error deleting mail");
427 } 443 }
428} 444}
429 445
430void POP3wrapper::answeredMail(const RecMail&) 446void POP3wrapper::answeredMail(const RecMail&)
431{ 447{
432} 448}
433 449
434encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 450encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
435{ 451{
436 return new encodedString(); 452 return new encodedString();
437} 453}
438 454
439encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 455encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
440{ 456{
441 return new encodedString(); 457 return new encodedString();
442} 458}
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 22a4c70..b0b985c 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,442 +1,458 @@
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 <libetpan/mailpop3.h> 5#include <libetpan/mailpop3.h>
5#include <libetpan/mailmime.h> 6#include <libetpan/mailmime.h>
6#include <libetpan/data_message_driver.h> 7#include <libetpan/data_message_driver.h>
7#include <qfile.h> 8#include <qfile.h>
8 9
9/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
10#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
11 12
12POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
13{ 14{
14 account = a; 15 account = a;
15 m_pop3 = NULL; 16 m_pop3 = NULL;
16 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
17 last_msg_id = 0; 18 last_msg_id = 0;
18} 19}
19 20
20POP3wrapper::~POP3wrapper() 21POP3wrapper::~POP3wrapper()
21{ 22{
22 logout(); 23 logout();
23 QFile msg_cache(msgTempName); 24 QFile msg_cache(msgTempName);
24 if (msg_cache.exists()) { 25 if (msg_cache.exists()) {
25 msg_cache.remove(); 26 msg_cache.remove();
26 } 27 }
27} 28}
28 29
29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 30void POP3wrapper::pop3_progress( size_t current, size_t maximum )
30{ 31{
31 //qDebug( "POP3: %i of %i", current, maximum ); 32 //qDebug( "POP3: %i of %i", current, maximum );
32} 33}
33 34
34RecBody POP3wrapper::fetchBody( const RecMail &mail ) 35RecBody POP3wrapper::fetchBody( const RecMail &mail )
35{ 36{
36 int err = MAILPOP3_NO_ERROR; 37 int err = MAILPOP3_NO_ERROR;
37 char *message; 38 char *message;
38 size_t length = 0; 39 size_t length = 0;
39 40
40 login(); 41 login();
41 if ( !m_pop3 ) { 42 if ( !m_pop3 ) {
42 return RecBody(); 43 return RecBody();
43 } 44 }
44 45
45 RecBody body; 46 RecBody body;
46 47
47 QFile msg_cache(msgTempName); 48 QFile msg_cache(msgTempName);
48 49
49 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
51 return body; 52 return body;
52 } 53 }
53 if (mail.getNumber()!=last_msg_id) { 54 if (mail.getNumber()!=last_msg_id) {
54 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
55 msg_cache.remove(); 56 msg_cache.remove();
56 } 57 }
57 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
58 last_msg_id = mail.getNumber(); 59 last_msg_id = mail.getNumber();
59 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 60 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
60 if ( err != MAILPOP3_NO_ERROR ) { 61 if ( err != MAILPOP3_NO_ERROR ) {
61 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 62 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
62 last_msg_id = 0; 63 last_msg_id = 0;
63 return RecBody(); 64 return RecBody();
64 } 65 }
65 msg_cache.writeBlock(message,length); 66 msg_cache.writeBlock(message,length);
66 } else { 67 } else {
67 QString msg=""; 68 QString msg="";
68 msg_cache.open(IO_ReadOnly); 69 msg_cache.open(IO_ReadOnly);
69 message = new char[4096]; 70 message = new char[4096];
70 memset(message,0,4096); 71 memset(message,0,4096);
71 while (msg_cache.readBlock(message,4095)>0) { 72 while (msg_cache.readBlock(message,4095)>0) {
72 msg+=message; 73 msg+=message;
73 memset(message,0,4096); 74 memset(message,0,4096);
74 } 75 }
75 delete message; 76 delete message;
76 message = (char*)malloc(msg.length()+1*sizeof(char)); 77 message = (char*)malloc(msg.length()+1*sizeof(char));
77 memset(message,0,msg.length()+1); 78 memset(message,0,msg.length()+1);
78 memcpy(message,msg.latin1(),msg.length()); 79 memcpy(message,msg.latin1(),msg.length());
79 } 80 }
80 body = parseMail(message); 81 body = parseMail(message);
81 free(message); 82 free(message);
82 return body; 83 return body;
83} 84}
84 85
85RecBody POP3wrapper::parseMail( char *message ) 86RecBody POP3wrapper::parseMail( char *message )
86{ 87{
87 int err = MAILIMF_NO_ERROR; 88 int err = MAILIMF_NO_ERROR;
88 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 89 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
89 size_t curTok = 0; 90 size_t curTok = 0;
90 mailimf_message *result = 0; 91 mailimf_message *result = 0;
91 mailmessage * msg=0; 92 mailmessage * msg=0;
92 struct mailmime * mime=0; 93 struct mailmime * mime=0;
93 struct mailmime_single_fields fields; 94 struct mailmime_single_fields fields;
94 95
95 RecBody body; 96 RecBody body;
96 97
97 98
98 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 99 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
99 if ( err != MAILIMF_NO_ERROR ) { 100 if ( err != MAILIMF_NO_ERROR ) {
100 if (result) mailimf_message_free(result); 101 if (result) mailimf_message_free(result);
101 return body; 102 return body;
102 } 103 }
103 104
104#if 0 105#if 0
105 char*body_msg = message; 106 char*body_msg = message;
106 if ( result && result->msg_body && result->msg_body->bd_text ) { 107 if ( result && result->msg_body && result->msg_body->bd_text ) {
107 body_msg = (char*)result->msg_body->bd_text; 108 body_msg = (char*)result->msg_body->bd_text;
108 result->msg_body->bd_text = 0; 109 result->msg_body->bd_text = 0;
109 } 110 }
110 111
111 msg = mailmessage_new(); 112 msg = mailmessage_new();
112 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); 113 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg));
113 generic_message_t * msg_data; 114 generic_message_t * msg_data;
114 msg_data = (generic_message_t *)msg->msg_data; 115 msg_data = (generic_message_t *)msg->msg_data;
115 msg_data->msg_fetched = 1; 116 msg_data->msg_fetched = 1;
116 msg_data->msg_message = body_msg; 117 msg_data->msg_message = body_msg;
117 msg_data->msg_length = strlen(body_msg); 118 msg_data->msg_length = strlen(body_msg);
118 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 119 memset(&fields, 0, sizeof(struct mailmime_single_fields));
119 err = mailmessage_get_bodystructure(msg,&mime); 120 err = mailmessage_get_bodystructure(msg,&mime);
120 121
121 if (mime->mm_mime_fields != NULL) { 122 if (mime->mm_mime_fields != NULL) {
122 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 123 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
123 mime->mm_content_type); 124 mime->mm_content_type);
124 } 125 }
125#endif 126#endif
126 127
127#if 1 128#if 1
128 if ( result && result->msg_body && result->msg_body->bd_text ) { 129 if ( result && result->msg_body && result->msg_body->bd_text ) {
129 qDebug( "POP3: bodytext found" ); 130 qDebug( "POP3: bodytext found" );
130 // when curTok isn't set to 0 this line will fault! 'cause upper line faults! 131 // when curTok isn't set to 0 this line will fault! 'cause upper line faults!
131 body.setBodytext( QString( result->msg_body->bd_text ) ); 132 body.setBodytext( QString( result->msg_body->bd_text ) );
132#if 0 133#if 0
133 curTok = 0; 134 curTok = 0;
134 mailmime_content*mresult = 0; 135 mailmime_content*mresult = 0;
135 size_t index = 0; 136 size_t index = 0;
136 mailmime_content_parse(result->msg_body->bd_text, 137 mailmime_content_parse(result->msg_body->bd_text,
137 strlen(result->msg_body->bd_text),&index,&mresult); 138 strlen(result->msg_body->bd_text),&index,&mresult);
138 if (mresult) { 139 if (mresult) {
139 mailmime_content_free(mresult); 140 mailmime_content_free(mresult);
140 } 141 }
141#endif 142#endif
142 mailimf_message_free(result); 143 mailimf_message_free(result);
143 } 144 }
144#endif 145#endif
145 return body; 146 return body;
146} 147}
147 148
148void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 149void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
149{ 150{
150 int err = MAILPOP3_NO_ERROR; 151 int err = MAILPOP3_NO_ERROR;
151 char * header = 0; 152 char * header = 0;
152 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ 153 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
153 size_t length = 0; 154 size_t length = 0;
154 carray * messages = 0; 155 carray * messages = 0;
155 156
156 login(); 157 login();
157 if (!m_pop3) return; 158 if (!m_pop3) return;
158 mailpop3_list( m_pop3, &messages ); 159 mailpop3_list( m_pop3, &messages );
159 160
160 for (unsigned int i = 0; i < carray_count(messages);++i) { 161 for (unsigned int i = 0; i < carray_count(messages);++i) {
161 mailpop3_msg_info *info; 162 mailpop3_msg_info *info;
162 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 163 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
163 if (info->msg_deleted) 164 if (info->msg_deleted)
164 continue; 165 continue;
165 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 166 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
166 if ( err != MAILPOP3_NO_ERROR ) { 167 if ( err != MAILPOP3_NO_ERROR ) {
167 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 168 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
168 free(header); 169 free(header);
169 return; 170 return;
170 } 171 }
171 RecMail *mail = parseHeader( header ); 172 RecMail *mail = parseHeader( header );
172 mail->setNumber( info->msg_index ); 173 mail->setNumber( info->msg_index );
173 mail->setWrapper(this); 174 mail->setWrapper(this);
174 mail->setMsgsize(info->msg_size); 175 mail->setMsgsize(info->msg_size);
175 target.append( mail ); 176 target.append( mail );
176 free(header); 177 free(header);
177 } 178 }
178} 179}
179 180
180RecMail *POP3wrapper::parseHeader( const char *header ) 181RecMail *POP3wrapper::parseHeader( const char *header )
181{ 182{
182 int err = MAILIMF_NO_ERROR; 183 int err = MAILIMF_NO_ERROR;
183 size_t curTok = 0; 184 size_t curTok = 0;
184 RecMail *mail = new RecMail(); 185 RecMail *mail = new RecMail();
185 mailimf_fields *fields; 186 mailimf_fields *fields;
186 mailimf_references * refs; 187 mailimf_references * refs;
187 mailimf_keywords*keys; 188 mailimf_keywords*keys;
188 QString status; 189 QString status;
189 QString value; 190 QString value;
190 QBitArray mFlags(7); 191 QBitArray mFlags(7);
191 192
192 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 193 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
193 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 194 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
194 mailimf_field *field = (mailimf_field *) current->data; 195 mailimf_field *field = (mailimf_field *) current->data;
195 switch ( field->fld_type ) { 196 switch ( field->fld_type ) {
196 case MAILIMF_FIELD_FROM: 197 case MAILIMF_FIELD_FROM:
197 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 198 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
198 break; 199 break;
199 case MAILIMF_FIELD_TO: 200 case MAILIMF_FIELD_TO:
200 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 201 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
201 break; 202 break;
202 case MAILIMF_FIELD_CC: 203 case MAILIMF_FIELD_CC:
203 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 204 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
204 break; 205 break;
205 case MAILIMF_FIELD_BCC: 206 case MAILIMF_FIELD_BCC:
206 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 207 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
207 break; 208 break;
208 case MAILIMF_FIELD_SUBJECT: 209 case MAILIMF_FIELD_SUBJECT:
209 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 210 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
210 break; 211 break;
211 case MAILIMF_FIELD_ORIG_DATE: 212 case MAILIMF_FIELD_ORIG_DATE:
212 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 213 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
213 break; 214 break;
214 case MAILIMF_FIELD_MESSAGE_ID: 215 case MAILIMF_FIELD_MESSAGE_ID:
215 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 216 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
216 break; 217 break;
217 case MAILIMF_FIELD_REFERENCES: 218 case MAILIMF_FIELD_REFERENCES:
218 refs = field->fld_data.fld_references; 219 refs = field->fld_data.fld_references;
219 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 220 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
220 char * text = (char*)refs->mid_list->first->data; 221 char * text = (char*)refs->mid_list->first->data;
221 mail->setReplyto(QString(text)); 222 mail->setReplyto(QString(text));
222 } 223 }
223 break; 224 break;
224 case MAILIMF_FIELD_KEYWORDS: 225 case MAILIMF_FIELD_KEYWORDS:
225 keys = field->fld_data.fld_keywords; 226 keys = field->fld_data.fld_keywords;
226 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 227 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
227 qDebug("Keyword: %s",(char*)cur->data); 228 qDebug("Keyword: %s",(char*)cur->data);
228 } 229 }
229 break; 230 break;
230 case MAILIMF_FIELD_OPTIONAL_FIELD: 231 case MAILIMF_FIELD_OPTIONAL_FIELD:
231 status = field->fld_data.fld_optional_field->fld_name; 232 status = field->fld_data.fld_optional_field->fld_name;
232 value = field->fld_data.fld_optional_field->fld_value; 233 value = field->fld_data.fld_optional_field->fld_value;
233 if (status.lower()=="status") { 234 if (status.lower()=="status") {
234 if (value.lower()=="ro") { 235 if (value.lower()=="ro") {
235 mFlags.setBit(FLAG_SEEN); 236 mFlags.setBit(FLAG_SEEN);
236 } 237 }
237 } else if (status.lower()=="x-status") { 238 } else if (status.lower()=="x-status") {
238 qDebug("X-Status: %s",value.latin1()); 239 qDebug("X-Status: %s",value.latin1());
239 if (value.lower()=="a") { 240 if (value.lower()=="a") {
240 mFlags.setBit(FLAG_ANSWERED); 241 mFlags.setBit(FLAG_ANSWERED);
241 } 242 }
242 } else { 243 } else {
243// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 244// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
244// field->fld_data.fld_optional_field->fld_value); 245// field->fld_data.fld_optional_field->fld_value);
245 } 246 }
246 break; 247 break;
247 default: 248 default:
248 qDebug("Non parsed field"); 249 qDebug("Non parsed field");
249 break; 250 break;
250 } 251 }
251 } 252 }
252 if (fields) mailimf_fields_free(fields); 253 if (fields) mailimf_fields_free(fields);
253 mail->setFlags(mFlags); 254 mail->setFlags(mFlags);
254 return mail; 255 return mail;
255} 256}
256 257
257QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 258QString POP3wrapper::parseDateTime( mailimf_date_time *date )
258{ 259{
259 char tmp[23]; 260 char tmp[23];
260 261
261 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 262 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
262 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 263 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
263 264
264 return QString( tmp ); 265 return QString( tmp );
265} 266}
266 267
267QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 268QString POP3wrapper::parseAddressList( mailimf_address_list *list )
268{ 269{
269 QString result( "" ); 270 QString result( "" );
270 271
271 bool first = true; 272 bool first = true;
272 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 273 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
273 mailimf_address *addr = (mailimf_address *) current->data; 274 mailimf_address *addr = (mailimf_address *) current->data;
274 275
275 if ( !first ) { 276 if ( !first ) {
276 result.append( "," ); 277 result.append( "," );
277 } else { 278 } else {
278 first = false; 279 first = false;
279 } 280 }
280 281
281 switch ( addr->ad_type ) { 282 switch ( addr->ad_type ) {
282 case MAILIMF_ADDRESS_MAILBOX: 283 case MAILIMF_ADDRESS_MAILBOX:
283 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 284 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
284 break; 285 break;
285 case MAILIMF_ADDRESS_GROUP: 286 case MAILIMF_ADDRESS_GROUP:
286 result.append( parseGroup( addr->ad_data.ad_group ) ); 287 result.append( parseGroup( addr->ad_data.ad_group ) );
287 break; 288 break;
288 default: 289 default:
289 qDebug( "POP3: unkown mailimf address type" ); 290 qDebug( "POP3: unkown mailimf address type" );
290 break; 291 break;
291 } 292 }
292 } 293 }
293 294
294 return result; 295 return result;
295} 296}
296 297
297QString POP3wrapper::parseGroup( mailimf_group *group ) 298QString POP3wrapper::parseGroup( mailimf_group *group )
298{ 299{
299 QString result( "" ); 300 QString result( "" );
300 301
301 result.append( group->grp_display_name ); 302 result.append( group->grp_display_name );
302 result.append( ": " ); 303 result.append( ": " );
303 304
304 if ( group->grp_mb_list != NULL ) { 305 if ( group->grp_mb_list != NULL ) {
305 result.append( parseMailboxList( group->grp_mb_list ) ); 306 result.append( parseMailboxList( group->grp_mb_list ) );
306 } 307 }
307 308
308 result.append( ";" ); 309 result.append( ";" );
309 310
310 return result; 311 return result;
311} 312}
312 313
313QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 314QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
314{ 315{
315 QString result( "" ); 316 QString result( "" );
316 317
317 if ( box->mb_display_name == NULL ) { 318 if ( box->mb_display_name == NULL ) {
318 result.append( box->mb_addr_spec ); 319 result.append( box->mb_addr_spec );
319 } else { 320 } else {
320 result.append( convert_String(box->mb_display_name).latin1() ); 321 result.append( convert_String(box->mb_display_name).latin1() );
321 result.append( " <" ); 322 result.append( " <" );
322 result.append( box->mb_addr_spec ); 323 result.append( box->mb_addr_spec );
323 result.append( ">" ); 324 result.append( ">" );
324 } 325 }
325 326
326 return result; 327 return result;
327} 328}
328 329
329QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 330QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
330{ 331{
331 QString result( "" ); 332 QString result( "" );
332 333
333 bool first = true; 334 bool first = true;
334 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 335 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
335 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 336 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
336 337
337 if ( !first ) { 338 if ( !first ) {
338 result.append( "," ); 339 result.append( "," );
339 } else { 340 } else {
340 first = false; 341 first = false;
341 } 342 }
342 343
343 result.append( parseMailbox( box ) ); 344 result.append( parseMailbox( box ) );
344 } 345 }
345 346
346 return result; 347 return result;
347} 348}
348 349
349void POP3wrapper::login() 350void POP3wrapper::login()
350{ 351{
351 /* we'll hold the line */ 352 /* we'll hold the line */
352 if ( m_pop3 != NULL ) return; 353 if ( m_pop3 != NULL ) return;
353 354
354 const char *server, *user, *pass; 355 const char *server, *user, *pass;
355 uint16_t port; 356 uint16_t port;
356 int err = MAILPOP3_NO_ERROR; 357 int err = MAILPOP3_NO_ERROR;
357 358
358 server = account->getServer().latin1(); 359 server = account->getServer().latin1();
359 port = account->getPort().toUInt(); 360 port = account->getPort().toUInt();
360 user = account->getUser().latin1(); 361
361 pass = account->getPassword().latin1(); 362 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
363 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
364 login.show();
365 if ( QDialog::Accepted == login.exec() ) {
366 // ok
367 user = strdup( login.getUser().latin1() );
368 pass = strdup( login.getPassword().latin1() );
369 } else {
370 // cancel
371 qDebug( "POP3: Login canceled" );
372 return;
373 }
374 } else {
375 user = account->getUser().latin1();
376 pass = account->getPassword().latin1();
377 }
362 378
363 m_pop3 = mailpop3_new( 200, &pop3_progress ); 379 m_pop3 = mailpop3_new( 200, &pop3_progress );
364 380
365 // connect 381 // connect
366 if (account->getSSL()) { 382 if (account->getSSL()) {
367 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 383 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
368 } else { 384 } else {
369 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 385 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
370 } 386 }
371 387
372 if ( err != MAILPOP3_NO_ERROR ) { 388 if ( err != MAILPOP3_NO_ERROR ) {
373 qDebug( "pop3: error connecting to %s\n reason: %s", server, 389 qDebug( "pop3: error connecting to %s\n reason: %s", server,
374 m_pop3->pop3_response ); 390 m_pop3->pop3_response );
375 mailpop3_free( m_pop3 ); 391 mailpop3_free( m_pop3 );
376 m_pop3 = NULL; 392 m_pop3 = NULL;
377 return; 393 return;
378 } 394 }
379 qDebug( "POP3: connected!" ); 395 qDebug( "POP3: connected!" );
380 396
381 // login 397 // login
382 // TODO: decide if apop or plain login should be used 398 // TODO: decide if apop or plain login should be used
383 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 399 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
384 if ( err != MAILPOP3_NO_ERROR ) { 400 if ( err != MAILPOP3_NO_ERROR ) {
385 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 401 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
386 logout(); 402 logout();
387 return; 403 return;
388 } 404 }
389 405
390 qDebug( "POP3: logged in!" ); 406 qDebug( "POP3: logged in!" );
391} 407}
392 408
393void POP3wrapper::logout() 409void POP3wrapper::logout()
394{ 410{
395 int err = MAILPOP3_NO_ERROR; 411 int err = MAILPOP3_NO_ERROR;
396 if ( m_pop3 == NULL ) return; 412 if ( m_pop3 == NULL ) return;
397 err = mailpop3_quit( m_pop3 ); 413 err = mailpop3_quit( m_pop3 );
398 mailpop3_free( m_pop3 ); 414 mailpop3_free( m_pop3 );
399 m_pop3 = NULL; 415 m_pop3 = NULL;
400} 416}
401 417
402 418
403QList<Folder>* POP3wrapper::listFolders() 419QList<Folder>* POP3wrapper::listFolders()
404{ 420{
405 /* TODO: integrate MH directories 421 /* TODO: integrate MH directories
406 but not before version 0.1 ;) 422 but not before version 0.1 ;)
407 */ 423 */
408 QList<Folder> * folders = new QList<Folder>(); 424 QList<Folder> * folders = new QList<Folder>();
409 folders->setAutoDelete( false ); 425 folders->setAutoDelete( false );
410 Folder*inb=new Folder("INBOX","/"); 426 Folder*inb=new Folder("INBOX","/");
411 folders->append(inb); 427 folders->append(inb);
412 return folders; 428 return folders;
413} 429}
414 430
415QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&) 431QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
416{ 432{
417 return ""; 433 return "";
418} 434}
419 435
420void POP3wrapper::deleteMail(const RecMail&mail) 436void POP3wrapper::deleteMail(const RecMail&mail)
421{ 437{
422 login(); 438 login();
423 if (!m_pop3) return; 439 if (!m_pop3) return;
424 int err = mailpop3_dele(m_pop3,mail.getNumber()); 440 int err = mailpop3_dele(m_pop3,mail.getNumber());
425 if (err != MAILPOP3_NO_ERROR) { 441 if (err != MAILPOP3_NO_ERROR) {
426 qDebug("error deleting mail"); 442 qDebug("error deleting mail");
427 } 443 }
428} 444}
429 445
430void POP3wrapper::answeredMail(const RecMail&) 446void POP3wrapper::answeredMail(const RecMail&)
431{ 447{
432} 448}
433 449
434encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&) 450encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
435{ 451{
436 return new encodedString(); 452 return new encodedString();
437} 453}
438 454
439encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) 455encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
440{ 456{
441 return new encodedString(); 457 return new encodedString();
442} 458}