Diffstat (limited to 'kmicromail/libmailwrapper/genericwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 0b6adf7..633ab42 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp | |||
@@ -1,40 +1,42 @@ | |||
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 | #include <kconfig.h> | 6 | #include <kconfig.h> |
7 | #include <kglobal.h> | 7 | #include <kglobal.h> |
8 | #include <kstandarddirs.h> | 8 | #include <kstandarddirs.h> |
9 | //Added by qt3to4: | ||
10 | #include <Q3ValueList> | ||
9 | 11 | ||
10 | 12 | ||
11 | using namespace Opie::Core; | 13 | using namespace Opie::Core; |
12 | Genericwrapper::Genericwrapper() | 14 | Genericwrapper::Genericwrapper() |
13 | : AbstractMail() | 15 | : AbstractMail() |
14 | { | 16 | { |
15 | bodyCache.clear(); | 17 | bodyCache.clear(); |
16 | m_storage = 0; | 18 | m_storage = 0; |
17 | m_folder = 0; | 19 | m_folder = 0; |
18 | } | 20 | } |
19 | 21 | ||
20 | Genericwrapper::~Genericwrapper() | 22 | Genericwrapper::~Genericwrapper() |
21 | { | 23 | { |
22 | if (m_folder) { | 24 | if (m_folder) { |
23 | mailfolder_free(m_folder); | 25 | mailfolder_free(m_folder); |
24 | } | 26 | } |
25 | if (m_storage) { | 27 | if (m_storage) { |
26 | mailstorage_free(m_storage); | 28 | mailstorage_free(m_storage); |
27 | } | 29 | } |
28 | cleanMimeCache(); | 30 | cleanMimeCache(); |
29 | } | 31 | } |
30 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) | 32 | const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) |
31 | { | 33 | { |
32 | 34 | ||
33 | QDate da (date->dt_year,date->dt_month, date->dt_day ); | 35 | QDate da (date->dt_year,date->dt_month, date->dt_day ); |
34 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); | 36 | QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); |
35 | QDateTime dt ( da ,ti ); | 37 | QDateTime dt ( da ,ti ); |
36 | int addsec = -date->dt_zone*36; | 38 | int addsec = -date->dt_zone*36; |
37 | //qDebug("adsec1 %d ",addsec ); | 39 | //qDebug("adsec1 %d ",addsec ); |
38 | dt = dt.addSecs( addsec ); | 40 | dt = dt.addSecs( addsec ); |
39 | int off = KGlobal::locale()->localTimeOffset( dt ); | 41 | int off = KGlobal::locale()->localTimeOffset( dt ); |
40 | //qDebug("adsec2 %d ",off*60 ); | 42 | //qDebug("adsec2 %d ",off*60 ); |
@@ -153,185 +155,185 @@ void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) | |||
153 | } | 155 | } |
154 | 156 | ||
155 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) | 157 | QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) |
156 | { | 158 | { |
157 | QString enc="7bit"; | 159 | QString enc="7bit"; |
158 | if (!aEnc) return enc; | 160 | if (!aEnc) return enc; |
159 | switch(aEnc->enc_type) { | 161 | switch(aEnc->enc_type) { |
160 | case MAILMIME_MECHANISM_7BIT: | 162 | case MAILMIME_MECHANISM_7BIT: |
161 | enc = "7bit"; | 163 | enc = "7bit"; |
162 | break; | 164 | break; |
163 | case MAILMIME_MECHANISM_8BIT: | 165 | case MAILMIME_MECHANISM_8BIT: |
164 | enc = "8bit"; | 166 | enc = "8bit"; |
165 | break; | 167 | break; |
166 | case MAILMIME_MECHANISM_BINARY: | 168 | case MAILMIME_MECHANISM_BINARY: |
167 | enc = "binary"; | 169 | enc = "binary"; |
168 | break; | 170 | break; |
169 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | 171 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: |
170 | enc = "quoted-printable"; | 172 | enc = "quoted-printable"; |
171 | break; | 173 | break; |
172 | case MAILMIME_MECHANISM_BASE64: | 174 | case MAILMIME_MECHANISM_BASE64: |
173 | enc = "base64"; | 175 | enc = "base64"; |
174 | break; | 176 | break; |
175 | case MAILMIME_MECHANISM_TOKEN: | 177 | case MAILMIME_MECHANISM_TOKEN: |
176 | default: | 178 | default: |
177 | if (aEnc->enc_token) { | 179 | if (aEnc->enc_token) { |
178 | enc = QString(aEnc->enc_token); | 180 | enc = QString(aEnc->enc_token); |
179 | } | 181 | } |
180 | break; | 182 | break; |
181 | } | 183 | } |
182 | return enc; | 184 | return enc; |
183 | } | 185 | } |
184 | 186 | ||
185 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) | 187 | void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,Q3ValueList<int>recList,unsigned int current_rec,int current_count) |
186 | { | 188 | { |
187 | if (current_rec >= 10) { | 189 | if (current_rec >= 10) { |
188 | ; // odebug << "too deep recursion!" << oendl; | 190 | ; // odebug << "too deep recursion!" << oendl; |
189 | } | 191 | } |
190 | if (!message || !mime) { | 192 | if (!message || !mime) { |
191 | return; | 193 | return; |
192 | } | 194 | } |
193 | int r; | 195 | int r; |
194 | char*data = 0; | 196 | char*data = 0; |
195 | size_t len; | 197 | size_t len; |
196 | clistiter * cur = 0; | 198 | clistiter * cur = 0; |
197 | QString b; | 199 | QString b; |
198 | RecPartP part = new RecPart(); | 200 | RecPartP part = new RecPart(); |
199 | 201 | ||
200 | switch (mime->mm_type) { | 202 | switch (mime->mm_type) { |
201 | case MAILMIME_SINGLE: | 203 | case MAILMIME_SINGLE: |
202 | { | 204 | { |
203 | QValueList<int>countlist = recList; | 205 | Q3ValueList<int>countlist = recList; |
204 | countlist.append(current_count); | 206 | countlist.append(current_count); |
205 | r = mailmessage_fetch_section(message,mime,&data,&len); | 207 | r = mailmessage_fetch_section(message,mime,&data,&len); |
206 | part->setSize(len); | 208 | part->setSize(len); |
207 | part->setPositionlist(countlist); | 209 | part->setPositionlist(countlist); |
208 | b = gen_attachment_id(); | 210 | b = gen_attachment_id(); |
209 | part->setIdentifier(b); | 211 | part->setIdentifier(b); |
210 | fillSingleBody(part,message,mime); | 212 | fillSingleBody(part,message,mime); |
211 | if (part->Type()=="text" && target->Bodytext().isNull()) { | 213 | if (part->Type()=="text" && target->Bodytext().isNull()) { |
212 | encodedString*rs = new encodedString(); | 214 | encodedString*rs = new encodedString(); |
213 | rs->setContent(data,len); | 215 | rs->setContent(data,len); |
214 | encodedString*res = decode_String(rs,part->Encoding()); | 216 | encodedString*res = decode_String(rs,part->Encoding()); |
215 | if (countlist.count()>2) { | 217 | if (countlist.count()>2) { |
216 | bodyCache[b]=rs; | 218 | bodyCache[b]=rs; |
217 | target->addPart(part); | 219 | target->addPart(part); |
218 | } else { | 220 | } else { |
219 | delete rs; | 221 | delete rs; |
220 | } | 222 | } |
221 | b = QString(res->Content()); | 223 | b = QString(res->Content()); |
222 | delete res; | 224 | delete res; |
223 | size_t index = 0; | 225 | size_t index = 0; |
224 | char*resu = 0; | 226 | char*resu = 0; |
225 | int err = MAILIMF_NO_ERROR; | 227 | int err = MAILIMF_NO_ERROR; |
226 | QString charset = part->searchParamter( "charset"); | 228 | QString charset = part->searchParamter( "charset"); |
227 | qDebug("CHARSET %s ",charset.latin1() ); | 229 | qDebug("CHARSET %s ",charset.latin1() ); |
228 | #if 0 | 230 | #if 0 |
229 | if (false ) { | 231 | if (false ) { |
230 | //if ( !charset.isEmpty() ) { | 232 | //if ( !charset.isEmpty() ) { |
231 | target->setCharset( charset ); | 233 | target->setCharset( charset ); |
232 | err = mailmime_encoded_phrase_parse(charset.latin1(), | 234 | err = mailmime_encoded_phrase_parse(charset.latin1(), |
233 | b.latin1(), b.length(),&index, "utf-8",&resu); | 235 | b.latin1(), b.length(),&index, "utf-8",&resu); |
234 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { | 236 | if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { |
235 | //qDebug("res %d %s ", index, resu); | 237 | //qDebug("res %d %s ", index, resu); |
236 | b = QString::fromUtf8(resu); | 238 | b = QString::fromUtf8(resu); |
237 | } | 239 | } |
238 | if (resu) free(resu); | 240 | if (resu) free(resu); |
239 | } | 241 | } |
240 | #endif | 242 | #endif |
241 | target->setBodytext(b); | 243 | target->setBodytext(b); |
242 | target->setDescription(part); | 244 | target->setDescription(part); |
243 | } else { | 245 | } else { |
244 | bodyCache[b]=new encodedString(data,len); | 246 | bodyCache[b]=new encodedString(data,len); |
245 | target->addPart(part); | 247 | target->addPart(part); |
246 | } | 248 | } |
247 | } | 249 | } |
248 | break; | 250 | break; |
249 | case MAILMIME_MULTIPLE: | 251 | case MAILMIME_MULTIPLE: |
250 | { | 252 | { |
251 | unsigned int ccount = 1; | 253 | unsigned int ccount = 1; |
252 | mailmime*cbody=0; | 254 | mailmime*cbody=0; |
253 | QValueList<int>countlist = recList; | 255 | Q3ValueList<int>countlist = recList; |
254 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | 256 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { |
255 | cbody = (mailmime*)clist_content(cur); | 257 | cbody = (mailmime*)clist_content(cur); |
256 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 258 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
257 | RecPartP targetPart = new RecPart(); | 259 | RecPartP targetPart = new RecPart(); |
258 | targetPart->setType("multipart"); | 260 | targetPart->setType("multipart"); |
259 | countlist.append(current_count); | 261 | countlist.append(current_count); |
260 | targetPart->setPositionlist(countlist); | 262 | targetPart->setPositionlist(countlist); |
261 | target->addPart(targetPart); | 263 | target->addPart(targetPart); |
262 | } | 264 | } |
263 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); | 265 | traverseBody(target,message, cbody,countlist,current_rec+1,ccount); |
264 | if (cbody->mm_type==MAILMIME_MULTIPLE) { | 266 | if (cbody->mm_type==MAILMIME_MULTIPLE) { |
265 | countlist = recList; | 267 | countlist = recList; |
266 | } | 268 | } |
267 | ++ccount; | 269 | ++ccount; |
268 | } | 270 | } |
269 | } | 271 | } |
270 | break; | 272 | break; |
271 | case MAILMIME_MESSAGE: | 273 | case MAILMIME_MESSAGE: |
272 | { | 274 | { |
273 | QValueList<int>countlist = recList; | 275 | Q3ValueList<int>countlist = recList; |
274 | countlist.append(current_count); | 276 | countlist.append(current_count); |
275 | /* the own header is always at recursion 0 - we don't need that */ | 277 | /* the own header is always at recursion 0 - we don't need that */ |
276 | if (current_rec > 0) { | 278 | if (current_rec > 0) { |
277 | part->setPositionlist(countlist); | 279 | part->setPositionlist(countlist); |
278 | r = mailmessage_fetch_section(message,mime,&data,&len); | 280 | r = mailmessage_fetch_section(message,mime,&data,&len); |
279 | part->setSize(len); | 281 | part->setSize(len); |
280 | part->setPositionlist(countlist); | 282 | part->setPositionlist(countlist); |
281 | b = gen_attachment_id(); | 283 | b = gen_attachment_id(); |
282 | part->setIdentifier(b); | 284 | part->setIdentifier(b); |
283 | part->setType("message"); | 285 | part->setType("message"); |
284 | part->setSubtype("rfc822"); | 286 | part->setSubtype("rfc822"); |
285 | bodyCache[b]=new encodedString(data,len); | 287 | bodyCache[b]=new encodedString(data,len); |
286 | target->addPart(part); | 288 | target->addPart(part); |
287 | } | 289 | } |
288 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | 290 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { |
289 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); | 291 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); |
290 | } | 292 | } |
291 | } | 293 | } |
292 | break; | 294 | break; |
293 | } | 295 | } |
294 | } | 296 | } |
295 | 297 | ||
296 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) | 298 | RecBodyP Genericwrapper::parseMail( mailmessage * msg ) |
297 | { | 299 | { |
298 | int err = MAILIMF_NO_ERROR; | 300 | int err = MAILIMF_NO_ERROR; |
299 | //mailmime_single_fields fields; | 301 | //mailmime_single_fields fields; |
300 | /* is bound to msg and will be freed there */ | 302 | /* is bound to msg and will be freed there */ |
301 | mailmime * mime=0; | 303 | mailmime * mime=0; |
302 | RecBodyP body = new RecBody(); | 304 | RecBodyP body = new RecBody(); |
303 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 305 | //memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
304 | err = mailmessage_get_bodystructure(msg,&mime); | 306 | err = mailmessage_get_bodystructure(msg,&mime); |
305 | QValueList<int>recList; | 307 | Q3ValueList<int>recList; |
306 | traverseBody(body,msg,mime,recList); | 308 | traverseBody(body,msg,mime,recList); |
307 | return body; | 309 | return body; |
308 | } | 310 | } |
309 | 311 | ||
310 | 312 | ||
311 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) | 313 | QString Genericwrapper::parseAddressList( mailimf_address_list *list ) |
312 | { | 314 | { |
313 | QString result( "" ); | 315 | QString result( "" ); |
314 | 316 | ||
315 | bool first = true; | 317 | bool first = true; |
316 | if (list == 0) return result; | 318 | if (list == 0) return result; |
317 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { | 319 | for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { |
318 | mailimf_address *addr = (mailimf_address *) current->data; | 320 | mailimf_address *addr = (mailimf_address *) current->data; |
319 | 321 | ||
320 | if ( !first ) { | 322 | if ( !first ) { |
321 | result.append( "," ); | 323 | result.append( "," ); |
322 | } else { | 324 | } else { |
323 | first = false; | 325 | first = false; |
324 | } | 326 | } |
325 | 327 | ||
326 | switch ( addr->ad_type ) { | 328 | switch ( addr->ad_type ) { |
327 | case MAILIMF_ADDRESS_MAILBOX: | 329 | case MAILIMF_ADDRESS_MAILBOX: |
328 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); | 330 | result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); |
329 | break; | 331 | break; |
330 | case MAILIMF_ADDRESS_GROUP: | 332 | case MAILIMF_ADDRESS_GROUP: |
331 | result.append( parseGroup( addr->ad_data.ad_group ) ); | 333 | result.append( parseGroup( addr->ad_data.ad_group ) ); |
332 | break; | 334 | break; |
333 | default: | 335 | default: |
334 | ; // odebug << "Generic: unkown mailimf address type" << oendl; | 336 | ; // odebug << "Generic: unkown mailimf address type" << oendl; |
335 | break; | 337 | break; |
336 | } | 338 | } |
337 | } | 339 | } |
@@ -418,65 +420,65 @@ QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) | |||
418 | void Genericwrapper::cleanMimeCache() | 420 | void Genericwrapper::cleanMimeCache() |
419 | { | 421 | { |
420 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); | 422 | QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); |
421 | for (;it!=bodyCache.end();++it) { | 423 | for (;it!=bodyCache.end();++it) { |
422 | encodedString*t = it.data(); | 424 | encodedString*t = it.data(); |
423 | //it.setValue(0); | 425 | //it.setValue(0); |
424 | if (t) delete t; | 426 | if (t) delete t; |
425 | } | 427 | } |
426 | bodyCache.clear(); | 428 | bodyCache.clear(); |
427 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; | 429 | ; // odebug << "Genericwrapper: cache cleaned" << oendl; |
428 | } | 430 | } |
429 | 431 | ||
430 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) | 432 | QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) |
431 | { | 433 | { |
432 | QStringList res; | 434 | QStringList res; |
433 | if (!in_replies || !in_replies->mid_list) return res; | 435 | if (!in_replies || !in_replies->mid_list) return res; |
434 | clistiter * current = 0; | 436 | clistiter * current = 0; |
435 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { | 437 | for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { |
436 | QString h((char*)current->data); | 438 | QString h((char*)current->data); |
437 | while (h.length()>0 && h[0]=='<') { | 439 | while (h.length()>0 && h[0]=='<') { |
438 | h.remove(0,1); | 440 | h.remove(0,1); |
439 | } | 441 | } |
440 | while (h.length()>0 && h[h.length()-1]=='>') { | 442 | while (h.length()>0 && h[h.length()-1]=='>') { |
441 | h.remove(h.length()-1,1); | 443 | h.remove(h.length()-1,1); |
442 | } | 444 | } |
443 | if (h.length()>0) { | 445 | if (h.length()>0) { |
444 | res.append(h); | 446 | res.append(h); |
445 | } | 447 | } |
446 | } | 448 | } |
447 | return res; | 449 | return res; |
448 | } | 450 | } |
449 | 451 | ||
450 | void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) | 452 | void Genericwrapper::parseList(Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) |
451 | { | 453 | { |
452 | int r; | 454 | int r; |
453 | mailmessage_list * env_list = 0; | 455 | mailmessage_list * env_list = 0; |
454 | r = mailsession_get_messages_list(session,&env_list); | 456 | r = mailsession_get_messages_list(session,&env_list); |
455 | if (r != MAIL_NO_ERROR) { | 457 | if (r != MAIL_NO_ERROR) { |
456 | ; // odebug << "Error message list" << oendl; | 458 | ; // odebug << "Error message list" << oendl; |
457 | return; | 459 | return; |
458 | } | 460 | } |
459 | r = mailsession_get_envelopes_list(session, env_list); | 461 | r = mailsession_get_envelopes_list(session, env_list); |
460 | if (r != MAIL_NO_ERROR) { | 462 | if (r != MAIL_NO_ERROR) { |
461 | ; // odebug << "Error filling message list" << oendl; | 463 | ; // odebug << "Error filling message list" << oendl; |
462 | if (env_list) { | 464 | if (env_list) { |
463 | mailmessage_list_free(env_list); | 465 | mailmessage_list_free(env_list); |
464 | } | 466 | } |
465 | return; | 467 | return; |
466 | } | 468 | } |
467 | mailimf_references * refs = 0; | 469 | mailimf_references * refs = 0; |
468 | mailimf_in_reply_to * in_replies = 0; | 470 | mailimf_in_reply_to * in_replies = 0; |
469 | uint32_t i = 0; | 471 | uint32_t i = 0; |
470 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | 472 | for(; i < carray_count(env_list->msg_tab) ; ++i) { |
471 | mailmessage * msg; | 473 | mailmessage * msg; |
472 | QBitArray mFlags(7); | 474 | QBitArray mFlags(7); |
473 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); | 475 | msg = (mailmessage*)carray_get(env_list->msg_tab, i); |
474 | if (msg->msg_fields == NULL) { | 476 | if (msg->msg_fields == NULL) { |
475 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; | 477 | //; // odebug << "could not fetch envelope of message " << i << "" << oendl; |
476 | continue; | 478 | continue; |
477 | } | 479 | } |
478 | RecMailP mail = new RecMail(); | 480 | RecMailP mail = new RecMail(); |
479 | mail->setWrapper(this); | 481 | mail->setWrapper(this); |
480 | mail_flags * flag_result = 0; | 482 | mail_flags * flag_result = 0; |
481 | r = mailmessage_get_flags(msg,&flag_result); | 483 | r = mailmessage_get_flags(msg,&flag_result); |
482 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { | 484 | if (r == MAIL_ERROR_NOT_IMPLEMENTED) { |