summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp9
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp16
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp19
-rw-r--r--kmicromail/libmailwrapper/mboxwrapper.cpp1
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp1
5 files changed, 41 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 8ee112c..ed5c898 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -31,120 +31,121 @@ AbstractMail* AbstractMail::getWrapper(POP3account *a)
31} 31}
32 32
33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
34{ 34{
35 return new NNTPwrapper(a); 35 return new NNTPwrapper(a);
36} 36}
37 37
38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
39{ 39{
40 return new MHwrapper(a,name); 40 return new MHwrapper(a,name);
41} 41}
42 42
43AbstractMail* AbstractMail::getWrapper(Account*a) 43AbstractMail* AbstractMail::getWrapper(Account*a)
44{ 44{
45 if (!a) return 0; 45 if (!a) return 0;
46 switch (a->getType()) { 46 switch (a->getType()) {
47 case MAILLIB::A_IMAP: 47 case MAILLIB::A_IMAP:
48 return new IMAPwrapper((IMAPaccount*)a); 48 return new IMAPwrapper((IMAPaccount*)a);
49 break; 49 break;
50 case MAILLIB::A_POP3: 50 case MAILLIB::A_POP3:
51 return new POP3wrapper((POP3account*)a); 51 return new POP3wrapper((POP3account*)a);
52 break; 52 break;
53 case MAILLIB::A_NNTP: 53 case MAILLIB::A_NNTP:
54 return new NNTPwrapper((NNTPaccount*)a); 54 return new NNTPwrapper((NNTPaccount*)a);
55 break; 55 break;
56 default: 56 default:
57 return 0; 57 return 0;
58 } 58 }
59} 59}
60 60
61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
62{ 62{
63 // odebug << "Decode string start" << oendl; 63 // odebug << "Decode string start" << oendl;
64 char*result_text; 64 char*result_text;
65 size_t index = 0; 65 size_t index = 0;
66 /* reset for recursive use! */ 66 /* reset for recursive use! */
67 size_t target_length = 0; 67 size_t target_length = 0;
68 result_text = 0; 68 result_text = 0;
69 int mimetype = MAILMIME_MECHANISM_7BIT; 69 int mimetype = MAILMIME_MECHANISM_7BIT;
70 if (enc.lower()=="quoted-printable") { 70 if (enc.lower()=="quoted-printable") {
71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
72 } else if (enc.lower()=="base64") { 72 } else if (enc.lower()=="base64") {
73 mimetype = MAILMIME_MECHANISM_BASE64; 73 mimetype = MAILMIME_MECHANISM_BASE64;
74 } else if (enc.lower()=="8bit") { 74 } else if (enc.lower()=="8bit") {
75 mimetype = MAILMIME_MECHANISM_8BIT; 75 mimetype = MAILMIME_MECHANISM_8BIT;
76 } else if (enc.lower()=="binary") { 76 } else if (enc.lower()=="binary") {
77 mimetype = MAILMIME_MECHANISM_BINARY; 77 mimetype = MAILMIME_MECHANISM_BINARY;
78 } 78 }
79
80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 79 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
81 &result_text,&target_length); 80 &result_text,&target_length);
82 81
83 encodedString* result = new encodedString(); 82 encodedString* result = new encodedString();
84 if (err == MAILIMF_NO_ERROR) { 83 if (err == MAILIMF_NO_ERROR) {
85 result->setContent(result_text,target_length); 84 result->setContent(result_text,target_length);
86 } 85 }
87 //odebug << "Decode string finished" << oendl; 86 //odebug << "Decode string finished" << oendl;
88 return result; 87 return result;
89} 88}
90 89
91QString AbstractMail::convert_String(const char*text) 90QString AbstractMail::convert_String(const char*text)
92{ 91{
93 size_t index = 0; 92 size_t index = 0;
94 char*res = 0; 93 char*res = 0;
95 int err = MAILIMF_NO_ERROR; 94 int err = MAILIMF_NO_ERROR;
96 95
97 QString result(text); 96 QString result(text);
98 97 //qDebug("convert_String %s ", text);
98 //err = mailmime_encoded_phrase_parse("iso-8859-1",
99 // text, strlen(text),&index, "iso-8859-1",&res);
99 err = mailmime_encoded_phrase_parse("iso-8859-1", 100 err = mailmime_encoded_phrase_parse("iso-8859-1",
100 text, strlen(text),&index, "iso-8859-1",&res); 101 text, strlen(text),&index, "utf-8",&res);
101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 102 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
102 result = QString(res); 103 result = QString::fromUtf8(res);
103 } 104 }
104 //qDebug("convert_String:%s ",result.latin1() ); 105 //qDebug("convert_String:%s ",result.latin1() );
105 if (res) free(res); 106 if (res) free(res);
106 return result; 107 return result;
107} 108}
108 109
109/* cp & paste from launcher */ 110/* cp & paste from launcher */
110QString AbstractMail::gen_attachment_id() 111QString AbstractMail::gen_attachment_id()
111{ 112{
112 QFile file( "/proc/sys/kernel/random/uuid" ); 113 QFile file( "/proc/sys/kernel/random/uuid" );
113 if (!file.open(IO_ReadOnly ) ) 114 if (!file.open(IO_ReadOnly ) )
114 return QString::null; 115 return QString::null;
115 116
116 QTextStream stream(&file); 117 QTextStream stream(&file);
117 118
118 return "{" + stream.read().stripWhiteSpace() + "}"; 119 return "{" + stream.read().stripWhiteSpace() + "}";
119} 120}
120 121
121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 122int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
122{ 123{
123 return 0; 124 return 0;
124} 125}
125 126
126QString AbstractMail::defaultLocalfolder() 127QString AbstractMail::defaultLocalfolder()
127{ 128{
128 // QString f = getenv( "HOME" ); 129 // QString f = getenv( "HOME" );
129 QString f = locateLocal( "data", "kopiemail/localmail"); 130 QString f = locateLocal( "data", "kopiemail/localmail");
130 // f += "/Applications/opiemail/localmail"; 131 // f += "/Applications/opiemail/localmail";
131 return f; 132 return f;
132} 133}
133 134
134QString AbstractMail::draftFolder() 135QString AbstractMail::draftFolder()
135{ 136{
136 return QString("Drafts"); 137 return QString("Drafts");
137} 138}
138 139
139/* temporary - will be removed when implemented in all classes */ 140/* temporary - will be removed when implemented in all classes */
140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 141void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
141{ 142{
142} 143}
143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 144void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
144{ 145{
145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 146 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
146 // this is currently re-implemented in pop3wrapper and imapwrapper 147 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0; 148 int iii = 0;
148 int count = target.count(); 149 int count = target.count();
149 QProgressBar wid ( count ); 150 QProgressBar wid ( count );
150 wid.setCaption( i18n("Deleting ...")); 151 wid.setCaption( i18n("Deleting ..."));
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index d89a5f9..49227dd 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -175,96 +175,110 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
175 case MAILMIME_MECHANISM_TOKEN: 175 case MAILMIME_MECHANISM_TOKEN:
176 default: 176 default:
177 if (aEnc->enc_token) { 177 if (aEnc->enc_token) {
178 enc = QString(aEnc->enc_token); 178 enc = QString(aEnc->enc_token);
179 } 179 }
180 break; 180 break;
181 } 181 }
182 return enc; 182 return enc;
183} 183}
184 184
185void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 185void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count)
186{ 186{
187 if (current_rec >= 10) { 187 if (current_rec >= 10) {
188 ; // odebug << "too deep recursion!" << oendl; 188 ; // odebug << "too deep recursion!" << oendl;
189 } 189 }
190 if (!message || !mime) { 190 if (!message || !mime) {
191 return; 191 return;
192 } 192 }
193 int r; 193 int r;
194 char*data = 0; 194 char*data = 0;
195 size_t len; 195 size_t len;
196 clistiter * cur = 0; 196 clistiter * cur = 0;
197 QString b; 197 QString b;
198 RecPartP part = new RecPart(); 198 RecPartP part = new RecPart();
199 199
200 switch (mime->mm_type) { 200 switch (mime->mm_type) {
201 case MAILMIME_SINGLE: 201 case MAILMIME_SINGLE:
202 { 202 {
203 QValueList<int>countlist = recList; 203 QValueList<int>countlist = recList;
204 countlist.append(current_count); 204 countlist.append(current_count);
205 r = mailmessage_fetch_section(message,mime,&data,&len); 205 r = mailmessage_fetch_section(message,mime,&data,&len);
206 part->setSize(len); 206 part->setSize(len);
207 part->setPositionlist(countlist); 207 part->setPositionlist(countlist);
208 b = gen_attachment_id(); 208 b = gen_attachment_id();
209 part->setIdentifier(b); 209 part->setIdentifier(b);
210 fillSingleBody(part,message,mime); 210 fillSingleBody(part,message,mime);
211 if (part->Type()=="text" && target->Bodytext().isNull()) { 211 if (part->Type()=="text" && target->Bodytext().isNull()) {
212 encodedString*rs = new encodedString(); 212 encodedString*rs = new encodedString();
213 rs->setContent(data,len); 213 rs->setContent(data,len);
214 encodedString*res = decode_String(rs,part->Encoding()); 214 encodedString*res = decode_String(rs,part->Encoding());
215 if (countlist.count()>2) { 215 if (countlist.count()>2) {
216 bodyCache[b]=rs; 216 bodyCache[b]=rs;
217 target->addPart(part); 217 target->addPart(part);
218 } else { 218 } else {
219 delete rs; 219 delete rs;
220 } 220 }
221 b = QString(res->Content()); 221 b = QString(res->Content());
222 delete res; 222 delete res;
223 size_t index = 0;
224 char*resu = 0;
225 int err = MAILIMF_NO_ERROR;
226 QString charset = part->searchParamter( "charset");
227 qDebug("CHARSET %s ",charset.latin1() );
228 if ( !charset.isEmpty() ) {
229 err = mailmime_encoded_phrase_parse(charset.latin1(),
230 b.latin1(), b.length(),&index, "utf-8",&resu);
231 if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) {
232 //qDebug("res %d %s ", index, resu);
233 b = QString::fromUtf8(resu);
234 }
235 if (resu) free(resu);
236 }
223 target->setBodytext(b); 237 target->setBodytext(b);
224 target->setDescription(part); 238 target->setDescription(part);
225 } else { 239 } else {
226 bodyCache[b]=new encodedString(data,len); 240 bodyCache[b]=new encodedString(data,len);
227 target->addPart(part); 241 target->addPart(part);
228 } 242 }
229 } 243 }
230 break; 244 break;
231 case MAILMIME_MULTIPLE: 245 case MAILMIME_MULTIPLE:
232 { 246 {
233 unsigned int ccount = 1; 247 unsigned int ccount = 1;
234 mailmime*cbody=0; 248 mailmime*cbody=0;
235 QValueList<int>countlist = recList; 249 QValueList<int>countlist = recList;
236 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 250 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
237 cbody = (mailmime*)clist_content(cur); 251 cbody = (mailmime*)clist_content(cur);
238 if (cbody->mm_type==MAILMIME_MULTIPLE) { 252 if (cbody->mm_type==MAILMIME_MULTIPLE) {
239 RecPartP targetPart = new RecPart(); 253 RecPartP targetPart = new RecPart();
240 targetPart->setType("multipart"); 254 targetPart->setType("multipart");
241 countlist.append(current_count); 255 countlist.append(current_count);
242 targetPart->setPositionlist(countlist); 256 targetPart->setPositionlist(countlist);
243 target->addPart(targetPart); 257 target->addPart(targetPart);
244 } 258 }
245 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 259 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
246 if (cbody->mm_type==MAILMIME_MULTIPLE) { 260 if (cbody->mm_type==MAILMIME_MULTIPLE) {
247 countlist = recList; 261 countlist = recList;
248 } 262 }
249 ++ccount; 263 ++ccount;
250 } 264 }
251 } 265 }
252 break; 266 break;
253 case MAILMIME_MESSAGE: 267 case MAILMIME_MESSAGE:
254 { 268 {
255 QValueList<int>countlist = recList; 269 QValueList<int>countlist = recList;
256 countlist.append(current_count); 270 countlist.append(current_count);
257 /* the own header is always at recursion 0 - we don't need that */ 271 /* the own header is always at recursion 0 - we don't need that */
258 if (current_rec > 0) { 272 if (current_rec > 0) {
259 part->setPositionlist(countlist); 273 part->setPositionlist(countlist);
260 r = mailmessage_fetch_section(message,mime,&data,&len); 274 r = mailmessage_fetch_section(message,mime,&data,&len);
261 part->setSize(len); 275 part->setSize(len);
262 part->setPositionlist(countlist); 276 part->setPositionlist(countlist);
263 b = gen_attachment_id(); 277 b = gen_attachment_id();
264 part->setIdentifier(b); 278 part->setIdentifier(b);
265 part->setType("message"); 279 part->setType("message");
266 part->setSubtype("rfc822"); 280 part->setSubtype("rfc822");
267 bodyCache[b]=new encodedString(data,len); 281 bodyCache[b]=new encodedString(data,len);
268 target->addPart(part); 282 target->addPart(part);
269 } 283 }
270 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 284 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
@@ -299,97 +313,97 @@ QString Genericwrapper::parseAddressList( mailimf_address_list *list )
299 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 313 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
300 mailimf_address *addr = (mailimf_address *) current->data; 314 mailimf_address *addr = (mailimf_address *) current->data;
301 315
302 if ( !first ) { 316 if ( !first ) {
303 result.append( "," ); 317 result.append( "," );
304 } else { 318 } else {
305 first = false; 319 first = false;
306 } 320 }
307 321
308 switch ( addr->ad_type ) { 322 switch ( addr->ad_type ) {
309 case MAILIMF_ADDRESS_MAILBOX: 323 case MAILIMF_ADDRESS_MAILBOX:
310 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 324 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
311 break; 325 break;
312 case MAILIMF_ADDRESS_GROUP: 326 case MAILIMF_ADDRESS_GROUP:
313 result.append( parseGroup( addr->ad_data.ad_group ) ); 327 result.append( parseGroup( addr->ad_data.ad_group ) );
314 break; 328 break;
315 default: 329 default:
316 ; // odebug << "Generic: unkown mailimf address type" << oendl; 330 ; // odebug << "Generic: unkown mailimf address type" << oendl;
317 break; 331 break;
318 } 332 }
319 } 333 }
320 334
321 return result; 335 return result;
322} 336}
323 337
324QString Genericwrapper::parseGroup( mailimf_group *group ) 338QString Genericwrapper::parseGroup( mailimf_group *group )
325{ 339{
326 QString result( "" ); 340 QString result( "" );
327 341
328 result.append( group->grp_display_name ); 342 result.append( group->grp_display_name );
329 result.append( ": " ); 343 result.append( ": " );
330 344
331 if ( group->grp_mb_list != NULL ) { 345 if ( group->grp_mb_list != NULL ) {
332 result.append( parseMailboxList( group->grp_mb_list ) ); 346 result.append( parseMailboxList( group->grp_mb_list ) );
333 } 347 }
334 348
335 result.append( ";" ); 349 result.append( ";" );
336 350
337 return result; 351 return result;
338} 352}
339 353
340QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 354QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
341{ 355{
342 QString result( "" ); 356 QString result( "" );
343 357
344 if ( box->mb_display_name == NULL ) { 358 if ( box->mb_display_name == NULL ) {
345 result.append( box->mb_addr_spec ); 359 result.append( box->mb_addr_spec );
346 } else { 360 } else {
347 result.append( convert_String(box->mb_display_name).latin1() ); 361 result.append( convert_String(box->mb_display_name) );
348 result.append( " <" ); 362 result.append( " <" );
349 result.append( box->mb_addr_spec ); 363 result.append( box->mb_addr_spec );
350 result.append( ">" ); 364 result.append( ">" );
351 } 365 }
352 366
353 return result; 367 return result;
354} 368}
355 369
356QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 370QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
357{ 371{
358 QString result( "" ); 372 QString result( "" );
359 373
360 bool first = true; 374 bool first = true;
361 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 375 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
362 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 376 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
363 377
364 if ( !first ) { 378 if ( !first ) {
365 result.append( "," ); 379 result.append( "," );
366 } else { 380 } else {
367 first = false; 381 first = false;
368 } 382 }
369 383
370 result.append( parseMailbox( box ) ); 384 result.append( parseMailbox( box ) );
371 } 385 }
372 386
373 return result; 387 return result;
374} 388}
375 389
376encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 390encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
377{ 391{
378 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 392 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
379 if (it==bodyCache.end()) return new encodedString(); 393 if (it==bodyCache.end()) return new encodedString();
380 encodedString*t = decode_String(it.data(),part->Encoding()); 394 encodedString*t = decode_String(it.data(),part->Encoding());
381 return t; 395 return t;
382} 396}
383 397
384encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 398encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
385{ 399{
386 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 400 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
387 if (it==bodyCache.end()) return new encodedString(); 401 if (it==bodyCache.end()) return new encodedString();
388 encodedString*t = it.data(); 402 encodedString*t = it.data();
389 return t; 403 return t;
390} 404}
391 405
392QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 406QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
393{ 407{
394 encodedString*t = fetchDecodedPart(mail,part); 408 encodedString*t = fetchDecodedPart(mail,part);
395 QString text=t->Content(); 409 QString text=t->Content();
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index d90a8d2..eb2b47d 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -707,96 +707,115 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int
707 msg_att = (mailimap_msg_att*)current->data; 707 msg_att = (mailimap_msg_att*)current->data;
708 mailimap_msg_att_item*msg_att_item; 708 mailimap_msg_att_item*msg_att_item;
709 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 709 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
710 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 710 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
711 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 711 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
712 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 712 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
713 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 713 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
714 /* detach - we take over the content */ 714 /* detach - we take over the content */
715 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 715 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
716 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 716 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
717 } 717 }
718 } 718 }
719 } 719 }
720 } else { 720 } else {
721 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 721 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
722 } 722 }
723 if (result) mailimap_fetch_list_free(result); 723 if (result) mailimap_fetch_list_free(result);
724 return res; 724 return res;
725} 725}
726 726
727/* current_recursion is for recursive calls. 727/* current_recursion is for recursive calls.
728 current_count means the position inside the internal loop! */ 728 current_count means the position inside the internal loop! */
729void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 729void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
730 int current_recursion,QValueList<int>recList,int current_count) 730 int current_recursion,QValueList<int>recList,int current_count)
731{ 731{
732 if (!body || current_recursion>=10) { 732 if (!body || current_recursion>=10) {
733 return; 733 return;
734 } 734 }
735 switch (body->bd_type) { 735 switch (body->bd_type) {
736 case MAILIMAP_BODY_1PART: 736 case MAILIMAP_BODY_1PART:
737 { 737 {
738 QValueList<int>countlist = recList; 738 QValueList<int>countlist = recList;
739 countlist.append(current_count); 739 countlist.append(current_count);
740 RecPartP currentPart = new RecPart(); 740 RecPartP currentPart = new RecPart();
741 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 741 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
742 QString id(""); 742 QString id("");
743 currentPart->setPositionlist(countlist); 743 currentPart->setPositionlist(countlist);
744 for (unsigned int j = 0; j < countlist.count();++j) { 744 for (unsigned int j = 0; j < countlist.count();++j) {
745 id+=(j>0?" ":""); 745 id+=(j>0?" ":"");
746 id+=QString("%1").arg(countlist[j]); 746 id+=QString("%1").arg(countlist[j]);
747 } 747 }
748 //odebug << "ID = " << id.latin1() << "" << oendl; 748 //odebug << "ID = " << id.latin1() << "" << oendl;
749 currentPart->setIdentifier(id); 749 currentPart->setIdentifier(id);
750 fillSinglePart(currentPart,part1); 750 fillSinglePart(currentPart,part1);
751 /* important: Check for is NULL 'cause a body can be empty! 751 /* important: Check for is NULL 'cause a body can be empty!
752 And we put it only into the mail if it is the FIRST part */ 752 And we put it only into the mail if it is the FIRST part */
753 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 753 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
754 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 754 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
755
756 size_t index = 0;
757 char*res = 0;
758 int err = MAILIMF_NO_ERROR;
759
760 QString charset = currentPart->searchParamter( "charset");
761 qDebug("CHARSET %s ",charset.latin1() );
762 //if ( false ) {
763 if ( !charset.isEmpty() ) {
764 //err = mailmime_encoded_phrase_parse("iso-8859-1",
765 // text, strlen(text),&index, "iso-8859-1",&res);
766 err = mailmime_encoded_phrase_parse(charset.latin1(),
767 body_text.latin1(), body_text.length(),&index, "utf-8",&res);
768 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
769 //qDebug("res %d %s ", index, res);
770 body_text = QString::fromUtf8(res);
771 }
772 if (res) free(res);
773 }
755 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); 774 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
756 target_body->setDescription(currentPart); 775 target_body->setDescription(currentPart);
757 target_body->setBodytext(body_text); 776 target_body->setBodytext(body_text);
758 if (countlist.count()>1) { 777 if (countlist.count()>1) {
759 target_body->addPart(currentPart); 778 target_body->addPart(currentPart);
760 } 779 }
761 } else { 780 } else {
762 target_body->addPart(currentPart); 781 target_body->addPart(currentPart);
763 } 782 }
764 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 783 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
765 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 784 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
766 } 785 }
767 } 786 }
768 break; 787 break;
769 case MAILIMAP_BODY_MPART: 788 case MAILIMAP_BODY_MPART:
770 { 789 {
771 QValueList<int>countlist = recList; 790 QValueList<int>countlist = recList;
772 clistcell*current=0; 791 clistcell*current=0;
773 mailimap_body*current_body=0; 792 mailimap_body*current_body=0;
774 unsigned int ccount = 1; 793 unsigned int ccount = 1;
775 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 794 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
776 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 795 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
777 current_body = (mailimap_body*)current->data; 796 current_body = (mailimap_body*)current->data;
778 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 797 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
779 RecPartP targetPart = new RecPart(); 798 RecPartP targetPart = new RecPart();
780 targetPart->setType("multipart"); 799 targetPart->setType("multipart");
781 fillMultiPart(targetPart,mailDescription); 800 fillMultiPart(targetPart,mailDescription);
782 countlist.append(current_count); 801 countlist.append(current_count);
783 targetPart->setPositionlist(countlist); 802 targetPart->setPositionlist(countlist);
784 target_body->addPart(targetPart); 803 target_body->addPart(targetPart);
785 QString id(""); 804 QString id("");
786 for (unsigned int j = 0; j < countlist.count();++j) { 805 for (unsigned int j = 0; j < countlist.count();++j) {
787 id+=(j>0?" ":""); 806 id+=(j>0?" ":"");
788 id+=QString("%1").arg(countlist[j]); 807 id+=QString("%1").arg(countlist[j]);
789 } 808 }
790 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 809 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
791 } 810 }
792 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 811 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
793 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 812 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
794 countlist = recList; 813 countlist = recList;
795 } 814 }
796 ++ccount; 815 ++ccount;
797 } 816 }
798 } 817 }
799 break; 818 break;
800 default: 819 default:
801 break; 820 break;
802 } 821 }
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp
index 0cdbae4..87f8c8a 100644
--- a/kmicromail/libmailwrapper/mboxwrapper.cpp
+++ b/kmicromail/libmailwrapper/mboxwrapper.cpp
@@ -80,96 +80,97 @@ void MBOXwrapper::deleteMail(const RecMailP & mail)
80 } 80 }
81 r = mailsession_remove_message(folder->fld_session,mail->getNumber()); 81 r = mailsession_remove_message(folder->fld_session,mail->getNumber());
82 if (r != MAIL_NO_ERROR) { 82 if (r != MAIL_NO_ERROR) {
83 ; // << "error deleting mail" << oendl; 83 ; // << "error deleting mail" << oendl;
84 } 84 }
85 mailfolder_free(folder); 85 mailfolder_free(folder);
86 mailstorage_free(storage); 86 mailstorage_free(storage);
87} 87}
88 88
89void MBOXwrapper::answeredMail(const RecMailP&) 89void MBOXwrapper::answeredMail(const RecMailP&)
90{ 90{
91} 91}
92 92
93RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) 93RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail )
94{ 94{
95 RecBodyP body = new RecBody(); 95 RecBodyP body = new RecBody();
96 mailstorage*storage = mailstorage_new(NULL); 96 mailstorage*storage = mailstorage_new(NULL);
97 QString p = MBOXPath+"/"; 97 QString p = MBOXPath+"/";
98 p+=mail->getMbox(); 98 p+=mail->getMbox();
99 mailmessage * msg; 99 mailmessage * msg;
100 char*data=0; 100 char*data=0;
101 size_t size; 101 size_t size;
102 102
103 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 103 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
104 mailfolder*folder; 104 mailfolder*folder;
105 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 105 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
106 r = mailfolder_connect(folder); 106 r = mailfolder_connect(folder);
107 if (r != MAIL_NO_ERROR) { 107 if (r != MAIL_NO_ERROR) {
108 ; // << "Error initializing mbox" << oendl; 108 ; // << "Error initializing mbox" << oendl;
109 mailfolder_free(folder); 109 mailfolder_free(folder);
110 mailstorage_free(storage); 110 mailstorage_free(storage);
111 return body; 111 return body;
112 } 112 }
113 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 113 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
114 if (r != MAIL_NO_ERROR) { 114 if (r != MAIL_NO_ERROR) {
115 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 115 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
116 mailfolder_free(folder); 116 mailfolder_free(folder);
117 mailstorage_free(storage); 117 mailstorage_free(storage);
118 return body; 118 return body;
119 } 119 }
120 r = mailmessage_fetch(msg,&data,&size); 120 r = mailmessage_fetch(msg,&data,&size);
121 if (r != MAIL_NO_ERROR) { 121 if (r != MAIL_NO_ERROR) {
122 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 122 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
123 mailfolder_free(folder); 123 mailfolder_free(folder);
124 mailstorage_free(storage); 124 mailstorage_free(storage);
125 mailmessage_free(msg); 125 mailmessage_free(msg);
126 return body; 126 return body;
127 } 127 }
128 qDebug("MBOXwrapper::fetchBody ");
128 body = parseMail(msg); 129 body = parseMail(msg);
129 mailmessage_fetch_result_free(msg,data); 130 mailmessage_fetch_result_free(msg,data);
130 mailfolder_free(folder); 131 mailfolder_free(folder);
131 mailstorage_free(storage); 132 mailstorage_free(storage);
132 133
133 return body; 134 return body;
134} 135}
135 136
136void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 137void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
137{ 138{
138 ; // << "MBOX " << current << " von " << maximum << "" << oendl; 139 ; // << "MBOX " << current << " von " << maximum << "" << oendl;
139} 140}
140 141
141int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) 142int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool )
142{ 143{
143 QString p = MBOXPath+"/"; 144 QString p = MBOXPath+"/";
144 p+=folder; 145 p+=folder;
145 QFileInfo fi(p); 146 QFileInfo fi(p);
146 if (fi.exists()) { 147 if (fi.exists()) {
147 Global::statusMessage(i18n("Mailbox exists.")); 148 Global::statusMessage(i18n("Mailbox exists."));
148 return 0; 149 return 0;
149 } 150 }
150 mailmbox_folder*f = 0; 151 mailmbox_folder*f = 0;
151 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 152 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
152 Global::statusMessage(i18n("Error init folder")); 153 Global::statusMessage(i18n("Error init folder"));
153 return 0; 154 return 0;
154 } 155 }
155 if (f) mailmbox_done(f); 156 if (f) mailmbox_done(f);
156 return 1; 157 return 1;
157} 158}
158 159
159void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 160void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
160{ 161{
161 QString p = MBOXPath+"/"; 162 QString p = MBOXPath+"/";
162 p+=folder; 163 p+=folder;
163 mailmbox_folder*f = 0; 164 mailmbox_folder*f = 0;
164 int r = mailmbox_init(p.latin1(),0,1,0,&f); 165 int r = mailmbox_init(p.latin1(),0,1,0,&f);
165 if (r != MAIL_NO_ERROR) { 166 if (r != MAIL_NO_ERROR) {
166 Global::statusMessage(i18n("Error init folder")); 167 Global::statusMessage(i18n("Error init folder"));
167 return; 168 return;
168 } 169 }
169 r = mailmbox_append_message(f,msg,length); 170 r = mailmbox_append_message(f,msg,length);
170 if (r != MAIL_NO_ERROR) { 171 if (r != MAIL_NO_ERROR) {
171 Global::statusMessage(i18n("Error writing to message folder")); 172 Global::statusMessage(i18n("Error writing to message folder"));
172 } 173 }
173 mailmbox_done(f); 174 mailmbox_done(f);
174} 175}
175 176
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index 90b5d23..982d7a6 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -83,96 +83,97 @@ void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSm
83QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() 83QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders()
84{ 84{
85 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 85 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
86 /* this is needed! */ 86 /* this is needed! */
87 if (m_storage) mailstorage_disconnect(m_storage); 87 if (m_storage) mailstorage_disconnect(m_storage);
88 init_storage(); 88 init_storage();
89 if (!m_storage) { 89 if (!m_storage) {
90 return folders; 90 return folders;
91 } 91 }
92 mail_list*flist = 0; 92 mail_list*flist = 0;
93 clistcell*current=0; 93 clistcell*current=0;
94 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 94 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
95 if (r != MAIL_NO_ERROR || !flist) { 95 if (r != MAIL_NO_ERROR || !flist) {
96 qDebug("error getting folder list "); 96 qDebug("error getting folder list ");
97 return folders; 97 return folders;
98 } 98 }
99 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 99 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
100 QString t = (char*)current->data; 100 QString t = (char*)current->data;
101 t.replace(0,MHPath.length(),""); 101 t.replace(0,MHPath.length(),"");
102 folders->append(new MHFolder(t,MHPath)); 102 folders->append(new MHFolder(t,MHPath));
103 } 103 }
104 mail_list_free(flist); 104 mail_list_free(flist);
105 return folders; 105 return folders;
106} 106}
107 107
108void MHwrapper::deleteMail(const RecMailP&mail) 108void MHwrapper::deleteMail(const RecMailP&mail)
109{ 109{
110 init_storage(); 110 init_storage();
111 if (!m_storage) { 111 if (!m_storage) {
112 return; 112 return;
113 } 113 }
114 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 114 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
115 if (r!=MAIL_NO_ERROR) { 115 if (r!=MAIL_NO_ERROR) {
116 qDebug("error selecting folder! "); 116 qDebug("error selecting folder! ");
117 return; 117 return;
118 } 118 }
119 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); 119 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
120 if (r != MAIL_NO_ERROR) { 120 if (r != MAIL_NO_ERROR) {
121 qDebug("error deleting mail "); 121 qDebug("error deleting mail ");
122 } 122 }
123} 123}
124 124
125void MHwrapper::answeredMail(const RecMailP&) 125void MHwrapper::answeredMail(const RecMailP&)
126{ 126{
127} 127}
128 128
129RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) 129RecBodyP MHwrapper::fetchBody( const RecMailP &mail )
130{ 130{
131 qDebug("MHwrapper::fetchBody ");
131 RecBodyP body = new RecBody(); 132 RecBodyP body = new RecBody();
132 init_storage(); 133 init_storage();
133 if (!m_storage) { 134 if (!m_storage) {
134 return body; 135 return body;
135 } 136 }
136 mailmessage * msg; 137 mailmessage * msg;
137 char*data=0; 138 char*data=0;
138 139
139 /* mail should hold the complete path! */ 140 /* mail should hold the complete path! */
140 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 141 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
141 if (r != MAIL_NO_ERROR) { 142 if (r != MAIL_NO_ERROR) {
142 return body; 143 return body;
143 } 144 }
144 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 145 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
145 if (r != MAIL_NO_ERROR) { 146 if (r != MAIL_NO_ERROR) {
146 qDebug("Error fetching mail "); 147 qDebug("Error fetching mail ");
147 148
148 return body; 149 return body;
149 } 150 }
150 body = parseMail(msg); 151 body = parseMail(msg);
151 mailmessage_fetch_result_free(msg,data); 152 mailmessage_fetch_result_free(msg,data);
152 return body; 153 return body;
153} 154}
154 155
155void MHwrapper::mbox_progress( size_t current, size_t maximum ) 156void MHwrapper::mbox_progress( size_t current, size_t maximum )
156{ 157{
157 qDebug("MBox Progress %d of %d",current,maximum ); 158 qDebug("MBox Progress %d of %d",current,maximum );
158 //odebug << "MH " << current << " von " << maximum << "" << oendl; 159 //odebug << "MH " << current << " von " << maximum << "" << oendl;
159} 160}
160 161
161QString MHwrapper::buildPath(const QString&p) 162QString MHwrapper::buildPath(const QString&p)
162{ 163{
163 QString f=""; 164 QString f="";
164 if (p.length()==0||p=="/") 165 if (p.length()==0||p=="/")
165 return MHPath; 166 return MHPath;
166 if (!p.startsWith(MHPath)) { 167 if (!p.startsWith(MHPath)) {
167 f+=MHPath; 168 f+=MHPath;
168 } 169 }
169 if (!p.startsWith("/")) { 170 if (!p.startsWith("/")) {
170 f+="/"; 171 f+="/";
171 } 172 }
172 f+=p; 173 f+=p;
173 return f; 174 return f;
174} 175}
175 176
176int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) 177int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool )
177{ 178{
178 init_storage(); 179 init_storage();