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