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