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