summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-30 00:14:47 (UTC)
committer alwin <alwin>2003-12-30 00:14:47 (UTC)
commitb636d3d91e8456b22bc450b3d7f3a862b7f615a9 (patch) (unidiff)
tree2d7fe53175453a28e4e1d08496f6f611221c1936
parent2ecab614a6b91658b1608c62134cd14e257e55b7 (diff)
downloadopie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.zip
opie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.tar.gz
opie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.tar.bz2
re-worked pop3 (use the more generic interface)
shared some more functions between mbox and pop3
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/genericwrapper.cpp69
-rw-r--r--noncore/net/mail/genericwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp69
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp72
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp166
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h5
-rw-r--r--noncore/net/mail/mboxwrapper.cpp72
-rw-r--r--noncore/net/mail/pop3wrapper.cpp166
-rw-r--r--noncore/net/mail/pop3wrapper.h5
10 files changed, 284 insertions, 344 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp
index c1b6e48..bef6ae5 100644
--- a/noncore/net/mail/genericwrapper.cpp
+++ b/noncore/net/mail/genericwrapper.cpp
@@ -1,393 +1,458 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/mailmime.h> 2#include <libetpan/libetpan.h>
3#include <libetpan/data_message_driver.h>
4#include "mailtypes.h" 3#include "mailtypes.h"
5 4
6Genericwrapper::Genericwrapper() 5Genericwrapper::Genericwrapper()
7 : AbstractMail() 6 : AbstractMail()
8{ 7{
9 bodyCache.clear(); 8 bodyCache.clear();
10} 9}
11 10
12Genericwrapper::~Genericwrapper() 11Genericwrapper::~Genericwrapper()
13{ 12{
14 cleanMimeCache(); 13 cleanMimeCache();
15} 14}
16 15
17void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 16void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
18{ 17{
19 if (!mime) { 18 if (!mime) {
20 return; 19 return;
21 } 20 }
22 mailmime_field*field = 0; 21 mailmime_field*field = 0;
23 mailmime_single_fields fields; 22 mailmime_single_fields fields;
24 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 23 memset(&fields, 0, sizeof(struct mailmime_single_fields));
25 if (mime->mm_mime_fields != NULL) { 24 if (mime->mm_mime_fields != NULL) {
26 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 25 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
27 mime->mm_content_type); 26 mime->mm_content_type);
28 } 27 }
29 28
30 mailmime_content*type = fields.fld_content; 29 mailmime_content*type = fields.fld_content;
31 clistcell*current; 30 clistcell*current;
32 if (!type) { 31 if (!type) {
33 target.setType("text"); 32 target.setType("text");
34 target.setSubtype("plain"); 33 target.setSubtype("plain");
35 } else { 34 } else {
36 target.setSubtype(type->ct_subtype); 35 target.setSubtype(type->ct_subtype);
37 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 36 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
38 case MAILMIME_DISCRETE_TYPE_TEXT: 37 case MAILMIME_DISCRETE_TYPE_TEXT:
39 target.setType("text"); 38 target.setType("text");
40 break; 39 break;
41 case MAILMIME_DISCRETE_TYPE_IMAGE: 40 case MAILMIME_DISCRETE_TYPE_IMAGE:
42 target.setType("image"); 41 target.setType("image");
43 break; 42 break;
44 case MAILMIME_DISCRETE_TYPE_AUDIO: 43 case MAILMIME_DISCRETE_TYPE_AUDIO:
45 target.setType("audio"); 44 target.setType("audio");
46 break; 45 break;
47 case MAILMIME_DISCRETE_TYPE_VIDEO: 46 case MAILMIME_DISCRETE_TYPE_VIDEO:
48 target.setType("video"); 47 target.setType("video");
49 break; 48 break;
50 case MAILMIME_DISCRETE_TYPE_APPLICATION: 49 case MAILMIME_DISCRETE_TYPE_APPLICATION:
51 target.setType("application"); 50 target.setType("application");
52 break; 51 break;
53 case MAILMIME_DISCRETE_TYPE_EXTENSION: 52 case MAILMIME_DISCRETE_TYPE_EXTENSION:
54 default: 53 default:
55 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 54 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
56 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 55 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
57 } 56 }
58 break; 57 break;
59 } 58 }
60 if (type->ct_parameters) { 59 if (type->ct_parameters) {
61 fillParameters(target,type->ct_parameters); 60 fillParameters(target,type->ct_parameters);
62 } 61 }
63 } 62 }
64 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 63 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
65 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 64 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
66 field = (mailmime_field*)current->data; 65 field = (mailmime_field*)current->data;
67 switch(field->fld_type) { 66 switch(field->fld_type) {
68 case MAILMIME_FIELD_TRANSFER_ENCODING: 67 case MAILMIME_FIELD_TRANSFER_ENCODING:
69 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 68 target.setEncoding(getencoding(field->fld_data.fld_encoding));
70 break; 69 break;
71 case MAILMIME_FIELD_ID: 70 case MAILMIME_FIELD_ID:
72 target.setIdentifier(field->fld_data.fld_id); 71 target.setIdentifier(field->fld_data.fld_id);
73 break; 72 break;
74 case MAILMIME_FIELD_DESCRIPTION: 73 case MAILMIME_FIELD_DESCRIPTION:
75 target.setDescription(field->fld_data.fld_description); 74 target.setDescription(field->fld_data.fld_description);
76 break; 75 break;
77 default: 76 default:
78 break; 77 break;
79 } 78 }
80 } 79 }
81 } 80 }
82} 81}
83 82
84void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 83void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
85{ 84{
86 if (!parameters) {return;} 85 if (!parameters) {return;}
87 clistcell*current=0; 86 clistcell*current=0;
88 mailmime_parameter*param; 87 mailmime_parameter*param;
89 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 88 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
90 param = (mailmime_parameter*)current->data; 89 param = (mailmime_parameter*)current->data;
91 if (param) { 90 if (param) {
92 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 91 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
93 } 92 }
94 } 93 }
95} 94}
96 95
97QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 96QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
98{ 97{
99 QString enc="7bit"; 98 QString enc="7bit";
100 if (!aEnc) return enc; 99 if (!aEnc) return enc;
101 switch(aEnc->enc_type) { 100 switch(aEnc->enc_type) {
102 case MAILMIME_MECHANISM_7BIT: 101 case MAILMIME_MECHANISM_7BIT:
103 enc = "7bit"; 102 enc = "7bit";
104 break; 103 break;
105 case MAILMIME_MECHANISM_8BIT: 104 case MAILMIME_MECHANISM_8BIT:
106 enc = "8bit"; 105 enc = "8bit";
107 break; 106 break;
108 case MAILMIME_MECHANISM_BINARY: 107 case MAILMIME_MECHANISM_BINARY:
109 enc = "binary"; 108 enc = "binary";
110 break; 109 break;
111 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 110 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
112 enc = "quoted-printable"; 111 enc = "quoted-printable";
113 break; 112 break;
114 case MAILMIME_MECHANISM_BASE64: 113 case MAILMIME_MECHANISM_BASE64:
115 enc = "base64"; 114 enc = "base64";
116 break; 115 break;
117 case MAILMIME_MECHANISM_TOKEN: 116 case MAILMIME_MECHANISM_TOKEN:
118 default: 117 default:
119 if (aEnc->enc_token) { 118 if (aEnc->enc_token) {
120 enc = QString(aEnc->enc_token); 119 enc = QString(aEnc->enc_token);
121 } 120 }
122 break; 121 break;
123 } 122 }
124 return enc; 123 return enc;
125} 124}
126 125
127void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) 126void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
128{ 127{
129 if (current_rec >= 10) { 128 if (current_rec >= 10) {
130 qDebug("too deep recursion!"); 129 qDebug("too deep recursion!");
131 } 130 }
132 if (!message || !mime) { 131 if (!message || !mime) {
133 return; 132 return;
134 } 133 }
135 int r; 134 int r;
136 char*data = 0; 135 char*data = 0;
137 size_t len; 136 size_t len;
138 clistiter * cur = 0; 137 clistiter * cur = 0;
139 QString b; 138 QString b;
140 RecPart part; 139 RecPart part;
141 140
142 switch (mime->mm_type) { 141 switch (mime->mm_type) {
143 case MAILMIME_SINGLE: 142 case MAILMIME_SINGLE:
144 r = mailmessage_fetch_section(message,mime,&data,&len); 143 r = mailmessage_fetch_section(message,mime,&data,&len);
145 part.setSize(len); 144 part.setSize(len);
146 fillSingleBody(part,message,mime); 145 fillSingleBody(part,message,mime);
147 if (part.Type()=="text" && target.Bodytext().isNull()) { 146 if (part.Type()=="text" && target.Bodytext().isNull()) {
148 encodedString*r = new encodedString(); 147 encodedString*r = new encodedString();
149 r->setContent(data,len); 148 r->setContent(data,len);
150 encodedString*res = decode_String(r,part.Encoding()); 149 encodedString*res = decode_String(r,part.Encoding());
151 b = QString(res->Content()); 150 b = QString(res->Content());
152 delete r; 151 delete r;
153 delete res; 152 delete res;
154 target.setBodytext(b); 153 target.setBodytext(b);
155 target.setDescription(part); 154 target.setDescription(part);
156 } else { 155 } else {
157 b = gen_attachment_id(); 156 b = gen_attachment_id();
158 part.setIdentifier(b); 157 part.setIdentifier(b);
159 bodyCache[b]=new encodedString(data,len); 158 bodyCache[b]=new encodedString(data,len);
160 target.addPart(part); 159 target.addPart(part);
161 } 160 }
162 break; 161 break;
163 case MAILMIME_MULTIPLE: 162 case MAILMIME_MULTIPLE:
164 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 163 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
165 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); 164 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
166 } 165 }
167 break; 166 break;
168 case MAILMIME_MESSAGE: 167 case MAILMIME_MESSAGE:
169 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 168 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
170 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); 169 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
171 } 170 }
172 break; 171 break;
173 } 172 }
174} 173}
175 174
176RecBody Genericwrapper::parseMail( mailmessage * msg ) 175RecBody Genericwrapper::parseMail( mailmessage * msg )
177{ 176{
178 int err = MAILIMF_NO_ERROR; 177 int err = MAILIMF_NO_ERROR;
179 mailmime_single_fields fields; 178 mailmime_single_fields fields;
180 /* is bound to msg and will be freed there */ 179 /* is bound to msg and will be freed there */
181 mailmime * mime=0; 180 mailmime * mime=0;
182 RecBody body; 181 RecBody body;
183 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 182 memset(&fields, 0, sizeof(struct mailmime_single_fields));
184 err = mailmessage_get_bodystructure(msg,&mime); 183 err = mailmessage_get_bodystructure(msg,&mime);
185 traverseBody(body,msg,mime); 184 traverseBody(body,msg,mime);
186 return body; 185 return body;
187} 186}
188 187
189RecMail *Genericwrapper::parseHeader( const char *header ) 188RecMail *Genericwrapper::parseHeader( const char *header )
190{ 189{
191 int err = MAILIMF_NO_ERROR; 190 int err = MAILIMF_NO_ERROR;
192 size_t curTok = 0; 191 size_t curTok = 0;
193 RecMail *mail = new RecMail(); 192 RecMail *mail = new RecMail();
194 mailimf_fields *fields = 0; 193 mailimf_fields *fields = 0;
195 mailimf_references * refs = 0; 194 mailimf_references * refs = 0;
196 mailimf_keywords*keys = 0; 195 mailimf_keywords*keys = 0;
197 QString status; 196 QString status;
198 QString value; 197 QString value;
199 QBitArray mFlags(7); 198 QBitArray mFlags(7);
200 199
201 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 200 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
202 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 201 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
203 mailimf_field *field = (mailimf_field *) current->data; 202 mailimf_field *field = (mailimf_field *) current->data;
204 switch ( field->fld_type ) { 203 switch ( field->fld_type ) {
205 case MAILIMF_FIELD_FROM: 204 case MAILIMF_FIELD_FROM:
206 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 205 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
207 break; 206 break;
208 case MAILIMF_FIELD_TO: 207 case MAILIMF_FIELD_TO:
209 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 208 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
210 break; 209 break;
211 case MAILIMF_FIELD_CC: 210 case MAILIMF_FIELD_CC:
212 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 211 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
213 break; 212 break;
214 case MAILIMF_FIELD_BCC: 213 case MAILIMF_FIELD_BCC:
215 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 214 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
216 break; 215 break;
217 case MAILIMF_FIELD_SUBJECT: 216 case MAILIMF_FIELD_SUBJECT:
218 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 217 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
219 break; 218 break;
220 case MAILIMF_FIELD_ORIG_DATE: 219 case MAILIMF_FIELD_ORIG_DATE:
221 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 220 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
222 break; 221 break;
223 case MAILIMF_FIELD_MESSAGE_ID: 222 case MAILIMF_FIELD_MESSAGE_ID:
224 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 223 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
225 break; 224 break;
226 case MAILIMF_FIELD_REFERENCES: 225 case MAILIMF_FIELD_REFERENCES:
227 refs = field->fld_data.fld_references; 226 refs = field->fld_data.fld_references;
228 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 227 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
229 char * text = (char*)refs->mid_list->first->data; 228 char * text = (char*)refs->mid_list->first->data;
230 mail->setReplyto(QString(text)); 229 mail->setReplyto(QString(text));
231 } 230 }
232 break; 231 break;
233 case MAILIMF_FIELD_KEYWORDS: 232 case MAILIMF_FIELD_KEYWORDS:
234 keys = field->fld_data.fld_keywords; 233 keys = field->fld_data.fld_keywords;
235 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 234 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
236 qDebug("Keyword: %s",(char*)cur->data); 235 qDebug("Keyword: %s",(char*)cur->data);
237 } 236 }
238 break; 237 break;
239 case MAILIMF_FIELD_OPTIONAL_FIELD: 238 case MAILIMF_FIELD_OPTIONAL_FIELD:
240 status = field->fld_data.fld_optional_field->fld_name; 239 status = field->fld_data.fld_optional_field->fld_name;
241 value = field->fld_data.fld_optional_field->fld_value; 240 value = field->fld_data.fld_optional_field->fld_value;
242 if (status.lower()=="status") { 241 if (status.lower()=="status") {
243 if (value.lower()=="ro") { 242 if (value.lower()=="ro") {
244 mFlags.setBit(FLAG_SEEN); 243 mFlags.setBit(FLAG_SEEN);
245 } 244 }
246 } else if (status.lower()=="x-status") { 245 } else if (status.lower()=="x-status") {
247 qDebug("X-Status: %s",value.latin1()); 246 qDebug("X-Status: %s",value.latin1());
248 if (value.lower()=="a") { 247 if (value.lower()=="a") {
249 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
250 } 249 }
251 } else { 250 } else {
252// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 251// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
253// field->fld_data.fld_optional_field->fld_value); 252// field->fld_data.fld_optional_field->fld_value);
254 } 253 }
255 break; 254 break;
256 default: 255 default:
257 qDebug("Non parsed field"); 256 qDebug("Non parsed field");
258 break; 257 break;
259 } 258 }
260 } 259 }
261 if (fields) mailimf_fields_free(fields); 260 if (fields) mailimf_fields_free(fields);
262 mail->setFlags(mFlags); 261 mail->setFlags(mFlags);
263 return mail; 262 return mail;
264} 263}
265 264
266QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 265QString Genericwrapper::parseDateTime( mailimf_date_time *date )
267{ 266{
268 char tmp[23]; 267 char tmp[23];
269 268
270 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 269 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
271 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 270 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
272 271
273 return QString( tmp ); 272 return QString( tmp );
274} 273}
275 274
276QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 275QString Genericwrapper::parseAddressList( mailimf_address_list *list )
277{ 276{
278 QString result( "" ); 277 QString result( "" );
279 278
280 bool first = true; 279 bool first = true;
281 if (list == 0) return result; 280 if (list == 0) return result;
282 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 281 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
283 mailimf_address *addr = (mailimf_address *) current->data; 282 mailimf_address *addr = (mailimf_address *) current->data;
284 283
285 if ( !first ) { 284 if ( !first ) {
286 result.append( "," ); 285 result.append( "," );
287 } else { 286 } else {
288 first = false; 287 first = false;
289 } 288 }
290 289
291 switch ( addr->ad_type ) { 290 switch ( addr->ad_type ) {
292 case MAILIMF_ADDRESS_MAILBOX: 291 case MAILIMF_ADDRESS_MAILBOX:
293 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 292 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
294 break; 293 break;
295 case MAILIMF_ADDRESS_GROUP: 294 case MAILIMF_ADDRESS_GROUP:
296 result.append( parseGroup( addr->ad_data.ad_group ) ); 295 result.append( parseGroup( addr->ad_data.ad_group ) );
297 break; 296 break;
298 default: 297 default:
299 qDebug( "Generic: unkown mailimf address type" ); 298 qDebug( "Generic: unkown mailimf address type" );
300 break; 299 break;
301 } 300 }
302 } 301 }
303 302
304 return result; 303 return result;
305} 304}
306 305
307QString Genericwrapper::parseGroup( mailimf_group *group ) 306QString Genericwrapper::parseGroup( mailimf_group *group )
308{ 307{
309 QString result( "" ); 308 QString result( "" );
310 309
311 result.append( group->grp_display_name ); 310 result.append( group->grp_display_name );
312 result.append( ": " ); 311 result.append( ": " );
313 312
314 if ( group->grp_mb_list != NULL ) { 313 if ( group->grp_mb_list != NULL ) {
315 result.append( parseMailboxList( group->grp_mb_list ) ); 314 result.append( parseMailboxList( group->grp_mb_list ) );
316 } 315 }
317 316
318 result.append( ";" ); 317 result.append( ";" );
319 318
320 return result; 319 return result;
321} 320}
322 321
323QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 322QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
324{ 323{
325 QString result( "" ); 324 QString result( "" );
326 325
327 if ( box->mb_display_name == NULL ) { 326 if ( box->mb_display_name == NULL ) {
328 result.append( box->mb_addr_spec ); 327 result.append( box->mb_addr_spec );
329 } else { 328 } else {
330 result.append( convert_String(box->mb_display_name).latin1() ); 329 result.append( convert_String(box->mb_display_name).latin1() );
331 result.append( " <" ); 330 result.append( " <" );
332 result.append( box->mb_addr_spec ); 331 result.append( box->mb_addr_spec );
333 result.append( ">" ); 332 result.append( ">" );
334 } 333 }
335 334
336 return result; 335 return result;
337} 336}
338 337
339QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 338QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
340{ 339{
341 QString result( "" ); 340 QString result( "" );
342 341
343 bool first = true; 342 bool first = true;
344 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 343 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
345 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 344 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
346 345
347 if ( !first ) { 346 if ( !first ) {
348 result.append( "," ); 347 result.append( "," );
349 } else { 348 } else {
350 first = false; 349 first = false;
351 } 350 }
352 351
353 result.append( parseMailbox( box ) ); 352 result.append( parseMailbox( box ) );
354 } 353 }
355 354
356 return result; 355 return result;
357} 356}
358 357
359encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 358encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
360{ 359{
361 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 360 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
362 if (it==bodyCache.end()) return new encodedString(); 361 if (it==bodyCache.end()) return new encodedString();
363 encodedString*t = decode_String(it.data(),part.Encoding()); 362 encodedString*t = decode_String(it.data(),part.Encoding());
364 return t; 363 return t;
365} 364}
366 365
367encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 366encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
368{ 367{
369 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 368 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
370 if (it==bodyCache.end()) return new encodedString(); 369 if (it==bodyCache.end()) return new encodedString();
371 encodedString*t = it.data(); 370 encodedString*t = it.data();
372 return t; 371 return t;
373} 372}
374 373
375QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 374QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
376{ 375{
377 encodedString*t = fetchDecodedPart(mail,part); 376 encodedString*t = fetchDecodedPart(mail,part);
378 QString text=t->Content(); 377 QString text=t->Content();
379 delete t; 378 delete t;
380 return text; 379 return text;
381} 380}
382 381
383void Genericwrapper::cleanMimeCache() 382void Genericwrapper::cleanMimeCache()
384{ 383{
385 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 384 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
386 for (;it!=bodyCache.end();++it) { 385 for (;it!=bodyCache.end();++it) {
387 encodedString*t = it.data(); 386 encodedString*t = it.data();
388 //it.setValue(0); 387 //it.setValue(0);
389 if (t) delete t; 388 if (t) delete t;
390 } 389 }
391 bodyCache.clear(); 390 bodyCache.clear();
392 qDebug("Genericwrapper: cache cleaned"); 391 qDebug("Genericwrapper: cache cleaned");
393} 392}
393
394void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
395{
396 int r;
397 mailmessage_list * env_list = 0;
398 r = mailsession_get_messages_list(session,&env_list);
399 if (r != MAIL_NO_ERROR) {
400 qDebug("Error message list");
401 return;
402 }
403 r = mailsession_get_envelopes_list(session, env_list);
404 if (r != MAIL_NO_ERROR) {
405 qDebug("Error filling message list");
406 if (env_list) {
407 mailmessage_list_free(env_list);
408 }
409 return;
410 }
411 mailimf_references * refs;
412 uint32_t i = 0;
413 for(; i < carray_count(env_list->msg_tab) ; ++i) {
414 mailmessage * msg;
415 QBitArray mFlags(7);
416 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
417 if (msg->msg_fields == NULL) {
418 qDebug("could not fetch envelope of message %i", i);
419 continue;
420 }
421 RecMail * mail = new RecMail();
422 mail->setWrapper(this);
423 mail_flags * flag_result = 0;
424 r = mailmessage_get_flags(msg,&flag_result);
425 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
426 mFlags.setBit(FLAG_SEEN);
427 }
428 mailimf_single_fields single_fields;
429 mailimf_single_fields_init(&single_fields, msg->msg_fields);
430 mail->setMsgsize(msg->msg_size);
431 mail->setFlags(mFlags);
432 mail->setMbox(mailbox);
433 mail->setNumber(i+1);
434 if (single_fields.fld_subject)
435 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
436 if (single_fields.fld_from)
437 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
438 if (single_fields.fld_to)
439 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
440 if (single_fields.fld_cc)
441 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
442 if (single_fields.fld_bcc)
443 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
444 if (single_fields.fld_orig_date)
445 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
446 if (single_fields.fld_message_id->mid_value)
447 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
448 refs = single_fields.fld_references;
449 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
450 char * text = (char*)refs->mid_list->first->data;
451 mail->setReplyto(QString(text));
452 }
453 target.append(mail);
454 }
455 if (env_list) {
456 mailmessage_list_free(env_list);
457 }
458}
diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h
index 90c4b50..54d6ea9 100644
--- a/noncore/net/mail/genericwrapper.h
+++ b/noncore/net/mail/genericwrapper.h
@@ -1,57 +1,59 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class encodedString; 11class encodedString;
12struct mailpop3; 12struct mailpop3;
13struct mailmessage; 13struct mailmessage;
14struct mailmime; 14struct mailmime;
15struct mailmime_mechanism; 15struct mailmime_mechanism;
16struct mailimf_mailbox_list; 16struct mailimf_mailbox_list;
17struct mailimf_mailbox; 17struct mailimf_mailbox;
18struct mailimf_date_time; 18struct mailimf_date_time;
19struct mailimf_group; 19struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession;
21 22
22/* this class hold just the funs shared between 23/* this class hold just the funs shared between
23 * mbox and pop3 (later mh, too) mail access. 24 * mbox and pop3 (later mh, too) mail access.
24 * it is not desigend to make a instance of it! 25 * it is not desigend to make a instance of it!
25 */ 26 */
26class Genericwrapper : public AbstractMail 27class Genericwrapper : public AbstractMail
27{ 28{
28 Q_OBJECT 29 Q_OBJECT
29public: 30public:
30 Genericwrapper(); 31 Genericwrapper();
31 virtual ~Genericwrapper(); 32 virtual ~Genericwrapper();
32 33
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual void cleanMimeCache(); 37 virtual void cleanMimeCache();
37 38
38protected: 39protected:
39 RecMail *parseHeader( const char *header ); 40 RecMail *parseHeader( const char *header );
40 RecBody parseMail( mailmessage * msg ); 41 RecBody parseMail( mailmessage * msg );
41 QString parseMailboxList( mailimf_mailbox_list *list ); 42 QString parseMailboxList( mailimf_mailbox_list *list );
42 QString parseMailbox( mailimf_mailbox *box ); 43 QString parseMailbox( mailimf_mailbox *box );
43 QString parseGroup( mailimf_group *group ); 44 QString parseGroup( mailimf_group *group );
44 QString parseAddressList( mailimf_address_list *list ); 45 QString parseAddressList( mailimf_address_list *list );
45 QString parseDateTime( mailimf_date_time *date ); 46 QString parseDateTime( mailimf_date_time *date );
46 47
47 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); 48 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
48 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 49 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
49 static void fillParameters(RecPart&target,clist*parameters); 50 static void fillParameters(RecPart&target,clist*parameters);
50 static QString getencoding(mailmime_mechanism*aEnc); 51 static QString getencoding(mailmime_mechanism*aEnc);
52 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox);
51 53
52 QString msgTempName; 54 QString msgTempName;
53 unsigned int last_msg_id; 55 unsigned int last_msg_id;
54 QMap<QString,encodedString*> bodyCache; 56 QMap<QString,encodedString*> bodyCache;
55}; 57};
56 58
57#endif 59#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index c1b6e48..bef6ae5 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,393 +1,458 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/mailmime.h> 2#include <libetpan/libetpan.h>
3#include <libetpan/data_message_driver.h>
4#include "mailtypes.h" 3#include "mailtypes.h"
5 4
6Genericwrapper::Genericwrapper() 5Genericwrapper::Genericwrapper()
7 : AbstractMail() 6 : AbstractMail()
8{ 7{
9 bodyCache.clear(); 8 bodyCache.clear();
10} 9}
11 10
12Genericwrapper::~Genericwrapper() 11Genericwrapper::~Genericwrapper()
13{ 12{
14 cleanMimeCache(); 13 cleanMimeCache();
15} 14}
16 15
17void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 16void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
18{ 17{
19 if (!mime) { 18 if (!mime) {
20 return; 19 return;
21 } 20 }
22 mailmime_field*field = 0; 21 mailmime_field*field = 0;
23 mailmime_single_fields fields; 22 mailmime_single_fields fields;
24 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 23 memset(&fields, 0, sizeof(struct mailmime_single_fields));
25 if (mime->mm_mime_fields != NULL) { 24 if (mime->mm_mime_fields != NULL) {
26 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 25 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
27 mime->mm_content_type); 26 mime->mm_content_type);
28 } 27 }
29 28
30 mailmime_content*type = fields.fld_content; 29 mailmime_content*type = fields.fld_content;
31 clistcell*current; 30 clistcell*current;
32 if (!type) { 31 if (!type) {
33 target.setType("text"); 32 target.setType("text");
34 target.setSubtype("plain"); 33 target.setSubtype("plain");
35 } else { 34 } else {
36 target.setSubtype(type->ct_subtype); 35 target.setSubtype(type->ct_subtype);
37 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 36 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
38 case MAILMIME_DISCRETE_TYPE_TEXT: 37 case MAILMIME_DISCRETE_TYPE_TEXT:
39 target.setType("text"); 38 target.setType("text");
40 break; 39 break;
41 case MAILMIME_DISCRETE_TYPE_IMAGE: 40 case MAILMIME_DISCRETE_TYPE_IMAGE:
42 target.setType("image"); 41 target.setType("image");
43 break; 42 break;
44 case MAILMIME_DISCRETE_TYPE_AUDIO: 43 case MAILMIME_DISCRETE_TYPE_AUDIO:
45 target.setType("audio"); 44 target.setType("audio");
46 break; 45 break;
47 case MAILMIME_DISCRETE_TYPE_VIDEO: 46 case MAILMIME_DISCRETE_TYPE_VIDEO:
48 target.setType("video"); 47 target.setType("video");
49 break; 48 break;
50 case MAILMIME_DISCRETE_TYPE_APPLICATION: 49 case MAILMIME_DISCRETE_TYPE_APPLICATION:
51 target.setType("application"); 50 target.setType("application");
52 break; 51 break;
53 case MAILMIME_DISCRETE_TYPE_EXTENSION: 52 case MAILMIME_DISCRETE_TYPE_EXTENSION:
54 default: 53 default:
55 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 54 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
56 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 55 target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
57 } 56 }
58 break; 57 break;
59 } 58 }
60 if (type->ct_parameters) { 59 if (type->ct_parameters) {
61 fillParameters(target,type->ct_parameters); 60 fillParameters(target,type->ct_parameters);
62 } 61 }
63 } 62 }
64 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 63 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
65 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 64 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
66 field = (mailmime_field*)current->data; 65 field = (mailmime_field*)current->data;
67 switch(field->fld_type) { 66 switch(field->fld_type) {
68 case MAILMIME_FIELD_TRANSFER_ENCODING: 67 case MAILMIME_FIELD_TRANSFER_ENCODING:
69 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 68 target.setEncoding(getencoding(field->fld_data.fld_encoding));
70 break; 69 break;
71 case MAILMIME_FIELD_ID: 70 case MAILMIME_FIELD_ID:
72 target.setIdentifier(field->fld_data.fld_id); 71 target.setIdentifier(field->fld_data.fld_id);
73 break; 72 break;
74 case MAILMIME_FIELD_DESCRIPTION: 73 case MAILMIME_FIELD_DESCRIPTION:
75 target.setDescription(field->fld_data.fld_description); 74 target.setDescription(field->fld_data.fld_description);
76 break; 75 break;
77 default: 76 default:
78 break; 77 break;
79 } 78 }
80 } 79 }
81 } 80 }
82} 81}
83 82
84void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 83void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
85{ 84{
86 if (!parameters) {return;} 85 if (!parameters) {return;}
87 clistcell*current=0; 86 clistcell*current=0;
88 mailmime_parameter*param; 87 mailmime_parameter*param;
89 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 88 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
90 param = (mailmime_parameter*)current->data; 89 param = (mailmime_parameter*)current->data;
91 if (param) { 90 if (param) {
92 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 91 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
93 } 92 }
94 } 93 }
95} 94}
96 95
97QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 96QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
98{ 97{
99 QString enc="7bit"; 98 QString enc="7bit";
100 if (!aEnc) return enc; 99 if (!aEnc) return enc;
101 switch(aEnc->enc_type) { 100 switch(aEnc->enc_type) {
102 case MAILMIME_MECHANISM_7BIT: 101 case MAILMIME_MECHANISM_7BIT:
103 enc = "7bit"; 102 enc = "7bit";
104 break; 103 break;
105 case MAILMIME_MECHANISM_8BIT: 104 case MAILMIME_MECHANISM_8BIT:
106 enc = "8bit"; 105 enc = "8bit";
107 break; 106 break;
108 case MAILMIME_MECHANISM_BINARY: 107 case MAILMIME_MECHANISM_BINARY:
109 enc = "binary"; 108 enc = "binary";
110 break; 109 break;
111 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 110 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
112 enc = "quoted-printable"; 111 enc = "quoted-printable";
113 break; 112 break;
114 case MAILMIME_MECHANISM_BASE64: 113 case MAILMIME_MECHANISM_BASE64:
115 enc = "base64"; 114 enc = "base64";
116 break; 115 break;
117 case MAILMIME_MECHANISM_TOKEN: 116 case MAILMIME_MECHANISM_TOKEN:
118 default: 117 default:
119 if (aEnc->enc_token) { 118 if (aEnc->enc_token) {
120 enc = QString(aEnc->enc_token); 119 enc = QString(aEnc->enc_token);
121 } 120 }
122 break; 121 break;
123 } 122 }
124 return enc; 123 return enc;
125} 124}
126 125
127void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) 126void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec)
128{ 127{
129 if (current_rec >= 10) { 128 if (current_rec >= 10) {
130 qDebug("too deep recursion!"); 129 qDebug("too deep recursion!");
131 } 130 }
132 if (!message || !mime) { 131 if (!message || !mime) {
133 return; 132 return;
134 } 133 }
135 int r; 134 int r;
136 char*data = 0; 135 char*data = 0;
137 size_t len; 136 size_t len;
138 clistiter * cur = 0; 137 clistiter * cur = 0;
139 QString b; 138 QString b;
140 RecPart part; 139 RecPart part;
141 140
142 switch (mime->mm_type) { 141 switch (mime->mm_type) {
143 case MAILMIME_SINGLE: 142 case MAILMIME_SINGLE:
144 r = mailmessage_fetch_section(message,mime,&data,&len); 143 r = mailmessage_fetch_section(message,mime,&data,&len);
145 part.setSize(len); 144 part.setSize(len);
146 fillSingleBody(part,message,mime); 145 fillSingleBody(part,message,mime);
147 if (part.Type()=="text" && target.Bodytext().isNull()) { 146 if (part.Type()=="text" && target.Bodytext().isNull()) {
148 encodedString*r = new encodedString(); 147 encodedString*r = new encodedString();
149 r->setContent(data,len); 148 r->setContent(data,len);
150 encodedString*res = decode_String(r,part.Encoding()); 149 encodedString*res = decode_String(r,part.Encoding());
151 b = QString(res->Content()); 150 b = QString(res->Content());
152 delete r; 151 delete r;
153 delete res; 152 delete res;
154 target.setBodytext(b); 153 target.setBodytext(b);
155 target.setDescription(part); 154 target.setDescription(part);
156 } else { 155 } else {
157 b = gen_attachment_id(); 156 b = gen_attachment_id();
158 part.setIdentifier(b); 157 part.setIdentifier(b);
159 bodyCache[b]=new encodedString(data,len); 158 bodyCache[b]=new encodedString(data,len);
160 target.addPart(part); 159 target.addPart(part);
161 } 160 }
162 break; 161 break;
163 case MAILMIME_MULTIPLE: 162 case MAILMIME_MULTIPLE:
164 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 163 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
165 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); 164 traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1);
166 } 165 }
167 break; 166 break;
168 case MAILMIME_MESSAGE: 167 case MAILMIME_MESSAGE:
169 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 168 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
170 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); 169 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1);
171 } 170 }
172 break; 171 break;
173 } 172 }
174} 173}
175 174
176RecBody Genericwrapper::parseMail( mailmessage * msg ) 175RecBody Genericwrapper::parseMail( mailmessage * msg )
177{ 176{
178 int err = MAILIMF_NO_ERROR; 177 int err = MAILIMF_NO_ERROR;
179 mailmime_single_fields fields; 178 mailmime_single_fields fields;
180 /* is bound to msg and will be freed there */ 179 /* is bound to msg and will be freed there */
181 mailmime * mime=0; 180 mailmime * mime=0;
182 RecBody body; 181 RecBody body;
183 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 182 memset(&fields, 0, sizeof(struct mailmime_single_fields));
184 err = mailmessage_get_bodystructure(msg,&mime); 183 err = mailmessage_get_bodystructure(msg,&mime);
185 traverseBody(body,msg,mime); 184 traverseBody(body,msg,mime);
186 return body; 185 return body;
187} 186}
188 187
189RecMail *Genericwrapper::parseHeader( const char *header ) 188RecMail *Genericwrapper::parseHeader( const char *header )
190{ 189{
191 int err = MAILIMF_NO_ERROR; 190 int err = MAILIMF_NO_ERROR;
192 size_t curTok = 0; 191 size_t curTok = 0;
193 RecMail *mail = new RecMail(); 192 RecMail *mail = new RecMail();
194 mailimf_fields *fields = 0; 193 mailimf_fields *fields = 0;
195 mailimf_references * refs = 0; 194 mailimf_references * refs = 0;
196 mailimf_keywords*keys = 0; 195 mailimf_keywords*keys = 0;
197 QString status; 196 QString status;
198 QString value; 197 QString value;
199 QBitArray mFlags(7); 198 QBitArray mFlags(7);
200 199
201 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 200 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
202 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 201 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
203 mailimf_field *field = (mailimf_field *) current->data; 202 mailimf_field *field = (mailimf_field *) current->data;
204 switch ( field->fld_type ) { 203 switch ( field->fld_type ) {
205 case MAILIMF_FIELD_FROM: 204 case MAILIMF_FIELD_FROM:
206 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 205 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
207 break; 206 break;
208 case MAILIMF_FIELD_TO: 207 case MAILIMF_FIELD_TO:
209 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 208 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
210 break; 209 break;
211 case MAILIMF_FIELD_CC: 210 case MAILIMF_FIELD_CC:
212 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 211 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
213 break; 212 break;
214 case MAILIMF_FIELD_BCC: 213 case MAILIMF_FIELD_BCC:
215 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 214 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
216 break; 215 break;
217 case MAILIMF_FIELD_SUBJECT: 216 case MAILIMF_FIELD_SUBJECT:
218 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 217 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
219 break; 218 break;
220 case MAILIMF_FIELD_ORIG_DATE: 219 case MAILIMF_FIELD_ORIG_DATE:
221 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 220 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
222 break; 221 break;
223 case MAILIMF_FIELD_MESSAGE_ID: 222 case MAILIMF_FIELD_MESSAGE_ID:
224 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 223 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
225 break; 224 break;
226 case MAILIMF_FIELD_REFERENCES: 225 case MAILIMF_FIELD_REFERENCES:
227 refs = field->fld_data.fld_references; 226 refs = field->fld_data.fld_references;
228 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 227 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
229 char * text = (char*)refs->mid_list->first->data; 228 char * text = (char*)refs->mid_list->first->data;
230 mail->setReplyto(QString(text)); 229 mail->setReplyto(QString(text));
231 } 230 }
232 break; 231 break;
233 case MAILIMF_FIELD_KEYWORDS: 232 case MAILIMF_FIELD_KEYWORDS:
234 keys = field->fld_data.fld_keywords; 233 keys = field->fld_data.fld_keywords;
235 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 234 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
236 qDebug("Keyword: %s",(char*)cur->data); 235 qDebug("Keyword: %s",(char*)cur->data);
237 } 236 }
238 break; 237 break;
239 case MAILIMF_FIELD_OPTIONAL_FIELD: 238 case MAILIMF_FIELD_OPTIONAL_FIELD:
240 status = field->fld_data.fld_optional_field->fld_name; 239 status = field->fld_data.fld_optional_field->fld_name;
241 value = field->fld_data.fld_optional_field->fld_value; 240 value = field->fld_data.fld_optional_field->fld_value;
242 if (status.lower()=="status") { 241 if (status.lower()=="status") {
243 if (value.lower()=="ro") { 242 if (value.lower()=="ro") {
244 mFlags.setBit(FLAG_SEEN); 243 mFlags.setBit(FLAG_SEEN);
245 } 244 }
246 } else if (status.lower()=="x-status") { 245 } else if (status.lower()=="x-status") {
247 qDebug("X-Status: %s",value.latin1()); 246 qDebug("X-Status: %s",value.latin1());
248 if (value.lower()=="a") { 247 if (value.lower()=="a") {
249 mFlags.setBit(FLAG_ANSWERED); 248 mFlags.setBit(FLAG_ANSWERED);
250 } 249 }
251 } else { 250 } else {
252// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 251// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
253// field->fld_data.fld_optional_field->fld_value); 252// field->fld_data.fld_optional_field->fld_value);
254 } 253 }
255 break; 254 break;
256 default: 255 default:
257 qDebug("Non parsed field"); 256 qDebug("Non parsed field");
258 break; 257 break;
259 } 258 }
260 } 259 }
261 if (fields) mailimf_fields_free(fields); 260 if (fields) mailimf_fields_free(fields);
262 mail->setFlags(mFlags); 261 mail->setFlags(mFlags);
263 return mail; 262 return mail;
264} 263}
265 264
266QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 265QString Genericwrapper::parseDateTime( mailimf_date_time *date )
267{ 266{
268 char tmp[23]; 267 char tmp[23];
269 268
270 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 269 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
271 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 270 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
272 271
273 return QString( tmp ); 272 return QString( tmp );
274} 273}
275 274
276QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 275QString Genericwrapper::parseAddressList( mailimf_address_list *list )
277{ 276{
278 QString result( "" ); 277 QString result( "" );
279 278
280 bool first = true; 279 bool first = true;
281 if (list == 0) return result; 280 if (list == 0) return result;
282 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 281 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
283 mailimf_address *addr = (mailimf_address *) current->data; 282 mailimf_address *addr = (mailimf_address *) current->data;
284 283
285 if ( !first ) { 284 if ( !first ) {
286 result.append( "," ); 285 result.append( "," );
287 } else { 286 } else {
288 first = false; 287 first = false;
289 } 288 }
290 289
291 switch ( addr->ad_type ) { 290 switch ( addr->ad_type ) {
292 case MAILIMF_ADDRESS_MAILBOX: 291 case MAILIMF_ADDRESS_MAILBOX:
293 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 292 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
294 break; 293 break;
295 case MAILIMF_ADDRESS_GROUP: 294 case MAILIMF_ADDRESS_GROUP:
296 result.append( parseGroup( addr->ad_data.ad_group ) ); 295 result.append( parseGroup( addr->ad_data.ad_group ) );
297 break; 296 break;
298 default: 297 default:
299 qDebug( "Generic: unkown mailimf address type" ); 298 qDebug( "Generic: unkown mailimf address type" );
300 break; 299 break;
301 } 300 }
302 } 301 }
303 302
304 return result; 303 return result;
305} 304}
306 305
307QString Genericwrapper::parseGroup( mailimf_group *group ) 306QString Genericwrapper::parseGroup( mailimf_group *group )
308{ 307{
309 QString result( "" ); 308 QString result( "" );
310 309
311 result.append( group->grp_display_name ); 310 result.append( group->grp_display_name );
312 result.append( ": " ); 311 result.append( ": " );
313 312
314 if ( group->grp_mb_list != NULL ) { 313 if ( group->grp_mb_list != NULL ) {
315 result.append( parseMailboxList( group->grp_mb_list ) ); 314 result.append( parseMailboxList( group->grp_mb_list ) );
316 } 315 }
317 316
318 result.append( ";" ); 317 result.append( ";" );
319 318
320 return result; 319 return result;
321} 320}
322 321
323QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 322QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
324{ 323{
325 QString result( "" ); 324 QString result( "" );
326 325
327 if ( box->mb_display_name == NULL ) { 326 if ( box->mb_display_name == NULL ) {
328 result.append( box->mb_addr_spec ); 327 result.append( box->mb_addr_spec );
329 } else { 328 } else {
330 result.append( convert_String(box->mb_display_name).latin1() ); 329 result.append( convert_String(box->mb_display_name).latin1() );
331 result.append( " <" ); 330 result.append( " <" );
332 result.append( box->mb_addr_spec ); 331 result.append( box->mb_addr_spec );
333 result.append( ">" ); 332 result.append( ">" );
334 } 333 }
335 334
336 return result; 335 return result;
337} 336}
338 337
339QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 338QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
340{ 339{
341 QString result( "" ); 340 QString result( "" );
342 341
343 bool first = true; 342 bool first = true;
344 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 343 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
345 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 344 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
346 345
347 if ( !first ) { 346 if ( !first ) {
348 result.append( "," ); 347 result.append( "," );
349 } else { 348 } else {
350 first = false; 349 first = false;
351 } 350 }
352 351
353 result.append( parseMailbox( box ) ); 352 result.append( parseMailbox( box ) );
354 } 353 }
355 354
356 return result; 355 return result;
357} 356}
358 357
359encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 358encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
360{ 359{
361 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 360 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
362 if (it==bodyCache.end()) return new encodedString(); 361 if (it==bodyCache.end()) return new encodedString();
363 encodedString*t = decode_String(it.data(),part.Encoding()); 362 encodedString*t = decode_String(it.data(),part.Encoding());
364 return t; 363 return t;
365} 364}
366 365
367encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 366encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
368{ 367{
369 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 368 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
370 if (it==bodyCache.end()) return new encodedString(); 369 if (it==bodyCache.end()) return new encodedString();
371 encodedString*t = it.data(); 370 encodedString*t = it.data();
372 return t; 371 return t;
373} 372}
374 373
375QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 374QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
376{ 375{
377 encodedString*t = fetchDecodedPart(mail,part); 376 encodedString*t = fetchDecodedPart(mail,part);
378 QString text=t->Content(); 377 QString text=t->Content();
379 delete t; 378 delete t;
380 return text; 379 return text;
381} 380}
382 381
383void Genericwrapper::cleanMimeCache() 382void Genericwrapper::cleanMimeCache()
384{ 383{
385 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 384 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
386 for (;it!=bodyCache.end();++it) { 385 for (;it!=bodyCache.end();++it) {
387 encodedString*t = it.data(); 386 encodedString*t = it.data();
388 //it.setValue(0); 387 //it.setValue(0);
389 if (t) delete t; 388 if (t) delete t;
390 } 389 }
391 bodyCache.clear(); 390 bodyCache.clear();
392 qDebug("Genericwrapper: cache cleaned"); 391 qDebug("Genericwrapper: cache cleaned");
393} 392}
393
394void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
395{
396 int r;
397 mailmessage_list * env_list = 0;
398 r = mailsession_get_messages_list(session,&env_list);
399 if (r != MAIL_NO_ERROR) {
400 qDebug("Error message list");
401 return;
402 }
403 r = mailsession_get_envelopes_list(session, env_list);
404 if (r != MAIL_NO_ERROR) {
405 qDebug("Error filling message list");
406 if (env_list) {
407 mailmessage_list_free(env_list);
408 }
409 return;
410 }
411 mailimf_references * refs;
412 uint32_t i = 0;
413 for(; i < carray_count(env_list->msg_tab) ; ++i) {
414 mailmessage * msg;
415 QBitArray mFlags(7);
416 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
417 if (msg->msg_fields == NULL) {
418 qDebug("could not fetch envelope of message %i", i);
419 continue;
420 }
421 RecMail * mail = new RecMail();
422 mail->setWrapper(this);
423 mail_flags * flag_result = 0;
424 r = mailmessage_get_flags(msg,&flag_result);
425 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
426 mFlags.setBit(FLAG_SEEN);
427 }
428 mailimf_single_fields single_fields;
429 mailimf_single_fields_init(&single_fields, msg->msg_fields);
430 mail->setMsgsize(msg->msg_size);
431 mail->setFlags(mFlags);
432 mail->setMbox(mailbox);
433 mail->setNumber(i+1);
434 if (single_fields.fld_subject)
435 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
436 if (single_fields.fld_from)
437 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
438 if (single_fields.fld_to)
439 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
440 if (single_fields.fld_cc)
441 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
442 if (single_fields.fld_bcc)
443 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
444 if (single_fields.fld_orig_date)
445 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
446 if (single_fields.fld_message_id->mid_value)
447 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
448 refs = single_fields.fld_references;
449 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
450 char * text = (char*)refs->mid_list->first->data;
451 mail->setReplyto(QString(text));
452 }
453 target.append(mail);
454 }
455 if (env_list) {
456 mailmessage_list_free(env_list);
457 }
458}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 90c4b50..54d6ea9 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,57 +1,59 @@
1#ifndef __GENERIC_WRAPPER_H 1#ifndef __GENERIC_WRAPPER_H
2#define __GENERIC_WRAPPER_H 2#define __GENERIC_WRAPPER_H
3 3
4#include "abstractmail.h" 4#include "abstractmail.h"
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9class RecMail; 9class RecMail;
10class RecBody; 10class RecBody;
11class encodedString; 11class encodedString;
12struct mailpop3; 12struct mailpop3;
13struct mailmessage; 13struct mailmessage;
14struct mailmime; 14struct mailmime;
15struct mailmime_mechanism; 15struct mailmime_mechanism;
16struct mailimf_mailbox_list; 16struct mailimf_mailbox_list;
17struct mailimf_mailbox; 17struct mailimf_mailbox;
18struct mailimf_date_time; 18struct mailimf_date_time;
19struct mailimf_group; 19struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession;
21 22
22/* this class hold just the funs shared between 23/* this class hold just the funs shared between
23 * mbox and pop3 (later mh, too) mail access. 24 * mbox and pop3 (later mh, too) mail access.
24 * it is not desigend to make a instance of it! 25 * it is not desigend to make a instance of it!
25 */ 26 */
26class Genericwrapper : public AbstractMail 27class Genericwrapper : public AbstractMail
27{ 28{
28 Q_OBJECT 29 Q_OBJECT
29public: 30public:
30 Genericwrapper(); 31 Genericwrapper();
31 virtual ~Genericwrapper(); 32 virtual ~Genericwrapper();
32 33
33 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 34 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
34 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
35 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 36 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
36 virtual void cleanMimeCache(); 37 virtual void cleanMimeCache();
37 38
38protected: 39protected:
39 RecMail *parseHeader( const char *header ); 40 RecMail *parseHeader( const char *header );
40 RecBody parseMail( mailmessage * msg ); 41 RecBody parseMail( mailmessage * msg );
41 QString parseMailboxList( mailimf_mailbox_list *list ); 42 QString parseMailboxList( mailimf_mailbox_list *list );
42 QString parseMailbox( mailimf_mailbox *box ); 43 QString parseMailbox( mailimf_mailbox *box );
43 QString parseGroup( mailimf_group *group ); 44 QString parseGroup( mailimf_group *group );
44 QString parseAddressList( mailimf_address_list *list ); 45 QString parseAddressList( mailimf_address_list *list );
45 QString parseDateTime( mailimf_date_time *date ); 46 QString parseDateTime( mailimf_date_time *date );
46 47
47 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); 48 void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0);
48 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); 49 static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime);
49 static void fillParameters(RecPart&target,clist*parameters); 50 static void fillParameters(RecPart&target,clist*parameters);
50 static QString getencoding(mailmime_mechanism*aEnc); 51 static QString getencoding(mailmime_mechanism*aEnc);
52 virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox);
51 53
52 QString msgTempName; 54 QString msgTempName;
53 unsigned int last_msg_id; 55 unsigned int last_msg_id;
54 QMap<QString,encodedString*> bodyCache; 56 QMap<QString,encodedString*> bodyCache;
55}; 57};
56 58
57#endif 59#endif
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 162a0c9..0aa33dd 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,364 +1,300 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 9MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
10 : Genericwrapper(),MBOXPath(mbox_dir) 10 : Genericwrapper(),MBOXPath(mbox_dir)
11{ 11{
12 QDir dir(MBOXPath); 12 QDir dir(MBOXPath);
13 if (!dir.exists()) { 13 if (!dir.exists()) {
14 dir.mkdir(MBOXPath); 14 dir.mkdir(MBOXPath);
15 } 15 }
16} 16}
17 17
18MBOXwrapper::~MBOXwrapper() 18MBOXwrapper::~MBOXwrapper()
19{ 19{
20} 20}
21 21
22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
23{ 23{
24 mailstorage*storage = mailstorage_new(NULL); 24 mailstorage*storage = mailstorage_new(NULL);
25 QString p = MBOXPath+"/"; 25 QString p = MBOXPath+"/";
26 p+=mailbox; 26 p+=mailbox;
27 27
28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
29 mailfolder*folder; 29 mailfolder*folder;
30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
31 r = mailfolder_connect(folder); 31 r = mailfolder_connect(folder);
32 if (r != MAIL_NO_ERROR) { 32 if (r != MAIL_NO_ERROR) {
33 qDebug("Error initializing mbox"); 33 qDebug("Error initializing mbox");
34 mailfolder_free(folder); 34 mailfolder_free(folder);
35 mailstorage_free(storage); 35 mailstorage_free(storage);
36 return; 36 return;
37 } 37 }
38 mailmessage_list * env_list = 0; 38
39 r = mailsession_get_messages_list(folder->fld_session,&env_list); 39 parseList(target,folder->fld_session,mailbox);
40 if (r != MAIL_NO_ERROR) { 40
41 qDebug("Error message list");
42 mailfolder_free(folder);
43 mailstorage_free(storage);
44 return;
45 }
46 r = mailsession_get_envelopes_list(folder->fld_session, env_list);
47 if (r != MAIL_NO_ERROR) {
48 qDebug("Error filling message list");
49 if (env_list) {
50 mailmessage_list_free(env_list);
51 }
52 mailfolder_free(folder);
53 mailstorage_free(storage);
54 return;
55 }
56 mailimf_references * refs;
57
58 uint32_t i = 0;
59 for(; i < carray_count(env_list->msg_tab) ; ++i) {
60 mailmessage * msg;
61 QBitArray mFlags(7);
62 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
63 if (msg->msg_fields == NULL) {
64 qDebug("could not fetch envelope of message %i", i);
65 continue;
66 }
67 RecMail * mail = new RecMail();
68 mail->setWrapper(this);
69 mail_flags * flag_result = 0;
70 r = mailmessage_get_flags(msg,&flag_result);
71 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
72 mFlags.setBit(FLAG_SEEN);
73 }
74 mailimf_single_fields single_fields;
75 mailimf_single_fields_init(&single_fields, msg->msg_fields);
76 mail->setMsgsize(msg->msg_size);
77 mail->setFlags(mFlags);
78 mail->setMbox(mailbox);
79 mail->setNumber(i+1);
80 if (single_fields.fld_subject)
81 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
82 if (single_fields.fld_from)
83 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
84 if (single_fields.fld_to)
85 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
86 if (single_fields.fld_cc)
87 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
88 if (single_fields.fld_bcc)
89 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
90 if (single_fields.fld_orig_date)
91 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
92 if (single_fields.fld_message_id->mid_value)
93 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
94 refs = single_fields.fld_references;
95 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
96 char * text = (char*)refs->mid_list->first->data;
97 mail->setReplyto(QString(text));
98 }
99
100 target.append(mail);
101 }
102 if (env_list) {
103 mailmessage_list_free(env_list);
104 }
105 mailfolder_disconnect(folder); 41 mailfolder_disconnect(folder);
106 mailfolder_free(folder); 42 mailfolder_free(folder);
107 mailstorage_free(storage); 43 mailstorage_free(storage);
108 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); 44 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
109} 45}
110 46
111QList<Folder>* MBOXwrapper::listFolders() 47QList<Folder>* MBOXwrapper::listFolders()
112{ 48{
113 QList<Folder> * folders = new QList<Folder>(); 49 QList<Folder> * folders = new QList<Folder>();
114 folders->setAutoDelete( false ); 50 folders->setAutoDelete( false );
115 QDir dir(MBOXPath); 51 QDir dir(MBOXPath);
116 if (!dir.exists()) return folders; 52 if (!dir.exists()) return folders;
117 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 53 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
118 QStringList entries = dir.entryList(); 54 QStringList entries = dir.entryList();
119 QStringList::ConstIterator it = entries.begin(); 55 QStringList::ConstIterator it = entries.begin();
120 for (;it!=entries.end();++it) { 56 for (;it!=entries.end();++it) {
121 Folder*inb=new Folder(*it,"/"); 57 Folder*inb=new Folder(*it,"/");
122 folders->append(inb); 58 folders->append(inb);
123 } 59 }
124 return folders; 60 return folders;
125} 61}
126 62
127void MBOXwrapper::deleteMail(const RecMail&mail) 63void MBOXwrapper::deleteMail(const RecMail&mail)
128{ 64{
129 mailstorage*storage = mailstorage_new(NULL); 65 mailstorage*storage = mailstorage_new(NULL);
130 QString p = MBOXPath+"/"; 66 QString p = MBOXPath+"/";
131 p+=mail.getMbox(); 67 p+=mail.getMbox();
132 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 68 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
133 mailfolder*folder; 69 mailfolder*folder;
134 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 70 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
135 r = mailfolder_connect(folder); 71 r = mailfolder_connect(folder);
136 if (r != MAIL_NO_ERROR) { 72 if (r != MAIL_NO_ERROR) {
137 qDebug("Error initializing mbox"); 73 qDebug("Error initializing mbox");
138 mailfolder_free(folder); 74 mailfolder_free(folder);
139 mailstorage_free(storage); 75 mailstorage_free(storage);
140 return; 76 return;
141 } 77 }
142 r = mailsession_remove_message(folder->fld_session,mail.getNumber()); 78 r = mailsession_remove_message(folder->fld_session,mail.getNumber());
143 if (r != MAIL_NO_ERROR) { 79 if (r != MAIL_NO_ERROR) {
144 qDebug("error deleting mail"); 80 qDebug("error deleting mail");
145 } 81 }
146 mailfolder_free(folder); 82 mailfolder_free(folder);
147 mailstorage_free(storage); 83 mailstorage_free(storage);
148} 84}
149 85
150void MBOXwrapper::answeredMail(const RecMail&) 86void MBOXwrapper::answeredMail(const RecMail&)
151{ 87{
152} 88}
153 89
154RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 90RecBody MBOXwrapper::fetchBody( const RecMail &mail )
155{ 91{
156 RecBody body; 92 RecBody body;
157 mailstorage*storage = mailstorage_new(NULL); 93 mailstorage*storage = mailstorage_new(NULL);
158 QString p = MBOXPath+"/"; 94 QString p = MBOXPath+"/";
159 p+=mail.getMbox(); 95 p+=mail.getMbox();
160 mailmessage * msg; 96 mailmessage * msg;
161 char*data=0; 97 char*data=0;
162 size_t size; 98 size_t size;
163 99
164 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 100 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
165 mailfolder*folder; 101 mailfolder*folder;
166 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 102 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
167 r = mailfolder_connect(folder); 103 r = mailfolder_connect(folder);
168 if (r != MAIL_NO_ERROR) { 104 if (r != MAIL_NO_ERROR) {
169 qDebug("Error initializing mbox"); 105 qDebug("Error initializing mbox");
170 mailfolder_free(folder); 106 mailfolder_free(folder);
171 mailstorage_free(storage); 107 mailstorage_free(storage);
172 return body; 108 return body;
173 } 109 }
174 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 110 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
175 if (r != MAIL_NO_ERROR) { 111 if (r != MAIL_NO_ERROR) {
176 qDebug("Error fetching mail %i",mail.getNumber()); 112 qDebug("Error fetching mail %i",mail.getNumber());
177 mailfolder_free(folder); 113 mailfolder_free(folder);
178 mailstorage_free(storage); 114 mailstorage_free(storage);
179 return body; 115 return body;
180 } 116 }
181 r = mailmessage_fetch(msg,&data,&size); 117 r = mailmessage_fetch(msg,&data,&size);
182 if (r != MAIL_NO_ERROR) { 118 if (r != MAIL_NO_ERROR) {
183 qDebug("Error fetching mail %i",mail.getNumber()); 119 qDebug("Error fetching mail %i",mail.getNumber());
184 mailfolder_free(folder); 120 mailfolder_free(folder);
185 mailstorage_free(storage); 121 mailstorage_free(storage);
186 mailmessage_free(msg); 122 mailmessage_free(msg);
187 return body; 123 return body;
188 } 124 }
189 body = parseMail(msg); 125 body = parseMail(msg);
190 mailmessage_fetch_result_free(msg,data); 126 mailmessage_fetch_result_free(msg,data);
191 mailfolder_free(folder); 127 mailfolder_free(folder);
192 mailstorage_free(storage); 128 mailstorage_free(storage);
193 129
194 return body; 130 return body;
195} 131}
196 132
197void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 133void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
198{ 134{
199 qDebug("MBOX %i von %i",current,maximum); 135 qDebug("MBOX %i von %i",current,maximum);
200} 136}
201 137
202int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) 138int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
203{ 139{
204 QString p = MBOXPath+"/"; 140 QString p = MBOXPath+"/";
205 p+=folder; 141 p+=folder;
206 QFileInfo fi(p); 142 QFileInfo fi(p);
207 if (fi.exists()) { 143 if (fi.exists()) {
208 Global::statusMessage(tr("Mailbox exists.")); 144 Global::statusMessage(tr("Mailbox exists."));
209 return 0; 145 return 0;
210 } 146 }
211 mailmbox_folder*f = 0; 147 mailmbox_folder*f = 0;
212 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 148 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
213 Global::statusMessage(tr("Error init folder")); 149 Global::statusMessage(tr("Error init folder"));
214 return 0; 150 return 0;
215 } 151 }
216 if (f) mailmbox_done(f); 152 if (f) mailmbox_done(f);
217 return 1; 153 return 1;
218} 154}
219 155
220void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 156void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
221{ 157{
222 QString p = MBOXPath+"/"; 158 QString p = MBOXPath+"/";
223 p+=folder; 159 p+=folder;
224 mailmbox_folder*f = 0; 160 mailmbox_folder*f = 0;
225 int r = mailmbox_init(p.latin1(),0,1,0,&f); 161 int r = mailmbox_init(p.latin1(),0,1,0,&f);
226 if (r != MAIL_NO_ERROR) { 162 if (r != MAIL_NO_ERROR) {
227 Global::statusMessage(tr("Error init folder")); 163 Global::statusMessage(tr("Error init folder"));
228 return; 164 return;
229 } 165 }
230 r = mailmbox_append_message(f,msg,length); 166 r = mailmbox_append_message(f,msg,length);
231 if (r != MAIL_NO_ERROR) { 167 if (r != MAIL_NO_ERROR) {
232 Global::statusMessage(tr("Error writing to message folder")); 168 Global::statusMessage(tr("Error writing to message folder"));
233 } 169 }
234 mailmbox_done(f); 170 mailmbox_done(f);
235} 171}
236 172
237void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 173void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
238{ 174{
239 RecBody body; 175 RecBody body;
240 mailstorage*storage = mailstorage_new(NULL); 176 mailstorage*storage = mailstorage_new(NULL);
241 QString p = MBOXPath+"/"; 177 QString p = MBOXPath+"/";
242 p+=mail.getMbox(); 178 p+=mail.getMbox();
243 mailmessage * msg; 179 mailmessage * msg;
244 char*data=0; 180 char*data=0;
245 size_t size; 181 size_t size;
246 182
247 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 183 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
248 mailfolder*folder; 184 mailfolder*folder;
249 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 185 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
250 r = mailfolder_connect(folder); 186 r = mailfolder_connect(folder);
251 if (r != MAIL_NO_ERROR) { 187 if (r != MAIL_NO_ERROR) {
252 Global::statusMessage(tr("Error initializing mbox")); 188 Global::statusMessage(tr("Error initializing mbox"));
253 mailfolder_free(folder); 189 mailfolder_free(folder);
254 mailstorage_free(storage); 190 mailstorage_free(storage);
255 return; 191 return;
256 } 192 }
257 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 193 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
258 if (r != MAIL_NO_ERROR) { 194 if (r != MAIL_NO_ERROR) {
259 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 195 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
260 mailfolder_free(folder); 196 mailfolder_free(folder);
261 mailstorage_free(storage); 197 mailstorage_free(storage);
262 return; 198 return;
263 } 199 }
264 r = mailmessage_fetch(msg,&data,&size); 200 r = mailmessage_fetch(msg,&data,&size);
265 if (r != MAIL_NO_ERROR) { 201 if (r != MAIL_NO_ERROR) {
266 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 202 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
267 mailfolder_free(folder); 203 mailfolder_free(folder);
268 mailstorage_free(storage); 204 mailstorage_free(storage);
269 mailmessage_free(msg); 205 mailmessage_free(msg);
270 return; 206 return;
271 } 207 }
272 *target = data; 208 *target = data;
273 *length = size; 209 *length = size;
274 mailfolder_free(folder); 210 mailfolder_free(folder);
275 mailstorage_free(storage); 211 mailstorage_free(storage);
276 mailmessage_free(msg); 212 mailmessage_free(msg);
277} 213}
278 214
279void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 215void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
280{ 216{
281 QString p = MBOXPath+"/"; 217 QString p = MBOXPath+"/";
282 p+=mailbox; 218 p+=mailbox;
283 mailmbox_folder*f = 0; 219 mailmbox_folder*f = 0;
284 int r = mailmbox_init(p.latin1(),0,1,0,&f); 220 int r = mailmbox_init(p.latin1(),0,1,0,&f);
285 if (r != MAIL_NO_ERROR) { 221 if (r != MAIL_NO_ERROR) {
286 qDebug("Error init folder"); 222 qDebug("Error init folder");
287 return; 223 return;
288 } 224 }
289 deleteMails(f,target); 225 deleteMails(f,target);
290 mailmbox_done(f); 226 mailmbox_done(f);
291} 227}
292 228
293void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) 229void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
294{ 230{
295 if (!f) return; 231 if (!f) return;
296 int r; 232 int r;
297 for (unsigned int i=0; i < target.count();++i) { 233 for (unsigned int i=0; i < target.count();++i) {
298 r = mailmbox_delete_msg(f,target.at(i)->getNumber()); 234 r = mailmbox_delete_msg(f,target.at(i)->getNumber());
299 if (r!=MAILMBOX_NO_ERROR) { 235 if (r!=MAILMBOX_NO_ERROR) {
300 qDebug("error delete mail"); 236 qDebug("error delete mail");
301 } 237 }
302 } 238 }
303 r = mailmbox_expunge(f); 239 r = mailmbox_expunge(f);
304 if (r != MAILMBOX_NO_ERROR) { 240 if (r != MAILMBOX_NO_ERROR) {
305 qDebug("error expunge mailbox"); 241 qDebug("error expunge mailbox");
306 } 242 }
307} 243}
308 244
309int MBOXwrapper::deleteAllMail(const Folder*tfolder) 245int MBOXwrapper::deleteAllMail(const Folder*tfolder)
310{ 246{
311 if (!tfolder) return 0; 247 if (!tfolder) return 0;
312 QString p = MBOXPath+tfolder->getDisplayName(); 248 QString p = MBOXPath+tfolder->getDisplayName();
313 int res = 1; 249 int res = 1;
314 250
315 mailfolder*folder = 0; 251 mailfolder*folder = 0;
316 mailmessage_list*l=0; 252 mailmessage_list*l=0;
317 mailstorage*storage = mailstorage_new(NULL); 253 mailstorage*storage = mailstorage_new(NULL);
318 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 254 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
319 if (r != MAIL_NO_ERROR) { 255 if (r != MAIL_NO_ERROR) {
320 Global::statusMessage(tr("Error initializing mbox")); 256 Global::statusMessage(tr("Error initializing mbox"));
321 res = 0; 257 res = 0;
322 } 258 }
323 if (res) { 259 if (res) {
324 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 260 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
325 r = mailfolder_connect(folder); 261 r = mailfolder_connect(folder);
326 if (r != MAIL_NO_ERROR) { 262 if (r != MAIL_NO_ERROR) {
327 Global::statusMessage(tr("Error initializing mbox")); 263 Global::statusMessage(tr("Error initializing mbox"));
328 res = 0; 264 res = 0;
329 } 265 }
330 } 266 }
331 if (res) { 267 if (res) {
332 r = mailsession_get_messages_list(folder->fld_session,&l); 268 r = mailsession_get_messages_list(folder->fld_session,&l);
333 if (r != MAIL_NO_ERROR) { 269 if (r != MAIL_NO_ERROR) {
334 qDebug("Error message list"); 270 qDebug("Error message list");
335 res=0; 271 res=0;
336 } 272 }
337 } 273 }
338 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 274 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
339 r = mailsession_remove_message(folder->fld_session,i+1); 275 r = mailsession_remove_message(folder->fld_session,i+1);
340 if (r != MAIL_NO_ERROR) { 276 if (r != MAIL_NO_ERROR) {
341 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 277 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
342 res = 0; 278 res = 0;
343 break; 279 break;
344 } 280 }
345 } 281 }
346 if (l) mailmessage_list_free(l); 282 if (l) mailmessage_list_free(l);
347 if (folder) mailfolder_free(folder); 283 if (folder) mailfolder_free(folder);
348 if (storage) mailstorage_free(storage); 284 if (storage) mailstorage_free(storage);
349 return res; 285 return res;
350} 286}
351 287
352int MBOXwrapper::deleteMbox(const Folder*tfolder) 288int MBOXwrapper::deleteMbox(const Folder*tfolder)
353{ 289{
354 if (!tfolder) return 0; 290 if (!tfolder) return 0;
355 QString p = MBOXPath+tfolder->getDisplayName(); 291 QString p = MBOXPath+tfolder->getDisplayName();
356 QFile fi(p); 292 QFile fi(p);
357 if (!fi.exists()) { 293 if (!fi.exists()) {
358 Global::statusMessage(tr("Mailbox doesn't exist.")); 294 Global::statusMessage(tr("Mailbox doesn't exist."));
359 return 0; 295 return 0;
360 } 296 }
361 if (!fi.remove()) { 297 if (!fi.remove()) {
362 Global::statusMessage(tr("Error deleting Mailbox.")); 298 Global::statusMessage(tr("Error deleting Mailbox."));
363 return 0; 299 return 0;
364 } 300 }
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 2e70dee..de90dd1 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,254 +1,218 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h>
8 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 : Genericwrapper() 14 : Genericwrapper()
14{ 15{
15 account = a; 16 account = a;
16 m_pop3 = NULL; 17 m_pop3 = NULL;
18 m_folder = NULL;
17 msgTempName = a->getFileName()+"_msg_cache"; 19 msgTempName = a->getFileName()+"_msg_cache";
18 last_msg_id = 0; 20 last_msg_id = 0;
19} 21}
20 22
21POP3wrapper::~POP3wrapper() 23POP3wrapper::~POP3wrapper()
22{ 24{
23 logout(); 25 logout();
24 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
25 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
26 msg_cache.remove(); 28 msg_cache.remove();
27 } 29 }
28} 30}
29 31
30void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
31{ 33{
32 //qDebug( "POP3: %i of %i", current, maximum ); 34 qDebug( "POP3: %i of %i", current, maximum );
33} 35}
34 36
35RecBody POP3wrapper::fetchBody( const RecMail &mail ) 37RecBody POP3wrapper::fetchBody( const RecMail &mail )
36{ 38{
37 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
38 char *message; 40 char *message = 0;
39 size_t length = 0; 41 size_t length = 0;
40 42
41 login(); 43 login();
42 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
43 return RecBody(); 45 return RecBody();
44 } 46 }
45 47
46 RecBody body; 48 RecBody body;
47 mailmessage * msg = 0; 49 mailmessage * mailmsg;
48
49 QFile msg_cache(msgTempName);
50
51 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
52 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
53 return body; 52 return body;
54 } 53 }
54
55 QFile msg_cache(msgTempName);
56
55 cleanMimeCache(); 57 cleanMimeCache();
58
56 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
57 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
58 msg_cache.remove(); 61 msg_cache.remove();
59 } 62 }
60 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
61 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
62 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
63 if ( err != MAILPOP3_NO_ERROR ) { 66 err = mailmessage_fetch(mailmsg,&message,&length);
64 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
65 last_msg_id = 0;
66 return RecBody();
67 }
68 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
69 } else { 68 } else {
70 QString msg=""; 69 QString msg="";
71 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
72 message = new char[4096]; 71 message = new char[4096];
73 memset(message,0,4096); 72 memset(message,0,4096);
74 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
75 msg+=message; 74 msg+=message;
76 memset(message,0,4096); 75 memset(message,0,4096);
77 } 76 }
78 delete message; 77 delete message;
79 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
80 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
81 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message);
82 } 89 }
90 body = parseMail(mailmsg);
83 91
84 /* transform to libetpan stuff */
85 msg = mailmessage_new();
86 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
87 generic_message_t * msg_data;
88 msg_data = (generic_message_t *)msg->msg_data;
89 msg_data->msg_fetched = 1;
90 msg_data->msg_message = message;
91 msg_data->msg_length = strlen(message);
92
93 /* parse the mail */
94 body = parseMail(msg);
95
96 /* clean up */ 92 /* clean up */
97 mailmessage_free(msg); 93 if (mailmsg) mailmessage_free(mailmsg);
98 free(message); 94 if (message) free(message);
99 95
100 /* finish */
101 return body; 96 return body;
102} 97}
103 98
104void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
105{ 100{
106 int err = MAILPOP3_NO_ERROR;
107 char * header = 0;
108 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
109 size_t length = 0;
110 carray * messages = 0;
111
112 login(); 101 login();
113 if (!m_pop3) return; 102 if (!m_pop3) return;
114 103 uint32_t res_messages,res_recent,res_unseen;
115 mailpop3_list( m_pop3, &messages ); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
116 105 parseList(target,m_folder->fld_session,"INBOX");
117 for (unsigned int i = 0; i < carray_count(messages);++i) { 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
118 mailpop3_msg_info *info;
119 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
120 if (info->msg_deleted)
121 continue;
122 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
123 if ( err != MAILPOP3_NO_ERROR ) {
124 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
125 free(header);
126 return;
127 }
128 RecMail *mail = parseHeader( header );
129 mail->setNumber( info->msg_index );
130 mail->setWrapper(this);
131 mail->setMsgsize(info->msg_size);
132 target.append( mail );
133 free(header);
134 }
135 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count));
136} 107}
137 108
138void POP3wrapper::login() 109void POP3wrapper::login()
139{ 110{
140 /* we'll hold the line */ 111 /* we'll hold the line */
141 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
142 113
143 const char *server, *user, *pass; 114 const char *server, *user, *pass;
144 uint16_t port; 115 uint16_t port;
145 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
146 117
147 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
148 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
149 120
150 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
151 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
152 login.show(); 123 login.show();
153 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
154 // ok 125 // ok
155 user = strdup( login.getUser().latin1() ); 126 user = login.getUser().latin1();
156 pass = strdup( login.getPassword().latin1() ); 127 pass = login.getPassword().latin1();
157 } else { 128 } else {
158 // cancel 129 // cancel
159 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
160 return; 131 return;
161 } 132 }
162 } else { 133 } else {
163 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
164 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
165 } 136 }
166 137
167 m_pop3 = mailpop3_new( 200, &pop3_progress ); 138 bool ssl = account->getSSL();
168 139
169 // connect 140 m_pop3=mailstorage_new(NULL);
170 if (account->getSSL()) { 141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
171 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 142 (char*)user,(char*)pass,0,0,0);
172 } else { 143
173 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
174 }
175 145
176 if ( err != MAILPOP3_NO_ERROR ) { 146 if (m_folder==0) {
177 qDebug( "pop3: error connecting to %s\n reason: %s", server, 147 Global::statusMessage(tr("Error initializing folder"));
178 m_pop3->pop3_response ); 148 mailstorage_free(m_pop3);
179 mailpop3_free( m_pop3 );
180 m_pop3 = NULL; 149 m_pop3 = NULL;
181 return; 150 return;
182 } 151 }
183 qDebug( "POP3: connected!" ); 152 err = mailfolder_connect(m_folder);
184 153 if (err != MAIL_NO_ERROR) {
185 // login 154 Global::statusMessage(tr("Error initializing folder"));
186 // TODO: decide if apop or plain login should be used 155 mailfolder_free(m_folder);
187 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 156 m_folder = 0;
188 if ( err != MAILPOP3_NO_ERROR ) { 157 mailstorage_free(m_pop3);
189 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 158 m_pop3 = 0;
190 logout();
191 return;
192 } 159 }
193
194 qDebug( "POP3: logged in!" ); 160 qDebug( "POP3: logged in!" );
195} 161}
196 162
197void POP3wrapper::logout() 163void POP3wrapper::logout()
198{ 164{
199 int err = MAILPOP3_NO_ERROR; 165 int err = MAILPOP3_NO_ERROR;
200 if ( m_pop3 == NULL ) return; 166 if ( m_pop3 == NULL ) return;
201 err = mailpop3_quit( m_pop3 ); 167 mailfolder_free(m_folder);
202 mailpop3_free( m_pop3 ); 168 m_folder = 0;
203 m_pop3 = NULL; 169 mailstorage_free(m_pop3);
170 m_pop3 = 0;
204} 171}
205 172
206 173
207QList<Folder>* POP3wrapper::listFolders() 174QList<Folder>* POP3wrapper::listFolders()
208{ 175{
209 QList<Folder> * folders = new QList<Folder>(); 176 QList<Folder> * folders = new QList<Folder>();
210 folders->setAutoDelete( false ); 177 folders->setAutoDelete( false );
211 Folder*inb=new Folder("INBOX","/"); 178 Folder*inb=new Folder("INBOX","/");
212 folders->append(inb); 179 folders->append(inb);
213 return folders; 180 return folders;
214} 181}
215 182
216void POP3wrapper::deleteMail(const RecMail&mail) 183void POP3wrapper::deleteMail(const RecMail&mail)
217{ 184{
218 login(); 185 login();
219 if (!m_pop3) return; 186 if (!m_pop3) return;
220 int err = mailpop3_dele(m_pop3,mail.getNumber()); 187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
221 if (err != MAILPOP3_NO_ERROR) { 188 if (err != MAIL_NO_ERROR) {
222 Global::statusMessage(tr("error deleting mail")); 189 Global::statusMessage(tr("error deleting mail"));
223 } 190 }
224} 191}
225 192
226void POP3wrapper::answeredMail(const RecMail&) 193void POP3wrapper::answeredMail(const RecMail&)
227{ 194{
228} 195}
229 196
230int POP3wrapper::deleteAllMail(const Folder*) 197int POP3wrapper::deleteAllMail(const Folder*)
231{ 198{
232 login(); 199 login();
233 if (!m_pop3) return 0; 200 if (!m_pop3) return 0;
234 carray * messages = 0;
235
236 /* if connected this info is cached! */
237 int err = 0;
238 mailpop3_list( m_pop3, &messages );
239
240 int res = 1; 201 int res = 1;
241 for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { 202
242 mailpop3_msg_info *info; 203 uint32_t result = 0;
243 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
244 if (info->msg_deleted) 205 if (err != MAIL_NO_ERROR) {
245 continue; 206 Global::statusMessage(tr("Error getting folder info"));
246 err = mailpop3_dele(m_pop3,i+1); 207 return 0;
247 if (err != MAILPOP3_NO_ERROR) { 208 }
209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) {
248 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
249 res = 0; 213 res=0;
250 break;
251 } 214 }
252 } 215 break;
216 }
253 return res; 217 return res;
254} 218}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 2efffdd..b3a42be 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,34 +1,37 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8struct mailstorage;
9struct mailfolder;
8 10
9class POP3wrapper : public Genericwrapper 11class POP3wrapper : public Genericwrapper
10{ 12{
11 Q_OBJECT 13 Q_OBJECT
12 14
13public: 15public:
14 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
15 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
16 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
18 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
19 21
20 virtual void deleteMail(const RecMail&mail); 22 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 23 virtual void answeredMail(const RecMail&mail);
22 virtual int deleteAllMail(const Folder*); 24 virtual int deleteAllMail(const Folder*);
23 25
24 virtual RecBody fetchBody( const RecMail &mail ); 26 virtual RecBody fetchBody( const RecMail &mail );
25 static void pop3_progress( size_t current, size_t maximum ); 27 static void pop3_progress( size_t current, size_t maximum );
26 28
27protected: 29protected:
28 void login(); 30 void login();
29 void logout(); 31 void logout();
30 POP3account *account; 32 POP3account *account;
31 mailpop3 *m_pop3; 33 mailstorage*m_pop3;
34 mailfolder*m_folder;
32}; 35};
33 36
34#endif 37#endif
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp
index 162a0c9..0aa33dd 100644
--- a/noncore/net/mail/mboxwrapper.cpp
+++ b/noncore/net/mail/mboxwrapper.cpp
@@ -1,364 +1,300 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9MBOXwrapper::MBOXwrapper(const QString & mbox_dir) 9MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
10 : Genericwrapper(),MBOXPath(mbox_dir) 10 : Genericwrapper(),MBOXPath(mbox_dir)
11{ 11{
12 QDir dir(MBOXPath); 12 QDir dir(MBOXPath);
13 if (!dir.exists()) { 13 if (!dir.exists()) {
14 dir.mkdir(MBOXPath); 14 dir.mkdir(MBOXPath);
15 } 15 }
16} 16}
17 17
18MBOXwrapper::~MBOXwrapper() 18MBOXwrapper::~MBOXwrapper()
19{ 19{
20} 20}
21 21
22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 22void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
23{ 23{
24 mailstorage*storage = mailstorage_new(NULL); 24 mailstorage*storage = mailstorage_new(NULL);
25 QString p = MBOXPath+"/"; 25 QString p = MBOXPath+"/";
26 p+=mailbox; 26 p+=mailbox;
27 27
28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 28 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
29 mailfolder*folder; 29 mailfolder*folder;
30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 30 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
31 r = mailfolder_connect(folder); 31 r = mailfolder_connect(folder);
32 if (r != MAIL_NO_ERROR) { 32 if (r != MAIL_NO_ERROR) {
33 qDebug("Error initializing mbox"); 33 qDebug("Error initializing mbox");
34 mailfolder_free(folder); 34 mailfolder_free(folder);
35 mailstorage_free(storage); 35 mailstorage_free(storage);
36 return; 36 return;
37 } 37 }
38 mailmessage_list * env_list = 0; 38
39 r = mailsession_get_messages_list(folder->fld_session,&env_list); 39 parseList(target,folder->fld_session,mailbox);
40 if (r != MAIL_NO_ERROR) { 40
41 qDebug("Error message list");
42 mailfolder_free(folder);
43 mailstorage_free(storage);
44 return;
45 }
46 r = mailsession_get_envelopes_list(folder->fld_session, env_list);
47 if (r != MAIL_NO_ERROR) {
48 qDebug("Error filling message list");
49 if (env_list) {
50 mailmessage_list_free(env_list);
51 }
52 mailfolder_free(folder);
53 mailstorage_free(storage);
54 return;
55 }
56 mailimf_references * refs;
57
58 uint32_t i = 0;
59 for(; i < carray_count(env_list->msg_tab) ; ++i) {
60 mailmessage * msg;
61 QBitArray mFlags(7);
62 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
63 if (msg->msg_fields == NULL) {
64 qDebug("could not fetch envelope of message %i", i);
65 continue;
66 }
67 RecMail * mail = new RecMail();
68 mail->setWrapper(this);
69 mail_flags * flag_result = 0;
70 r = mailmessage_get_flags(msg,&flag_result);
71 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
72 mFlags.setBit(FLAG_SEEN);
73 }
74 mailimf_single_fields single_fields;
75 mailimf_single_fields_init(&single_fields, msg->msg_fields);
76 mail->setMsgsize(msg->msg_size);
77 mail->setFlags(mFlags);
78 mail->setMbox(mailbox);
79 mail->setNumber(i+1);
80 if (single_fields.fld_subject)
81 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
82 if (single_fields.fld_from)
83 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
84 if (single_fields.fld_to)
85 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
86 if (single_fields.fld_cc)
87 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
88 if (single_fields.fld_bcc)
89 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
90 if (single_fields.fld_orig_date)
91 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
92 if (single_fields.fld_message_id->mid_value)
93 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
94 refs = single_fields.fld_references;
95 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
96 char * text = (char*)refs->mid_list->first->data;
97 mail->setReplyto(QString(text));
98 }
99
100 target.append(mail);
101 }
102 if (env_list) {
103 mailmessage_list_free(env_list);
104 }
105 mailfolder_disconnect(folder); 41 mailfolder_disconnect(folder);
106 mailfolder_free(folder); 42 mailfolder_free(folder);
107 mailstorage_free(storage); 43 mailstorage_free(storage);
108 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); 44 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
109} 45}
110 46
111QList<Folder>* MBOXwrapper::listFolders() 47QList<Folder>* MBOXwrapper::listFolders()
112{ 48{
113 QList<Folder> * folders = new QList<Folder>(); 49 QList<Folder> * folders = new QList<Folder>();
114 folders->setAutoDelete( false ); 50 folders->setAutoDelete( false );
115 QDir dir(MBOXPath); 51 QDir dir(MBOXPath);
116 if (!dir.exists()) return folders; 52 if (!dir.exists()) return folders;
117 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 53 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
118 QStringList entries = dir.entryList(); 54 QStringList entries = dir.entryList();
119 QStringList::ConstIterator it = entries.begin(); 55 QStringList::ConstIterator it = entries.begin();
120 for (;it!=entries.end();++it) { 56 for (;it!=entries.end();++it) {
121 Folder*inb=new Folder(*it,"/"); 57 Folder*inb=new Folder(*it,"/");
122 folders->append(inb); 58 folders->append(inb);
123 } 59 }
124 return folders; 60 return folders;
125} 61}
126 62
127void MBOXwrapper::deleteMail(const RecMail&mail) 63void MBOXwrapper::deleteMail(const RecMail&mail)
128{ 64{
129 mailstorage*storage = mailstorage_new(NULL); 65 mailstorage*storage = mailstorage_new(NULL);
130 QString p = MBOXPath+"/"; 66 QString p = MBOXPath+"/";
131 p+=mail.getMbox(); 67 p+=mail.getMbox();
132 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 68 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
133 mailfolder*folder; 69 mailfolder*folder;
134 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 70 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
135 r = mailfolder_connect(folder); 71 r = mailfolder_connect(folder);
136 if (r != MAIL_NO_ERROR) { 72 if (r != MAIL_NO_ERROR) {
137 qDebug("Error initializing mbox"); 73 qDebug("Error initializing mbox");
138 mailfolder_free(folder); 74 mailfolder_free(folder);
139 mailstorage_free(storage); 75 mailstorage_free(storage);
140 return; 76 return;
141 } 77 }
142 r = mailsession_remove_message(folder->fld_session,mail.getNumber()); 78 r = mailsession_remove_message(folder->fld_session,mail.getNumber());
143 if (r != MAIL_NO_ERROR) { 79 if (r != MAIL_NO_ERROR) {
144 qDebug("error deleting mail"); 80 qDebug("error deleting mail");
145 } 81 }
146 mailfolder_free(folder); 82 mailfolder_free(folder);
147 mailstorage_free(storage); 83 mailstorage_free(storage);
148} 84}
149 85
150void MBOXwrapper::answeredMail(const RecMail&) 86void MBOXwrapper::answeredMail(const RecMail&)
151{ 87{
152} 88}
153 89
154RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 90RecBody MBOXwrapper::fetchBody( const RecMail &mail )
155{ 91{
156 RecBody body; 92 RecBody body;
157 mailstorage*storage = mailstorage_new(NULL); 93 mailstorage*storage = mailstorage_new(NULL);
158 QString p = MBOXPath+"/"; 94 QString p = MBOXPath+"/";
159 p+=mail.getMbox(); 95 p+=mail.getMbox();
160 mailmessage * msg; 96 mailmessage * msg;
161 char*data=0; 97 char*data=0;
162 size_t size; 98 size_t size;
163 99
164 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 100 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
165 mailfolder*folder; 101 mailfolder*folder;
166 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 102 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
167 r = mailfolder_connect(folder); 103 r = mailfolder_connect(folder);
168 if (r != MAIL_NO_ERROR) { 104 if (r != MAIL_NO_ERROR) {
169 qDebug("Error initializing mbox"); 105 qDebug("Error initializing mbox");
170 mailfolder_free(folder); 106 mailfolder_free(folder);
171 mailstorage_free(storage); 107 mailstorage_free(storage);
172 return body; 108 return body;
173 } 109 }
174 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 110 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
175 if (r != MAIL_NO_ERROR) { 111 if (r != MAIL_NO_ERROR) {
176 qDebug("Error fetching mail %i",mail.getNumber()); 112 qDebug("Error fetching mail %i",mail.getNumber());
177 mailfolder_free(folder); 113 mailfolder_free(folder);
178 mailstorage_free(storage); 114 mailstorage_free(storage);
179 return body; 115 return body;
180 } 116 }
181 r = mailmessage_fetch(msg,&data,&size); 117 r = mailmessage_fetch(msg,&data,&size);
182 if (r != MAIL_NO_ERROR) { 118 if (r != MAIL_NO_ERROR) {
183 qDebug("Error fetching mail %i",mail.getNumber()); 119 qDebug("Error fetching mail %i",mail.getNumber());
184 mailfolder_free(folder); 120 mailfolder_free(folder);
185 mailstorage_free(storage); 121 mailstorage_free(storage);
186 mailmessage_free(msg); 122 mailmessage_free(msg);
187 return body; 123 return body;
188 } 124 }
189 body = parseMail(msg); 125 body = parseMail(msg);
190 mailmessage_fetch_result_free(msg,data); 126 mailmessage_fetch_result_free(msg,data);
191 mailfolder_free(folder); 127 mailfolder_free(folder);
192 mailstorage_free(storage); 128 mailstorage_free(storage);
193 129
194 return body; 130 return body;
195} 131}
196 132
197void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 133void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
198{ 134{
199 qDebug("MBOX %i von %i",current,maximum); 135 qDebug("MBOX %i von %i",current,maximum);
200} 136}
201 137
202int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) 138int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
203{ 139{
204 QString p = MBOXPath+"/"; 140 QString p = MBOXPath+"/";
205 p+=folder; 141 p+=folder;
206 QFileInfo fi(p); 142 QFileInfo fi(p);
207 if (fi.exists()) { 143 if (fi.exists()) {
208 Global::statusMessage(tr("Mailbox exists.")); 144 Global::statusMessage(tr("Mailbox exists."));
209 return 0; 145 return 0;
210 } 146 }
211 mailmbox_folder*f = 0; 147 mailmbox_folder*f = 0;
212 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 148 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
213 Global::statusMessage(tr("Error init folder")); 149 Global::statusMessage(tr("Error init folder"));
214 return 0; 150 return 0;
215 } 151 }
216 if (f) mailmbox_done(f); 152 if (f) mailmbox_done(f);
217 return 1; 153 return 1;
218} 154}
219 155
220void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 156void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
221{ 157{
222 QString p = MBOXPath+"/"; 158 QString p = MBOXPath+"/";
223 p+=folder; 159 p+=folder;
224 mailmbox_folder*f = 0; 160 mailmbox_folder*f = 0;
225 int r = mailmbox_init(p.latin1(),0,1,0,&f); 161 int r = mailmbox_init(p.latin1(),0,1,0,&f);
226 if (r != MAIL_NO_ERROR) { 162 if (r != MAIL_NO_ERROR) {
227 Global::statusMessage(tr("Error init folder")); 163 Global::statusMessage(tr("Error init folder"));
228 return; 164 return;
229 } 165 }
230 r = mailmbox_append_message(f,msg,length); 166 r = mailmbox_append_message(f,msg,length);
231 if (r != MAIL_NO_ERROR) { 167 if (r != MAIL_NO_ERROR) {
232 Global::statusMessage(tr("Error writing to message folder")); 168 Global::statusMessage(tr("Error writing to message folder"));
233 } 169 }
234 mailmbox_done(f); 170 mailmbox_done(f);
235} 171}
236 172
237void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 173void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
238{ 174{
239 RecBody body; 175 RecBody body;
240 mailstorage*storage = mailstorage_new(NULL); 176 mailstorage*storage = mailstorage_new(NULL);
241 QString p = MBOXPath+"/"; 177 QString p = MBOXPath+"/";
242 p+=mail.getMbox(); 178 p+=mail.getMbox();
243 mailmessage * msg; 179 mailmessage * msg;
244 char*data=0; 180 char*data=0;
245 size_t size; 181 size_t size;
246 182
247 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 183 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
248 mailfolder*folder; 184 mailfolder*folder;
249 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 185 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
250 r = mailfolder_connect(folder); 186 r = mailfolder_connect(folder);
251 if (r != MAIL_NO_ERROR) { 187 if (r != MAIL_NO_ERROR) {
252 Global::statusMessage(tr("Error initializing mbox")); 188 Global::statusMessage(tr("Error initializing mbox"));
253 mailfolder_free(folder); 189 mailfolder_free(folder);
254 mailstorage_free(storage); 190 mailstorage_free(storage);
255 return; 191 return;
256 } 192 }
257 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); 193 r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
258 if (r != MAIL_NO_ERROR) { 194 if (r != MAIL_NO_ERROR) {
259 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 195 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
260 mailfolder_free(folder); 196 mailfolder_free(folder);
261 mailstorage_free(storage); 197 mailstorage_free(storage);
262 return; 198 return;
263 } 199 }
264 r = mailmessage_fetch(msg,&data,&size); 200 r = mailmessage_fetch(msg,&data,&size);
265 if (r != MAIL_NO_ERROR) { 201 if (r != MAIL_NO_ERROR) {
266 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 202 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
267 mailfolder_free(folder); 203 mailfolder_free(folder);
268 mailstorage_free(storage); 204 mailstorage_free(storage);
269 mailmessage_free(msg); 205 mailmessage_free(msg);
270 return; 206 return;
271 } 207 }
272 *target = data; 208 *target = data;
273 *length = size; 209 *length = size;
274 mailfolder_free(folder); 210 mailfolder_free(folder);
275 mailstorage_free(storage); 211 mailstorage_free(storage);
276 mailmessage_free(msg); 212 mailmessage_free(msg);
277} 213}
278 214
279void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 215void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
280{ 216{
281 QString p = MBOXPath+"/"; 217 QString p = MBOXPath+"/";
282 p+=mailbox; 218 p+=mailbox;
283 mailmbox_folder*f = 0; 219 mailmbox_folder*f = 0;
284 int r = mailmbox_init(p.latin1(),0,1,0,&f); 220 int r = mailmbox_init(p.latin1(),0,1,0,&f);
285 if (r != MAIL_NO_ERROR) { 221 if (r != MAIL_NO_ERROR) {
286 qDebug("Error init folder"); 222 qDebug("Error init folder");
287 return; 223 return;
288 } 224 }
289 deleteMails(f,target); 225 deleteMails(f,target);
290 mailmbox_done(f); 226 mailmbox_done(f);
291} 227}
292 228
293void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) 229void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
294{ 230{
295 if (!f) return; 231 if (!f) return;
296 int r; 232 int r;
297 for (unsigned int i=0; i < target.count();++i) { 233 for (unsigned int i=0; i < target.count();++i) {
298 r = mailmbox_delete_msg(f,target.at(i)->getNumber()); 234 r = mailmbox_delete_msg(f,target.at(i)->getNumber());
299 if (r!=MAILMBOX_NO_ERROR) { 235 if (r!=MAILMBOX_NO_ERROR) {
300 qDebug("error delete mail"); 236 qDebug("error delete mail");
301 } 237 }
302 } 238 }
303 r = mailmbox_expunge(f); 239 r = mailmbox_expunge(f);
304 if (r != MAILMBOX_NO_ERROR) { 240 if (r != MAILMBOX_NO_ERROR) {
305 qDebug("error expunge mailbox"); 241 qDebug("error expunge mailbox");
306 } 242 }
307} 243}
308 244
309int MBOXwrapper::deleteAllMail(const Folder*tfolder) 245int MBOXwrapper::deleteAllMail(const Folder*tfolder)
310{ 246{
311 if (!tfolder) return 0; 247 if (!tfolder) return 0;
312 QString p = MBOXPath+tfolder->getDisplayName(); 248 QString p = MBOXPath+tfolder->getDisplayName();
313 int res = 1; 249 int res = 1;
314 250
315 mailfolder*folder = 0; 251 mailfolder*folder = 0;
316 mailmessage_list*l=0; 252 mailmessage_list*l=0;
317 mailstorage*storage = mailstorage_new(NULL); 253 mailstorage*storage = mailstorage_new(NULL);
318 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 254 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
319 if (r != MAIL_NO_ERROR) { 255 if (r != MAIL_NO_ERROR) {
320 Global::statusMessage(tr("Error initializing mbox")); 256 Global::statusMessage(tr("Error initializing mbox"));
321 res = 0; 257 res = 0;
322 } 258 }
323 if (res) { 259 if (res) {
324 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 260 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
325 r = mailfolder_connect(folder); 261 r = mailfolder_connect(folder);
326 if (r != MAIL_NO_ERROR) { 262 if (r != MAIL_NO_ERROR) {
327 Global::statusMessage(tr("Error initializing mbox")); 263 Global::statusMessage(tr("Error initializing mbox"));
328 res = 0; 264 res = 0;
329 } 265 }
330 } 266 }
331 if (res) { 267 if (res) {
332 r = mailsession_get_messages_list(folder->fld_session,&l); 268 r = mailsession_get_messages_list(folder->fld_session,&l);
333 if (r != MAIL_NO_ERROR) { 269 if (r != MAIL_NO_ERROR) {
334 qDebug("Error message list"); 270 qDebug("Error message list");
335 res=0; 271 res=0;
336 } 272 }
337 } 273 }
338 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 274 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
339 r = mailsession_remove_message(folder->fld_session,i+1); 275 r = mailsession_remove_message(folder->fld_session,i+1);
340 if (r != MAIL_NO_ERROR) { 276 if (r != MAIL_NO_ERROR) {
341 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 277 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
342 res = 0; 278 res = 0;
343 break; 279 break;
344 } 280 }
345 } 281 }
346 if (l) mailmessage_list_free(l); 282 if (l) mailmessage_list_free(l);
347 if (folder) mailfolder_free(folder); 283 if (folder) mailfolder_free(folder);
348 if (storage) mailstorage_free(storage); 284 if (storage) mailstorage_free(storage);
349 return res; 285 return res;
350} 286}
351 287
352int MBOXwrapper::deleteMbox(const Folder*tfolder) 288int MBOXwrapper::deleteMbox(const Folder*tfolder)
353{ 289{
354 if (!tfolder) return 0; 290 if (!tfolder) return 0;
355 QString p = MBOXPath+tfolder->getDisplayName(); 291 QString p = MBOXPath+tfolder->getDisplayName();
356 QFile fi(p); 292 QFile fi(p);
357 if (!fi.exists()) { 293 if (!fi.exists()) {
358 Global::statusMessage(tr("Mailbox doesn't exist.")); 294 Global::statusMessage(tr("Mailbox doesn't exist."));
359 return 0; 295 return 0;
360 } 296 }
361 if (!fi.remove()) { 297 if (!fi.remove()) {
362 Global::statusMessage(tr("Error deleting Mailbox.")); 298 Global::statusMessage(tr("Error deleting Mailbox."));
363 return 0; 299 return 0;
364 } 300 }
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 2e70dee..de90dd1 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,254 +1,218 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h>
8 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 : Genericwrapper() 14 : Genericwrapper()
14{ 15{
15 account = a; 16 account = a;
16 m_pop3 = NULL; 17 m_pop3 = NULL;
18 m_folder = NULL;
17 msgTempName = a->getFileName()+"_msg_cache"; 19 msgTempName = a->getFileName()+"_msg_cache";
18 last_msg_id = 0; 20 last_msg_id = 0;
19} 21}
20 22
21POP3wrapper::~POP3wrapper() 23POP3wrapper::~POP3wrapper()
22{ 24{
23 logout(); 25 logout();
24 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
25 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
26 msg_cache.remove(); 28 msg_cache.remove();
27 } 29 }
28} 30}
29 31
30void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
31{ 33{
32 //qDebug( "POP3: %i of %i", current, maximum ); 34 qDebug( "POP3: %i of %i", current, maximum );
33} 35}
34 36
35RecBody POP3wrapper::fetchBody( const RecMail &mail ) 37RecBody POP3wrapper::fetchBody( const RecMail &mail )
36{ 38{
37 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
38 char *message; 40 char *message = 0;
39 size_t length = 0; 41 size_t length = 0;
40 42
41 login(); 43 login();
42 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
43 return RecBody(); 45 return RecBody();
44 } 46 }
45 47
46 RecBody body; 48 RecBody body;
47 mailmessage * msg = 0; 49 mailmessage * mailmsg;
48
49 QFile msg_cache(msgTempName);
50
51 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
52 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
53 return body; 52 return body;
54 } 53 }
54
55 QFile msg_cache(msgTempName);
56
55 cleanMimeCache(); 57 cleanMimeCache();
58
56 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
57 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
58 msg_cache.remove(); 61 msg_cache.remove();
59 } 62 }
60 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
61 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
62 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
63 if ( err != MAILPOP3_NO_ERROR ) { 66 err = mailmessage_fetch(mailmsg,&message,&length);
64 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
65 last_msg_id = 0;
66 return RecBody();
67 }
68 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
69 } else { 68 } else {
70 QString msg=""; 69 QString msg="";
71 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
72 message = new char[4096]; 71 message = new char[4096];
73 memset(message,0,4096); 72 memset(message,0,4096);
74 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
75 msg+=message; 74 msg+=message;
76 memset(message,0,4096); 75 memset(message,0,4096);
77 } 76 }
78 delete message; 77 delete message;
79 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
80 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
81 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message);
82 } 89 }
90 body = parseMail(mailmsg);
83 91
84 /* transform to libetpan stuff */
85 msg = mailmessage_new();
86 mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
87 generic_message_t * msg_data;
88 msg_data = (generic_message_t *)msg->msg_data;
89 msg_data->msg_fetched = 1;
90 msg_data->msg_message = message;
91 msg_data->msg_length = strlen(message);
92
93 /* parse the mail */
94 body = parseMail(msg);
95
96 /* clean up */ 92 /* clean up */
97 mailmessage_free(msg); 93 if (mailmsg) mailmessage_free(mailmsg);
98 free(message); 94 if (message) free(message);
99 95
100 /* finish */
101 return body; 96 return body;
102} 97}
103 98
104void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
105{ 100{
106 int err = MAILPOP3_NO_ERROR;
107 char * header = 0;
108 /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
109 size_t length = 0;
110 carray * messages = 0;
111
112 login(); 101 login();
113 if (!m_pop3) return; 102 if (!m_pop3) return;
114 103 uint32_t res_messages,res_recent,res_unseen;
115 mailpop3_list( m_pop3, &messages ); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
116 105 parseList(target,m_folder->fld_session,"INBOX");
117 for (unsigned int i = 0; i < carray_count(messages);++i) { 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
118 mailpop3_msg_info *info;
119 err = mailpop3_get_msg_info(m_pop3,i+1,&info);
120 if (info->msg_deleted)
121 continue;
122 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
123 if ( err != MAILPOP3_NO_ERROR ) {
124 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
125 free(header);
126 return;
127 }
128 RecMail *mail = parseHeader( header );
129 mail->setNumber( info->msg_index );
130 mail->setWrapper(this);
131 mail->setMsgsize(info->msg_size);
132 target.append( mail );
133 free(header);
134 }
135 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count));
136} 107}
137 108
138void POP3wrapper::login() 109void POP3wrapper::login()
139{ 110{
140 /* we'll hold the line */ 111 /* we'll hold the line */
141 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
142 113
143 const char *server, *user, *pass; 114 const char *server, *user, *pass;
144 uint16_t port; 115 uint16_t port;
145 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
146 117
147 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
148 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
149 120
150 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
151 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
152 login.show(); 123 login.show();
153 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
154 // ok 125 // ok
155 user = strdup( login.getUser().latin1() ); 126 user = login.getUser().latin1();
156 pass = strdup( login.getPassword().latin1() ); 127 pass = login.getPassword().latin1();
157 } else { 128 } else {
158 // cancel 129 // cancel
159 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
160 return; 131 return;
161 } 132 }
162 } else { 133 } else {
163 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
164 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
165 } 136 }
166 137
167 m_pop3 = mailpop3_new( 200, &pop3_progress ); 138 bool ssl = account->getSSL();
168 139
169 // connect 140 m_pop3=mailstorage_new(NULL);
170 if (account->getSSL()) { 141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
171 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 142 (char*)user,(char*)pass,0,0,0);
172 } else { 143
173 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 144 m_folder = mailfolder_new(m_pop3, NULL, NULL);
174 }
175 145
176 if ( err != MAILPOP3_NO_ERROR ) { 146 if (m_folder==0) {
177 qDebug( "pop3: error connecting to %s\n reason: %s", server, 147 Global::statusMessage(tr("Error initializing folder"));
178 m_pop3->pop3_response ); 148 mailstorage_free(m_pop3);
179 mailpop3_free( m_pop3 );
180 m_pop3 = NULL; 149 m_pop3 = NULL;
181 return; 150 return;
182 } 151 }
183 qDebug( "POP3: connected!" ); 152 err = mailfolder_connect(m_folder);
184 153 if (err != MAIL_NO_ERROR) {
185 // login 154 Global::statusMessage(tr("Error initializing folder"));
186 // TODO: decide if apop or plain login should be used 155 mailfolder_free(m_folder);
187 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 156 m_folder = 0;
188 if ( err != MAILPOP3_NO_ERROR ) { 157 mailstorage_free(m_pop3);
189 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 158 m_pop3 = 0;
190 logout();
191 return;
192 } 159 }
193
194 qDebug( "POP3: logged in!" ); 160 qDebug( "POP3: logged in!" );
195} 161}
196 162
197void POP3wrapper::logout() 163void POP3wrapper::logout()
198{ 164{
199 int err = MAILPOP3_NO_ERROR; 165 int err = MAILPOP3_NO_ERROR;
200 if ( m_pop3 == NULL ) return; 166 if ( m_pop3 == NULL ) return;
201 err = mailpop3_quit( m_pop3 ); 167 mailfolder_free(m_folder);
202 mailpop3_free( m_pop3 ); 168 m_folder = 0;
203 m_pop3 = NULL; 169 mailstorage_free(m_pop3);
170 m_pop3 = 0;
204} 171}
205 172
206 173
207QList<Folder>* POP3wrapper::listFolders() 174QList<Folder>* POP3wrapper::listFolders()
208{ 175{
209 QList<Folder> * folders = new QList<Folder>(); 176 QList<Folder> * folders = new QList<Folder>();
210 folders->setAutoDelete( false ); 177 folders->setAutoDelete( false );
211 Folder*inb=new Folder("INBOX","/"); 178 Folder*inb=new Folder("INBOX","/");
212 folders->append(inb); 179 folders->append(inb);
213 return folders; 180 return folders;
214} 181}
215 182
216void POP3wrapper::deleteMail(const RecMail&mail) 183void POP3wrapper::deleteMail(const RecMail&mail)
217{ 184{
218 login(); 185 login();
219 if (!m_pop3) return; 186 if (!m_pop3) return;
220 int err = mailpop3_dele(m_pop3,mail.getNumber()); 187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
221 if (err != MAILPOP3_NO_ERROR) { 188 if (err != MAIL_NO_ERROR) {
222 Global::statusMessage(tr("error deleting mail")); 189 Global::statusMessage(tr("error deleting mail"));
223 } 190 }
224} 191}
225 192
226void POP3wrapper::answeredMail(const RecMail&) 193void POP3wrapper::answeredMail(const RecMail&)
227{ 194{
228} 195}
229 196
230int POP3wrapper::deleteAllMail(const Folder*) 197int POP3wrapper::deleteAllMail(const Folder*)
231{ 198{
232 login(); 199 login();
233 if (!m_pop3) return 0; 200 if (!m_pop3) return 0;
234 carray * messages = 0;
235
236 /* if connected this info is cached! */
237 int err = 0;
238 mailpop3_list( m_pop3, &messages );
239
240 int res = 1; 201 int res = 1;
241 for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) { 202
242 mailpop3_msg_info *info; 203 uint32_t result = 0;
243 err = mailpop3_get_msg_info(m_pop3,i+1,&info); 204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
244 if (info->msg_deleted) 205 if (err != MAIL_NO_ERROR) {
245 continue; 206 Global::statusMessage(tr("Error getting folder info"));
246 err = mailpop3_dele(m_pop3,i+1); 207 return 0;
247 if (err != MAILPOP3_NO_ERROR) { 208 }
209 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) {
248 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
249 res = 0; 213 res=0;
250 break;
251 } 214 }
252 } 215 break;
216 }
253 return res; 217 return res;
254} 218}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 2efffdd..b3a42be 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,34 +1,37 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "genericwrapper.h" 5#include "genericwrapper.h"
6#include <qstring.h> 6#include <qstring.h>
7 7
8struct mailstorage;
9struct mailfolder;
8 10
9class POP3wrapper : public Genericwrapper 11class POP3wrapper : public Genericwrapper
10{ 12{
11 Q_OBJECT 13 Q_OBJECT
12 14
13public: 15public:
14 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
15 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
16 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
17 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
18 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
19 21
20 virtual void deleteMail(const RecMail&mail); 22 virtual void deleteMail(const RecMail&mail);
21 virtual void answeredMail(const RecMail&mail); 23 virtual void answeredMail(const RecMail&mail);
22 virtual int deleteAllMail(const Folder*); 24 virtual int deleteAllMail(const Folder*);
23 25
24 virtual RecBody fetchBody( const RecMail &mail ); 26 virtual RecBody fetchBody( const RecMail &mail );
25 static void pop3_progress( size_t current, size_t maximum ); 27 static void pop3_progress( size_t current, size_t maximum );
26 28
27protected: 29protected:
28 void login(); 30 void login();
29 void logout(); 31 void logout();
30 POP3account *account; 32 POP3account *account;
31 mailpop3 *m_pop3; 33 mailstorage*m_pop3;
34 mailfolder*m_folder;
32}; 35};
33 36
34#endif 37#endif