summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-11-07 10:11:25 (UTC)
committer zautrix <zautrix>2004-11-07 10:11:25 (UTC)
commitb6ef669713ee1d52adcfc9754dd039a4ff6675da (patch) (unidiff)
treeeac59d1b135cbf87e0b9aca21213115331995203 /kmicromail/libmailwrapper
parentdcb3a171bca38934185de67e378956e6fd044f17 (diff)
downloadkdepimpi-b6ef669713ee1d52adcfc9754dd039a4ff6675da.zip
kdepimpi-b6ef669713ee1d52adcfc9754dd039a4ff6675da.tar.gz
kdepimpi-b6ef669713ee1d52adcfc9754dd039a4ff6675da.tar.bz2
encoding fixes
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp1
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp11
-rw-r--r--kmicromail/libmailwrapper/mailtypes.cpp11
-rw-r--r--kmicromail/libmailwrapper/mailtypes.h3
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.h5
-rw-r--r--kmicromail/libmailwrapper/storemail.cpp12
6 files changed, 35 insertions, 8 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 49227dd..28d45ce 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -165,128 +165,129 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
165 break; 165 break;
166 case MAILMIME_MECHANISM_BINARY: 166 case MAILMIME_MECHANISM_BINARY:
167 enc = "binary"; 167 enc = "binary";
168 break; 168 break;
169 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 169 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
170 enc = "quoted-printable"; 170 enc = "quoted-printable";
171 break; 171 break;
172 case MAILMIME_MECHANISM_BASE64: 172 case MAILMIME_MECHANISM_BASE64:
173 enc = "base64"; 173 enc = "base64";
174 break; 174 break;
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; 223 size_t index = 0;
224 char*resu = 0; 224 char*resu = 0;
225 int err = MAILIMF_NO_ERROR; 225 int err = MAILIMF_NO_ERROR;
226 QString charset = part->searchParamter( "charset"); 226 QString charset = part->searchParamter( "charset");
227 qDebug("CHARSET %s ",charset.latin1() ); 227 qDebug("CHARSET %s ",charset.latin1() );
228 if ( !charset.isEmpty() ) { 228 if ( !charset.isEmpty() ) {
229 target->setCharset( charset );
229 err = mailmime_encoded_phrase_parse(charset.latin1(), 230 err = mailmime_encoded_phrase_parse(charset.latin1(),
230 b.latin1(), b.length(),&index, "utf-8",&resu); 231 b.latin1(), b.length(),&index, "utf-8",&resu);
231 if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { 232 if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) {
232 //qDebug("res %d %s ", index, resu); 233 //qDebug("res %d %s ", index, resu);
233 b = QString::fromUtf8(resu); 234 b = QString::fromUtf8(resu);
234 } 235 }
235 if (resu) free(resu); 236 if (resu) free(resu);
236 } 237 }
237 target->setBodytext(b); 238 target->setBodytext(b);
238 target->setDescription(part); 239 target->setDescription(part);
239 } else { 240 } else {
240 bodyCache[b]=new encodedString(data,len); 241 bodyCache[b]=new encodedString(data,len);
241 target->addPart(part); 242 target->addPart(part);
242 } 243 }
243 } 244 }
244 break; 245 break;
245 case MAILMIME_MULTIPLE: 246 case MAILMIME_MULTIPLE:
246 { 247 {
247 unsigned int ccount = 1; 248 unsigned int ccount = 1;
248 mailmime*cbody=0; 249 mailmime*cbody=0;
249 QValueList<int>countlist = recList; 250 QValueList<int>countlist = recList;
250 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 251 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
251 cbody = (mailmime*)clist_content(cur); 252 cbody = (mailmime*)clist_content(cur);
252 if (cbody->mm_type==MAILMIME_MULTIPLE) { 253 if (cbody->mm_type==MAILMIME_MULTIPLE) {
253 RecPartP targetPart = new RecPart(); 254 RecPartP targetPart = new RecPart();
254 targetPart->setType("multipart"); 255 targetPart->setType("multipart");
255 countlist.append(current_count); 256 countlist.append(current_count);
256 targetPart->setPositionlist(countlist); 257 targetPart->setPositionlist(countlist);
257 target->addPart(targetPart); 258 target->addPart(targetPart);
258 } 259 }
259 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 260 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
260 if (cbody->mm_type==MAILMIME_MULTIPLE) { 261 if (cbody->mm_type==MAILMIME_MULTIPLE) {
261 countlist = recList; 262 countlist = recList;
262 } 263 }
263 ++ccount; 264 ++ccount;
264 } 265 }
265 } 266 }
266 break; 267 break;
267 case MAILMIME_MESSAGE: 268 case MAILMIME_MESSAGE:
268 { 269 {
269 QValueList<int>countlist = recList; 270 QValueList<int>countlist = recList;
270 countlist.append(current_count); 271 countlist.append(current_count);
271 /* the own header is always at recursion 0 - we don't need that */ 272 /* the own header is always at recursion 0 - we don't need that */
272 if (current_rec > 0) { 273 if (current_rec > 0) {
273 part->setPositionlist(countlist); 274 part->setPositionlist(countlist);
274 r = mailmessage_fetch_section(message,mime,&data,&len); 275 r = mailmessage_fetch_section(message,mime,&data,&len);
275 part->setSize(len); 276 part->setSize(len);
276 part->setPositionlist(countlist); 277 part->setPositionlist(countlist);
277 b = gen_attachment_id(); 278 b = gen_attachment_id();
278 part->setIdentifier(b); 279 part->setIdentifier(b);
279 part->setType("message"); 280 part->setType("message");
280 part->setSubtype("rfc822"); 281 part->setSubtype("rfc822");
281 bodyCache[b]=new encodedString(data,len); 282 bodyCache[b]=new encodedString(data,len);
282 target->addPart(part); 283 target->addPart(part);
283 } 284 }
284 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 285 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
285 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 286 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
286 } 287 }
287 } 288 }
288 break; 289 break;
289 } 290 }
290} 291}
291 292
292RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 293RecBodyP Genericwrapper::parseMail( mailmessage * msg )
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index eb2b47d..2a54381 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,117 +1,117 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h> 9#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h> 11#include <kglobal.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 18 : AbstractMail()
19{ 19{
20 account = a; 20 account = a;
21 m_imap = 0; 21 m_imap = 0;
22 m_Lastmbox = ""; 22 m_Lastmbox = "";
23 mCurrent = 0; 23 mCurrent = 0;
24 mMax = 0; 24 mMax = 0;
25} 25}
26 26
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
28{ 28{
29 logout(); 29 logout();
30} 30}
31 31
32/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
35{ 35{
36 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
38 } 38 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 41 m_Lastmbox = "";
42 return err; 42 return err;
43 } 43 }
44 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
45 return err; 45 return err;
46} 46}
47 47
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 49{
50 //qDebug("imap progress %d of %d ",current,maximum ); 50 //qDebug("imap progress %d of %d ",current,maximum );
51 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); 51 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
52 //qApp->processEvents() 52 //qApp->processEvents()
53 static int last = 0; 53 static unsigned int last = 0;
54 if ( last != current ) 54 if ( last != current )
55 IMAPwrapper::progress(); 55 IMAPwrapper::progress();
56 last = current; 56 last = current;
57} 57}
58void IMAPwrapper::progress( QString m ) 58void IMAPwrapper::progress( QString m )
59{ 59{
60 60
61 static QString mProgrMess; 61 static QString mProgrMess;
62 if ( m != QString::null ) { 62 if ( m != QString::null ) {
63 mProgrMess = m; 63 mProgrMess = m;
64 mCurrent = 1; 64 mCurrent = 1;
65 return; 65 return;
66 } 66 }
67 QString mess; 67 QString mess;
68 //qDebug("progress "); 68 //qDebug("progress ");
69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
71 Global::statusMessage(mess); 71 Global::statusMessage(mess);
72 //qDebug("Progress %s %s", mess.latin1(), m.latin1()); 72 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
73 qApp->processEvents(); 73 qApp->processEvents();
74} 74}
75bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
76{ 76{
77 int err; 77 int err;
78 bool try_tls = force_tls; 78 bool try_tls = force_tls;
79 mailimap_capability_data * cap_data = 0; 79 mailimap_capability_data * cap_data = 0;
80 80
81 err = mailimap_capability(m_imap,&cap_data); 81 err = mailimap_capability(m_imap,&cap_data);
82 if (err != MAILIMAP_NO_ERROR) { 82 if (err != MAILIMAP_NO_ERROR) {
83 Global::statusMessage("error getting capabilities!"); 83 Global::statusMessage("error getting capabilities!");
84 return false; 84 return false;
85 } 85 }
86 clistiter * cur; 86 clistiter * cur;
87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
88 struct mailimap_capability * cap; 88 struct mailimap_capability * cap;
89 cap = (struct mailimap_capability *)clist_content(cur); 89 cap = (struct mailimap_capability *)clist_content(cur);
90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
92 try_tls = true; 92 try_tls = true;
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 if (cap_data) { 97 if (cap_data) {
98 mailimap_capability_data_free(cap_data); 98 mailimap_capability_data_free(cap_data);
99 } 99 }
100 if (try_tls) { 100 if (try_tls) {
101 err = mailimap_starttls(m_imap); 101 err = mailimap_starttls(m_imap);
102 if (err != MAILIMAP_NO_ERROR && force_tls) { 102 if (err != MAILIMAP_NO_ERROR && force_tls) {
103 Global::statusMessage(i18n("Server has no TLS support!")); 103 Global::statusMessage(i18n("Server has no TLS support!"));
104 try_tls = false; 104 try_tls = false;
105 } else { 105 } else {
106 mailstream_low * low; 106 mailstream_low * low;
107 mailstream_low * new_low; 107 mailstream_low * new_low;
108 low = mailstream_get_low(m_imap->imap_stream); 108 low = mailstream_get_low(m_imap->imap_stream);
109 if (!low) { 109 if (!low) {
110 try_tls = false; 110 try_tls = false;
111 } else { 111 } else {
112 int fd = mailstream_low_get_fd(low); 112 int fd = mailstream_low_get_fd(low);
113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
114 mailstream_low_free(low); 114 mailstream_low_free(low);
115 mailstream_set_low(m_imap->imap_stream, new_low); 115 mailstream_set_low(m_imap->imap_stream, new_low);
116 } else { 116 } else {
117 try_tls = false; 117 try_tls = false;
@@ -228,255 +228,255 @@ void IMAPwrapper::logout()
228 if (!m_imap) return; 228 if (!m_imap) return;
229 err = mailimap_logout( m_imap ); 229 err = mailimap_logout( m_imap );
230 err = mailimap_close( m_imap ); 230 err = mailimap_close( m_imap );
231 mailimap_free( m_imap ); 231 mailimap_free( m_imap );
232 m_imap = 0; 232 m_imap = 0;
233 m_Lastmbox = ""; 233 m_Lastmbox = "";
234} 234}
235 235
236void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 236void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
237{ 237{
238 238
239 int tryAgain = 1; 239 int tryAgain = 1;
240 while ( tryAgain >= 0 ) { 240 while ( tryAgain >= 0 ) {
241 int err = MAILIMAP_NO_ERROR; 241 int err = MAILIMAP_NO_ERROR;
242 clist *result = 0; 242 clist *result = 0;
243 clistcell *current; 243 clistcell *current;
244 mailimap_fetch_type *fetchType = 0; 244 mailimap_fetch_type *fetchType = 0;
245 mailimap_set *set = 0; 245 mailimap_set *set = 0;
246 246
247 login(); 247 login();
248 if (!m_imap) { 248 if (!m_imap) {
249 return; 249 return;
250 } 250 }
251 /* select mailbox READONLY for operations */ 251 /* select mailbox READONLY for operations */
252 err = selectMbox(mailbox); 252 err = selectMbox(mailbox);
253 if ( err != MAILIMAP_NO_ERROR ) { 253 if ( err != MAILIMAP_NO_ERROR ) {
254 return; 254 return;
255 } 255 }
256 256
257 int last = m_imap->imap_selection_info->sel_exists; 257 int last = m_imap->imap_selection_info->sel_exists;
258 258
259 if (last == 0) { 259 if (last == 0) {
260 Global::statusMessage(i18n("Mailbox has no mails")); 260 Global::statusMessage(i18n("Mailbox has no mails"));
261 return; 261 return;
262 } else { 262 } else {
263 } 263 }
264 progress( i18n("Fetch ")); 264 progress( i18n("Fetch "));
265 mMax = last; 265 mMax = last;
266 //qDebug("last %d ", last); 266 //qDebug("last %d ", last);
267 Global::statusMessage(i18n("Fetching header list")); 267 Global::statusMessage(i18n("Fetching header list"));
268 qApp->processEvents(); 268 qApp->processEvents();
269 /* the range has to start at 1!!! not with 0!!!! */ 269 /* the range has to start at 1!!! not with 0!!!! */
270 //LR the access to web.de imap server is no working with value 1 270 //LR the access to web.de imap server is no working with value 1
271 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 271 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
272 set = mailimap_set_new_interval( tryAgain, last ); 272 set = mailimap_set_new_interval( tryAgain, last );
273 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 273 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
277 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 277 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
278 278
279 err = mailimap_fetch( m_imap, set, fetchType, &result ); 279 err = mailimap_fetch( m_imap, set, fetchType, &result );
280 mailimap_set_free( set ); 280 mailimap_set_free( set );
281 mailimap_fetch_type_free( fetchType ); 281 mailimap_fetch_type_free( fetchType );
282 282
283 QString date,subject,from; 283 QString date,subject,from;
284 284
285 if ( err == MAILIMAP_NO_ERROR ) { 285 if ( err == MAILIMAP_NO_ERROR ) {
286 tryAgain = -1; 286 tryAgain = -1;
287 mailimap_msg_att * msg_att; 287 mailimap_msg_att * msg_att;
288 int i = 0; 288 int i = 0;
289 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 289 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
290 ++i; 290 ++i;
291 //qDebug("iii %d ",i); 291 //qDebug("iii %d ",i);
292 msg_att = (mailimap_msg_att*)current->data; 292 msg_att = (mailimap_msg_att*)current->data;
293 RecMail*m = parse_list_result(msg_att); 293 RecMail*m = parse_list_result(msg_att);
294 if (m) { 294 if (m) {
295 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 295 if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) {
296 m->setNumber(i); 296 m->setNumber(i);
297 m->setMbox(mailbox); 297 m->setMbox(mailbox);
298 m->setWrapper(this); 298 m->setWrapper(this);
299 target.append(m); 299 target.append(m);
300 } 300 }
301 } 301 }
302 } 302 }
303 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); 303 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
304 } else { 304 } else {
305 --tryAgain; 305 --tryAgain;
306 --tryAgain;//disabled tryagain by adding this line 306 --tryAgain;//disabled tryagain by adding this line
307 if ( tryAgain < 0 ) 307 if ( tryAgain < 0 )
308 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); 308 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
309 else 309 else
310 qDebug("try again... "); 310 qDebug("try again... ");
311 } 311 }
312 312
313 if (result) mailimap_fetch_list_free(result); 313 if (result) mailimap_fetch_list_free(result);
314 } 314 }
315} 315}
316 316
317QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 317QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
318{ 318{
319 const char *path, *mask; 319 const char *path, *mask;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result = 0; 321 clist *result = 0;
322 clistcell *current = 0; 322 clistcell *current = 0;
323 clistcell*cur_flag = 0; 323 clistcell*cur_flag = 0;
324 mailimap_mbx_list_flags*bflags = 0; 324 mailimap_mbx_list_flags*bflags = 0;
325 325
326 QValueList<FolderP>* folders = new QValueList<FolderP>(); 326 QValueList<FolderP>* folders = new QValueList<FolderP>();
327 login(); 327 login();
328 if (!m_imap) { 328 if (!m_imap) {
329 return folders; 329 return folders;
330 } 330 }
331 331
332/* 332/*
333 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 333 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
334 * We must not forget to filter them out in next loop! 334 * We must not forget to filter them out in next loop!
335 * it seems like ugly code. and yes - it is ugly code. but the best way. 335 * it seems like ugly code. and yes - it is ugly code. but the best way.
336 */ 336 */
337 Global::statusMessage(i18n("Fetching folder list")); 337 Global::statusMessage(i18n("Fetching folder list"));
338 qApp->processEvents(); 338 qApp->processEvents();
339 QString temp; 339 QString temp;
340 mask = "INBOX" ; 340 mask = "INBOX" ;
341 mailimap_mailbox_list *list; 341 mailimap_mailbox_list *list;
342 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 342 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
343 QString del; 343 QString del;
344 bool selectable = true; 344 bool selectable = true;
345 bool no_inferiors = false; 345 bool no_inferiors = false;
346 if ( err == MAILIMAP_NO_ERROR ) { 346 if ( err == MAILIMAP_NO_ERROR ) {
347 current = result->first; 347 current = result->first;
348 for ( int i = result->count; i > 0; i-- ) { 348 for ( int i = result->count; i > 0; i-- ) {
349 list = (mailimap_mailbox_list *) current->data; 349 list = (mailimap_mailbox_list *) current->data;
350 // it is better use the deep copy mechanism of qt itself 350 // it is better use the deep copy mechanism of qt itself
351 // instead of using strdup! 351 // instead of using strdup!
352 temp = list->mb_name; 352 temp = list->mb_name;
353 del = list->mb_delimiter; 353 del = list->mb_delimiter;
354 current = current->next; 354 current = current->next;
355 if ( (bflags = list->mb_flag) ) { 355 if ( (bflags = list->mb_flag) ) {
356 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 356 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
357 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 357 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
358 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 358 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
359 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 359 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
360 no_inferiors = true; 360 no_inferiors = true;
361 } 361 }
362 } 362 }
363 } 363 }
364 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 364 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
365 } 365 }
366 } else { 366 } else {
367 qDebug("error fetching folders: "); 367 qDebug("error fetching folders: ");
368 368
369 } 369 }
370 mailimap_list_result_free( result ); 370 mailimap_list_result_free( result );
371 371
372/* 372/*
373 * second stage - get the other then inbox folders 373 * second stage - get the other then inbox folders
374 */ 374 */
375 mask = "*" ; 375 mask = "*" ;
376 path = account->getPrefix().latin1(); 376 path = account->getPrefix().latin1();
377 if (!path) path = ""; 377 if (!path) path = "";
378 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 378 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
379 if ( err == MAILIMAP_NO_ERROR ) { 379 if ( err == MAILIMAP_NO_ERROR ) {
380 current = result->first; 380 current = result->first;
381 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 381 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
382 no_inferiors = false; 382 no_inferiors = false;
383 list = (mailimap_mailbox_list *) current->data; 383 list = (mailimap_mailbox_list *) current->data;
384 // it is better use the deep copy mechanism of qt itself 384 // it is better use the deep copy mechanism of qt itself
385 // instead of using strdup! 385 // instead of using strdup!
386 temp = list->mb_name; 386 temp = list->mb_name;
387 if (temp.lower()=="inbox") 387 if (temp.lower()=="inbox")
388 continue; 388 continue;
389 if (temp.lower()==account->getPrefix().lower()) 389 if (temp.lower()==account->getPrefix().lower())
390 continue; 390 continue;
391 if ( (bflags = list->mb_flag) ) { 391 if ( (bflags = list->mb_flag) ) {
392 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 392 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
393 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 393 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
394 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 394 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
395 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 395 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
396 no_inferiors = true; 396 no_inferiors = true;
397 } 397 }
398 } 398 }
399 } 399 }
400 del = list->mb_delimiter; 400 del = list->mb_delimiter;
401 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 401 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
402 } 402 }
403 } else { 403 } else {
404 qDebug("error fetching folders "); 404 qDebug("error fetching folders ");
405 405
406 } 406 }
407 if (result) mailimap_list_result_free( result ); 407 if (result) mailimap_list_result_free( result );
408 return folders; 408 return folders;
409} 409}
410 410
411RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 411RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
412{ 412{
413 RecMail * m = 0; 413 RecMail * m = 0;
414 mailimap_msg_att_item *item=0; 414 mailimap_msg_att_item *item=0;
415 clistcell *current,*c,*cf; 415 clistcell *current,*c,*cf;
416 mailimap_msg_att_dynamic*flist; 416 mailimap_msg_att_dynamic*flist;
417 mailimap_flag_fetch*cflag; 417 mailimap_flag_fetch*cflag;
418 int size; 418 int size = 0;
419 QBitArray mFlags(7); 419 QBitArray mFlags(7);
420 QStringList addresslist; 420 QStringList addresslist;
421 421
422 if (!m_att) { 422 if (!m_att) {
423 return m; 423 return m;
424 } 424 }
425 m = new RecMail(); 425 m = new RecMail();
426 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 426 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
427 current = c; 427 current = c;
428 size = 0; 428 size = 0;
429 item = (mailimap_msg_att_item*)current->data; 429 item = (mailimap_msg_att_item*)current->data;
430 if ( !item ) 430 if ( !item )
431 continue; 431 continue;
432 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 432 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
433 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 433 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
434 if (!flist || !flist->att_list) { 434 if (!flist || !flist->att_list) {
435 continue; 435 continue;
436 } 436 }
437 cf = flist->att_list->first; 437 cf = flist->att_list->first;
438 if( ! cf ) 438 if( ! cf )
439 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 439 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
440 cflag = (mailimap_flag_fetch*)cf->data; 440 cflag = (mailimap_flag_fetch*)cf->data;
441 if( ! cflag ) 441 if( ! cflag )
442 qDebug("imap:not cflag "); 442 qDebug("imap:not cflag ");
443 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 443 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
444 switch (cflag->fl_flag->fl_type) { 444 switch (cflag->fl_flag->fl_type) {
445 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 445 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
446 mFlags.setBit(FLAG_ANSWERED); 446 mFlags.setBit(FLAG_ANSWERED);
447 break; 447 break;
448 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 448 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
449 mFlags.setBit(FLAG_FLAGGED); 449 mFlags.setBit(FLAG_FLAGGED);
450 break; 450 break;
451 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 451 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
452 mFlags.setBit(FLAG_DELETED); 452 mFlags.setBit(FLAG_DELETED);
453 break; 453 break;
454 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 454 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
455 mFlags.setBit(FLAG_SEEN); 455 mFlags.setBit(FLAG_SEEN);
456 break; 456 break;
457 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 457 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
458 mFlags.setBit(FLAG_DRAFT); 458 mFlags.setBit(FLAG_DRAFT);
459 break; 459 break;
460 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 460 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
461 break; 461 break;
462 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 462 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
463 break; 463 break;
464 default: 464 default:
465 break; 465 break;
466 } 466 }
467 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 467 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
468 mFlags.setBit(FLAG_RECENT); 468 mFlags.setBit(FLAG_RECENT);
469 } 469 }
470 } 470 }
471 continue; 471 continue;
472 } 472 }
473 if ( item->att_data.att_static == NULL ) 473 if ( item->att_data.att_static == NULL )
474 continue; 474 continue;
475 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 475 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
476 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 476 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
477 if ( head == NULL ) 477 if ( head == NULL )
478 continue; 478 continue;
479 if ( head->env_date != NULL ) { 479 if ( head->env_date != NULL ) {
480 m->setDate(head->env_date); 480 m->setDate(head->env_date);
481 //struct mailimf_date_time result; 481 //struct mailimf_date_time result;
482 struct mailimf_date_time* date;// = &result; 482 struct mailimf_date_time* date;// = &result;
@@ -700,128 +700,129 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int
700 700
701 err = mailimap_fetch( m_imap, set, fetchType, &result ); 701 err = mailimap_fetch( m_imap, set, fetchType, &result );
702 mailimap_set_free( set ); 702 mailimap_set_free( set );
703 mailimap_fetch_type_free( fetchType ); 703 mailimap_fetch_type_free( fetchType );
704 704
705 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 705 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
706 mailimap_msg_att * msg_att; 706 mailimap_msg_att * msg_att;
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 755
756 size_t index = 0; 756 size_t index = 0;
757 char*res = 0; 757 char*res = 0;
758 int err = MAILIMF_NO_ERROR; 758 int err = MAILIMF_NO_ERROR;
759 759
760 QString charset = currentPart->searchParamter( "charset"); 760 QString charset = currentPart->searchParamter( "charset");
761 qDebug("CHARSET %s ",charset.latin1() ); 761 qDebug("CHARSET %s ",charset.latin1() );
762 //if ( false ) { 762 //if ( false ) {
763 if ( !charset.isEmpty() ) { 763 if ( !charset.isEmpty() ) {
764 target_body->setCharset( charset );
764 //err = mailmime_encoded_phrase_parse("iso-8859-1", 765 //err = mailmime_encoded_phrase_parse("iso-8859-1",
765 // text, strlen(text),&index, "iso-8859-1",&res); 766 // text, strlen(text),&index, "iso-8859-1",&res);
766 err = mailmime_encoded_phrase_parse(charset.latin1(), 767 err = mailmime_encoded_phrase_parse(charset.latin1(),
767 body_text.latin1(), body_text.length(),&index, "utf-8",&res); 768 body_text.latin1(), body_text.length(),&index, "utf-8",&res);
768 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 769 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
769 //qDebug("res %d %s ", index, res); 770 //qDebug("res %d %s ", index, res);
770 body_text = QString::fromUtf8(res); 771 body_text = QString::fromUtf8(res);
771 } 772 }
772 if (res) free(res); 773 if (res) free(res);
773 } 774 }
774 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); 775 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
775 target_body->setDescription(currentPart); 776 target_body->setDescription(currentPart);
776 target_body->setBodytext(body_text); 777 target_body->setBodytext(body_text);
777 if (countlist.count()>1) { 778 if (countlist.count()>1) {
778 target_body->addPart(currentPart); 779 target_body->addPart(currentPart);
779 } 780 }
780 } else { 781 } else {
781 target_body->addPart(currentPart); 782 target_body->addPart(currentPart);
782 } 783 }
783 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 784 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
784 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 785 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
785 } 786 }
786 } 787 }
787 break; 788 break;
788 case MAILIMAP_BODY_MPART: 789 case MAILIMAP_BODY_MPART:
789 { 790 {
790 QValueList<int>countlist = recList; 791 QValueList<int>countlist = recList;
791 clistcell*current=0; 792 clistcell*current=0;
792 mailimap_body*current_body=0; 793 mailimap_body*current_body=0;
793 unsigned int ccount = 1; 794 unsigned int ccount = 1;
794 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 795 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
795 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 796 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
796 current_body = (mailimap_body*)current->data; 797 current_body = (mailimap_body*)current->data;
797 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 798 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
798 RecPartP targetPart = new RecPart(); 799 RecPartP targetPart = new RecPart();
799 targetPart->setType("multipart"); 800 targetPart->setType("multipart");
800 fillMultiPart(targetPart,mailDescription); 801 fillMultiPart(targetPart,mailDescription);
801 countlist.append(current_count); 802 countlist.append(current_count);
802 targetPart->setPositionlist(countlist); 803 targetPart->setPositionlist(countlist);
803 target_body->addPart(targetPart); 804 target_body->addPart(targetPart);
804 QString id(""); 805 QString id("");
805 for (unsigned int j = 0; j < countlist.count();++j) { 806 for (unsigned int j = 0; j < countlist.count();++j) {
806 id+=(j>0?" ":""); 807 id+=(j>0?" ":"");
807 id+=QString("%1").arg(countlist[j]); 808 id+=QString("%1").arg(countlist[j]);
808 } 809 }
809 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 810 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
810 } 811 }
811 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 812 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
812 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 813 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
813 countlist = recList; 814 countlist = recList;
814 } 815 }
815 ++ccount; 816 ++ccount;
816 } 817 }
817 } 818 }
818 break; 819 break;
819 default: 820 default:
820 break; 821 break;
821 } 822 }
822} 823}
823 824
824void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 825void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
825{ 826{
826 if (!Description) { 827 if (!Description) {
827 return; 828 return;
@@ -1121,129 +1122,129 @@ QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1121{ 1122{
1122 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1123 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1123} 1124}
1124 1125
1125encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1126encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1126{ 1127{
1127 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1128 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1128 encodedString*r = decode_String(res,part->Encoding()); 1129 encodedString*r = decode_String(res,part->Encoding());
1129 delete res; 1130 delete res;
1130 return r; 1131 return r;
1131} 1132}
1132 1133
1133encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1134encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1134{ 1135{
1135 return fetchRawPart(mail,part->Positionlist(),false); 1136 return fetchRawPart(mail,part->Positionlist(),false);
1136} 1137}
1137 1138
1138int IMAPwrapper::deleteAllMail(const FolderP&folder) 1139int IMAPwrapper::deleteAllMail(const FolderP&folder)
1139{ 1140{
1140 login(); 1141 login();
1141 if (!m_imap) { 1142 if (!m_imap) {
1142 return 0; 1143 return 0;
1143 } 1144 }
1144 mailimap_flag_list*flist; 1145 mailimap_flag_list*flist;
1145 mailimap_set *set; 1146 mailimap_set *set;
1146 mailimap_store_att_flags * store_flags; 1147 mailimap_store_att_flags * store_flags;
1147 int err = selectMbox(folder->getName()); 1148 int err = selectMbox(folder->getName());
1148 if ( err != MAILIMAP_NO_ERROR ) { 1149 if ( err != MAILIMAP_NO_ERROR ) {
1149 return 0; 1150 return 0;
1150 } 1151 }
1151 1152
1152 int last = m_imap->imap_selection_info->sel_exists; 1153 int last = m_imap->imap_selection_info->sel_exists;
1153 if (last == 0) { 1154 if (last == 0) {
1154 Global::statusMessage(i18n("Mailbox has no mails!")); 1155 Global::statusMessage(i18n("Mailbox has no mails!"));
1155 return 0; 1156 return 0;
1156 } 1157 }
1157 flist = mailimap_flag_list_new_empty(); 1158 flist = mailimap_flag_list_new_empty();
1158 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1159 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1159 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1160 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1160 set = mailimap_set_new_interval( 1, last ); 1161 set = mailimap_set_new_interval( 1, last );
1161 err = mailimap_store(m_imap,set,store_flags); 1162 err = mailimap_store(m_imap,set,store_flags);
1162 mailimap_set_free( set ); 1163 mailimap_set_free( set );
1163 mailimap_store_att_flags_free(store_flags); 1164 mailimap_store_att_flags_free(store_flags);
1164 if (err != MAILIMAP_NO_ERROR) { 1165 if (err != MAILIMAP_NO_ERROR) {
1165 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1166 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1166 return 0; 1167 return 0;
1167 } 1168 }
1168 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1169 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1169 /* should we realy do that at this moment? */ 1170 /* should we realy do that at this moment? */
1170 err = mailimap_expunge(m_imap); 1171 err = mailimap_expunge(m_imap);
1171 if (err != MAILIMAP_NO_ERROR) { 1172 if (err != MAILIMAP_NO_ERROR) {
1172 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1173 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1173 return 0; 1174 return 0;
1174 } 1175 }
1175 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1176 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1176 return 1; 1177 return 1;
1177} 1178}
1178 1179
1179int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1180int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1180{ 1181{
1181 if (folder.length()==0) return 0; 1182 if (folder.length()==0) return 0;
1182 login(); 1183 login();
1183 if (!m_imap) {return 0;} 1184 if (!m_imap) {return 0;}
1184 QString pre = account->getPrefix(); 1185 QString pre = account->getPrefix();
1185 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1186 if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) {
1186 pre+=delemiter; 1187 pre+=delemiter;
1187 } 1188 }
1188 if (parentfolder) { 1189 if (parentfolder) {
1189 pre += parentfolder->getDisplayName()+delemiter; 1190 pre += parentfolder->getDisplayName()+delemiter;
1190 } 1191 }
1191 pre+=folder; 1192 pre+=folder;
1192 if (getsubfolder) { 1193 if (getsubfolder) {
1193 if (delemiter.length()>0) { 1194 if (delemiter.length()>0) {
1194 pre+=delemiter; 1195 pre+=delemiter;
1195 } else { 1196 } else {
1196 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); 1197 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
1197 return 0; 1198 return 0;
1198 } 1199 }
1199 } 1200 }
1200 // odebug << "Creating " << pre.latin1() << "" << oendl; 1201 // odebug << "Creating " << pre.latin1() << "" << oendl;
1201 int res = mailimap_create(m_imap,pre.latin1()); 1202 int res = mailimap_create(m_imap,pre.latin1());
1202 if (res != MAILIMAP_NO_ERROR) { 1203 if (res != MAILIMAP_NO_ERROR) {
1203 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1204 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1204 return 0; 1205 return 0;
1205 } 1206 }
1206 return 1; 1207 return 1;
1207} 1208}
1208 1209
1209int IMAPwrapper::deleteMbox(const FolderP&folder) 1210int IMAPwrapper::deleteMbox(const FolderP&folder)
1210{ 1211{
1211 if (!folder) return 0; 1212 if (!folder) return 0;
1212 login(); 1213 login();
1213 if (!m_imap) {return 0;} 1214 if (!m_imap) {return 0;}
1214 int res = mailimap_delete(m_imap,folder->getName()); 1215 int res = mailimap_delete(m_imap,folder->getName());
1215 if (res != MAILIMAP_NO_ERROR) { 1216 if (res != MAILIMAP_NO_ERROR) {
1216 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1217 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1217 return 0; 1218 return 0;
1218 } 1219 }
1219 return 1; 1220 return 1;
1220} 1221}
1221 1222
1222void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1223void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1223{ 1224{
1224 mailimap_status_att_list * att_list =0; 1225 mailimap_status_att_list * att_list =0;
1225 mailimap_mailbox_data_status * status=0; 1226 mailimap_mailbox_data_status * status=0;
1226 clistiter * cur = 0; 1227 clistiter * cur = 0;
1227 int r = 0; 1228 int r = 0;
1228 target_stat.message_count = 0; 1229 target_stat.message_count = 0;
1229 target_stat.message_unseen = 0; 1230 target_stat.message_unseen = 0;
1230 target_stat.message_recent = 0; 1231 target_stat.message_recent = 0;
1231 login(); 1232 login();
1232 if (!m_imap) { 1233 if (!m_imap) {
1233 return; 1234 return;
1234 } 1235 }
1235 att_list = mailimap_status_att_list_new_empty(); 1236 att_list = mailimap_status_att_list_new_empty();
1236 if (!att_list) return; 1237 if (!att_list) return;
1237 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1238 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1238 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1239 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1239 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1240 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1240 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1241 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1241 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1242 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1242 for (cur = clist_begin(status->st_info_list); 1243 for (cur = clist_begin(status->st_info_list);
1243 cur != NULL ; cur = clist_next(cur)) { 1244 cur != NULL ; cur = clist_next(cur)) {
1244 mailimap_status_info * status_info; 1245 mailimap_status_info * status_info;
1245 status_info = (mailimap_status_info *)clist_content(cur); 1246 status_info = (mailimap_status_info *)clist_content(cur);
1246 switch (status_info->st_att) { 1247 switch (status_info->st_att) {
1247 case MAILIMAP_STATUS_ATT_MESSAGES: 1248 case MAILIMAP_STATUS_ATT_MESSAGES:
1248 target_stat.message_count = status_info->st_value; 1249 target_stat.message_count = status_info->st_value;
1249 break; 1250 break;
diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp
index af3b9d0..89150ad 100644
--- a/kmicromail/libmailwrapper/mailtypes.cpp
+++ b/kmicromail/libmailwrapper/mailtypes.cpp
@@ -226,171 +226,182 @@ const QString& RecPart::Encoding()const
226} 226}
227 227
228void RecPart::setEncoding(const QString&encoding) 228void RecPart::setEncoding(const QString&encoding)
229{ 229{
230 m_encoding = encoding; 230 m_encoding = encoding;
231} 231}
232 232
233const QString& RecPart::Description()const 233const QString& RecPart::Description()const
234{ 234{
235 return m_description; 235 return m_description;
236} 236}
237 237
238void RecPart::setDescription(const QString&desc) 238void RecPart::setDescription(const QString&desc)
239{ 239{
240 m_description = desc; 240 m_description = desc;
241} 241}
242 242
243void RecPart::setParameters(const part_plist_t&list) 243void RecPart::setParameters(const part_plist_t&list)
244{ 244{
245 m_Parameters = list; 245 m_Parameters = list;
246} 246}
247 247
248const part_plist_t& RecPart::Parameters()const 248const part_plist_t& RecPart::Parameters()const
249{ 249{
250 return m_Parameters; 250 return m_Parameters;
251} 251}
252 252
253void RecPart::addParameter(const QString&key,const QString&value) 253void RecPart::addParameter(const QString&key,const QString&value)
254{ 254{
255 m_Parameters[key]=value; 255 m_Parameters[key]=value;
256} 256}
257 257
258const QString RecPart::searchParamter(const QString&key)const 258const QString RecPart::searchParamter(const QString&key)const
259{ 259{
260 QString value(""); 260 QString value("");
261 part_plist_t::ConstIterator it = m_Parameters.find(key); 261 part_plist_t::ConstIterator it = m_Parameters.find(key);
262 if (it != m_Parameters.end()) { 262 if (it != m_Parameters.end()) {
263 value = it.data(); 263 value = it.data();
264 } 264 }
265 return value; 265 return value;
266} 266}
267 267
268void RecPart::setPositionlist(const QValueList<int>&poslist) 268void RecPart::setPositionlist(const QValueList<int>&poslist)
269{ 269{
270 m_poslist = poslist; 270 m_poslist = poslist;
271} 271}
272 272
273const QValueList<int>& RecPart::Positionlist()const 273const QValueList<int>& RecPart::Positionlist()const
274{ 274{
275 return m_poslist; 275 return m_poslist;
276} 276}
277 277
278RecBody::RecBody() 278RecBody::RecBody()
279 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) 279 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart())
280{ 280{
281 m_PartsList.clear(); 281 m_PartsList.clear();
282} 282}
283 283
284RecBody::RecBody(const RecBody&old) 284RecBody::RecBody(const RecBody&old)
285 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) 285 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart())
286{ 286{
287 m_BodyText = old.m_BodyText; 287 m_BodyText = old.m_BodyText;
288 m_PartsList = old.m_PartsList; 288 m_PartsList = old.m_PartsList;
289 m_description = old.m_description; 289 m_description = old.m_description;
290 mCharset = old.mCharset;
290 // odebug << "Recbody copy constructor" << oendl; 291 // odebug << "Recbody copy constructor" << oendl;
291} 292}
292 293
293RecBody::~RecBody() 294RecBody::~RecBody()
294{ 295{
295} 296}
296 297
297void RecBody::setBodytext(const QString&bodyText) 298void RecBody::setBodytext(const QString&bodyText)
298{ 299{
299 m_BodyText = bodyText; 300 m_BodyText = bodyText;
300} 301}
301 302
302const QString& RecBody::Bodytext()const 303const QString& RecBody::Bodytext()const
303{ 304{
304 return m_BodyText; 305 return m_BodyText;
305} 306}
306 307
307void RecBody::setParts(const QValueList<RecPartP>&parts) 308void RecBody::setParts(const QValueList<RecPartP>&parts)
308{ 309{
309 m_PartsList.clear(); 310 m_PartsList.clear();
310 m_PartsList = parts; 311 m_PartsList = parts;
311} 312}
312 313
313const QValueList<RecPartP>& RecBody::Parts()const 314const QValueList<RecPartP>& RecBody::Parts()const
314{ 315{
315 return m_PartsList; 316 return m_PartsList;
316} 317}
317 318
318void RecBody::addPart(const RecPartP& part) 319void RecBody::addPart(const RecPartP& part)
319{ 320{
320 m_PartsList.append(part); 321 m_PartsList.append(part);
321} 322}
322 323
323void RecBody::setDescription(const RecPartP&des) 324void RecBody::setDescription(const RecPartP&des)
324{ 325{
325 m_description = des; 326 m_description = des;
326} 327}
327 328
328const RecPartP& RecBody::Description()const 329const RecPartP& RecBody::Description()const
329{ 330{
330 return m_description; 331 return m_description;
331} 332}
332 333
334void RecBody::setCharset(const QString& str)
335{
336 mCharset = str;
337}
338
339QString RecBody::getCharset()const
340{
341 return mCharset;
342}
343
333/* handling encoded content */ 344/* handling encoded content */
334encodedString::encodedString() 345encodedString::encodedString()
335{ 346{
336 init(); 347 init();
337} 348}
338 349
339encodedString::encodedString(const char*nContent,unsigned int nSize) 350encodedString::encodedString(const char*nContent,unsigned int nSize)
340{ 351{
341 init(); 352 init();
342 setContent(nContent,nSize); 353 setContent(nContent,nSize);
343} 354}
344 355
345encodedString::encodedString(char*nContent,unsigned int nSize) 356encodedString::encodedString(char*nContent,unsigned int nSize)
346{ 357{
347 init(); 358 init();
348 setContent(nContent,nSize); 359 setContent(nContent,nSize);
349} 360}
350 361
351encodedString::encodedString(const encodedString&old) 362encodedString::encodedString(const encodedString&old)
352{ 363{
353 init(); 364 init();
354 copy_old(old); 365 copy_old(old);
355 // odebug << "encodedeString: copy constructor!" << oendl; 366 // odebug << "encodedeString: copy constructor!" << oendl;
356} 367}
357 368
358encodedString& encodedString::operator=(const encodedString&old) 369encodedString& encodedString::operator=(const encodedString&old)
359{ 370{
360 init(); 371 init();
361 copy_old(old); 372 copy_old(old);
362 // odebug << "encodedString: assign operator!" << oendl; 373 // odebug << "encodedString: assign operator!" << oendl;
363 return *this; 374 return *this;
364} 375}
365 376
366encodedString::~encodedString() 377encodedString::~encodedString()
367{ 378{
368 clean(); 379 clean();
369} 380}
370 381
371void encodedString::init() 382void encodedString::init()
372{ 383{
373 content = 0; 384 content = 0;
374 size = 0; 385 size = 0;
375} 386}
376 387
377void encodedString::clean() 388void encodedString::clean()
378{ 389{
379 if (content) { 390 if (content) {
380 free(content); 391 free(content);
381 } 392 }
382 content = 0; 393 content = 0;
383 size = 0; 394 size = 0;
384} 395}
385 396
386void encodedString::copy_old(const encodedString&old) 397void encodedString::copy_old(const encodedString&old)
387{ 398{
388 clean(); 399 clean();
389 if (old.size>0 && old.content) { 400 if (old.size>0 && old.content) {
390 content = (char*)malloc(old.size*sizeof(char)); 401 content = (char*)malloc(old.size*sizeof(char));
391 memcpy(content,old.content,size); 402 memcpy(content,old.content,size);
392 size = old.size; 403 size = old.size;
393 } 404 }
394} 405}
395 406
396const char*encodedString::Content()const 407const char*encodedString::Content()const
diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h
index c1c1a74..32d92c0 100644
--- a/kmicromail/libmailwrapper/mailtypes.h
+++ b/kmicromail/libmailwrapper/mailtypes.h
@@ -72,137 +72,140 @@ public:
72 void setFlags(const QBitArray&flags){msg_flags = flags;} 72 void setFlags(const QBitArray&flags){msg_flags = flags;}
73 73
74 void setWrapper(AbstractMail*wrapper); 74 void setWrapper(AbstractMail*wrapper);
75 AbstractMail* Wrapper(); 75 AbstractMail* Wrapper();
76 // public for debugging 76 // public for debugging
77 QString subject,date,isodate,from,mbox,msg_id,replyto; 77 QString subject,date,isodate,from,mbox,msg_id,replyto;
78 78
79protected: 79protected:
80 //QString subject,date,isodate,from,mbox,msg_id,replyto; 80 //QString subject,date,isodate,from,mbox,msg_id,replyto;
81 unsigned int msg_number,msg_size; 81 unsigned int msg_number,msg_size;
82 QBitArray msg_flags; 82 QBitArray msg_flags;
83 QStringList to,cc,bcc,in_reply_to,references; 83 QStringList to,cc,bcc,in_reply_to,references;
84 AbstractMail*wrapper; 84 AbstractMail*wrapper;
85 void init(); 85 void init();
86 void copy_old(const RecMail&old); 86 void copy_old(const RecMail&old);
87}; 87};
88 88
89typedef Opie::Core::OSmartPointer<RecMail> RecMailP; 89typedef Opie::Core::OSmartPointer<RecMail> RecMailP;
90typedef QMap<QString,QString> part_plist_t; 90typedef QMap<QString,QString> part_plist_t;
91 91
92class RecPart:public Opie::Core::ORefCount 92class RecPart:public Opie::Core::ORefCount
93{ 93{
94protected: 94protected:
95 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 95 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
96 unsigned int m_lines,m_size; 96 unsigned int m_lines,m_size;
97 part_plist_t m_Parameters; 97 part_plist_t m_Parameters;
98 /* describes the position in the mail */ 98 /* describes the position in the mail */
99 QValueList<int> m_poslist; 99 QValueList<int> m_poslist;
100 100
101public: 101public:
102 RecPart(); 102 RecPart();
103 RecPart(const RecPart&); 103 RecPart(const RecPart&);
104 virtual ~RecPart(); 104 virtual ~RecPart();
105 105
106 const QString&Type()const; 106 const QString&Type()const;
107 void setType(const QString&type); 107 void setType(const QString&type);
108 const QString&Subtype()const; 108 const QString&Subtype()const;
109 void setSubtype(const QString&subtype); 109 void setSubtype(const QString&subtype);
110 const QString&Identifier()const; 110 const QString&Identifier()const;
111 void setIdentifier(const QString&identifier); 111 void setIdentifier(const QString&identifier);
112 const QString&Encoding()const; 112 const QString&Encoding()const;
113 void setEncoding(const QString&encoding); 113 void setEncoding(const QString&encoding);
114 const QString&Description()const; 114 const QString&Description()const;
115 void setDescription(const QString&desc); 115 void setDescription(const QString&desc);
116 void setLines(unsigned int lines); 116 void setLines(unsigned int lines);
117 const unsigned int Lines()const; 117 const unsigned int Lines()const;
118 void setSize(unsigned int size); 118 void setSize(unsigned int size);
119 const unsigned int Size()const; 119 const unsigned int Size()const;
120 120
121 121
122 void setParameters(const part_plist_t&list); 122 void setParameters(const part_plist_t&list);
123 const part_plist_t&Parameters()const; 123 const part_plist_t&Parameters()const;
124 void addParameter(const QString&key,const QString&value); 124 void addParameter(const QString&key,const QString&value);
125 const QString searchParamter(const QString&key)const; 125 const QString searchParamter(const QString&key)const;
126 void setPositionlist(const QValueList<int>&poslist); 126 void setPositionlist(const QValueList<int>&poslist);
127 const QValueList<int>& Positionlist()const; 127 const QValueList<int>& Positionlist()const;
128}; 128};
129 129
130typedef Opie::Core::OSmartPointer<RecPart> RecPartP; 130typedef Opie::Core::OSmartPointer<RecPart> RecPartP;
131 131
132class RecBody:public Opie::Core::ORefCount 132class RecBody:public Opie::Core::ORefCount
133{ 133{
134protected: 134protected:
135 QString m_BodyText; 135 QString m_BodyText;
136 QString mCharset;
136 QValueList<RecPartP> m_PartsList; 137 QValueList<RecPartP> m_PartsList;
137 RecPartP m_description; 138 RecPartP m_description;
138 139
139public: 140public:
140 RecBody(); 141 RecBody();
141 RecBody(const RecBody&old); 142 RecBody(const RecBody&old);
142 virtual ~RecBody(); 143 virtual ~RecBody();
143 void setBodytext(const QString&); 144 void setBodytext(const QString&);
144 const QString& Bodytext()const; 145 const QString& Bodytext()const;
146 void setCharset(const QString&);
147 QString getCharset()const;
145 148
146 void setDescription(const RecPartP&des); 149 void setDescription(const RecPartP&des);
147 const RecPartP& Description()const; 150 const RecPartP& Description()const;
148 151
149 void setParts(const QValueList<RecPartP>&parts); 152 void setParts(const QValueList<RecPartP>&parts);
150 const QValueList<RecPartP>& Parts()const; 153 const QValueList<RecPartP>& Parts()const;
151 void addPart(const RecPartP&part); 154 void addPart(const RecPartP&part);
152}; 155};
153 156
154typedef Opie::Core::OSmartPointer<RecBody> RecBodyP; 157typedef Opie::Core::OSmartPointer<RecBody> RecBodyP;
155 158
156class encodedString 159class encodedString
157{ 160{
158public: 161public:
159 encodedString(); 162 encodedString();
160 /* 163 /*
161 creates an new content string. 164 creates an new content string.
162 it makes a deep copy of it! 165 it makes a deep copy of it!
163 */ 166 */
164 encodedString(const char*nContent,unsigned int length); 167 encodedString(const char*nContent,unsigned int length);
165 /* 168 /*
166 Take over the nContent. Means: it will just copy the pointer, not the content. 169 Take over the nContent. Means: it will just copy the pointer, not the content.
167 so make sure: No one else frees the string, the string has allocated with 170 so make sure: No one else frees the string, the string has allocated with
168 malloc for compatibility with c-based libs 171 malloc for compatibility with c-based libs
169 */ 172 */
170 encodedString(char*nContent,unsigned int nSize); 173 encodedString(char*nContent,unsigned int nSize);
171 /* copy construkor - makes ALWAYS a deep copy!!!! */ 174 /* copy construkor - makes ALWAYS a deep copy!!!! */
172 encodedString(const encodedString&old); 175 encodedString(const encodedString&old);
173 /* assign operator - makes ALWAYS a deep copy!!!! */ 176 /* assign operator - makes ALWAYS a deep copy!!!! */
174 encodedString& operator=(const encodedString&old); 177 encodedString& operator=(const encodedString&old);
175 /* destructor - cleans the content */ 178 /* destructor - cleans the content */
176 virtual ~encodedString(); 179 virtual ~encodedString();
177 180
178 /* returns a pointer to the content - do not delete yoursel! */ 181 /* returns a pointer to the content - do not delete yoursel! */
179 const char*Content()const; 182 const char*Content()const;
180 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 183 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
181 const int Length()const; 184 const int Length()const;
182 185
183 /* 186 /*
184 makes a deep copy of nContent! 187 makes a deep copy of nContent!
185 */ 188 */
186 void setContent(const char*nContent,int nSize); 189 void setContent(const char*nContent,int nSize);
187 /* 190 /*
188 Take over the nContent. Means: it will just copy the pointer, not the content. 191 Take over the nContent. Means: it will just copy the pointer, not the content.
189 so make sure: No one else frees the string, the string has allocated with 192 so make sure: No one else frees the string, the string has allocated with
190 malloc for compatibility with c-based libs 193 malloc for compatibility with c-based libs
191 */ 194 */
192 void setContent(char*nContent,int nSize); 195 void setContent(char*nContent,int nSize);
193 196
194protected: 197protected:
195 char * content; 198 char * content;
196 unsigned int size; 199 unsigned int size;
197 200
198 void init(); 201 void init();
199 void copy_old(const encodedString&old); 202 void copy_old(const encodedString&old);
200 void clean(); 203 void clean();
201}; 204};
202 205
203struct folderStat 206struct folderStat
204{ 207{
205 unsigned int message_count; 208 unsigned int message_count;
206 unsigned int message_unseen; 209 unsigned int message_unseen;
207 unsigned int message_recent; 210 unsigned int message_recent;
208 folderStat&operator=(const folderStat&old); 211 folderStat&operator=(const folderStat&old);
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h
index 88f10da..ea6bf36 100644
--- a/kmicromail/libmailwrapper/mailwrapper.h
+++ b/kmicromail/libmailwrapper/mailwrapper.h
@@ -21,108 +21,111 @@ public:
21 const QString getName()const{ return doc.name(); } 21 const QString getName()const{ return doc.name(); }
22 const QString getMimeType()const{ return doc.type(); } 22 const QString getMimeType()const{ return doc.type(); }
23 const QPixmap getPixmap()const{ return doc.pixmap(); } 23 const QPixmap getPixmap()const{ return doc.pixmap(); }
24 const int getSize()const { return size; } 24 const int getSize()const { return size; }
25 DocLnk getDocLnk() { return doc; } 25 DocLnk getDocLnk() { return doc; }
26 26
27protected: 27protected:
28 DocLnk doc; 28 DocLnk doc;
29 int size; 29 int size;
30 30
31}; 31};
32*/ 32*/
33 33
34class Attachment 34class Attachment
35{ 35{
36public: 36public:
37 Attachment( QString lnk ); 37 Attachment( QString lnk );
38 virtual ~Attachment(){} 38 virtual ~Attachment(){}
39 const QString getFileName()const{ return doc; } 39 const QString getFileName()const{ return doc; }
40 const QString getName()const{ return QFileInfo( doc ).baseName (); } 40 const QString getName()const{ return QFileInfo( doc ).baseName (); }
41 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } 41 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); }
42 const QPixmap getPixmap()const{ return mPix; } 42 const QPixmap getPixmap()const{ return mPix; }
43 const int getSize()const { return size; } 43 const int getSize()const { return size; }
44 QString getDocLnk() { return doc; } 44 QString getDocLnk() { return doc; }
45 45
46protected: 46protected:
47 QPixmap mPix; 47 QPixmap mPix;
48 QString doc; 48 QString doc;
49 int size; 49 int size;
50 50
51}; 51};
52 52
53class Mail:public Opie::Core::ORefCount 53class Mail:public Opie::Core::ORefCount
54{ 54{
55public: 55public:
56 Mail(); 56 Mail();
57 /* Possible that this destructor must not be declared virtual 57 /* Possible that this destructor must not be declared virtual
58 * 'cause it seems that it will never have some child classes. 58 * 'cause it seems that it will never have some child classes.
59 * in this case this object will not get a virtual table -> memory and 59 * in this case this object will not get a virtual table -> memory and
60 * speed will be a little bit better? 60 * speed will be a little bit better?
61 */ 61 */
62 virtual ~Mail(){} 62 virtual ~Mail(){}
63 void addAttachment( Attachment *att ) { attList.append( att ); } 63 void addAttachment( Attachment *att ) { attList.append( att ); }
64 const QList<Attachment>& getAttachments()const { return attList; } 64 const QList<Attachment>& getAttachments()const { return attList; }
65 void removeAttachment( Attachment *att ) { attList.remove( att ); } 65 void removeAttachment( Attachment *att ) { attList.remove( att ); }
66 const QString&getName()const { return name; } 66 const QString&getName()const { return name; }
67 void setName( QString s ) { name = s; } 67 void setName( QString s ) { name = s; }
68 const QString&getMail()const{ return mail; } 68 const QString&getMail()const{ return mail; }
69 void setMail( const QString&s ) { mail = s; } 69 void setMail( const QString&s ) { mail = s; }
70 const QString&getTo()const{ return to; } 70 const QString&getTo()const{ return to; }
71 void setTo( const QString&s ) { to = s; } 71 void setTo( const QString&s ) { to = s; }
72 const QString&getCC()const{ return cc; } 72 const QString&getCC()const{ return cc; }
73 void setCC( const QString&s ) { cc = s; } 73 void setCC( const QString&s ) { cc = s; }
74 const QString&getBCC()const { return bcc; } 74 const QString&getBCC()const { return bcc; }
75 void setBCC( const QString&s ) { bcc = s; } 75 void setBCC( const QString&s ) { bcc = s; }
76 const QString&getMessage()const { return message; } 76 const QString&getMessage()const { return message; }
77 void setMessage( const QString&s ) { message = s; } 77 void setMessage( const QString&s ) { message = s; }
78 const QString&getSubject()const { return subject; } 78 const QString&getSubject()const { return subject; }
79 void setSubject( const QString&s ) { subject = s; } 79 void setSubject( const QString&s ) { subject = s; }
80 const QString&getReply()const{ return reply; } 80 const QString&getReply()const{ return reply; }
81 void setReply( const QString&a ) { reply = a; } 81 void setReply( const QString&a ) { reply = a; }
82 void setInreply(const QStringList&list){m_in_reply_to = list;} 82 void setInreply(const QStringList&list){m_in_reply_to = list;}
83 const QStringList&Inreply()const{return m_in_reply_to;} 83 const QStringList&Inreply()const{return m_in_reply_to;}
84 84
85 void setCharset( const QString&a ) { charset= a; }
86 const QString& getCharset() { return charset; }
87
85private: 88private:
86 QList<Attachment> attList; 89 QList<Attachment> attList;
87 QString name, mail, to, cc, bcc, reply, subject, message; 90 QString name, mail, to, cc, bcc, reply, subject, message, charset;
88 QStringList m_in_reply_to; 91 QStringList m_in_reply_to;
89}; 92};
90 93
91class Folder:public Opie::Core::ORefCount 94class Folder:public Opie::Core::ORefCount
92{ 95{
93public: 96public:
94 Folder( const QString&init_name,const QString&sep ); 97 Folder( const QString&init_name,const QString&sep );
95 virtual ~Folder(); 98 virtual ~Folder();
96 const QString&getDisplayName()const { return nameDisplay; } 99 const QString&getDisplayName()const { return nameDisplay; }
97 const QString&getName()const { return name; } 100 const QString&getName()const { return name; }
98 const QString&getPrefix()const{return prefix; } 101 const QString&getPrefix()const{return prefix; }
99 virtual bool may_select()const{return true;} 102 virtual bool may_select()const{return true;}
100 virtual bool no_inferior()const{return true;} 103 virtual bool no_inferior()const{return true;}
101 const QString&Separator()const; 104 const QString&Separator()const;
102 105
103protected: 106protected:
104 QString nameDisplay, name, separator,prefix; 107 QString nameDisplay, name, separator,prefix;
105}; 108};
106 109
107typedef Opie::Core::OSmartPointer<Folder> FolderP; 110typedef Opie::Core::OSmartPointer<Folder> FolderP;
108 111
109class MHFolder : public Folder 112class MHFolder : public Folder
110{ 113{
111public: 114public:
112 MHFolder(const QString&disp_name,const QString&mbox); 115 MHFolder(const QString&disp_name,const QString&mbox);
113 virtual ~MHFolder(); 116 virtual ~MHFolder();
114}; 117};
115 118
116class IMAPFolder : public Folder 119class IMAPFolder : public Folder
117{ 120{
118 public: 121 public:
119 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); 122 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
120 virtual ~IMAPFolder(); 123 virtual ~IMAPFolder();
121 virtual bool may_select()const{return m_MaySelect;} 124 virtual bool may_select()const{return m_MaySelect;}
122 virtual bool no_inferior()const{return m_NoInferior;} 125 virtual bool no_inferior()const{return m_NoInferior;}
123 static QString decodeFolderName( const QString &name ); 126 static QString decodeFolderName( const QString &name );
124 private: 127 private:
125 bool m_MaySelect,m_NoInferior; 128 bool m_MaySelect,m_NoInferior;
126}; 129};
127 130
128#endif 131#endif
diff --git a/kmicromail/libmailwrapper/storemail.cpp b/kmicromail/libmailwrapper/storemail.cpp
index ed1d44a..9d1735f 100644
--- a/kmicromail/libmailwrapper/storemail.cpp
+++ b/kmicromail/libmailwrapper/storemail.cpp
@@ -1,90 +1,98 @@
1#include "storemail.h" 1#include "storemail.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3#include "settings.h" 3#include "settings.h"
4#include "abstractmail.h" 4#include "abstractmail.h"
5 5
6#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
7#include <qstring.h> 7#include <qstring.h>
8 8
9#include <stdlib.h> 9#include <stdlib.h>
10#include <kglobal.h>
10 11
11using namespace Opie::Core; 12using namespace Opie::Core;
12Storemail::Storemail(Account*aAccount,const QString&aFolder) 13Storemail::Storemail(Account*aAccount,const QString&aFolder)
13 : Generatemail() 14 : Generatemail()
14{ 15{
15 wrapper = 0; 16 wrapper = 0;
16 m_Account = aAccount; 17 m_Account = aAccount;
17 m_tfolder = aFolder; 18 m_tfolder = aFolder;
18 wrapper = AbstractMail::getWrapper(m_Account); 19 wrapper = AbstractMail::getWrapper(m_Account);
19 if (wrapper) { 20 if (wrapper) {
20 wrapper->createMbox(m_tfolder); 21 wrapper->createMbox(m_tfolder);
21 } 22 }
22} 23}
23 24
24Storemail::Storemail(const QString&dir,const QString&aFolder) 25Storemail::Storemail(const QString&dir,const QString&aFolder)
25 : Generatemail() 26 : Generatemail()
26{ 27{
27 wrapper = 0; 28 wrapper = 0;
28 m_Account = 0; 29 m_Account = 0;
29 m_tfolder = aFolder; 30 m_tfolder = aFolder;
30 wrapper = AbstractMail::getWrapper(dir); 31 wrapper = AbstractMail::getWrapper(dir);
31 if (wrapper) { 32 if (wrapper) {
32 wrapper->createMbox(m_tfolder); 33 wrapper->createMbox(m_tfolder);
33 } 34 }
34} 35}
35 36
36Storemail::Storemail(const QString&aFolder) 37Storemail::Storemail(const QString&aFolder)
37 : Generatemail() 38 : Generatemail()
38{ 39{
39 wrapper = 0; 40 wrapper = 0;
40 m_Account = 0; 41 m_Account = 0;
41 m_tfolder = aFolder; 42 m_tfolder = aFolder;
42 wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder()); 43 wrapper = AbstractMail::getWrapper(AbstractMail::defaultLocalfolder());
43 if (wrapper) { 44 if (wrapper) {
44 wrapper->createMbox(m_tfolder); 45 wrapper->createMbox(m_tfolder);
45 } 46 }
46} 47}
47 48
48Storemail::~Storemail() 49Storemail::~Storemail()
49{ 50{
50} 51}
51 52
52int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail) 53int Storemail::storeMail(const Opie::Core::OSmartPointer<Mail>&mail)
53{ 54{
54 if (!wrapper) return 0; 55 if (!wrapper) return 0;
55 int ret = 1; 56 int ret = 1;
56 57
57 mailmime * mimeMail = 0; 58 mailmime * mimeMail = 0;
58 mimeMail = createMimeMail(mail ); 59 mimeMail = createMimeMail(mail );
59 if ( mimeMail == NULL ) { 60 if ( mimeMail == NULL ) {
60 qDebug("storeMail: error creating mime mail "); 61 qDebug("storeMail: error creating mime mail ");
61 return 0; 62 return 0;
62 } 63 }
63 char *data; 64 char *data;
64 size_t size; 65 size_t size;
65 data = 0; 66 data = 0;
66 67
67 mailmessage * msg = 0; 68 mailmessage * msg = 0;
68 msg = mime_message_init(mimeMail); 69 msg = mime_message_init(mimeMail);
69 mime_message_set_tmpdir(msg,getenv( "HOME" )); 70 QString fileName;
71#ifdef DESKTOP_VERSION
72 fileName = locateLocal("tmp", "");
73#else
74 fileName = "/tmp/";
75#endif
76 //mime_message_set_tmpdir(msg,getenv( "HOME" ));
77 mime_message_set_tmpdir(msg,(char*)fileName.latin1());
70 int r = mailmessage_fetch(msg,&data,&size); 78 int r = mailmessage_fetch(msg,&data,&size);
71 mime_message_detach_mime(msg); 79 mime_message_detach_mime(msg);
72 mailmessage_free(msg); 80 mailmessage_free(msg);
73 msg = 0; 81 msg = 0;
74 if (r != MAIL_NO_ERROR || !data) { 82 if (r != MAIL_NO_ERROR || !data) {
75 qDebug("Error fetching mime... "); 83 qDebug("Error fetching mime... ");
76 ret = 0; 84 ret = 0;
77 } 85 }
78 86
79 if (ret) { 87 if (ret) {
80 wrapper->storeMessage(data,size,m_tfolder); 88 wrapper->storeMessage(data,size,m_tfolder);
81 } 89 }
82 90
83 if (data) { 91 if (data) {
84 free(data); 92 free(data);
85 } 93 }
86 if (mimeMail) { 94 if (mimeMail) {
87 mailmime_free( mimeMail ); 95 mailmime_free( mimeMail );
88 } 96 }
89 return ret; 97 return ret;
90} 98}