summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-02 14:46:42 (UTC)
committer alwin <alwin>2004-01-02 14:46:42 (UTC)
commitf238d6cc096cd1baf3e821af80ecd51917d615ad (patch) (unidiff)
tree28ea5754277dad74a01adba74c5bf0336fa075f5
parenteac3f38c7d1c56a1800894a488e9ce35ddeb396c (diff)
downloadopie-f238d6cc096cd1baf3e821af80ecd51917d615ad.zip
opie-f238d6cc096cd1baf3e821af80ecd51917d615ad.tar.gz
opie-f238d6cc096cd1baf3e821af80ecd51917d615ad.tar.bz2
bugfix while assigning mail-numbers
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/genericwrapper.cpp2
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp
index 5de9299..62116ba 100644
--- a/noncore/net/mail/genericwrapper.cpp
+++ b/noncore/net/mail/genericwrapper.cpp
@@ -78,410 +78,410 @@ void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
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 //current_count; 141 //current_count;
142 142
143 switch (mime->mm_type) { 143 switch (mime->mm_type) {
144 case MAILMIME_SINGLE: 144 case MAILMIME_SINGLE:
145 { 145 {
146 QValueList<int>countlist = recList; 146 QValueList<int>countlist = recList;
147 countlist.append(current_count); 147 countlist.append(current_count);
148 r = mailmessage_fetch_section(message,mime,&data,&len); 148 r = mailmessage_fetch_section(message,mime,&data,&len);
149 part.setSize(len); 149 part.setSize(len);
150 part.setPositionlist(countlist); 150 part.setPositionlist(countlist);
151 b = gen_attachment_id(); 151 b = gen_attachment_id();
152 part.setIdentifier(b); 152 part.setIdentifier(b);
153 fillSingleBody(part,message,mime); 153 fillSingleBody(part,message,mime);
154 if (part.Type()=="text" && target.Bodytext().isNull()) { 154 if (part.Type()=="text" && target.Bodytext().isNull()) {
155 encodedString*r = new encodedString(); 155 encodedString*r = new encodedString();
156 r->setContent(data,len); 156 r->setContent(data,len);
157 encodedString*res = decode_String(r,part.Encoding()); 157 encodedString*res = decode_String(r,part.Encoding());
158 b = QString(res->Content()); 158 b = QString(res->Content());
159 delete r; 159 delete r;
160 delete res; 160 delete res;
161 target.setBodytext(b); 161 target.setBodytext(b);
162 target.setDescription(part); 162 target.setDescription(part);
163 } else { 163 } else {
164 bodyCache[b]=new encodedString(data,len); 164 bodyCache[b]=new encodedString(data,len);
165 target.addPart(part); 165 target.addPart(part);
166 } 166 }
167 } 167 }
168 break; 168 break;
169 case MAILMIME_MULTIPLE: 169 case MAILMIME_MULTIPLE:
170 { 170 {
171 unsigned int ccount = current_count; 171 unsigned int ccount = current_count;
172 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 172 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
173 traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount); 173 traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount);
174 ++ccount; 174 ++ccount;
175 } 175 }
176 } 176 }
177 break; 177 break;
178 case MAILMIME_MESSAGE: 178 case MAILMIME_MESSAGE:
179 { 179 {
180 QValueList<int>countlist = recList; 180 QValueList<int>countlist = recList;
181 countlist.append(current_count); 181 countlist.append(current_count);
182 /* the own header is always at recursion 0 - we don't need that */ 182 /* the own header is always at recursion 0 - we don't need that */
183 if (current_rec > 0) { 183 if (current_rec > 0) {
184 part.setPositionlist(countlist); 184 part.setPositionlist(countlist);
185 r = mailmessage_fetch_section(message,mime,&data,&len); 185 r = mailmessage_fetch_section(message,mime,&data,&len);
186 part.setSize(len); 186 part.setSize(len);
187 part.setPositionlist(countlist); 187 part.setPositionlist(countlist);
188 b = gen_attachment_id(); 188 b = gen_attachment_id();
189 part.setIdentifier(b); 189 part.setIdentifier(b);
190 part.setType("message"); 190 part.setType("message");
191 part.setSubtype("rfc822"); 191 part.setSubtype("rfc822");
192 bodyCache[b]=new encodedString(data,len); 192 bodyCache[b]=new encodedString(data,len);
193 target.addPart(part); 193 target.addPart(part);
194 } 194 }
195 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 195 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
196 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 196 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
197 } 197 }
198 } 198 }
199 break; 199 break;
200 } 200 }
201} 201}
202 202
203RecBody Genericwrapper::parseMail( mailmessage * msg ) 203RecBody Genericwrapper::parseMail( mailmessage * msg )
204{ 204{
205 int err = MAILIMF_NO_ERROR; 205 int err = MAILIMF_NO_ERROR;
206 mailmime_single_fields fields; 206 mailmime_single_fields fields;
207 /* is bound to msg and will be freed there */ 207 /* is bound to msg and will be freed there */
208 mailmime * mime=0; 208 mailmime * mime=0;
209 RecBody body; 209 RecBody body;
210 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 210 memset(&fields, 0, sizeof(struct mailmime_single_fields));
211 err = mailmessage_get_bodystructure(msg,&mime); 211 err = mailmessage_get_bodystructure(msg,&mime);
212 QValueList<int>recList; 212 QValueList<int>recList;
213 traverseBody(body,msg,mime,recList); 213 traverseBody(body,msg,mime,recList);
214 return body; 214 return body;
215} 215}
216 216
217RecMail *Genericwrapper::parseHeader( const char *header ) 217RecMail *Genericwrapper::parseHeader( const char *header )
218{ 218{
219 int err = MAILIMF_NO_ERROR; 219 int err = MAILIMF_NO_ERROR;
220 size_t curTok = 0; 220 size_t curTok = 0;
221 RecMail *mail = new RecMail(); 221 RecMail *mail = new RecMail();
222 mailimf_fields *fields = 0; 222 mailimf_fields *fields = 0;
223 mailimf_references * refs = 0; 223 mailimf_references * refs = 0;
224 mailimf_keywords*keys = 0; 224 mailimf_keywords*keys = 0;
225 QString status; 225 QString status;
226 QString value; 226 QString value;
227 QBitArray mFlags(7); 227 QBitArray mFlags(7);
228 228
229 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 229 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
230 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 230 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
231 mailimf_field *field = (mailimf_field *) current->data; 231 mailimf_field *field = (mailimf_field *) current->data;
232 switch ( field->fld_type ) { 232 switch ( field->fld_type ) {
233 case MAILIMF_FIELD_FROM: 233 case MAILIMF_FIELD_FROM:
234 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 234 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
235 break; 235 break;
236 case MAILIMF_FIELD_TO: 236 case MAILIMF_FIELD_TO:
237 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 237 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
238 break; 238 break;
239 case MAILIMF_FIELD_CC: 239 case MAILIMF_FIELD_CC:
240 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 240 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
241 break; 241 break;
242 case MAILIMF_FIELD_BCC: 242 case MAILIMF_FIELD_BCC:
243 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 243 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
244 break; 244 break;
245 case MAILIMF_FIELD_SUBJECT: 245 case MAILIMF_FIELD_SUBJECT:
246 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 246 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
247 break; 247 break;
248 case MAILIMF_FIELD_ORIG_DATE: 248 case MAILIMF_FIELD_ORIG_DATE:
249 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 249 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
250 break; 250 break;
251 case MAILIMF_FIELD_MESSAGE_ID: 251 case MAILIMF_FIELD_MESSAGE_ID:
252 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 252 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
253 break; 253 break;
254 case MAILIMF_FIELD_REFERENCES: 254 case MAILIMF_FIELD_REFERENCES:
255 refs = field->fld_data.fld_references; 255 refs = field->fld_data.fld_references;
256 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 256 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
257 char * text = (char*)refs->mid_list->first->data; 257 char * text = (char*)refs->mid_list->first->data;
258 mail->setReplyto(QString(text)); 258 mail->setReplyto(QString(text));
259 } 259 }
260 break; 260 break;
261 case MAILIMF_FIELD_KEYWORDS: 261 case MAILIMF_FIELD_KEYWORDS:
262 keys = field->fld_data.fld_keywords; 262 keys = field->fld_data.fld_keywords;
263 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 263 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
264 qDebug("Keyword: %s",(char*)cur->data); 264 qDebug("Keyword: %s",(char*)cur->data);
265 } 265 }
266 break; 266 break;
267 case MAILIMF_FIELD_OPTIONAL_FIELD: 267 case MAILIMF_FIELD_OPTIONAL_FIELD:
268 status = field->fld_data.fld_optional_field->fld_name; 268 status = field->fld_data.fld_optional_field->fld_name;
269 value = field->fld_data.fld_optional_field->fld_value; 269 value = field->fld_data.fld_optional_field->fld_value;
270 if (status.lower()=="status") { 270 if (status.lower()=="status") {
271 if (value.lower()=="ro") { 271 if (value.lower()=="ro") {
272 mFlags.setBit(FLAG_SEEN); 272 mFlags.setBit(FLAG_SEEN);
273 } 273 }
274 } else if (status.lower()=="x-status") { 274 } else if (status.lower()=="x-status") {
275 qDebug("X-Status: %s",value.latin1()); 275 qDebug("X-Status: %s",value.latin1());
276 if (value.lower()=="a") { 276 if (value.lower()=="a") {
277 mFlags.setBit(FLAG_ANSWERED); 277 mFlags.setBit(FLAG_ANSWERED);
278 } 278 }
279 } else { 279 } else {
280// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 280// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
281// field->fld_data.fld_optional_field->fld_value); 281// field->fld_data.fld_optional_field->fld_value);
282 } 282 }
283 break; 283 break;
284 default: 284 default:
285 qDebug("Non parsed field"); 285 qDebug("Non parsed field");
286 break; 286 break;
287 } 287 }
288 } 288 }
289 if (fields) mailimf_fields_free(fields); 289 if (fields) mailimf_fields_free(fields);
290 mail->setFlags(mFlags); 290 mail->setFlags(mFlags);
291 return mail; 291 return mail;
292} 292}
293 293
294QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 294QString Genericwrapper::parseDateTime( mailimf_date_time *date )
295{ 295{
296 char tmp[23]; 296 char tmp[23];
297 297
298 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 298 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
299 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 299 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
300 300
301 return QString( tmp ); 301 return QString( tmp );
302} 302}
303 303
304QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 304QString Genericwrapper::parseAddressList( mailimf_address_list *list )
305{ 305{
306 QString result( "" ); 306 QString result( "" );
307 307
308 bool first = true; 308 bool first = true;
309 if (list == 0) return result; 309 if (list == 0) return result;
310 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 310 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
311 mailimf_address *addr = (mailimf_address *) current->data; 311 mailimf_address *addr = (mailimf_address *) current->data;
312 312
313 if ( !first ) { 313 if ( !first ) {
314 result.append( "," ); 314 result.append( "," );
315 } else { 315 } else {
316 first = false; 316 first = false;
317 } 317 }
318 318
319 switch ( addr->ad_type ) { 319 switch ( addr->ad_type ) {
320 case MAILIMF_ADDRESS_MAILBOX: 320 case MAILIMF_ADDRESS_MAILBOX:
321 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 321 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
322 break; 322 break;
323 case MAILIMF_ADDRESS_GROUP: 323 case MAILIMF_ADDRESS_GROUP:
324 result.append( parseGroup( addr->ad_data.ad_group ) ); 324 result.append( parseGroup( addr->ad_data.ad_group ) );
325 break; 325 break;
326 default: 326 default:
327 qDebug( "Generic: unkown mailimf address type" ); 327 qDebug( "Generic: unkown mailimf address type" );
328 break; 328 break;
329 } 329 }
330 } 330 }
331 331
332 return result; 332 return result;
333} 333}
334 334
335QString Genericwrapper::parseGroup( mailimf_group *group ) 335QString Genericwrapper::parseGroup( mailimf_group *group )
336{ 336{
337 QString result( "" ); 337 QString result( "" );
338 338
339 result.append( group->grp_display_name ); 339 result.append( group->grp_display_name );
340 result.append( ": " ); 340 result.append( ": " );
341 341
342 if ( group->grp_mb_list != NULL ) { 342 if ( group->grp_mb_list != NULL ) {
343 result.append( parseMailboxList( group->grp_mb_list ) ); 343 result.append( parseMailboxList( group->grp_mb_list ) );
344 } 344 }
345 345
346 result.append( ";" ); 346 result.append( ";" );
347 347
348 return result; 348 return result;
349} 349}
350 350
351QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 351QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
352{ 352{
353 QString result( "" ); 353 QString result( "" );
354 354
355 if ( box->mb_display_name == NULL ) { 355 if ( box->mb_display_name == NULL ) {
356 result.append( box->mb_addr_spec ); 356 result.append( box->mb_addr_spec );
357 } else { 357 } else {
358 result.append( convert_String(box->mb_display_name).latin1() ); 358 result.append( convert_String(box->mb_display_name).latin1() );
359 result.append( " <" ); 359 result.append( " <" );
360 result.append( box->mb_addr_spec ); 360 result.append( box->mb_addr_spec );
361 result.append( ">" ); 361 result.append( ">" );
362 } 362 }
363 363
364 return result; 364 return result;
365} 365}
366 366
367QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 367QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
368{ 368{
369 QString result( "" ); 369 QString result( "" );
370 370
371 bool first = true; 371 bool first = true;
372 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 372 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
373 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 373 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
374 374
375 if ( !first ) { 375 if ( !first ) {
376 result.append( "," ); 376 result.append( "," );
377 } else { 377 } else {
378 first = false; 378 first = false;
379 } 379 }
380 380
381 result.append( parseMailbox( box ) ); 381 result.append( parseMailbox( box ) );
382 } 382 }
383 383
384 return result; 384 return result;
385} 385}
386 386
387encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 387encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
388{ 388{
389 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 389 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
390 if (it==bodyCache.end()) return new encodedString(); 390 if (it==bodyCache.end()) return new encodedString();
391 encodedString*t = decode_String(it.data(),part.Encoding()); 391 encodedString*t = decode_String(it.data(),part.Encoding());
392 return t; 392 return t;
393} 393}
394 394
395encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 395encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
396{ 396{
397 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 397 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
398 if (it==bodyCache.end()) return new encodedString(); 398 if (it==bodyCache.end()) return new encodedString();
399 encodedString*t = it.data(); 399 encodedString*t = it.data();
400 return t; 400 return t;
401} 401}
402 402
403QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 403QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
404{ 404{
405 encodedString*t = fetchDecodedPart(mail,part); 405 encodedString*t = fetchDecodedPart(mail,part);
406 QString text=t->Content(); 406 QString text=t->Content();
407 delete t; 407 delete t;
408 return text; 408 return text;
409} 409}
410 410
411void Genericwrapper::cleanMimeCache() 411void Genericwrapper::cleanMimeCache()
412{ 412{
413 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 413 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
414 for (;it!=bodyCache.end();++it) { 414 for (;it!=bodyCache.end();++it) {
415 encodedString*t = it.data(); 415 encodedString*t = it.data();
416 //it.setValue(0); 416 //it.setValue(0);
417 if (t) delete t; 417 if (t) delete t;
418 } 418 }
419 bodyCache.clear(); 419 bodyCache.clear();
420 qDebug("Genericwrapper: cache cleaned"); 420 qDebug("Genericwrapper: cache cleaned");
421} 421}
422 422
423void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) 423void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
424{ 424{
425 int r; 425 int r;
426 mailmessage_list * env_list = 0; 426 mailmessage_list * env_list = 0;
427 r = mailsession_get_messages_list(session,&env_list); 427 r = mailsession_get_messages_list(session,&env_list);
428 if (r != MAIL_NO_ERROR) { 428 if (r != MAIL_NO_ERROR) {
429 qDebug("Error message list"); 429 qDebug("Error message list");
430 return; 430 return;
431 } 431 }
432 r = mailsession_get_envelopes_list(session, env_list); 432 r = mailsession_get_envelopes_list(session, env_list);
433 if (r != MAIL_NO_ERROR) { 433 if (r != MAIL_NO_ERROR) {
434 qDebug("Error filling message list"); 434 qDebug("Error filling message list");
435 if (env_list) { 435 if (env_list) {
436 mailmessage_list_free(env_list); 436 mailmessage_list_free(env_list);
437 } 437 }
438 return; 438 return;
439 } 439 }
440 mailimf_references * refs; 440 mailimf_references * refs;
441 uint32_t i = 0; 441 uint32_t i = 0;
442 for(; i < carray_count(env_list->msg_tab) ; ++i) { 442 for(; i < carray_count(env_list->msg_tab) ; ++i) {
443 mailmessage * msg; 443 mailmessage * msg;
444 QBitArray mFlags(7); 444 QBitArray mFlags(7);
445 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 445 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
446 if (msg->msg_fields == NULL) { 446 if (msg->msg_fields == NULL) {
447 qDebug("could not fetch envelope of message %i", i); 447 qDebug("could not fetch envelope of message %i", i);
448 continue; 448 continue;
449 } 449 }
450 RecMail * mail = new RecMail(); 450 RecMail * mail = new RecMail();
451 mail->setWrapper(this); 451 mail->setWrapper(this);
452 mail_flags * flag_result = 0; 452 mail_flags * flag_result = 0;
453 r = mailmessage_get_flags(msg,&flag_result); 453 r = mailmessage_get_flags(msg,&flag_result);
454 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 454 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
455 mFlags.setBit(FLAG_SEEN); 455 mFlags.setBit(FLAG_SEEN);
456 } 456 }
457 mailimf_single_fields single_fields; 457 mailimf_single_fields single_fields;
458 mailimf_single_fields_init(&single_fields, msg->msg_fields); 458 mailimf_single_fields_init(&single_fields, msg->msg_fields);
459 mail->setMsgsize(msg->msg_size); 459 mail->setMsgsize(msg->msg_size);
460 mail->setFlags(mFlags); 460 mail->setFlags(mFlags);
461 mail->setMbox(mailbox); 461 mail->setMbox(mailbox);
462 mail->setNumber(i+1); 462 mail->setNumber(msg->msg_index);
463 if (single_fields.fld_subject) 463 if (single_fields.fld_subject)
464 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 464 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
465 if (single_fields.fld_from) 465 if (single_fields.fld_from)
466 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 466 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
467 if (single_fields.fld_to) 467 if (single_fields.fld_to)
468 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 468 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
469 if (single_fields.fld_cc) 469 if (single_fields.fld_cc)
470 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 470 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
471 if (single_fields.fld_bcc) 471 if (single_fields.fld_bcc)
472 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 472 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
473 if (single_fields.fld_orig_date) 473 if (single_fields.fld_orig_date)
474 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 474 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
475 if (single_fields.fld_message_id->mid_value) 475 if (single_fields.fld_message_id->mid_value)
476 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 476 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
477 refs = single_fields.fld_references; 477 refs = single_fields.fld_references;
478 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 478 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
479 char * text = (char*)refs->mid_list->first->data; 479 char * text = (char*)refs->mid_list->first->data;
480 mail->setReplyto(QString(text)); 480 mail->setReplyto(QString(text));
481 } 481 }
482 target.append(mail); 482 target.append(mail);
483 } 483 }
484 if (env_list) { 484 if (env_list) {
485 mailmessage_list_free(env_list); 485 mailmessage_list_free(env_list);
486 } 486 }
487} 487}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 5de9299..62116ba 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -78,410 +78,410 @@ void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
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 //current_count; 141 //current_count;
142 142
143 switch (mime->mm_type) { 143 switch (mime->mm_type) {
144 case MAILMIME_SINGLE: 144 case MAILMIME_SINGLE:
145 { 145 {
146 QValueList<int>countlist = recList; 146 QValueList<int>countlist = recList;
147 countlist.append(current_count); 147 countlist.append(current_count);
148 r = mailmessage_fetch_section(message,mime,&data,&len); 148 r = mailmessage_fetch_section(message,mime,&data,&len);
149 part.setSize(len); 149 part.setSize(len);
150 part.setPositionlist(countlist); 150 part.setPositionlist(countlist);
151 b = gen_attachment_id(); 151 b = gen_attachment_id();
152 part.setIdentifier(b); 152 part.setIdentifier(b);
153 fillSingleBody(part,message,mime); 153 fillSingleBody(part,message,mime);
154 if (part.Type()=="text" && target.Bodytext().isNull()) { 154 if (part.Type()=="text" && target.Bodytext().isNull()) {
155 encodedString*r = new encodedString(); 155 encodedString*r = new encodedString();
156 r->setContent(data,len); 156 r->setContent(data,len);
157 encodedString*res = decode_String(r,part.Encoding()); 157 encodedString*res = decode_String(r,part.Encoding());
158 b = QString(res->Content()); 158 b = QString(res->Content());
159 delete r; 159 delete r;
160 delete res; 160 delete res;
161 target.setBodytext(b); 161 target.setBodytext(b);
162 target.setDescription(part); 162 target.setDescription(part);
163 } else { 163 } else {
164 bodyCache[b]=new encodedString(data,len); 164 bodyCache[b]=new encodedString(data,len);
165 target.addPart(part); 165 target.addPart(part);
166 } 166 }
167 } 167 }
168 break; 168 break;
169 case MAILMIME_MULTIPLE: 169 case MAILMIME_MULTIPLE:
170 { 170 {
171 unsigned int ccount = current_count; 171 unsigned int ccount = current_count;
172 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 172 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
173 traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount); 173 traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount);
174 ++ccount; 174 ++ccount;
175 } 175 }
176 } 176 }
177 break; 177 break;
178 case MAILMIME_MESSAGE: 178 case MAILMIME_MESSAGE:
179 { 179 {
180 QValueList<int>countlist = recList; 180 QValueList<int>countlist = recList;
181 countlist.append(current_count); 181 countlist.append(current_count);
182 /* the own header is always at recursion 0 - we don't need that */ 182 /* the own header is always at recursion 0 - we don't need that */
183 if (current_rec > 0) { 183 if (current_rec > 0) {
184 part.setPositionlist(countlist); 184 part.setPositionlist(countlist);
185 r = mailmessage_fetch_section(message,mime,&data,&len); 185 r = mailmessage_fetch_section(message,mime,&data,&len);
186 part.setSize(len); 186 part.setSize(len);
187 part.setPositionlist(countlist); 187 part.setPositionlist(countlist);
188 b = gen_attachment_id(); 188 b = gen_attachment_id();
189 part.setIdentifier(b); 189 part.setIdentifier(b);
190 part.setType("message"); 190 part.setType("message");
191 part.setSubtype("rfc822"); 191 part.setSubtype("rfc822");
192 bodyCache[b]=new encodedString(data,len); 192 bodyCache[b]=new encodedString(data,len);
193 target.addPart(part); 193 target.addPart(part);
194 } 194 }
195 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 195 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
196 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 196 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
197 } 197 }
198 } 198 }
199 break; 199 break;
200 } 200 }
201} 201}
202 202
203RecBody Genericwrapper::parseMail( mailmessage * msg ) 203RecBody Genericwrapper::parseMail( mailmessage * msg )
204{ 204{
205 int err = MAILIMF_NO_ERROR; 205 int err = MAILIMF_NO_ERROR;
206 mailmime_single_fields fields; 206 mailmime_single_fields fields;
207 /* is bound to msg and will be freed there */ 207 /* is bound to msg and will be freed there */
208 mailmime * mime=0; 208 mailmime * mime=0;
209 RecBody body; 209 RecBody body;
210 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 210 memset(&fields, 0, sizeof(struct mailmime_single_fields));
211 err = mailmessage_get_bodystructure(msg,&mime); 211 err = mailmessage_get_bodystructure(msg,&mime);
212 QValueList<int>recList; 212 QValueList<int>recList;
213 traverseBody(body,msg,mime,recList); 213 traverseBody(body,msg,mime,recList);
214 return body; 214 return body;
215} 215}
216 216
217RecMail *Genericwrapper::parseHeader( const char *header ) 217RecMail *Genericwrapper::parseHeader( const char *header )
218{ 218{
219 int err = MAILIMF_NO_ERROR; 219 int err = MAILIMF_NO_ERROR;
220 size_t curTok = 0; 220 size_t curTok = 0;
221 RecMail *mail = new RecMail(); 221 RecMail *mail = new RecMail();
222 mailimf_fields *fields = 0; 222 mailimf_fields *fields = 0;
223 mailimf_references * refs = 0; 223 mailimf_references * refs = 0;
224 mailimf_keywords*keys = 0; 224 mailimf_keywords*keys = 0;
225 QString status; 225 QString status;
226 QString value; 226 QString value;
227 QBitArray mFlags(7); 227 QBitArray mFlags(7);
228 228
229 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 229 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
230 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 230 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
231 mailimf_field *field = (mailimf_field *) current->data; 231 mailimf_field *field = (mailimf_field *) current->data;
232 switch ( field->fld_type ) { 232 switch ( field->fld_type ) {
233 case MAILIMF_FIELD_FROM: 233 case MAILIMF_FIELD_FROM:
234 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 234 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
235 break; 235 break;
236 case MAILIMF_FIELD_TO: 236 case MAILIMF_FIELD_TO:
237 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 237 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
238 break; 238 break;
239 case MAILIMF_FIELD_CC: 239 case MAILIMF_FIELD_CC:
240 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 240 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
241 break; 241 break;
242 case MAILIMF_FIELD_BCC: 242 case MAILIMF_FIELD_BCC:
243 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 243 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
244 break; 244 break;
245 case MAILIMF_FIELD_SUBJECT: 245 case MAILIMF_FIELD_SUBJECT:
246 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); 246 mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) );
247 break; 247 break;
248 case MAILIMF_FIELD_ORIG_DATE: 248 case MAILIMF_FIELD_ORIG_DATE:
249 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 249 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
250 break; 250 break;
251 case MAILIMF_FIELD_MESSAGE_ID: 251 case MAILIMF_FIELD_MESSAGE_ID:
252 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); 252 mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value));
253 break; 253 break;
254 case MAILIMF_FIELD_REFERENCES: 254 case MAILIMF_FIELD_REFERENCES:
255 refs = field->fld_data.fld_references; 255 refs = field->fld_data.fld_references;
256 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 256 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
257 char * text = (char*)refs->mid_list->first->data; 257 char * text = (char*)refs->mid_list->first->data;
258 mail->setReplyto(QString(text)); 258 mail->setReplyto(QString(text));
259 } 259 }
260 break; 260 break;
261 case MAILIMF_FIELD_KEYWORDS: 261 case MAILIMF_FIELD_KEYWORDS:
262 keys = field->fld_data.fld_keywords; 262 keys = field->fld_data.fld_keywords;
263 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { 263 for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) {
264 qDebug("Keyword: %s",(char*)cur->data); 264 qDebug("Keyword: %s",(char*)cur->data);
265 } 265 }
266 break; 266 break;
267 case MAILIMF_FIELD_OPTIONAL_FIELD: 267 case MAILIMF_FIELD_OPTIONAL_FIELD:
268 status = field->fld_data.fld_optional_field->fld_name; 268 status = field->fld_data.fld_optional_field->fld_name;
269 value = field->fld_data.fld_optional_field->fld_value; 269 value = field->fld_data.fld_optional_field->fld_value;
270 if (status.lower()=="status") { 270 if (status.lower()=="status") {
271 if (value.lower()=="ro") { 271 if (value.lower()=="ro") {
272 mFlags.setBit(FLAG_SEEN); 272 mFlags.setBit(FLAG_SEEN);
273 } 273 }
274 } else if (status.lower()=="x-status") { 274 } else if (status.lower()=="x-status") {
275 qDebug("X-Status: %s",value.latin1()); 275 qDebug("X-Status: %s",value.latin1());
276 if (value.lower()=="a") { 276 if (value.lower()=="a") {
277 mFlags.setBit(FLAG_ANSWERED); 277 mFlags.setBit(FLAG_ANSWERED);
278 } 278 }
279 } else { 279 } else {
280// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, 280// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name,
281// field->fld_data.fld_optional_field->fld_value); 281// field->fld_data.fld_optional_field->fld_value);
282 } 282 }
283 break; 283 break;
284 default: 284 default:
285 qDebug("Non parsed field"); 285 qDebug("Non parsed field");
286 break; 286 break;
287 } 287 }
288 } 288 }
289 if (fields) mailimf_fields_free(fields); 289 if (fields) mailimf_fields_free(fields);
290 mail->setFlags(mFlags); 290 mail->setFlags(mFlags);
291 return mail; 291 return mail;
292} 292}
293 293
294QString Genericwrapper::parseDateTime( mailimf_date_time *date ) 294QString Genericwrapper::parseDateTime( mailimf_date_time *date )
295{ 295{
296 char tmp[23]; 296 char tmp[23];
297 297
298 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 298 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
299 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 299 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
300 300
301 return QString( tmp ); 301 return QString( tmp );
302} 302}
303 303
304QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 304QString Genericwrapper::parseAddressList( mailimf_address_list *list )
305{ 305{
306 QString result( "" ); 306 QString result( "" );
307 307
308 bool first = true; 308 bool first = true;
309 if (list == 0) return result; 309 if (list == 0) return result;
310 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 310 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
311 mailimf_address *addr = (mailimf_address *) current->data; 311 mailimf_address *addr = (mailimf_address *) current->data;
312 312
313 if ( !first ) { 313 if ( !first ) {
314 result.append( "," ); 314 result.append( "," );
315 } else { 315 } else {
316 first = false; 316 first = false;
317 } 317 }
318 318
319 switch ( addr->ad_type ) { 319 switch ( addr->ad_type ) {
320 case MAILIMF_ADDRESS_MAILBOX: 320 case MAILIMF_ADDRESS_MAILBOX:
321 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 321 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
322 break; 322 break;
323 case MAILIMF_ADDRESS_GROUP: 323 case MAILIMF_ADDRESS_GROUP:
324 result.append( parseGroup( addr->ad_data.ad_group ) ); 324 result.append( parseGroup( addr->ad_data.ad_group ) );
325 break; 325 break;
326 default: 326 default:
327 qDebug( "Generic: unkown mailimf address type" ); 327 qDebug( "Generic: unkown mailimf address type" );
328 break; 328 break;
329 } 329 }
330 } 330 }
331 331
332 return result; 332 return result;
333} 333}
334 334
335QString Genericwrapper::parseGroup( mailimf_group *group ) 335QString Genericwrapper::parseGroup( mailimf_group *group )
336{ 336{
337 QString result( "" ); 337 QString result( "" );
338 338
339 result.append( group->grp_display_name ); 339 result.append( group->grp_display_name );
340 result.append( ": " ); 340 result.append( ": " );
341 341
342 if ( group->grp_mb_list != NULL ) { 342 if ( group->grp_mb_list != NULL ) {
343 result.append( parseMailboxList( group->grp_mb_list ) ); 343 result.append( parseMailboxList( group->grp_mb_list ) );
344 } 344 }
345 345
346 result.append( ";" ); 346 result.append( ";" );
347 347
348 return result; 348 return result;
349} 349}
350 350
351QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 351QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
352{ 352{
353 QString result( "" ); 353 QString result( "" );
354 354
355 if ( box->mb_display_name == NULL ) { 355 if ( box->mb_display_name == NULL ) {
356 result.append( box->mb_addr_spec ); 356 result.append( box->mb_addr_spec );
357 } else { 357 } else {
358 result.append( convert_String(box->mb_display_name).latin1() ); 358 result.append( convert_String(box->mb_display_name).latin1() );
359 result.append( " <" ); 359 result.append( " <" );
360 result.append( box->mb_addr_spec ); 360 result.append( box->mb_addr_spec );
361 result.append( ">" ); 361 result.append( ">" );
362 } 362 }
363 363
364 return result; 364 return result;
365} 365}
366 366
367QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 367QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
368{ 368{
369 QString result( "" ); 369 QString result( "" );
370 370
371 bool first = true; 371 bool first = true;
372 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 372 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
373 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 373 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
374 374
375 if ( !first ) { 375 if ( !first ) {
376 result.append( "," ); 376 result.append( "," );
377 } else { 377 } else {
378 first = false; 378 first = false;
379 } 379 }
380 380
381 result.append( parseMailbox( box ) ); 381 result.append( parseMailbox( box ) );
382 } 382 }
383 383
384 return result; 384 return result;
385} 385}
386 386
387encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) 387encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part)
388{ 388{
389 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 389 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
390 if (it==bodyCache.end()) return new encodedString(); 390 if (it==bodyCache.end()) return new encodedString();
391 encodedString*t = decode_String(it.data(),part.Encoding()); 391 encodedString*t = decode_String(it.data(),part.Encoding());
392 return t; 392 return t;
393} 393}
394 394
395encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 395encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
396{ 396{
397 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); 397 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier());
398 if (it==bodyCache.end()) return new encodedString(); 398 if (it==bodyCache.end()) return new encodedString();
399 encodedString*t = it.data(); 399 encodedString*t = it.data();
400 return t; 400 return t;
401} 401}
402 402
403QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 403QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
404{ 404{
405 encodedString*t = fetchDecodedPart(mail,part); 405 encodedString*t = fetchDecodedPart(mail,part);
406 QString text=t->Content(); 406 QString text=t->Content();
407 delete t; 407 delete t;
408 return text; 408 return text;
409} 409}
410 410
411void Genericwrapper::cleanMimeCache() 411void Genericwrapper::cleanMimeCache()
412{ 412{
413 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 413 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
414 for (;it!=bodyCache.end();++it) { 414 for (;it!=bodyCache.end();++it) {
415 encodedString*t = it.data(); 415 encodedString*t = it.data();
416 //it.setValue(0); 416 //it.setValue(0);
417 if (t) delete t; 417 if (t) delete t;
418 } 418 }
419 bodyCache.clear(); 419 bodyCache.clear();
420 qDebug("Genericwrapper: cache cleaned"); 420 qDebug("Genericwrapper: cache cleaned");
421} 421}
422 422
423void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox) 423void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox)
424{ 424{
425 int r; 425 int r;
426 mailmessage_list * env_list = 0; 426 mailmessage_list * env_list = 0;
427 r = mailsession_get_messages_list(session,&env_list); 427 r = mailsession_get_messages_list(session,&env_list);
428 if (r != MAIL_NO_ERROR) { 428 if (r != MAIL_NO_ERROR) {
429 qDebug("Error message list"); 429 qDebug("Error message list");
430 return; 430 return;
431 } 431 }
432 r = mailsession_get_envelopes_list(session, env_list); 432 r = mailsession_get_envelopes_list(session, env_list);
433 if (r != MAIL_NO_ERROR) { 433 if (r != MAIL_NO_ERROR) {
434 qDebug("Error filling message list"); 434 qDebug("Error filling message list");
435 if (env_list) { 435 if (env_list) {
436 mailmessage_list_free(env_list); 436 mailmessage_list_free(env_list);
437 } 437 }
438 return; 438 return;
439 } 439 }
440 mailimf_references * refs; 440 mailimf_references * refs;
441 uint32_t i = 0; 441 uint32_t i = 0;
442 for(; i < carray_count(env_list->msg_tab) ; ++i) { 442 for(; i < carray_count(env_list->msg_tab) ; ++i) {
443 mailmessage * msg; 443 mailmessage * msg;
444 QBitArray mFlags(7); 444 QBitArray mFlags(7);
445 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 445 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
446 if (msg->msg_fields == NULL) { 446 if (msg->msg_fields == NULL) {
447 qDebug("could not fetch envelope of message %i", i); 447 qDebug("could not fetch envelope of message %i", i);
448 continue; 448 continue;
449 } 449 }
450 RecMail * mail = new RecMail(); 450 RecMail * mail = new RecMail();
451 mail->setWrapper(this); 451 mail->setWrapper(this);
452 mail_flags * flag_result = 0; 452 mail_flags * flag_result = 0;
453 r = mailmessage_get_flags(msg,&flag_result); 453 r = mailmessage_get_flags(msg,&flag_result);
454 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 454 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
455 mFlags.setBit(FLAG_SEEN); 455 mFlags.setBit(FLAG_SEEN);
456 } 456 }
457 mailimf_single_fields single_fields; 457 mailimf_single_fields single_fields;
458 mailimf_single_fields_init(&single_fields, msg->msg_fields); 458 mailimf_single_fields_init(&single_fields, msg->msg_fields);
459 mail->setMsgsize(msg->msg_size); 459 mail->setMsgsize(msg->msg_size);
460 mail->setFlags(mFlags); 460 mail->setFlags(mFlags);
461 mail->setMbox(mailbox); 461 mail->setMbox(mailbox);
462 mail->setNumber(i+1); 462 mail->setNumber(msg->msg_index);
463 if (single_fields.fld_subject) 463 if (single_fields.fld_subject)
464 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 464 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
465 if (single_fields.fld_from) 465 if (single_fields.fld_from)
466 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 466 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
467 if (single_fields.fld_to) 467 if (single_fields.fld_to)
468 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 468 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
469 if (single_fields.fld_cc) 469 if (single_fields.fld_cc)
470 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 470 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
471 if (single_fields.fld_bcc) 471 if (single_fields.fld_bcc)
472 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 472 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
473 if (single_fields.fld_orig_date) 473 if (single_fields.fld_orig_date)
474 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); 474 mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
475 if (single_fields.fld_message_id->mid_value) 475 if (single_fields.fld_message_id->mid_value)
476 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 476 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
477 refs = single_fields.fld_references; 477 refs = single_fields.fld_references;
478 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 478 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
479 char * text = (char*)refs->mid_list->first->data; 479 char * text = (char*)refs->mid_list->first->data;
480 mail->setReplyto(QString(text)); 480 mail->setReplyto(QString(text));
481 } 481 }
482 target.append(mail); 482 target.append(mail);
483 } 483 }
484 if (env_list) { 484 if (env_list) {
485 mailmessage_list_free(env_list); 485 mailmessage_list_free(env_list);
486 } 486 }
487} 487}