summaryrefslogtreecommitdiff
authoralwin <alwin>2005-03-11 22:15:12 (UTC)
committer alwin <alwin>2005-03-11 22:15:12 (UTC)
commitcff58fc3b963a09506a17d17cf4e3f9a3887d491 (patch) (unidiff)
tree450d113bd74f5a4934b9540dd6ec883a6e23e6cf
parente851ff8f826be005a2aa935133d40b162f23de53 (diff)
downloadopie-cff58fc3b963a09506a17d17cf4e3f9a3887d491.zip
opie-cff58fc3b963a09506a17d17cf4e3f9a3887d491.tar.gz
opie-cff58fc3b963a09506a17d17cf4e3f9a3887d491.tar.bz2
even a full correct mail comes via generic protocoll like pop3 or mh
parts of were stored with wrong identifier inside cache.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp17
1 files changed, 9 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 0ac842d..6fcc701 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -23,327 +23,328 @@ Genericwrapper::~Genericwrapper()
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;
152 RecPartP part = new RecPart(); 151 RecPartP part = new RecPart();
153 152
154 switch (mime->mm_type) { 153 switch (mime->mm_type) {
155 case MAILMIME_SINGLE: 154 case MAILMIME_SINGLE:
156 { 155 {
157 QValueList<int>countlist = recList; 156 QValueList<int>countlist = recList;
158 countlist.append(current_count); 157 countlist.append(current_count);
159 r = mailmessage_fetch_section(message,mime,&data,&len); 158 r = mailmessage_fetch_section(message,mime,&data,&len);
160 part->setSize(len); 159 part->setSize(len);
161 part->setPositionlist(countlist); 160 part->setPositionlist(countlist);
162 b = gen_attachment_id();
163 part->setIdentifier(b);
164 fillSingleBody(part,message,mime); 161 fillSingleBody(part,message,mime);
162 if (part->Identifier().isEmpty()) {
163 part->setIdentifier(gen_attachment_id());
164 }
165
165 if (part->Type()=="text" && target->Bodytext().isNull()) { 166 if (part->Type()=="text" && target->Bodytext().isNull()) {
166 encodedString*rs = new encodedString(); 167 encodedString*rs = new encodedString();
167 rs->setContent(data,len); 168 rs->setContent(data,len);
168 encodedString*res = decode_String(rs,part->Encoding()); 169 encodedString*res = decode_String(rs,part->Encoding());
169 if (countlist.count()>2) { 170 if (countlist.count()>2) {
170 bodyCache[b]=rs; 171 bodyCache[part->Identifier()]=rs;
171 target->addPart(part); 172 target->addPart(part);
172 } else { 173 } else {
173 delete rs; 174 delete rs;
174 } 175 }
176 QString b;
175 b = QString(res->Content()); 177 b = QString(res->Content());
176 delete res; 178 delete res;
177 target->setBodytext(b); 179 target->setBodytext(b);
178 target->setDescription(part); 180 target->setDescription(part);
179 } else { 181 } else {
180 bodyCache[b]=new encodedString(data,len); 182 bodyCache[part->Identifier()]=new encodedString(data,len);
181 target->addPart(part); 183 target->addPart(part);
182 } 184 }
183 } 185 }
184 break; 186 break;
185 case MAILMIME_MULTIPLE: 187 case MAILMIME_MULTIPLE:
186 { 188 {
187 unsigned int ccount = 1; 189 unsigned int ccount = 1;
188 mailmime*cbody=0; 190 mailmime*cbody=0;
189 QValueList<int>countlist = recList; 191 QValueList<int>countlist = recList;
190 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 192 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
191 cbody = (mailmime*)clist_content(cur); 193 cbody = (mailmime*)clist_content(cur);
192 if (cbody->mm_type==MAILMIME_MULTIPLE) { 194 if (cbody->mm_type==MAILMIME_MULTIPLE) {
193 RecPartP targetPart = new RecPart(); 195 RecPartP targetPart = new RecPart();
194 targetPart->setType("multipart"); 196 targetPart->setType("multipart");
195 countlist.append(current_count); 197 countlist.append(current_count);
196 targetPart->setPositionlist(countlist); 198 targetPart->setPositionlist(countlist);
197 target->addPart(targetPart); 199 target->addPart(targetPart);
198 } 200 }
199 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 201 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
200 if (cbody->mm_type==MAILMIME_MULTIPLE) { 202 if (cbody->mm_type==MAILMIME_MULTIPLE) {
201 countlist = recList; 203 countlist = recList;
202 } 204 }
203 ++ccount; 205 ++ccount;
204 } 206 }
205 } 207 }
206 break; 208 break;
207 case MAILMIME_MESSAGE: 209 case MAILMIME_MESSAGE:
208 { 210 {
209 QValueList<int>countlist = recList; 211 QValueList<int>countlist = recList;
210 countlist.append(current_count); 212 countlist.append(current_count);
211 /* the own header is always at recursion 0 - we don't need that */ 213 /* the own header is always at recursion 0 - we don't need that */
212 if (current_rec > 0) { 214 if (current_rec > 0) {
213 part->setPositionlist(countlist); 215 part->setPositionlist(countlist);
214 r = mailmessage_fetch_section(message,mime,&data,&len); 216 r = mailmessage_fetch_section(message,mime,&data,&len);
215 part->setSize(len); 217 part->setSize(len);
216 part->setPositionlist(countlist); 218 part->setPositionlist(countlist);
217 b = gen_attachment_id(); 219 part->setIdentifier(gen_attachment_id());
218 part->setIdentifier(b);
219 part->setType("message"); 220 part->setType("message");
220 part->setSubtype("rfc822"); 221 part->setSubtype("rfc822");
221 bodyCache[b]=new encodedString(data,len); 222 bodyCache[part->Identifier()]=new encodedString(data,len);
222 target->addPart(part); 223 target->addPart(part);
223 } 224 }
224 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 225 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); 226 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
226 } 227 }
227 } 228 }
228 break; 229 break;
229 } 230 }
230} 231}
231 232
232RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 233RecBodyP Genericwrapper::parseMail( mailmessage * msg )
233{ 234{
234 int err = MAILIMF_NO_ERROR; 235 int err = MAILIMF_NO_ERROR;
235 mailmime_single_fields fields; 236 mailmime_single_fields fields;
236 /* is bound to msg and will be freed there */ 237 /* is bound to msg and will be freed there */
237 mailmime * mime=0; 238 mailmime * mime=0;
238 RecBodyP body = new RecBody(); 239 RecBodyP body = new RecBody();
239 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 240 memset(&fields, 0, sizeof(struct mailmime_single_fields));
240 err = mailmessage_get_bodystructure(msg,&mime); 241 err = mailmessage_get_bodystructure(msg,&mime);
241 QValueList<int>recList; 242 QValueList<int>recList;
242 traverseBody(body,msg,mime,recList); 243 traverseBody(body,msg,mime,recList);
243 return body; 244 return body;
244} 245}
245 246
246QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 247QString Genericwrapper::parseAddressList( mailimf_address_list *list )
247{ 248{
248 QString result( "" ); 249 QString result( "" );
249 250
250 bool first = true; 251 bool first = true;
251 if (list == 0) return result; 252 if (list == 0) return result;
252 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 253 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
253 mailimf_address *addr = (mailimf_address *) current->data; 254 mailimf_address *addr = (mailimf_address *) current->data;
254 255
255 if ( !first ) { 256 if ( !first ) {
256 result.append( "," ); 257 result.append( "," );
257 } else { 258 } else {
258 first = false; 259 first = false;
259 } 260 }
260 261
261 switch ( addr->ad_type ) { 262 switch ( addr->ad_type ) {
262 case MAILIMF_ADDRESS_MAILBOX: 263 case MAILIMF_ADDRESS_MAILBOX:
263 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 264 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
264 break; 265 break;
265 case MAILIMF_ADDRESS_GROUP: 266 case MAILIMF_ADDRESS_GROUP:
266 result.append( parseGroup( addr->ad_data.ad_group ) ); 267 result.append( parseGroup( addr->ad_data.ad_group ) );
267 break; 268 break;
268 default: 269 default:
269 odebug << "Generic: unkown mailimf address type" << oendl; 270 odebug << "Generic: unkown mailimf address type" << oendl;
270 break; 271 break;
271 } 272 }
272 } 273 }
273 274
274 return result; 275 return result;
275} 276}
276 277
277QString Genericwrapper::parseGroup( mailimf_group *group ) 278QString Genericwrapper::parseGroup( mailimf_group *group )
278{ 279{
279 QString result( "" ); 280 QString result( "" );
280 281
281 result.append( group->grp_display_name ); 282 result.append( group->grp_display_name );
282 result.append( ": " ); 283 result.append( ": " );
283 284
284 if ( group->grp_mb_list != NULL ) { 285 if ( group->grp_mb_list != NULL ) {
285 result.append( parseMailboxList( group->grp_mb_list ) ); 286 result.append( parseMailboxList( group->grp_mb_list ) );
286 } 287 }
287 288
288 result.append( ";" ); 289 result.append( ";" );
289 290
290 return result; 291 return result;
291} 292}
292 293
293QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 294QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
294{ 295{
295 QString result( "" ); 296 QString result( "" );
296 297
297 if ( box->mb_display_name == NULL ) { 298 if ( box->mb_display_name == NULL ) {
298 result.append( box->mb_addr_spec ); 299 result.append( box->mb_addr_spec );
299 } else { 300 } else {
300 result.append( convert_String(box->mb_display_name).latin1() ); 301 result.append( convert_String(box->mb_display_name).latin1() );
301 result.append( " <" ); 302 result.append( " <" );
302 result.append( box->mb_addr_spec ); 303 result.append( box->mb_addr_spec );
303 result.append( ">" ); 304 result.append( ">" );
304 } 305 }
305 306
306 return result; 307 return result;
307} 308}
308 309
309QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 310QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
310{ 311{
311 QString result( "" ); 312 QString result( "" );
312 313
313 bool first = true; 314 bool first = true;
314 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 315 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
315 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 316 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
316 317
317 if ( !first ) { 318 if ( !first ) {
318 result.append( "," ); 319 result.append( "," );
319 } else { 320 } else {
320 first = false; 321 first = false;
321 } 322 }
322 323
323 result.append( parseMailbox( box ) ); 324 result.append( parseMailbox( box ) );
324 } 325 }
325 326
326 return result; 327 return result;
327} 328}
328 329
329encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 330encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
330{ 331{
331 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 332 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
332 if (it==bodyCache.end()) return new encodedString(); 333 if (it==bodyCache.end()) return new encodedString();
333 encodedString*t = decode_String(it.data(),part->Encoding()); 334 encodedString*t = decode_String(it.data(),part->Encoding());
334 return t; 335 return t;
335} 336}
336 337
337encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 338encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
338{ 339{
339 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 340 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
340 if (it==bodyCache.end()) return new encodedString(); 341 if (it==bodyCache.end()) return new encodedString();
341 encodedString*t = it.data(); 342 encodedString*t = it.data();
342 return t; 343 return t;
343} 344}
344 345
345QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 346QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
346{ 347{
347 encodedString*t = fetchDecodedPart(mail,part); 348 encodedString*t = fetchDecodedPart(mail,part);
348 QString text=t->Content(); 349 QString text=t->Content();
349 delete t; 350 delete t;