summaryrefslogtreecommitdiff
authorjgf <jgf>2004-01-07 00:24:52 (UTC)
committer jgf <jgf>2004-01-07 00:24:52 (UTC)
commit656e80e7b35c4aefd49ffe7756d895f4e7370de1 (patch) (unidiff)
tree41448111df3e76f9185203f97405b141e830d9e6
parenta0ea0a96c91d95aa379a086238de18075ee5e4b5 (diff)
downloadopie-656e80e7b35c4aefd49ffe7756d895f4e7370de1.zip
opie-656e80e7b35c4aefd49ffe7756d895f4e7370de1.tar.gz
opie-656e80e7b35c4aefd49ffe7756d895f4e7370de1.tar.bz2
pop3 crash - quick fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 714396b..2d1596d 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,503 +1,504 @@
1#include "genericwrapper.h" 1#include "genericwrapper.h"
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include "mailtypes.h" 3#include "mailtypes.h"
4 4
5Genericwrapper::Genericwrapper() 5Genericwrapper::Genericwrapper()
6 : AbstractMail() 6 : AbstractMail()
7{ 7{
8 bodyCache.clear(); 8 bodyCache.clear();
9} 9}
10 10
11Genericwrapper::~Genericwrapper() 11Genericwrapper::~Genericwrapper()
12{ 12{
13 cleanMimeCache(); 13 cleanMimeCache();
14} 14}
15 15
16void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) 16void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
17{ 17{
18 if (!mime) { 18 if (!mime) {
19 return; 19 return;
20 } 20 }
21 mailmime_field*field = 0; 21 mailmime_field*field = 0;
22 mailmime_single_fields fields; 22 mailmime_single_fields fields;
23 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 23 memset(&fields, 0, sizeof(struct mailmime_single_fields));
24 if (mime->mm_mime_fields != NULL) { 24 if (mime->mm_mime_fields != NULL) {
25 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 25 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
26 mime->mm_content_type); 26 mime->mm_content_type);
27 } 27 }
28 28
29 mailmime_content*type = fields.fld_content; 29 mailmime_content*type = fields.fld_content;
30 clistcell*current; 30 clistcell*current;
31 if (!type) { 31 if (!type) {
32 target.setType("text"); 32 target.setType("text");
33 target.setSubtype("plain"); 33 target.setSubtype("plain");
34 } else { 34 } else {
35 target.setSubtype(type->ct_subtype); 35 target.setSubtype(type->ct_subtype);
36 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 36 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
37 case MAILMIME_DISCRETE_TYPE_TEXT: 37 case MAILMIME_DISCRETE_TYPE_TEXT:
38 target.setType("text"); 38 target.setType("text");
39 break; 39 break;
40 case MAILMIME_DISCRETE_TYPE_IMAGE: 40 case MAILMIME_DISCRETE_TYPE_IMAGE:
41 target.setType("image"); 41 target.setType("image");
42 break; 42 break;
43 case MAILMIME_DISCRETE_TYPE_AUDIO: 43 case MAILMIME_DISCRETE_TYPE_AUDIO:
44 target.setType("audio"); 44 target.setType("audio");
45 break; 45 break;
46 case MAILMIME_DISCRETE_TYPE_VIDEO: 46 case MAILMIME_DISCRETE_TYPE_VIDEO:
47 target.setType("video"); 47 target.setType("video");
48 break; 48 break;
49 case MAILMIME_DISCRETE_TYPE_APPLICATION: 49 case MAILMIME_DISCRETE_TYPE_APPLICATION:
50 target.setType("application"); 50 target.setType("application");
51 break; 51 break;
52 case MAILMIME_DISCRETE_TYPE_EXTENSION: 52 case MAILMIME_DISCRETE_TYPE_EXTENSION:
53 default: 53 default:
54 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 54 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
55 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);
56 } 56 }
57 break; 57 break;
58 } 58 }
59 if (type->ct_parameters) { 59 if (type->ct_parameters) {
60 fillParameters(target,type->ct_parameters); 60 fillParameters(target,type->ct_parameters);
61 } 61 }
62 } 62 }
63 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 63 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
64 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)) {
65 field = (mailmime_field*)current->data; 65 field = (mailmime_field*)current->data;
66 switch(field->fld_type) { 66 switch(field->fld_type) {
67 case MAILMIME_FIELD_TRANSFER_ENCODING: 67 case MAILMIME_FIELD_TRANSFER_ENCODING:
68 target.setEncoding(getencoding(field->fld_data.fld_encoding)); 68 target.setEncoding(getencoding(field->fld_data.fld_encoding));
69 break; 69 break;
70 case MAILMIME_FIELD_ID: 70 case MAILMIME_FIELD_ID:
71 target.setIdentifier(field->fld_data.fld_id); 71 target.setIdentifier(field->fld_data.fld_id);
72 break; 72 break;
73 case MAILMIME_FIELD_DESCRIPTION: 73 case MAILMIME_FIELD_DESCRIPTION:
74 target.setDescription(field->fld_data.fld_description); 74 target.setDescription(field->fld_data.fld_description);
75 break; 75 break;
76 default: 76 default:
77 break; 77 break;
78 } 78 }
79 } 79 }
80 } 80 }
81} 81}
82 82
83void Genericwrapper::fillParameters(RecPart&target,clist*parameters) 83void Genericwrapper::fillParameters(RecPart&target,clist*parameters)
84{ 84{
85 if (!parameters) {return;} 85 if (!parameters) {return;}
86 clistcell*current=0; 86 clistcell*current=0;
87 mailmime_parameter*param; 87 mailmime_parameter*param;
88 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 88 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
89 param = (mailmime_parameter*)current->data; 89 param = (mailmime_parameter*)current->data;
90 if (param) { 90 if (param) {
91 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 91 target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
92 } 92 }
93 } 93 }
94} 94}
95 95
96QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 96QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
97{ 97{
98 QString enc="7bit"; 98 QString enc="7bit";
99 if (!aEnc) return enc; 99 if (!aEnc) return enc;
100 switch(aEnc->enc_type) { 100 switch(aEnc->enc_type) {
101 case MAILMIME_MECHANISM_7BIT: 101 case MAILMIME_MECHANISM_7BIT:
102 enc = "7bit"; 102 enc = "7bit";
103 break; 103 break;
104 case MAILMIME_MECHANISM_8BIT: 104 case MAILMIME_MECHANISM_8BIT:
105 enc = "8bit"; 105 enc = "8bit";
106 break; 106 break;
107 case MAILMIME_MECHANISM_BINARY: 107 case MAILMIME_MECHANISM_BINARY:
108 enc = "binary"; 108 enc = "binary";
109 break; 109 break;
110 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 110 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
111 enc = "quoted-printable"; 111 enc = "quoted-printable";
112 break; 112 break;
113 case MAILMIME_MECHANISM_BASE64: 113 case MAILMIME_MECHANISM_BASE64:
114 enc = "base64"; 114 enc = "base64";
115 break; 115 break;
116 case MAILMIME_MECHANISM_TOKEN: 116 case MAILMIME_MECHANISM_TOKEN:
117 default: 117 default:
118 if (aEnc->enc_token) { 118 if (aEnc->enc_token) {
119 enc = QString(aEnc->enc_token); 119 enc = QString(aEnc->enc_token);
120 } 120 }
121 break; 121 break;
122 } 122 }
123 return enc; 123 return enc;
124} 124}
125 125
126void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 126void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
127{ 127{
128 if (current_rec >= 10) { 128 if (current_rec >= 10) {
129 qDebug("too deep recursion!"); 129 qDebug("too deep recursion!");
130 } 130 }
131 if (!message || !mime) { 131 if (!message || !mime) {
132 return; 132 return;
133 } 133 }
134 int r; 134 int r;
135 char*data = 0; 135 char*data = 0;
136 size_t len; 136 size_t len;
137 clistiter * cur = 0; 137 clistiter * cur = 0;
138 QString b; 138 QString b;
139 RecPart part; 139 RecPart part;
140 140
141 switch (mime->mm_type) { 141 switch (mime->mm_type) {
142 case MAILMIME_SINGLE: 142 case MAILMIME_SINGLE:
143 { 143 {
144 QValueList<int>countlist = recList; 144 QValueList<int>countlist = recList;
145 countlist.append(current_count); 145 countlist.append(current_count);
146 r = mailmessage_fetch_section(message,mime,&data,&len); 146 r = mailmessage_fetch_section(message,mime,&data,&len);
147 part.setSize(len); 147 part.setSize(len);
148 part.setPositionlist(countlist); 148 part.setPositionlist(countlist);
149 b = gen_attachment_id(); 149 b = gen_attachment_id();
150 part.setIdentifier(b); 150 part.setIdentifier(b);
151 fillSingleBody(part,message,mime); 151 fillSingleBody(part,message,mime);
152 if (part.Type()=="text" && target.Bodytext().isNull()) { 152 if (part.Type()=="text" && target.Bodytext().isNull()) {
153 encodedString*r = new encodedString(); 153 encodedString*r = new encodedString();
154 r->setContent(data,len); 154 r->setContent(data,len);
155 encodedString*res = decode_String(r,part.Encoding()); 155 encodedString*res = decode_String(r,part.Encoding());
156 if (countlist.count()>2) { 156 if (countlist.count()>2) {
157 bodyCache[b]=r; 157 bodyCache[b]=r;
158 target.addPart(part); 158 target.addPart(part);
159 } else { 159 } else {
160 delete r; 160 delete r;
161 } 161 }
162 b = QString(res->Content()); 162 b = QString(res->Content());
163 delete res; 163 delete res;
164 target.setBodytext(b); 164 target.setBodytext(b);
165 target.setDescription(part); 165 target.setDescription(part);
166 } else { 166 } else {
167 bodyCache[b]=new encodedString(data,len); 167 bodyCache[b]=new encodedString(data,len);
168 target.addPart(part); 168 target.addPart(part);
169 } 169 }
170 } 170 }
171 break; 171 break;
172 case MAILMIME_MULTIPLE: 172 case MAILMIME_MULTIPLE:
173 { 173 {
174 unsigned int ccount = 1; 174 unsigned int ccount = 1;
175 mailmime*cbody=0; 175 mailmime*cbody=0;
176 QValueList<int>countlist = recList; 176 QValueList<int>countlist = recList;
177 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 177 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
178 cbody = (mailmime*)clist_content(cur); 178 cbody = (mailmime*)clist_content(cur);
179 if (cbody->mm_type==MAILMIME_MULTIPLE) { 179 if (cbody->mm_type==MAILMIME_MULTIPLE) {
180 RecPart targetPart; 180 RecPart targetPart;
181 targetPart.setType("multipart"); 181 targetPart.setType("multipart");
182 countlist.append(current_count); 182 countlist.append(current_count);
183 targetPart.setPositionlist(countlist); 183 targetPart.setPositionlist(countlist);
184 target.addPart(targetPart); 184 target.addPart(targetPart);
185 } 185 }
186 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 186 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
187 if (cbody->mm_type==MAILMIME_MULTIPLE) { 187 if (cbody->mm_type==MAILMIME_MULTIPLE) {
188 countlist = recList; 188 countlist = recList;
189 } 189 }
190 ++ccount; 190 ++ccount;
191 } 191 }
192 } 192 }
193 break; 193 break;
194 case MAILMIME_MESSAGE: 194 case MAILMIME_MESSAGE:
195 { 195 {
196 QValueList<int>countlist = recList; 196 QValueList<int>countlist = recList;
197 countlist.append(current_count); 197 countlist.append(current_count);
198 /* the own header is always at recursion 0 - we don't need that */ 198 /* the own header is always at recursion 0 - we don't need that */
199 if (current_rec > 0) { 199 if (current_rec > 0) {
200 part.setPositionlist(countlist); 200 part.setPositionlist(countlist);
201 r = mailmessage_fetch_section(message,mime,&data,&len); 201 r = mailmessage_fetch_section(message,mime,&data,&len);
202 part.setSize(len); 202 part.setSize(len);
203 part.setPositionlist(countlist); 203 part.setPositionlist(countlist);
204 b = gen_attachment_id(); 204 b = gen_attachment_id();
205 part.setIdentifier(b); 205 part.setIdentifier(b);
206 part.setType("message"); 206 part.setType("message");
207 part.setSubtype("rfc822"); 207 part.setSubtype("rfc822");
208 bodyCache[b]=new encodedString(data,len); 208 bodyCache[b]=new encodedString(data,len);
209 target.addPart(part); 209 target.addPart(part);
210 } 210 }
211 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 211 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
212 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 212 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
213 } 213 }
214 } 214 }
215 break; 215 break;
216 } 216 }
217} 217}
218 218
219RecBody Genericwrapper::parseMail( mailmessage * msg ) 219RecBody Genericwrapper::parseMail( mailmessage * msg )
220{ 220{
221 int err = MAILIMF_NO_ERROR; 221 int err = MAILIMF_NO_ERROR;
222 mailmime_single_fields fields; 222 mailmime_single_fields fields;
223 /* is bound to msg and will be freed there */ 223 /* is bound to msg and will be freed there */
224 mailmime * mime=0; 224 mailmime * mime=0;
225 RecBody body; 225 RecBody body;
226 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 226 memset(&fields, 0, sizeof(struct mailmime_single_fields));
227 err = mailmessage_get_bodystructure(msg,&mime); 227 err = mailmessage_get_bodystructure(msg,&mime);
228 QValueList<int>recList; 228 QValueList<int>recList;
229 traverseBody(body,msg,mime,recList); 229 traverseBody(body,msg,mime,recList);
230 return body; 230 return body;
231} 231}
232 232
233RecMail *Genericwrapper::parseHeader( const char *header ) 233RecMail *Genericwrapper::parseHeader( const char *header )
234{ 234{
235 int err = MAILIMF_NO_ERROR; 235 int err = MAILIMF_NO_ERROR;
236 size_t curTok = 0; 236 size_t curTok = 0;
237 RecMail *mail = new RecMail(); 237 RecMail *mail = new RecMail();
238 mailimf_fields *fields = 0; 238 mailimf_fields *fields = 0;
239 mailimf_references * refs = 0; 239 mailimf_references * refs = 0;
240 mailimf_keywords*keys = 0; 240 mailimf_keywords*keys = 0;
241 QString status; 241 QString status;
242 QString value; 242 QString value;
243 QBitArray mFlags(7); 243 QBitArray mFlags(7);
244 244
245 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 245 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
246 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 246 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
247 mailimf_field *field = (mailimf_field *) current->data; 247 mailimf_field *field = (mailimf_field *) current->data;
248 switch ( field->fld_type ) { 248 switch ( field->fld_type ) {
249 case MAILIMF_FIELD_FROM: 249 case MAILIMF_FIELD_FROM:
250 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 250 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
251 break; 251 break;
252 case MAILIMF_FIELD_TO: 252 case MAILIMF_FIELD_TO:
253 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 253 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
254 break; 254 break;
255 case MAILIMF_FIELD_CC: 255 case MAILIMF_FIELD_CC:
256 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 256 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
257 break; 257 break;
258 case MAILIMF_FIELD_BCC: 258 case MAILIMF_FIELD_BCC:
259 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 259 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
260 break; 260 break;
261 case MAILIMF_FIELD_SUBJECT: 261 case MAILIMF_FIELD_SUBJECT:
262 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 262 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
263 break; 263 break;
264 case MAILIMF_FIELD_ORIG_DATE: 264 case MAILIMF_FIELD_ORIG_DATE:
265 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 265 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
266 break; 266 break;
267 case MAILIMF_FIELD_MESSAGE_ID: 267 case MAILIMF_FIELD_MESSAGE_ID:
268 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 268 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
269 break; 269 break;
270 case MAILIMF_FIELD_REFERENCES: 270 case MAILIMF_FIELD_REFERENCES:
271 refs = field->fld_data.fld_references; 271 refs = field->fld_data.fld_references;
272 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 272 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
273 char * text = (char*)refs->mid_list->first->data; 273 char * text = (char*)refs->mid_list->first->data;
274 mail->setReplyto(QString(text)); 274 mail->setReplyto(QString(text));
275 } 275 }
276 break; 276 break;
277 case MAILIMF_FIELD_KEYWORDS: 277 case MAILIMF_FIELD_KEYWORDS:
278 keys = field->fld_data.fld_keywords; 278 keys = field->fld_data.fld_keywords;
279 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 279 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
280 qDebug("Keyword: %s",(char*)cur->data); 280 qDebug("Keyword: %s",(char*)cur->data);
281 } 281 }
282 break; 282 break;
283 case MAILIMF_FIELD_OPTIONAL_FIELD: 283 case MAILIMF_FIELD_OPTIONAL_FIELD:
284 status = field->fld_data.fld_optional_field->fld_name; 284 status = field->fld_data.fld_optional_field->fld_name;
285 value = field->fld_data.fld_optional_field->fld_value; 285 value = field->fld_data.fld_optional_field->fld_value;
286 if (status.lower()=="status") { 286 if (status.lower()=="status") {
287 if (value.lower()=="ro") { 287 if (value.lower()=="ro") {
288 mFlags.setBit(FLAG_SEEN); 288 mFlags.setBit(FLAG_SEEN);
289 } 289 }
290 } else if (status.lower()=="x-status") { 290 } else if (status.lower()=="x-status") {
291 qDebug("X-Status: %s",value.latin1()); 291 qDebug("X-Status: %s",value.latin1());
292 if (value.lower()=="a") { 292 if (value.lower()=="a") {
293 mFlags.setBit(FLAG_ANSWERED); 293 mFlags.setBit(FLAG_ANSWERED);
294 } 294 }
295 } else { 295 } else {
296// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 296// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
297// field->fld_data.fld_optional_field->fld_value); 297// field->fld_data.fld_optional_field->fld_value);
298 } 298 }
299 break; 299 break;
300 default: 300 default:
301 qDebug("Non parsed field"); 301 qDebug("Non parsed field");
302 break; 302 break;
303 } 303 }
304 } 304 }
305 if (fields) mailimf_fields_free(fields); 305 if (fields) mailimf_fields_free(fields);
306 mail->setFlags(mFlags); 306 mail->setFlags(mFlags);
307 return mail; 307 return mail;
308} 308}
309 309
310QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 310QString Genericwrapper::parseDateTime( mailimf_date_time *date )
311{ 311{
312 char tmp[23]; 312 char tmp[23];
313 313
314 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 314 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
315 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 315 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
316 316
317 return QString( tmp ); 317 return QString( tmp );
318} 318}
319 319
320QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 320QString Genericwrapper::parseAddressList( mailimf_address_list *list )
321{ 321{
322 QString result( "" ); 322 QString result( "" );
323 323
324 bool first = true; 324 bool first = true;
325 if (list == 0) return result; 325 if (list == 0) return result;
326 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 326 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
327 mailimf_address *addr = (mailimf_address *) current->data; 327 mailimf_address *addr = (mailimf_address *) current->data;
328 328
329 if ( !first ) { 329 if ( !first ) {
330 result.append( "," ); 330 result.append( "," );
331 } else { 331 } else {
332 first = false; 332 first = false;
333 } 333 }
334 334
335 switch ( addr->ad_type ) { 335 switch ( addr->ad_type ) {
336 case MAILIMF_ADDRESS_MAILBOX: 336 case MAILIMF_ADDRESS_MAILBOX:
337 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 337 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
338 break; 338 break;
339 case MAILIMF_ADDRESS_GROUP: 339 case MAILIMF_ADDRESS_GROUP:
340 result.append( parseGroup( addr->ad_data.ad_group ) ); 340 result.append( parseGroup( addr->ad_data.ad_group ) );
341 break; 341 break;
342 default: 342 default:
343 qDebug( "Generic: unkown mailimf address type" ); 343 qDebug( "Generic: unkown mailimf address type" );
344 break; 344 break;
345 } 345 }
346 } 346 }
347 347
348 return result; 348 return result;
349} 349}
350 350
351QString Genericwrapper::parseGroup( mailimf_group *group ) 351QString Genericwrapper::parseGroup( mailimf_group *group )
352{ 352{
353 QString result( "" ); 353 QString result( "" );
354 354
355 result.append( group->grp_display_name ); 355 result.append( group->grp_display_name );
356 result.append( ": " ); 356 result.append( ": " );
357 357
358 if ( group->grp_mb_list != NULL ) { 358 if ( group->grp_mb_list != NULL ) {
359 result.append( parseMailboxList( group->grp_mb_list ) ); 359 result.append( parseMailboxList( group->grp_mb_list ) );
360 } 360 }
361 361
362 result.append( ";" ); 362 result.append( ";" );
363 363
364 return result; 364 return result;
365} 365}
366 366
367QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 367QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
368{ 368{
369 QString result( "" ); 369 QString result( "" );
370 370
371 if ( box->mb_display_name == NULL ) { 371 if ( box->mb_display_name == NULL ) {
372 result.append( box->mb_addr_spec ); 372 result.append( box->mb_addr_spec );
373 } else { 373 } else {
374 result.append( convert_String(box->mb_display_name).latin1() ); 374 result.append( convert_String(box->mb_display_name).latin1() );
375 result.append( " <" ); 375 result.append( " <" );
376 result.append( box->mb_addr_spec ); 376 result.append( box->mb_addr_spec );
377 result.append( ">" ); 377 result.append( ">" );
378 } 378 }
379 379
380 return result; 380 return result;
381} 381}
382 382
383QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 383QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
384{ 384{
385 QString result( "" ); 385 QString result( "" );
386 386
387 bool first = true; 387 bool first = true;
388 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 388 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
389 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 389 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
390 390
391 if ( !first ) { 391 if ( !first ) {
392 result.append( "," ); 392 result.append( "," );
393 } else { 393 } else {
394 first = false; 394 first = false;
395 } 395 }
396 396
397 result.append( parseMailbox( box ) ); 397 result.append( parseMailbox( box ) );
398 } 398 }
399 399
400 return result; 400 return result;
401} 401}
402 402
403encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 403encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
404{ 404{
405 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 405 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
406 if (it==bodyCache.end()) return new encodedString(); 406 if (it==bodyCache.end()) return new encodedString();
407 encodedString*t = decode_String(it.data(),part.Encoding()); 407 encodedString*t = decode_String(it.data(),part.Encoding());
408 return t; 408 return t;
409} 409}
410 410
411encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 411encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
412{ 412{
413 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 413 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
414 if (it==bodyCache.end()) return new encodedString(); 414 if (it==bodyCache.end()) return new encodedString();
415 encodedString*t = it.data(); 415 encodedString*t = it.data();
416 return t; 416 return t;
417} 417}
418 418
419QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 419QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
420{ 420{
421 encodedString*t = fetchDecodedPart(mail,part); 421 encodedString*t = fetchDecodedPart(mail,part);
422 QString text=t->Content(); 422 QString text=t->Content();
423 delete t; 423 delete t;
424 return text; 424 return text;
425} 425}
426 426
427void Genericwrapper::cleanMimeCache() 427void Genericwrapper::cleanMimeCache()
428{ 428{
429 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 429 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
430 for (;it!=bodyCache.end();++it) { 430 for (;it!=bodyCache.end();++it) {
431 encodedString*t = it.data(); 431 encodedString*t = it.data();
432 //it.setValue(0); 432 //it.setValue(0);
433 if (t) delete t; 433 if (t) delete t;
434 } 434 }
435 bodyCache.clear(); 435 bodyCache.clear();
436 qDebug("Genericwrapper: cache cleaned"); 436 qDebug("Genericwrapper: cache cleaned");
437} 437}
438 438
439void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) 439void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
440{ 440{
441 int r; 441 int r;
442 mailmessage_list * env_list = 0; 442 mailmessage_list * env_list = 0;
443 r = mailsession_get_messages_list(session,&env_list); 443 r = mailsession_get_messages_list(session,&env_list);
444 if (r != MAIL_NO_ERROR) { 444 if (r != MAIL_NO_ERROR) {
445 qDebug("Error message list"); 445 qDebug("Error message list");
446 return; 446 return;
447 } 447 }
448 r = mailsession_get_envelopes_list(session, env_list); 448 r = mailsession_get_envelopes_list(session, env_list);
449 if (r != MAIL_NO_ERROR) { 449 if (r != MAIL_NO_ERROR) {
450 qDebug("Error filling message list"); 450 qDebug("Error filling message list");
451 if (env_list) { 451 if (env_list) {
452 mailmessage_list_free(env_list); 452 mailmessage_list_free(env_list);
453 } 453 }
454 return; 454 return;
455 } 455 }
456 mailimf_references * refs; 456 mailimf_references * refs;
457 uint32_t i = 0; 457 uint32_t i = 0;
458 for(; i < carray_count(env_list->msg_tab) ; ++i) { 458 for(; i < carray_count(env_list->msg_tab) ; ++i) {
459 mailmessage * msg; 459 mailmessage * msg;
460 QBitArray mFlags(7); 460 QBitArray mFlags(7);
461 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 461 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
462 if (msg->msg_fields == NULL) { 462 if (msg->msg_fields == NULL) {
463 qDebug("could not fetch envelope of message %i", i); 463 qDebug("could not fetch envelope of message %i", i);
464 continue; 464 continue;
465 } 465 }
466 RecMail * mail = new RecMail(); 466 RecMail * mail = new RecMail();
467 mail->setWrapper(this); 467 mail->setWrapper(this);
468 mail_flags * flag_result = 0; 468 mail_flags * flag_result = 0;
469 r = mailmessage_get_flags(msg,&flag_result); 469 r = mailmessage_get_flags(msg,&flag_result);
470 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 470 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
471 mFlags.setBit(FLAG_SEEN); 471 mFlags.setBit(FLAG_SEEN);
472 } 472 }
473 mailimf_single_fields single_fields; 473 mailimf_single_fields single_fields;
474 mailimf_single_fields_init(&single_fields, msg->msg_fields); 474 mailimf_single_fields_init(&single_fields, msg->msg_fields);
475 mail->setMsgsize(msg->msg_size); 475 mail->setMsgsize(msg->msg_size);
476 mail->setFlags(mFlags); 476 mail->setFlags(mFlags);
477 mail->setMbox(mailbox); 477 mail->setMbox(mailbox);
478 mail->setNumber(msg->msg_index); 478 mail->setNumber(msg->msg_index);
479 if (single_fields.fld_subject) 479 if (single_fields.fld_subject)
480 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 480 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
481 if (single_fields.fld_from) 481 if (single_fields.fld_from)
482 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 482 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
483 if (single_fields.fld_to) 483 if (single_fields.fld_to)
484 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 484 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
485 if (single_fields.fld_cc) 485 if (single_fields.fld_cc)
486 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 486 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
487 if (single_fields.fld_bcc) 487 if (single_fields.fld_bcc)
488 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 488 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
489 if (single_fields.fld_orig_date) 489 if (single_fields.fld_orig_date)
490 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 490 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
491 if (single_fields.fld_message_id->mid_value) 491 // crashes when accessing pop3 account
492 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 492 // if (single_fields.fld_message_id->mid_value)
493 // mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
493 refs = single_fields.fld_references; 494 refs = single_fields.fld_references;
494 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 495 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
495 char * text = (char*)refs->mid_list->first->data; 496 char * text = (char*)refs->mid_list->first->data;
496 mail->setReplyto(QString(text)); 497 mail->setReplyto(QString(text));
497 } 498 }
498 target.append(mail); 499 target.append(mail);
499 } 500 }
500 if (env_list) { 501 if (env_list) {
501 mailmessage_list_free(env_list); 502 mailmessage_list_free(env_list);
502 } 503 }
503} 504}