summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-11-06 23:30:02 (UTC)
committer zautrix <zautrix>2004-11-06 23:30:02 (UTC)
commit023e0e82dd8bf6421d12492a2dd25534fc43ad31 (patch) (unidiff)
treecf0533e3ccc642cb57a41953f184f457fa5365ba /kmicromail/libmailwrapper
parentf8841c92d5251f713eb7a025af8fdee52de45b3d (diff)
downloadkdepimpi-023e0e82dd8bf6421d12492a2dd25534fc43ad31.zip
kdepimpi-023e0e82dd8bf6421d12492a2dd25534fc43ad31.tar.gz
kdepimpi-023e0e82dd8bf6421d12492a2dd25534fc43ad31.tar.bz2
many ompi fixes
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
@@ -1,278 +1,279 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "abstractmail.h" 2#include "abstractmail.h"
3#include "imapwrapper.h" 3#include "imapwrapper.h"
4#include "pop3wrapper.h" 4#include "pop3wrapper.h"
5#include "nntpwrapper.h" 5#include "nntpwrapper.h"
6#include "mhwrapper.h" 6#include "mhwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include <qpe/global.h> 8#include <qpe/global.h>
9 9
10 10
11#include <qprogressbar.h> 11#include <qprogressbar.h>
12#include <qapplication.h> 12#include <qapplication.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14#include <klocale.h> 14#include <klocale.h>
15#include <kdecore/kstandarddirs.h> 15#include <kdecore/kstandarddirs.h>
16#include <qfile.h> 16#include <qfile.h>
17#include <qtextstream.h> 17#include <qtextstream.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <libetpan/mailmime_content.h> 19#include <libetpan/mailmime_content.h>
20#include <libetpan/mailmime.h> 20#include <libetpan/mailmime.h>
21 21
22using namespace Opie::Core; 22using namespace Opie::Core;
23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
24{ 24{
25 return new IMAPwrapper(a); 25 return new IMAPwrapper(a);
26} 26}
27 27
28AbstractMail* AbstractMail::getWrapper(POP3account *a) 28AbstractMail* AbstractMail::getWrapper(POP3account *a)
29{ 29{
30 return new POP3wrapper(a); 30 return new POP3wrapper(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 ..."));
151 wid.show(); 152 wid.show();
152 while (iii < count ) { 153 while (iii < count ) {
153 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 154 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
154 wid.setProgress( iii ); 155 wid.setProgress( iii );
155 wid.raise(); 156 wid.raise();
156 qApp->processEvents(); 157 qApp->processEvents();
157 RecMailP mail = (*target.at( iii )); 158 RecMailP mail = (*target.at( iii ));
158 deleteMail(mail); 159 deleteMail(mail);
159 ++iii; 160 ++iii;
160 } 161 }
161} 162}
162 163
163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) 164void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
164{ 165{
165 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); 166 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
166 // get local folder 167 // get local folder
167 Account * acc = getAccount(); 168 Account * acc = getAccount();
168 if ( !acc ) return; 169 if ( !acc ) return;
169 QString lfName = acc->getLocalFolder(); 170 QString lfName = acc->getLocalFolder();
170 if ( lfName.isEmpty() ) 171 if ( lfName.isEmpty() )
171 lfName = acc->getAccountName(); 172 lfName = acc->getAccountName();
172 // create local folder 173 // create local folder
173 if ( !targetMail->createMbox(lfName)) 174 if ( !targetMail->createMbox(lfName))
174 { 175 {
175 QMessageBox::critical(0,i18n("Error creating new Folder"), 176 QMessageBox::critical(0,i18n("Error creating new Folder"),
176 i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); 177 i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
177 return; 178 return;
178 } 179 }
179 QValueList<RecMailP> t; 180 QValueList<RecMailP> t;
180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); 181 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
181 if ( t.count() == 0 ) { 182 if ( t.count() == 0 ) {
182 qDebug("There are no new messages %s", fromFolder->getName().latin1()); 183 qDebug("There are no new messages %s", fromFolder->getName().latin1());
183 Global::statusMessage(i18n("There are no new messages")); 184 Global::statusMessage(i18n("There are no new messages"));
184 return; 185 return;
185 } 186 }
186 QValueList<RecMailP> e; 187 QValueList<RecMailP> e;
187 targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); 188 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
188 //qDebug("target has mails %d ", e.count()); 189 //qDebug("target has mails %d ", e.count());
189 QValueList<RecMailP> n; 190 QValueList<RecMailP> n;
190 int iii = 0; 191 int iii = 0;
191 int count = t.count(); 192 int count = t.count();
192 while (iii < count ) { 193 while (iii < count ) {
193 RecMailP r = (*t.at( iii )); 194 RecMailP r = (*t.at( iii ));
194 bool found = false; 195 bool found = false;
195 int jjj = 0; 196 int jjj = 0;
196 int countE = e.count(); 197 int countE = e.count();
197 while (jjj < countE ) { 198 while (jjj < countE ) {
198 RecMailP re = (*e.at( jjj )); 199 RecMailP re = (*e.at( jjj ));
199 if ( re->isEqual(r) ) { 200 if ( re->isEqual(r) ) {
200 found = true; 201 found = true;
201 break; 202 break;
202 } 203 }
203 ++jjj; 204 ++jjj;
204 } 205 }
205 if ( !found ) { 206 if ( !found ) {
206 //qDebug("AAAdate *%s* ", r->isodate.latin1() ); 207 //qDebug("AAAdate *%s* ", r->isodate.latin1() );
207 n.append( r ); 208 n.append( r );
208 } 209 }
209 ++iii; 210 ++iii;
210 } 211 }
211 qDebug("Downloaded %d messages ",n.count() ); 212 qDebug("Downloaded %d messages ",n.count() );
212 if ( n.count() == 0 ) { 213 if ( n.count() == 0 ) {
213 Global::statusMessage(i18n("There are no new messages")); 214 Global::statusMessage(i18n("There are no new messages"));
214 return; 215 return;
215 } 216 }
216 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); 217 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
217 Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); 218 Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count()));
218 219
219#if 0 220#if 0
220 QValueList<RecMailP> t; 221 QValueList<RecMailP> t;
221 listMessages(fromFolder->getName(),t, maxSizeInKb); 222 listMessages(fromFolder->getName(),t, maxSizeInKb);
222 mvcpMailList( t,targetFolder,targetWrapper,moveit); 223 mvcpMailList( t,targetFolder,targetWrapper,moveit);
223#endif 224#endif
224 225
225} 226}
226void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 227void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
227 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 228 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
228{ 229{
229 QValueList<RecMailP> t; 230 QValueList<RecMailP> t;
230 listMessages(fromFolder->getName(),t, maxSizeInKb); 231 listMessages(fromFolder->getName(),t, maxSizeInKb);
231 mvcpMailList( t,targetFolder,targetWrapper,moveit); 232 mvcpMailList( t,targetFolder,targetWrapper,moveit);
232 233
233} 234}
234void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 235void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
235 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 236 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
236{ 237{
237 encodedString*st = 0; 238 encodedString*st = 0;
238 int iii = 0; 239 int iii = 0;
239 int count = t.count(); 240 int count = t.count();
240 if ( count == 0 ) 241 if ( count == 0 )
241 return; 242 return;
242 // wel, processevents is qite strange, we need a widget for getting 243 // wel, processevents is qite strange, we need a widget for getting
243 // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye 244 // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye
244 245
245 QProgressBar wid ( count ); 246 QProgressBar wid ( count );
246 wid.setCaption( i18n("Copying...")); 247 wid.setCaption( i18n("Copying..."));
247 wid.show(); 248 wid.show();
248 while (iii < count ) { 249 while (iii < count ) {
249 Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); 250 Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count));
250 wid.setProgress( iii ); 251 wid.setProgress( iii );
251 wid.raise(); 252 wid.raise();
252 qApp->processEvents(); 253 qApp->processEvents();
253 RecMailP r = (*t.at( iii )); 254 RecMailP r = (*t.at( iii ));
254 st = fetchRawBody(r); 255 st = fetchRawBody(r);
255 if (st) { 256 if (st) {
256 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 257 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
257 delete st; 258 delete st;
258 } 259 }
259 ++iii; 260 ++iii;
260 } 261 }
261 if (moveit) { 262 if (moveit) {
262 deleteMailList( t ); 263 deleteMailList( t );
263 //deleteAllMail(fromFolder); 264 //deleteAllMail(fromFolder);
264 } 265 }
265} 266}
266 267
267void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 268void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
268{ 269{
269 encodedString*st = 0; 270 encodedString*st = 0;
270 st = fetchRawBody(mail); 271 st = fetchRawBody(mail);
271 if (st) { 272 if (st) {
272 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 273 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
273 delete st; 274 delete st;
274 } 275 }
275 if (moveit) { 276 if (moveit) {
276 deleteMail(mail); 277 deleteMail(mail);
277 } 278 }
278} 279}
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
@@ -1,530 +1,544 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "genericwrapper.h" 2#include "genericwrapper.h"
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <kconfig.h> 6#include <kconfig.h>
7#include <kglobal.h> 7#include <kglobal.h>
8#include <kstandarddirs.h> 8#include <kstandarddirs.h>
9 9
10 10
11using namespace Opie::Core; 11using namespace Opie::Core;
12Genericwrapper::Genericwrapper() 12Genericwrapper::Genericwrapper()
13 : AbstractMail() 13 : AbstractMail()
14{ 14{
15 bodyCache.clear(); 15 bodyCache.clear();
16 m_storage = 0; 16 m_storage = 0;
17 m_folder = 0; 17 m_folder = 0;
18} 18}
19 19
20Genericwrapper::~Genericwrapper() 20Genericwrapper::~Genericwrapper()
21{ 21{
22 if (m_folder) { 22 if (m_folder) {
23 mailfolder_free(m_folder); 23 mailfolder_free(m_folder);
24 } 24 }
25 if (m_storage) { 25 if (m_storage) {
26 mailstorage_free(m_storage); 26 mailstorage_free(m_storage);
27 } 27 }
28 cleanMimeCache(); 28 cleanMimeCache();
29} 29}
30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) 30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date )
31{ 31{
32 32
33 QDate da (date->dt_year,date->dt_month, date->dt_day ); 33 QDate da (date->dt_year,date->dt_month, date->dt_day );
34 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); 34 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
35 QDateTime dt ( da ,ti ); 35 QDateTime dt ( da ,ti );
36 int addsec = -date->dt_zone*36; 36 int addsec = -date->dt_zone*36;
37 //qDebug("adsec1 %d ",addsec ); 37 //qDebug("adsec1 %d ",addsec );
38 dt = dt.addSecs( addsec ); 38 dt = dt.addSecs( addsec );
39 int off = KGlobal::locale()->localTimeOffset( dt ); 39 int off = KGlobal::locale()->localTimeOffset( dt );
40 //qDebug("adsec2 %d ",off*60 ); 40 //qDebug("adsec2 %d ",off*60 );
41 41
42 dt = dt.addSecs( off*60 ); 42 dt = dt.addSecs( off*60 );
43 return dt; 43 return dt;
44#if 0 44#if 0
45 QString ret; 45 QString ret;
46 if ( dt.date() == QDate::currentDate () ) 46 if ( dt.date() == QDate::currentDate () )
47 ret = KGlobal::locale()->formatTime( dt.time(),true); 47 ret = KGlobal::locale()->formatTime( dt.time(),true);
48 48
49 else { 49 else {
50 ret = KGlobal::locale()->formatDateTime( dt,true,true); 50 ret = KGlobal::locale()->formatDateTime( dt,true,true);
51 } 51 }
52#endif 52#endif
53#if 0 53#if 0
54 if ( off < 0 ) 54 if ( off < 0 )
55 ret += " -"; 55 ret += " -";
56 else 56 else
57 ret += " +"; 57 ret += " +";
58 ret += QString::number( off / 60 ); 58 ret += QString::number( off / 60 );
59 ret += "h"; 59 ret += "h";
60#endif 60#endif
61#if 0 61#if 0
62 char tmp[23]; 62 char tmp[23];
63 63
64 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 64 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
65 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 65 // date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
66 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i", 66 snprintf( tmp, 23, "%04i-%02i-%02i %02i:%02i:%02i %+05i",
67 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 67 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
68 68
69 69
70 return QString( tmp ); 70 return QString( tmp );
71#endif 71#endif
72 //return ret; 72 //return ret;
73} 73}
74 74
75void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 75void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
76{ 76{
77 if (!mime) { 77 if (!mime) {
78 return; 78 return;
79 } 79 }
80 mailmime_field*field = 0; 80 mailmime_field*field = 0;
81 mailmime_single_fields fields; 81 mailmime_single_fields fields;
82 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 82 memset(&fields, 0, sizeof(struct mailmime_single_fields));
83 if (mime->mm_mime_fields != NULL) { 83 if (mime->mm_mime_fields != NULL) {
84 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 84 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
85 mime->mm_content_type); 85 mime->mm_content_type);
86 } 86 }
87 87
88 mailmime_content*type = fields.fld_content; 88 mailmime_content*type = fields.fld_content;
89 clistcell*current; 89 clistcell*current;
90 if (!type) { 90 if (!type) {
91 target->setType("text"); 91 target->setType("text");
92 target->setSubtype("plain"); 92 target->setSubtype("plain");
93 } else { 93 } else {
94 target->setSubtype(type->ct_subtype); 94 target->setSubtype(type->ct_subtype);
95 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 95 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
96 case MAILMIME_DISCRETE_TYPE_TEXT: 96 case MAILMIME_DISCRETE_TYPE_TEXT:
97 target->setType("text"); 97 target->setType("text");
98 break; 98 break;
99 case MAILMIME_DISCRETE_TYPE_IMAGE: 99 case MAILMIME_DISCRETE_TYPE_IMAGE:
100 target->setType("image"); 100 target->setType("image");
101 break; 101 break;
102 case MAILMIME_DISCRETE_TYPE_AUDIO: 102 case MAILMIME_DISCRETE_TYPE_AUDIO:
103 target->setType("audio"); 103 target->setType("audio");
104 break; 104 break;
105 case MAILMIME_DISCRETE_TYPE_VIDEO: 105 case MAILMIME_DISCRETE_TYPE_VIDEO:
106 target->setType("video"); 106 target->setType("video");
107 break; 107 break;
108 case MAILMIME_DISCRETE_TYPE_APPLICATION: 108 case MAILMIME_DISCRETE_TYPE_APPLICATION:
109 target->setType("application"); 109 target->setType("application");
110 break; 110 break;
111 case MAILMIME_DISCRETE_TYPE_EXTENSION: 111 case MAILMIME_DISCRETE_TYPE_EXTENSION:
112 default: 112 default:
113 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 113 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
114 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 114 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
115 } 115 }
116 break; 116 break;
117 } 117 }
118 if (type->ct_parameters) { 118 if (type->ct_parameters) {
119 fillParameters(target,type->ct_parameters); 119 fillParameters(target,type->ct_parameters);
120 } 120 }
121 } 121 }
122 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 122 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) {
123 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { 123 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
124 field = (mailmime_field*)current->data; 124 field = (mailmime_field*)current->data;
125 switch(field->fld_type) { 125 switch(field->fld_type) {
126 case MAILMIME_FIELD_TRANSFER_ENCODING: 126 case MAILMIME_FIELD_TRANSFER_ENCODING:
127 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 127 target->setEncoding(getencoding(field->fld_data.fld_encoding));
128 break; 128 break;
129 case MAILMIME_FIELD_ID: 129 case MAILMIME_FIELD_ID:
130 target->setIdentifier(field->fld_data.fld_id); 130 target->setIdentifier(field->fld_data.fld_id);
131 break; 131 break;
132 case MAILMIME_FIELD_DESCRIPTION: 132 case MAILMIME_FIELD_DESCRIPTION:
133 target->setDescription(field->fld_data.fld_description); 133 target->setDescription(field->fld_data.fld_description);
134 break; 134 break;
135 default: 135 default:
136 break; 136 break;
137 } 137 }
138 } 138 }
139 } 139 }
140} 140}
141 141
142void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 142void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
143{ 143{
144 if (!parameters) {return;} 144 if (!parameters) {return;}
145 clistcell*current=0; 145 clistcell*current=0;
146 mailmime_parameter*param; 146 mailmime_parameter*param;
147 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 147 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
148 param = (mailmime_parameter*)current->data; 148 param = (mailmime_parameter*)current->data;
149 if (param) { 149 if (param) {
150 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 150 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
151 } 151 }
152 } 152 }
153} 153}
154 154
155QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 155QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
156{ 156{
157 QString enc="7bit"; 157 QString enc="7bit";
158 if (!aEnc) return enc; 158 if (!aEnc) return enc;
159 switch(aEnc->enc_type) { 159 switch(aEnc->enc_type) {
160 case MAILMIME_MECHANISM_7BIT: 160 case MAILMIME_MECHANISM_7BIT:
161 enc = "7bit"; 161 enc = "7bit";
162 break; 162 break;
163 case MAILMIME_MECHANISM_8BIT: 163 case MAILMIME_MECHANISM_8BIT:
164 enc = "8bit"; 164 enc = "8bit";
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;
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) {
271 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 285 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
272 } 286 }
273 } 287 }
274 break; 288 break;
275 } 289 }
276} 290}
277 291
278RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 292RecBodyP Genericwrapper::parseMail( mailmessage * msg )
279{ 293{
280 int err = MAILIMF_NO_ERROR; 294 int err = MAILIMF_NO_ERROR;
281 //mailmime_single_fields fields; 295 //mailmime_single_fields fields;
282 /* is bound to msg and will be freed there */ 296 /* is bound to msg and will be freed there */
283 mailmime * mime=0; 297 mailmime * mime=0;
284 RecBodyP body = new RecBody(); 298 RecBodyP body = new RecBody();
285 //memset(&fields, 0, sizeof(struct mailmime_single_fields)); 299 //memset(&fields, 0, sizeof(struct mailmime_single_fields));
286 err = mailmessage_get_bodystructure(msg,&mime); 300 err = mailmessage_get_bodystructure(msg,&mime);
287 QValueList<int>recList; 301 QValueList<int>recList;
288 traverseBody(body,msg,mime,recList); 302 traverseBody(body,msg,mime,recList);
289 return body; 303 return body;
290} 304}
291 305
292 306
293QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 307QString Genericwrapper::parseAddressList( mailimf_address_list *list )
294{ 308{
295 QString result( "" ); 309 QString result( "" );
296 310
297 bool first = true; 311 bool first = true;
298 if (list == 0) return result; 312 if (list == 0) return result;
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();
396 delete t; 410 delete t;
397 return text; 411 return text;
398} 412}
399 413
400void Genericwrapper::cleanMimeCache() 414void Genericwrapper::cleanMimeCache()
401{ 415{
402 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 416 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
403 for (;it!=bodyCache.end();++it) { 417 for (;it!=bodyCache.end();++it) {
404 encodedString*t = it.data(); 418 encodedString*t = it.data();
405 //it.setValue(0); 419 //it.setValue(0);
406 if (t) delete t; 420 if (t) delete t;
407 } 421 }
408 bodyCache.clear(); 422 bodyCache.clear();
409 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 423 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
410} 424}
411 425
412QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 426QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
413{ 427{
414 QStringList res; 428 QStringList res;
415 if (!in_replies || !in_replies->mid_list) return res; 429 if (!in_replies || !in_replies->mid_list) return res;
416 clistiter * current = 0; 430 clistiter * current = 0;
417 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 431 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
418 QString h((char*)current->data); 432 QString h((char*)current->data);
419 while (h.length()>0 && h[0]=='<') { 433 while (h.length()>0 && h[0]=='<') {
420 h.remove(0,1); 434 h.remove(0,1);
421 } 435 }
422 while (h.length()>0 && h[h.length()-1]=='>') { 436 while (h.length()>0 && h[h.length()-1]=='>') {
423 h.remove(h.length()-1,1); 437 h.remove(h.length()-1,1);
424 } 438 }
425 if (h.length()>0) { 439 if (h.length()>0) {
426 res.append(h); 440 res.append(h);
427 } 441 }
428 } 442 }
429 return res; 443 return res;
430} 444}
431 445
432void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 446void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
433{ 447{
434 int r; 448 int r;
435 mailmessage_list * env_list = 0; 449 mailmessage_list * env_list = 0;
436 r = mailsession_get_messages_list(session,&env_list); 450 r = mailsession_get_messages_list(session,&env_list);
437 if (r != MAIL_NO_ERROR) { 451 if (r != MAIL_NO_ERROR) {
438 ; // odebug << "Error message list" << oendl; 452 ; // odebug << "Error message list" << oendl;
439 return; 453 return;
440 } 454 }
441 r = mailsession_get_envelopes_list(session, env_list); 455 r = mailsession_get_envelopes_list(session, env_list);
442 if (r != MAIL_NO_ERROR) { 456 if (r != MAIL_NO_ERROR) {
443 ; // odebug << "Error filling message list" << oendl; 457 ; // odebug << "Error filling message list" << oendl;
444 if (env_list) { 458 if (env_list) {
445 mailmessage_list_free(env_list); 459 mailmessage_list_free(env_list);
446 } 460 }
447 return; 461 return;
448 } 462 }
449 mailimf_references * refs = 0; 463 mailimf_references * refs = 0;
450 mailimf_in_reply_to * in_replies = 0; 464 mailimf_in_reply_to * in_replies = 0;
451 uint32_t i = 0; 465 uint32_t i = 0;
452 for(; i < carray_count(env_list->msg_tab) ; ++i) { 466 for(; i < carray_count(env_list->msg_tab) ; ++i) {
453 mailmessage * msg; 467 mailmessage * msg;
454 QBitArray mFlags(7); 468 QBitArray mFlags(7);
455 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 469 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
456 if (msg->msg_fields == NULL) { 470 if (msg->msg_fields == NULL) {
457 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 471 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
458 continue; 472 continue;
459 } 473 }
460 RecMailP mail = new RecMail(); 474 RecMailP mail = new RecMail();
461 mail->setWrapper(this); 475 mail->setWrapper(this);
462 mail_flags * flag_result = 0; 476 mail_flags * flag_result = 0;
463 r = mailmessage_get_flags(msg,&flag_result); 477 r = mailmessage_get_flags(msg,&flag_result);
464 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 478 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
465 mFlags.setBit(FLAG_SEEN); 479 mFlags.setBit(FLAG_SEEN);
466 } 480 }
467 mailimf_single_fields single_fields; 481 mailimf_single_fields single_fields;
468 mailimf_single_fields_init(&single_fields, msg->msg_fields); 482 mailimf_single_fields_init(&single_fields, msg->msg_fields);
469 mail->setMsgsize(msg->msg_size); 483 mail->setMsgsize(msg->msg_size);
470 mail->setFlags(mFlags); 484 mail->setFlags(mFlags);
471 mail->setMbox(mailbox); 485 mail->setMbox(mailbox);
472 mail->setNumber(msg->msg_index); 486 mail->setNumber(msg->msg_index);
473 if (single_fields.fld_subject) 487 if (single_fields.fld_subject)
474 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 488 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
475 if (single_fields.fld_from) 489 if (single_fields.fld_from)
476 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 490 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
477 if (!mbox_as_to) { 491 if (!mbox_as_to) {
478 if (single_fields.fld_to) 492 if (single_fields.fld_to)
479 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 493 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
480 } else { 494 } else {
481 mail->setTo(mailbox); 495 mail->setTo(mailbox);
482 } 496 }
483 if (single_fields.fld_cc) 497 if (single_fields.fld_cc)
484 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 498 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
485 if (single_fields.fld_bcc) 499 if (single_fields.fld_bcc)
486 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 500 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
487 if (single_fields.fld_orig_date) { 501 if (single_fields.fld_orig_date) {
488 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); 502 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time );
489 QString ret; 503 QString ret;
490 if ( dt.date() == QDate::currentDate () ) 504 if ( dt.date() == QDate::currentDate () )
491 ret = KGlobal::locale()->formatTime( dt.time(),true); 505 ret = KGlobal::locale()->formatTime( dt.time(),true);
492 else { 506 else {
493 ret = KGlobal::locale()->formatDateTime( dt,true,true); 507 ret = KGlobal::locale()->formatDateTime( dt,true,true);
494 } 508 }
495 mail->setDate( ret ); 509 mail->setDate( ret );
496 char tmp[20]; 510 char tmp[20];
497 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 511 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
498 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); 512 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
499 //qDebug(" iso %s ", tmp); 513 //qDebug(" iso %s ", tmp);
500 mail->setIsoDate( QString( tmp ) ); 514 mail->setIsoDate( QString( tmp ) );
501 } 515 }
502 // crashes when accessing pop3 account? 516 // crashes when accessing pop3 account?
503 if (single_fields.fld_message_id) { 517 if (single_fields.fld_message_id) {
504 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 518 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
505 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 519 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
506 } 520 }
507 if (single_fields.fld_reply_to) { 521 if (single_fields.fld_reply_to) {
508 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 522 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
509 if (t.count()>0) { 523 if (t.count()>0) {
510 mail->setReplyto(t[0]); 524 mail->setReplyto(t[0]);
511 } 525 }
512 } 526 }
513#if 0 527#if 0
514 refs = single_fields.fld_references; 528 refs = single_fields.fld_references;
515 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 529 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
516 char * text = (char*)refs->mid_list->first->data; 530 char * text = (char*)refs->mid_list->first->data;
517 mail->setReplyto(QString(text)); 531 mail->setReplyto(QString(text));
518 } 532 }
519#endif 533#endif
520 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 534 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
521 clist_count(single_fields.fld_in_reply_to->mid_list)) { 535 clist_count(single_fields.fld_in_reply_to->mid_list)) {
522 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 536 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
523 } 537 }
524 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 538 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
525 target.append(mail); 539 target.append(mail);
526 } 540 }
527 if (env_list) { 541 if (env_list) {
528 mailmessage_list_free(env_list); 542 mailmessage_list_free(env_list);
529 } 543 }
530} 544}
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
@@ -499,512 +499,531 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
499 m->setIsoDate( QString( tmp ) ); 499 m->setIsoDate( QString( tmp ) );
500 mailimf_date_time_free ( date ); 500 mailimf_date_time_free ( date );
501 } else { 501 } else {
502 m->setIsoDate(head->env_date); 502 m->setIsoDate(head->env_date);
503 } 503 }
504 } 504 }
505 if ( head->env_subject != NULL ) 505 if ( head->env_subject != NULL )
506 m->setSubject(convert_String((const char*)head->env_subject)); 506 m->setSubject(convert_String((const char*)head->env_subject));
507 //m->setSubject(head->env_subject); 507 //m->setSubject(head->env_subject);
508 if (head->env_from!=NULL) { 508 if (head->env_from!=NULL) {
509 addresslist = address_list_to_stringlist(head->env_from->frm_list); 509 addresslist = address_list_to_stringlist(head->env_from->frm_list);
510 if (addresslist.count()) { 510 if (addresslist.count()) {
511 m->setFrom(addresslist.first()); 511 m->setFrom(addresslist.first());
512 } 512 }
513 } 513 }
514 if (head->env_to!=NULL) { 514 if (head->env_to!=NULL) {
515 addresslist = address_list_to_stringlist(head->env_to->to_list); 515 addresslist = address_list_to_stringlist(head->env_to->to_list);
516 m->setTo(addresslist); 516 m->setTo(addresslist);
517 } 517 }
518 if (head->env_cc!=NULL) { 518 if (head->env_cc!=NULL) {
519 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 519 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
520 m->setCC(addresslist); 520 m->setCC(addresslist);
521 } 521 }
522 if (head->env_bcc!=NULL) { 522 if (head->env_bcc!=NULL) {
523 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 523 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
524 m->setBcc(addresslist); 524 m->setBcc(addresslist);
525 } 525 }
526 /* reply to address, eg. email. */ 526 /* reply to address, eg. email. */
527 if (head->env_reply_to!=NULL) { 527 if (head->env_reply_to!=NULL) {
528 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 528 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
529 if (addresslist.count()) { 529 if (addresslist.count()) {
530 m->setReplyto(addresslist.first()); 530 m->setReplyto(addresslist.first());
531 } 531 }
532 } 532 }
533 if (head->env_in_reply_to!=NULL) { 533 if (head->env_in_reply_to!=NULL) {
534 QString h(head->env_in_reply_to); 534 QString h(head->env_in_reply_to);
535 while (h.length()>0 && h[0]=='<') { 535 while (h.length()>0 && h[0]=='<') {
536 h.remove(0,1); 536 h.remove(0,1);
537 } 537 }
538 while (h.length()>0 && h[h.length()-1]=='>') { 538 while (h.length()>0 && h[h.length()-1]=='>') {
539 h.remove(h.length()-1,1); 539 h.remove(h.length()-1,1);
540 } 540 }
541 if (h.length()>0) { 541 if (h.length()>0) {
542 m->setInreply(QStringList(h)); 542 m->setInreply(QStringList(h));
543 } 543 }
544 } 544 }
545 if (head->env_message_id != NULL) { 545 if (head->env_message_id != NULL) {
546 m->setMsgid(QString(head->env_message_id)); 546 m->setMsgid(QString(head->env_message_id));
547 } 547 }
548 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 548 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
549#if 0 549#if 0
550 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 550 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
551 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 551 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
552 qDebug("time %s ",da.toString().latin1() ); 552 qDebug("time %s ",da.toString().latin1() );
553#endif 553#endif
554 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 554 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
555 size = item->att_data.att_static->att_data.att_rfc822_size; 555 size = item->att_data.att_static->att_data.att_rfc822_size;
556 } 556 }
557 } 557 }
558 /* msg is already deleted */ 558 /* msg is already deleted */
559 if (mFlags.testBit(FLAG_DELETED) && m) { 559 if (mFlags.testBit(FLAG_DELETED) && m) {
560 delete m; 560 delete m;
561 m = 0; 561 m = 0;
562 } 562 }
563 if (m) { 563 if (m) {
564 m->setFlags(mFlags); 564 m->setFlags(mFlags);
565 m->setMsgsize(size); 565 m->setMsgsize(size);
566 } 566 }
567 return m; 567 return m;
568} 568}
569 569
570RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 570RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
571{ 571{
572 RecBodyP body = new RecBody(); 572 RecBodyP body = new RecBody();
573 const char *mb; 573 const char *mb;
574 int err = MAILIMAP_NO_ERROR; 574 int err = MAILIMAP_NO_ERROR;
575 clist *result = 0; 575 clist *result = 0;
576 clistcell *current; 576 clistcell *current;
577 mailimap_fetch_att *fetchAtt = 0; 577 mailimap_fetch_att *fetchAtt = 0;
578 mailimap_fetch_type *fetchType = 0; 578 mailimap_fetch_type *fetchType = 0;
579 mailimap_set *set = 0; 579 mailimap_set *set = 0;
580 mailimap_body*body_desc = 0; 580 mailimap_body*body_desc = 0;
581 581
582 mb = mail->getMbox().latin1(); 582 mb = mail->getMbox().latin1();
583 583
584 login(); 584 login();
585 if (!m_imap) { 585 if (!m_imap) {
586 return body; 586 return body;
587 } 587 }
588 err = selectMbox(mail->getMbox()); 588 err = selectMbox(mail->getMbox());
589 if ( err != MAILIMAP_NO_ERROR ) { 589 if ( err != MAILIMAP_NO_ERROR ) {
590 return body; 590 return body;
591 } 591 }
592 592
593 /* the range has to start at 1!!! not with 0!!!! */ 593 /* the range has to start at 1!!! not with 0!!!! */
594 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 594 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
595 fetchAtt = mailimap_fetch_att_new_bodystructure(); 595 fetchAtt = mailimap_fetch_att_new_bodystructure();
596 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 596 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
597 err = mailimap_fetch( m_imap, set, fetchType, &result ); 597 err = mailimap_fetch( m_imap, set, fetchType, &result );
598 mailimap_set_free( set ); 598 mailimap_set_free( set );
599 mailimap_fetch_type_free( fetchType ); 599 mailimap_fetch_type_free( fetchType );
600 600
601 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 601 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
602 mailimap_msg_att * msg_att; 602 mailimap_msg_att * msg_att;
603 msg_att = (mailimap_msg_att*)current->data; 603 msg_att = (mailimap_msg_att*)current->data;
604 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 604 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
605 QValueList<int> path; 605 QValueList<int> path;
606 body_desc = item->att_data.att_static->att_data.att_body; 606 body_desc = item->att_data.att_static->att_data.att_body;
607 traverseBody(mail,body_desc,body,0,path); 607 traverseBody(mail,body_desc,body,0,path);
608 } else { 608 } else {
609 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 609 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
610 } 610 }
611 if (result) mailimap_fetch_list_free(result); 611 if (result) mailimap_fetch_list_free(result);
612 return body; 612 return body;
613} 613}
614 614
615QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 615QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
616{ 616{
617 QStringList l; 617 QStringList l;
618 QString from; 618 QString from;
619 bool named_from; 619 bool named_from;
620 clistcell *current = NULL; 620 clistcell *current = NULL;
621 mailimap_address * current_address=NULL; 621 mailimap_address * current_address=NULL;
622 if (!list) { 622 if (!list) {
623 return l; 623 return l;
624 } 624 }
625 unsigned int count = 0; 625 unsigned int count = 0;
626 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 626 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
627 from = ""; 627 from = "";
628 named_from = false; 628 named_from = false;
629 current_address=(mailimap_address*)current->data; 629 current_address=(mailimap_address*)current->data;
630 if (current_address->ad_personal_name){ 630 if (current_address->ad_personal_name){
631 from+=convert_String((const char*)current_address->ad_personal_name); 631 from+=convert_String((const char*)current_address->ad_personal_name);
632 from+=" "; 632 from+=" ";
633 named_from = true; 633 named_from = true;
634 } 634 }
635 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 635 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
636 from+="<"; 636 from+="<";
637 } 637 }
638 if (current_address->ad_mailbox_name) { 638 if (current_address->ad_mailbox_name) {
639 from+=QString(current_address->ad_mailbox_name); 639 from+=QString(current_address->ad_mailbox_name);
640 from+="@"; 640 from+="@";
641 } 641 }
642 if (current_address->ad_host_name) { 642 if (current_address->ad_host_name) {
643 from+=QString(current_address->ad_host_name); 643 from+=QString(current_address->ad_host_name);
644 } 644 }
645 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 645 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
646 from+=">"; 646 from+=">";
647 } 647 }
648 l.append(QString(from)); 648 l.append(QString(from));
649 if (++count > 99) { 649 if (++count > 99) {
650 break; 650 break;
651 } 651 }
652 } 652 }
653 return l; 653 return l;
654} 654}
655 655
656encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 656encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
657{ 657{
658 encodedString*res=new encodedString; 658 encodedString*res=new encodedString;
659 int err; 659 int err;
660 mailimap_fetch_type *fetchType; 660 mailimap_fetch_type *fetchType;
661 mailimap_set *set; 661 mailimap_set *set;
662 clistcell*current,*cur; 662 clistcell*current,*cur;
663 mailimap_section_part * section_part = 0; 663 mailimap_section_part * section_part = 0;
664 mailimap_section_spec * section_spec = 0; 664 mailimap_section_spec * section_spec = 0;
665 mailimap_section * section = 0; 665 mailimap_section * section = 0;
666 mailimap_fetch_att * fetch_att = 0; 666 mailimap_fetch_att * fetch_att = 0;
667 667
668 login(); 668 login();
669 if (!m_imap) { 669 if (!m_imap) {
670 return res; 670 return res;
671 } 671 }
672 if (!internal_call) { 672 if (!internal_call) {
673 err = selectMbox(mail->getMbox()); 673 err = selectMbox(mail->getMbox());
674 if ( err != MAILIMAP_NO_ERROR ) { 674 if ( err != MAILIMAP_NO_ERROR ) {
675 return res; 675 return res;
676 } 676 }
677 } 677 }
678 set = mailimap_set_new_single(mail->getNumber()); 678 set = mailimap_set_new_single(mail->getNumber());
679 679
680 clist*id_list = 0; 680 clist*id_list = 0;
681 681
682 /* if path == empty then its a request for the whole rfc822 mail and generates 682 /* if path == empty then its a request for the whole rfc822 mail and generates
683 a "fetch <id> (body[])" statement on imap server */ 683 a "fetch <id> (body[])" statement on imap server */
684 if (path.count()>0 ) { 684 if (path.count()>0 ) {
685 id_list = clist_new(); 685 id_list = clist_new();
686 for (unsigned j=0; j < path.count();++j) { 686 for (unsigned j=0; j < path.count();++j) {
687 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 687 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
688 *p_id = path[j]; 688 *p_id = path[j];
689 clist_append(id_list,p_id); 689 clist_append(id_list,p_id);
690 } 690 }
691 section_part = mailimap_section_part_new(id_list); 691 section_part = mailimap_section_part_new(id_list);
692 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 692 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
693 } 693 }
694 694
695 section = mailimap_section_new(section_spec); 695 section = mailimap_section_new(section_spec);
696 fetch_att = mailimap_fetch_att_new_body_section(section); 696 fetch_att = mailimap_fetch_att_new_body_section(section);
697 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 697 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
698 698
699 clist*result = 0; 699 clist*result = 0;
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
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 }
803} 822}
804 823
805void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 824void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
806{ 825{
807 if (!Description) { 826 if (!Description) {
808 return; 827 return;
809 } 828 }
810 switch (Description->bd_type) { 829 switch (Description->bd_type) {
811 case MAILIMAP_BODY_TYPE_1PART_TEXT: 830 case MAILIMAP_BODY_TYPE_1PART_TEXT:
812 target_part->setType("text"); 831 target_part->setType("text");
813 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 832 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
814 break; 833 break;
815 case MAILIMAP_BODY_TYPE_1PART_BASIC: 834 case MAILIMAP_BODY_TYPE_1PART_BASIC:
816 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 835 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
817 break; 836 break;
818 case MAILIMAP_BODY_TYPE_1PART_MSG: 837 case MAILIMAP_BODY_TYPE_1PART_MSG:
819 target_part->setType("message"); 838 target_part->setType("message");
820 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 839 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
821 break; 840 break;
822 default: 841 default:
823 break; 842 break;
824 } 843 }
825} 844}
826 845
827void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 846void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
828{ 847{
829 if (!which) { 848 if (!which) {
830 return; 849 return;
831 } 850 }
832 QString sub; 851 QString sub;
833 sub = which->bd_media_text; 852 sub = which->bd_media_text;
834 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 853 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
835 target_part->setSubtype(sub.lower()); 854 target_part->setSubtype(sub.lower());
836 target_part->setLines(which->bd_lines); 855 target_part->setLines(which->bd_lines);
837 fillBodyFields(target_part,which->bd_fields); 856 fillBodyFields(target_part,which->bd_fields);
838} 857}
839 858
840void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 859void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
841{ 860{
842 if (!which) { 861 if (!which) {
843 return; 862 return;
844 } 863 }
845 target_part->setSubtype("rfc822"); 864 target_part->setSubtype("rfc822");
846 //odebug << "Message part" << oendl; 865 //odebug << "Message part" << oendl;
847 /* we set this type to text/plain */ 866 /* we set this type to text/plain */
848 target_part->setLines(which->bd_lines); 867 target_part->setLines(which->bd_lines);
849 fillBodyFields(target_part,which->bd_fields); 868 fillBodyFields(target_part,which->bd_fields);
850} 869}
851 870
852void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 871void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
853{ 872{
854 if (!which) return; 873 if (!which) return;
855 QString sub = which->bd_media_subtype; 874 QString sub = which->bd_media_subtype;
856 target_part->setSubtype(sub.lower()); 875 target_part->setSubtype(sub.lower());
857 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 876 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
858 clistcell*cur = 0; 877 clistcell*cur = 0;
859 mailimap_single_body_fld_param*param=0; 878 mailimap_single_body_fld_param*param=0;
860 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 879 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
861 param = (mailimap_single_body_fld_param*)cur->data; 880 param = (mailimap_single_body_fld_param*)cur->data;
862 if (param) { 881 if (param) {
863 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 882 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
864 } 883 }
865 } 884 }
866 } 885 }
867} 886}
868 887
869void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 888void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
870{ 889{
871 if (!which) { 890 if (!which) {
872 return; 891 return;
873 } 892 }
874 QString type,sub; 893 QString type,sub;
875 switch (which->bd_media_basic->med_type) { 894 switch (which->bd_media_basic->med_type) {
876 case MAILIMAP_MEDIA_BASIC_APPLICATION: 895 case MAILIMAP_MEDIA_BASIC_APPLICATION:
877 type = "application"; 896 type = "application";
878 break; 897 break;
879 case MAILIMAP_MEDIA_BASIC_AUDIO: 898 case MAILIMAP_MEDIA_BASIC_AUDIO:
880 type = "audio"; 899 type = "audio";
881 break; 900 break;
882 case MAILIMAP_MEDIA_BASIC_IMAGE: 901 case MAILIMAP_MEDIA_BASIC_IMAGE:
883 type = "image"; 902 type = "image";
884 break; 903 break;
885 case MAILIMAP_MEDIA_BASIC_MESSAGE: 904 case MAILIMAP_MEDIA_BASIC_MESSAGE:
886 type = "message"; 905 type = "message";
887 break; 906 break;
888 case MAILIMAP_MEDIA_BASIC_VIDEO: 907 case MAILIMAP_MEDIA_BASIC_VIDEO:
889 type = "video"; 908 type = "video";
890 break; 909 break;
891 case MAILIMAP_MEDIA_BASIC_OTHER: 910 case MAILIMAP_MEDIA_BASIC_OTHER:
892 default: 911 default:
893 if (which->bd_media_basic->med_basic_type) { 912 if (which->bd_media_basic->med_basic_type) {
894 type = which->bd_media_basic->med_basic_type; 913 type = which->bd_media_basic->med_basic_type;
895 } else { 914 } else {
896 type = ""; 915 type = "";
897 } 916 }
898 break; 917 break;
899 } 918 }
900 if (which->bd_media_basic->med_subtype) { 919 if (which->bd_media_basic->med_subtype) {
901 sub = which->bd_media_basic->med_subtype; 920 sub = which->bd_media_basic->med_subtype;
902 } else { 921 } else {
903 sub = ""; 922 sub = "";
904 } 923 }
905 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 924 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
906 target_part->setType(type.lower()); 925 target_part->setType(type.lower());
907 target_part->setSubtype(sub.lower()); 926 target_part->setSubtype(sub.lower());
908 fillBodyFields(target_part,which->bd_fields); 927 fillBodyFields(target_part,which->bd_fields);
909} 928}
910 929
911void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 930void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
912{ 931{
913 if (!which) return; 932 if (!which) return;
914 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 933 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
915 clistcell*cur; 934 clistcell*cur;
916 mailimap_single_body_fld_param*param=0; 935 mailimap_single_body_fld_param*param=0;
917 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 936 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
918 param = (mailimap_single_body_fld_param*)cur->data; 937 param = (mailimap_single_body_fld_param*)cur->data;
919 if (param) { 938 if (param) {
920 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 939 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
921 } 940 }
922 } 941 }
923 } 942 }
924 mailimap_body_fld_enc*enc = which->bd_encoding; 943 mailimap_body_fld_enc*enc = which->bd_encoding;
925 QString encoding(""); 944 QString encoding("");
926 switch (enc->enc_type) { 945 switch (enc->enc_type) {
927 case MAILIMAP_BODY_FLD_ENC_7BIT: 946 case MAILIMAP_BODY_FLD_ENC_7BIT:
928 encoding = "7bit"; 947 encoding = "7bit";
929 break; 948 break;
930 case MAILIMAP_BODY_FLD_ENC_8BIT: 949 case MAILIMAP_BODY_FLD_ENC_8BIT:
931 encoding = "8bit"; 950 encoding = "8bit";
932 break; 951 break;
933 case MAILIMAP_BODY_FLD_ENC_BINARY: 952 case MAILIMAP_BODY_FLD_ENC_BINARY:
934 encoding="binary"; 953 encoding="binary";
935 break; 954 break;
936 case MAILIMAP_BODY_FLD_ENC_BASE64: 955 case MAILIMAP_BODY_FLD_ENC_BASE64:
937 encoding="base64"; 956 encoding="base64";
938 break; 957 break;
939 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 958 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
940 encoding="quoted-printable"; 959 encoding="quoted-printable";
941 break; 960 break;
942 case MAILIMAP_BODY_FLD_ENC_OTHER: 961 case MAILIMAP_BODY_FLD_ENC_OTHER:
943 default: 962 default:
944 if (enc->enc_value) { 963 if (enc->enc_value) {
945 char*t=enc->enc_value; 964 char*t=enc->enc_value;
946 encoding=QString(enc->enc_value); 965 encoding=QString(enc->enc_value);
947 enc->enc_value=0L; 966 enc->enc_value=0L;
948 free(t); 967 free(t);
949 } 968 }
950 } 969 }
951 if (which->bd_description) { 970 if (which->bd_description) {
952 target_part->setDescription(QString(which->bd_description)); 971 target_part->setDescription(QString(which->bd_description));
953 } 972 }
954 target_part->setEncoding(encoding); 973 target_part->setEncoding(encoding);
955 target_part->setSize(which->bd_size); 974 target_part->setSize(which->bd_size);
956} 975}
957void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 976void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
958{ 977{
959 //#if 0 978 //#if 0
960 mailimap_flag_list*flist; 979 mailimap_flag_list*flist;
961 mailimap_set *set; 980 mailimap_set *set;
962 mailimap_store_att_flags * store_flags; 981 mailimap_store_att_flags * store_flags;
963 int err; 982 int err;
964 login(); 983 login();
965 //#endif 984 //#endif
966 if (!m_imap) { 985 if (!m_imap) {
967 return; 986 return;
968 } 987 }
969 int iii = 0; 988 int iii = 0;
970 int count = target.count(); 989 int count = target.count();
971 // qDebug("imap remove count %d ", count); 990 // qDebug("imap remove count %d ", count);
972 991
973 992
974 mMax = count; 993 mMax = count;
975 progress( i18n("Delete")); 994 progress( i18n("Delete"));
976 995
977 QProgressBar wid ( count ); 996 QProgressBar wid ( count );
978 wid.setCaption( i18n("Deleting ...")); 997 wid.setCaption( i18n("Deleting ..."));
979 wid.show(); 998 wid.show();
980 while (iii < count ) { 999 while (iii < count ) {
981 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 1000 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
982 wid.setProgress( iii ); 1001 wid.setProgress( iii );
983 wid.raise(); 1002 wid.raise();
984 qApp->processEvents(); 1003 qApp->processEvents();
985 RecMailP mail = (*target.at( iii )); 1004 RecMailP mail = (*target.at( iii ));
986 //#if 0 1005 //#if 0
987 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 1006 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
988 err = selectMbox(mail->getMbox()); 1007 err = selectMbox(mail->getMbox());
989 if ( err != MAILIMAP_NO_ERROR ) { 1008 if ( err != MAILIMAP_NO_ERROR ) {
990 return; 1009 return;
991 } 1010 }
992 flist = mailimap_flag_list_new_empty(); 1011 flist = mailimap_flag_list_new_empty();
993 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1012 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
994 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1013 store_flags = mailimap_store_att_flags_new_set_flags(flist);
995 set = mailimap_set_new_single(mail->getNumber()); 1014 set = mailimap_set_new_single(mail->getNumber());
996 err = mailimap_store(m_imap,set,store_flags); 1015 err = mailimap_store(m_imap,set,store_flags);
997 mailimap_set_free( set ); 1016 mailimap_set_free( set );
998 mailimap_store_att_flags_free(store_flags); 1017 mailimap_store_att_flags_free(store_flags);
999 1018
1000 if (err != MAILIMAP_NO_ERROR) { 1019 if (err != MAILIMAP_NO_ERROR) {
1001 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1020 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1002 return; 1021 return;
1003 } 1022 }
1004 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1023 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1005 /* should we realy do that at this moment? */ 1024 /* should we realy do that at this moment? */
1006 1025
1007 // err = mailimap_expunge(m_imap); 1026 // err = mailimap_expunge(m_imap);
1008 //if (err != MAILIMAP_NO_ERROR) { 1027 //if (err != MAILIMAP_NO_ERROR) {
1009 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1028 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1010 // } 1029 // }
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
@@ -1,339 +1,340 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <klocale.h> 7#include <klocale.h>
8 8
9 9
10#include <qpe/global.h> 10#include <qpe/global.h>
11 11
12using namespace Opie::Core; 12using namespace Opie::Core;
13MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) 13MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name)
14 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) 14 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name)
15{ 15{
16 QDir dir(MBOXPath); 16 QDir dir(MBOXPath);
17 if (!dir.exists()) { 17 if (!dir.exists()) {
18 dir.mkdir(MBOXPath); 18 dir.mkdir(MBOXPath);
19 } 19 }
20} 20}
21 21
22MBOXwrapper::~MBOXwrapper() 22MBOXwrapper::~MBOXwrapper()
23{ 23{
24} 24}
25 25
26void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) 26void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target )
27{ 27{
28 mailstorage*storage = mailstorage_new(NULL); 28 mailstorage*storage = mailstorage_new(NULL);
29 QString p = MBOXPath+"/"; 29 QString p = MBOXPath+"/";
30 p+=mailbox; 30 p+=mailbox;
31 31
32 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 32 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
33 mailfolder*folder; 33 mailfolder*folder;
34 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 34 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
35 r = mailfolder_connect(folder); 35 r = mailfolder_connect(folder);
36 if (r != MAIL_NO_ERROR) { 36 if (r != MAIL_NO_ERROR) {
37 //odebug << "Error initializing mbox" << oendl; 37 //odebug << "Error initializing mbox" << oendl;
38 mailfolder_free(folder); 38 mailfolder_free(folder);
39 mailstorage_free(storage); 39 mailstorage_free(storage);
40 return; 40 return;
41 } 41 }
42 42
43 parseList(target,folder->fld_session,mailbox); 43 parseList(target,folder->fld_session,mailbox);
44 44
45 mailfolder_disconnect(folder); 45 mailfolder_disconnect(folder);
46 mailfolder_free(folder); 46 mailfolder_free(folder);
47 mailstorage_free(storage); 47 mailstorage_free(storage);
48 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); 48 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count()));
49} 49}
50 50
51QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() 51QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders()
52{ 52{
53 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 53 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
54 QDir dir(MBOXPath); 54 QDir dir(MBOXPath);
55 if (!dir.exists()) return folders; 55 if (!dir.exists()) return folders;
56 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 56 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
57 QStringList entries = dir.entryList(); 57 QStringList entries = dir.entryList();
58 QStringList::ConstIterator it = entries.begin(); 58 QStringList::ConstIterator it = entries.begin();
59 for (;it!=entries.end();++it) { 59 for (;it!=entries.end();++it) {
60 FolderP inb=new Folder(*it,"/"); 60 FolderP inb=new Folder(*it,"/");
61 folders->append(inb); 61 folders->append(inb);
62 } 62 }
63 return folders; 63 return folders;
64} 64}
65 65
66void MBOXwrapper::deleteMail(const RecMailP & mail) 66void MBOXwrapper::deleteMail(const RecMailP & mail)
67{ 67{
68 mailstorage*storage = mailstorage_new(NULL); 68 mailstorage*storage = mailstorage_new(NULL);
69 QString p = MBOXPath+"/"; 69 QString p = MBOXPath+"/";
70 p+=mail->getMbox(); 70 p+=mail->getMbox();
71 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 71 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
72 mailfolder*folder; 72 mailfolder*folder;
73 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 73 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
74 r = mailfolder_connect(folder); 74 r = mailfolder_connect(folder);
75 if (r != MAIL_NO_ERROR) { 75 if (r != MAIL_NO_ERROR) {
76 ; // << "Error initializing mbox" << oendl; 76 ; // << "Error initializing mbox" << oendl;
77 mailfolder_free(folder); 77 mailfolder_free(folder);
78 mailstorage_free(storage); 78 mailstorage_free(storage);
79 return; 79 return;
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
176encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) 177encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail)
177{ 178{
178 RecBody body; 179 RecBody body;
179 mailstorage*storage = mailstorage_new(NULL); 180 mailstorage*storage = mailstorage_new(NULL);
180 QString p = MBOXPath+"/"; 181 QString p = MBOXPath+"/";
181 p+=mail->getMbox(); 182 p+=mail->getMbox();
182 mailmessage * msg; 183 mailmessage * msg;
183 char*data=0; 184 char*data=0;
184 size_t size; 185 size_t size;
185 186
186 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 187 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
187 mailfolder*folder; 188 mailfolder*folder;
188 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 189 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
189 r = mailfolder_connect(folder); 190 r = mailfolder_connect(folder);
190 if (r != MAIL_NO_ERROR) { 191 if (r != MAIL_NO_ERROR) {
191 Global::statusMessage(i18n("Error initializing mbox")); 192 Global::statusMessage(i18n("Error initializing mbox"));
192 mailfolder_free(folder); 193 mailfolder_free(folder);
193 mailstorage_free(storage); 194 mailstorage_free(storage);
194 return 0; 195 return 0;
195 } 196 }
196 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 197 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
197 if (r != MAIL_NO_ERROR) { 198 if (r != MAIL_NO_ERROR) {
198 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 199 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
199 mailfolder_free(folder); 200 mailfolder_free(folder);
200 mailstorage_free(storage); 201 mailstorage_free(storage);
201 return 0; 202 return 0;
202 } 203 }
203 r = mailmessage_fetch(msg,&data,&size); 204 r = mailmessage_fetch(msg,&data,&size);
204 if (r != MAIL_NO_ERROR) { 205 if (r != MAIL_NO_ERROR) {
205 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 206 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
206 mailfolder_free(folder); 207 mailfolder_free(folder);
207 mailstorage_free(storage); 208 mailstorage_free(storage);
208 mailmessage_free(msg); 209 mailmessage_free(msg);
209 return 0; 210 return 0;
210 } 211 }
211 encodedString*result = new encodedString(data,size); 212 encodedString*result = new encodedString(data,size);
212 213
213 mailfolder_free(folder); 214 mailfolder_free(folder);
214 mailstorage_free(storage); 215 mailstorage_free(storage);
215 mailmessage_free(msg); 216 mailmessage_free(msg);
216 return result; 217 return result;
217} 218}
218 219
219void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 220void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
220{ 221{
221 QString p = MBOXPath+"/"; 222 QString p = MBOXPath+"/";
222 p+=mailbox; 223 p+=mailbox;
223 mailmbox_folder*f = 0; 224 mailmbox_folder*f = 0;
224 int r = mailmbox_init(p.latin1(),0,1,0,&f); 225 int r = mailmbox_init(p.latin1(),0,1,0,&f);
225 if (r != MAIL_NO_ERROR) { 226 if (r != MAIL_NO_ERROR) {
226 ; // << "Error init folder" << oendl; 227 ; // << "Error init folder" << oendl;
227 return; 228 return;
228 } 229 }
229 deleteMails(f,target); 230 deleteMails(f,target);
230 mailmbox_done(f); 231 mailmbox_done(f);
231} 232}
232 233
233void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) 234void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target)
234{ 235{
235 if (!f) return; 236 if (!f) return;
236 int r; 237 int r;
237 QValueList<RecMailP>::ConstIterator it; 238 QValueList<RecMailP>::ConstIterator it;
238 for (it=target.begin(); it != target.end();++it) { 239 for (it=target.begin(); it != target.end();++it) {
239 r = mailmbox_delete_msg(f,(*it)->getNumber()); 240 r = mailmbox_delete_msg(f,(*it)->getNumber());
240 if (r!=MAILMBOX_NO_ERROR) { 241 if (r!=MAILMBOX_NO_ERROR) {
241 ; // << "error delete mail" << oendl; 242 ; // << "error delete mail" << oendl;
242 } 243 }
243 } 244 }
244 r = mailmbox_expunge(f); 245 r = mailmbox_expunge(f);
245 if (r != MAILMBOX_NO_ERROR) { 246 if (r != MAILMBOX_NO_ERROR) {
246 ; // << "error expunge mailbox" << oendl; 247 ; // << "error expunge mailbox" << oendl;
247 } 248 }
248} 249}
249 250
250int MBOXwrapper::deleteAllMail(const FolderP&tfolder) 251int MBOXwrapper::deleteAllMail(const FolderP&tfolder)
251{ 252{
252 if (!tfolder) return 0; 253 if (!tfolder) return 0;
253 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 254 QString p = MBOXPath+"/"+tfolder->getDisplayName();
254 int res = 1; 255 int res = 1;
255 256
256 mailfolder*folder = 0; 257 mailfolder*folder = 0;
257 mailmessage_list*l=0; 258 mailmessage_list*l=0;
258 mailstorage*storage = mailstorage_new(NULL); 259 mailstorage*storage = mailstorage_new(NULL);
259 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 260 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
260 if (r != MAIL_NO_ERROR) { 261 if (r != MAIL_NO_ERROR) {
261 Global::statusMessage(i18n("Error initializing mbox")); 262 Global::statusMessage(i18n("Error initializing mbox"));
262 res = 0; 263 res = 0;
263 } 264 }
264 if (res) { 265 if (res) {
265 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 266 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
266 r = mailfolder_connect(folder); 267 r = mailfolder_connect(folder);
267 if (r != MAIL_NO_ERROR) { 268 if (r != MAIL_NO_ERROR) {
268 Global::statusMessage(i18n("Error initializing mbox")); 269 Global::statusMessage(i18n("Error initializing mbox"));
269 res = 0; 270 res = 0;
270 } 271 }
271 } 272 }
272 if (res) { 273 if (res) {
273 r = mailsession_get_messages_list(folder->fld_session,&l); 274 r = mailsession_get_messages_list(folder->fld_session,&l);
274 if (r != MAIL_NO_ERROR) { 275 if (r != MAIL_NO_ERROR) {
275 ; // << "Error message list" << oendl; 276 ; // << "Error message list" << oendl;
276 res=0; 277 res=0;
277 } 278 }
278 } 279 }
279 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 280 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
280 r = mailsession_remove_message(folder->fld_session,i+1); 281 r = mailsession_remove_message(folder->fld_session,i+1);
281 if (r != MAIL_NO_ERROR) { 282 if (r != MAIL_NO_ERROR) {
282 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 283 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
283 res = 0; 284 res = 0;
284 break; 285 break;
285 } 286 }
286 } 287 }
287 if (l) mailmessage_list_free(l); 288 if (l) mailmessage_list_free(l);
288 if (folder) mailfolder_free(folder); 289 if (folder) mailfolder_free(folder);
289 if (storage) mailstorage_free(storage); 290 if (storage) mailstorage_free(storage);
290 return res; 291 return res;
291} 292}
292 293
293int MBOXwrapper::deleteMbox(const FolderP&tfolder) 294int MBOXwrapper::deleteMbox(const FolderP&tfolder)
294{ 295{
295 if (!tfolder) return 0; 296 if (!tfolder) return 0;
296 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 297 QString p = MBOXPath+"/"+tfolder->getDisplayName();
297 QFile fi(p); 298 QFile fi(p);
298 if (!fi.exists()) { 299 if (!fi.exists()) {
299 Global::statusMessage(i18n("Mailbox doesn't exist.")); 300 Global::statusMessage(i18n("Mailbox doesn't exist."));
300 return 0; 301 return 0;
301 } 302 }
302 if (!fi.remove()) { 303 if (!fi.remove()) {
303 Global::statusMessage(i18n("Error deleting Mailbox.")); 304 Global::statusMessage(i18n("Error deleting Mailbox."));
304 return 0; 305 return 0;
305 } 306 }
306 return 1; 307 return 1;
307} 308}
308 309
309void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 310void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
310{ 311{
311 mailfolder*folder = 0; 312 mailfolder*folder = 0;
312 mailstorage*storage = mailstorage_new(NULL); 313 mailstorage*storage = mailstorage_new(NULL);
313 target_stat.message_count = 0; 314 target_stat.message_count = 0;
314 target_stat.message_unseen = 0; 315 target_stat.message_unseen = 0;
315 target_stat.message_recent = 0; 316 target_stat.message_recent = 0;
316 QString p = MBOXPath+"/"+mailbox; 317 QString p = MBOXPath+"/"+mailbox;
317 QFile fi(p); 318 QFile fi(p);
318 if (!fi.exists()) { 319 if (!fi.exists()) {
319 Global::statusMessage(i18n("Mailbox doesn't exist.")); 320 Global::statusMessage(i18n("Mailbox doesn't exist."));
320 return; 321 return;
321 } 322 }
322 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 323 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
323 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 324 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
324 r = mailfolder_connect(folder); 325 r = mailfolder_connect(folder);
325 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 326 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
326 &target_stat.message_recent,&target_stat.message_unseen); 327 &target_stat.message_recent,&target_stat.message_unseen);
327 if (folder) mailfolder_free(folder); 328 if (folder) mailfolder_free(folder);
328 if (storage) mailstorage_free(storage); 329 if (storage) mailstorage_free(storage);
329} 330}
330 331
331MAILLIB::ATYPE MBOXwrapper::getType()const 332MAILLIB::ATYPE MBOXwrapper::getType()const
332{ 333{
333 return MAILLIB::A_MBOX; 334 return MAILLIB::A_MBOX;
334} 335}
335 336
336const QString&MBOXwrapper::getName()const 337const QString&MBOXwrapper::getName()const
337{ 338{
338 return MBOXName; 339 return MBOXName;
339} 340}
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
@@ -1,386 +1,387 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "mhwrapper.h" 2#include "mhwrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qdir.h> 6#include <qdir.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <klocale.h> 10#include <klocale.h>
11#include <kglobal.h> 11#include <kglobal.h>
12//#include <opie2/odebug.h> 12//#include <opie2/odebug.h>
13 13
14using namespace Opie::Core; 14using namespace Opie::Core;
15MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 15MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
16 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 16 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
17{ 17{
18 if (MHPath.length()>0) { 18 if (MHPath.length()>0) {
19 if (MHPath[MHPath.length()-1]=='/') { 19 if (MHPath[MHPath.length()-1]=='/') {
20 MHPath=MHPath.left(MHPath.length()-1); 20 MHPath=MHPath.left(MHPath.length()-1);
21 } 21 }
22 //odebug << MHPath << oendl; 22 //odebug << MHPath << oendl;
23 QDir dir(MHPath); 23 QDir dir(MHPath);
24 if (!dir.exists()) { 24 if (!dir.exists()) {
25 dir.mkdir(MHPath); 25 dir.mkdir(MHPath);
26 } 26 }
27 init_storage(); 27 init_storage();
28 } 28 }
29} 29}
30 30
31void MHwrapper::init_storage() 31void MHwrapper::init_storage()
32{ 32{
33 int r; 33 int r;
34 QString pre = MHPath; 34 QString pre = MHPath;
35 if (!m_storage) { 35 if (!m_storage) {
36 m_storage = mailstorage_new(NULL); 36 m_storage = mailstorage_new(NULL);
37 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 37 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
38 if (r != MAIL_NO_ERROR) { 38 if (r != MAIL_NO_ERROR) {
39 qDebug(" error init storage "); 39 qDebug(" error init storage ");
40 mailstorage_free(m_storage); 40 mailstorage_free(m_storage);
41 m_storage = 0; 41 m_storage = 0;
42 return; 42 return;
43 } 43 }
44 } 44 }
45 r = mailstorage_connect(m_storage); 45 r = mailstorage_connect(m_storage);
46 if (r!=MAIL_NO_ERROR) { 46 if (r!=MAIL_NO_ERROR) {
47 qDebug("error connecting storage "); 47 qDebug("error connecting storage ");
48 mailstorage_free(m_storage); 48 mailstorage_free(m_storage);
49 m_storage = 0; 49 m_storage = 0;
50 } 50 }
51} 51}
52 52
53void MHwrapper::clean_storage() 53void MHwrapper::clean_storage()
54{ 54{
55 if (m_storage) { 55 if (m_storage) {
56 mailstorage_disconnect(m_storage); 56 mailstorage_disconnect(m_storage);
57 mailstorage_free(m_storage); 57 mailstorage_free(m_storage);
58 m_storage = 0; 58 m_storage = 0;
59 } 59 }
60} 60}
61 61
62MHwrapper::~MHwrapper() 62MHwrapper::~MHwrapper()
63{ 63{
64 clean_storage(); 64 clean_storage();
65} 65}
66 66
67void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 67void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
68{ 68{
69 init_storage(); 69 init_storage();
70 if (!m_storage) { 70 if (!m_storage) {
71 return; 71 return;
72 } 72 }
73 QString f = buildPath(mailbox); 73 QString f = buildPath(mailbox);
74 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 74 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
75 if (r!=MAIL_NO_ERROR) { 75 if (r!=MAIL_NO_ERROR) {
76 qDebug("listMessages: error selecting folder! "); 76 qDebug("listMessages: error selecting folder! ");
77 return; 77 return;
78 } 78 }
79 parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); 79 parseList(target,m_storage->sto_session,f, false, maxSizeInKb );
80 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); 80 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count()));
81} 81}
82 82
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();
179 if (!m_storage) { 180 if (!m_storage) {
180 return 0; 181 return 0;
181 } 182 }
182 QString f; 183 QString f;
183 if (!pfolder) { 184 if (!pfolder) {
184 // toplevel folder 185 // toplevel folder
185 f = buildPath(folder); 186 f = buildPath(folder);
186 } else { 187 } else {
187 f = pfolder->getName(); 188 f = pfolder->getName();
188 f+="/"; 189 f+="/";
189 f+=folder; 190 f+=folder;
190 } 191 }
191 192
192 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 193 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
193 if (r != MAIL_NO_ERROR) { 194 if (r != MAIL_NO_ERROR) {
194 qDebug("error creating folder "); 195 qDebug("error creating folder ");
195 return 0; 196 return 0;
196 } 197 }
197 return 1; 198 return 1;
198} 199}
199 200
200void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 201void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
201{ 202{
202 init_storage(); 203 init_storage();
203 if (!m_storage) { 204 if (!m_storage) {
204 return; 205 return;
205 } 206 }
206 QString f = buildPath(Folder); 207 QString f = buildPath(Folder);
207 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 208 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
208 if (r!=MAIL_NO_ERROR) { 209 if (r!=MAIL_NO_ERROR) {
209 qDebug("error selecting folder! "); 210 qDebug("error selecting folder! ");
210 return; 211 return;
211 } 212 }
212 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 213 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
213 if (r!=MAIL_NO_ERROR) { 214 if (r!=MAIL_NO_ERROR) {
214 qDebug("error storing mail "); 215 qDebug("error storing mail ");
215 } 216 }
216 return; 217 return;
217} 218}
218 219
219encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) 220encodedString* MHwrapper::fetchRawBody(const RecMailP&mail)
220{ 221{
221 encodedString*result = 0; 222 encodedString*result = 0;
222 init_storage(); 223 init_storage();
223 if (!m_storage) { 224 if (!m_storage) {
224 return result; 225 return result;
225 } 226 }
226 mailmessage * msg = 0; 227 mailmessage * msg = 0;
227 char*data=0; 228 char*data=0;
228 size_t size; 229 size_t size;
229 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 230 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
230 if (r!=MAIL_NO_ERROR) { 231 if (r!=MAIL_NO_ERROR) {
231 qDebug("error selecting folder! "); 232 qDebug("error selecting folder! ");
232 return result; 233 return result;
233 } 234 }
234 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 235 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
235 if (r != MAIL_NO_ERROR) { 236 if (r != MAIL_NO_ERROR) {
236 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 237 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
237 return 0; 238 return 0;
238 } 239 }
239 r = mailmessage_fetch(msg,&data,&size); 240 r = mailmessage_fetch(msg,&data,&size);
240 if (r != MAIL_NO_ERROR) { 241 if (r != MAIL_NO_ERROR) {
241 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 242 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
242 if (msg) mailmessage_free(msg); 243 if (msg) mailmessage_free(msg);
243 return 0; 244 return 0;
244 } 245 }
245 result = new encodedString(data,size); 246 result = new encodedString(data,size);
246 if (msg) mailmessage_free(msg); 247 if (msg) mailmessage_free(msg);
247 return result; 248 return result;
248} 249}
249 250
250void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 251void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
251{ 252{
252 QString f = buildPath(mailbox); 253 QString f = buildPath(mailbox);
253 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 254 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
254 if (r!=MAIL_NO_ERROR) { 255 if (r!=MAIL_NO_ERROR) {
255 qDebug("deleteMails: error selecting folder! "); 256 qDebug("deleteMails: error selecting folder! ");
256 return; 257 return;
257 } 258 }
258 QValueList<RecMailP>::ConstIterator it; 259 QValueList<RecMailP>::ConstIterator it;
259 for (it=target.begin(); it!=target.end();++it) { 260 for (it=target.begin(); it!=target.end();++it) {
260 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); 261 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
261 if (r != MAIL_NO_ERROR) { 262 if (r != MAIL_NO_ERROR) {
262 qDebug("error deleting mail "); 263 qDebug("error deleting mail ");
263 break; 264 break;
264 } 265 }
265 } 266 }
266} 267}
267 268
268int MHwrapper::deleteAllMail(const FolderP&tfolder) 269int MHwrapper::deleteAllMail(const FolderP&tfolder)
269{ 270{
270 init_storage(); 271 init_storage();
271 if (!m_storage) { 272 if (!m_storage) {
272 return 0; 273 return 0;
273 } 274 }
274 int res = 1; 275 int res = 1;
275 if (!tfolder) return 0; 276 if (!tfolder) return 0;
276 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 277 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
277 if (r!=MAIL_NO_ERROR) { 278 if (r!=MAIL_NO_ERROR) {
278 qDebug("error selecting folder! "); 279 qDebug("error selecting folder! ");
279 return 0; 280 return 0;
280 } 281 }
281 mailmessage_list*l=0; 282 mailmessage_list*l=0;
282 r = mailsession_get_messages_list(m_storage->sto_session,&l); 283 r = mailsession_get_messages_list(m_storage->sto_session,&l);
283 if (r != MAIL_NO_ERROR) { 284 if (r != MAIL_NO_ERROR) {
284 qDebug("Error message list "); 285 qDebug("Error message list ");
285 res = 0; 286 res = 0;
286 } 287 }
287 unsigned j = 0; 288 unsigned j = 0;
288 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 289 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
289 mailmessage * msg; 290 mailmessage * msg;
290 msg = (mailmessage*)carray_get(l->msg_tab, i); 291 msg = (mailmessage*)carray_get(l->msg_tab, i);
291 j = msg->msg_index; 292 j = msg->msg_index;
292 r = mailsession_remove_message(m_storage->sto_session,j); 293 r = mailsession_remove_message(m_storage->sto_session,j);
293 if (r != MAIL_NO_ERROR) { 294 if (r != MAIL_NO_ERROR) {
294 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 295 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
295 res = 0; 296 res = 0;
296 break; 297 break;
297 } 298 }
298 } 299 }
299 if (l) mailmessage_list_free(l); 300 if (l) mailmessage_list_free(l);
300 return res; 301 return res;
301} 302}
302bool MHwrapper::rmDir(QString folder) // absolute path! 303bool MHwrapper::rmDir(QString folder) // absolute path!
303{ 304{
304 QDir dir ( folder ); 305 QDir dir ( folder );
305 if ( !dir.exists() ) 306 if ( !dir.exists() )
306 return false; 307 return false;
307 int i; 308 int i;
308 // qDebug("rmdir %s ",folder.latin1()); 309 // qDebug("rmdir %s ",folder.latin1());
309 QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); 310 QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden );
310 for (i=0; i<list.count(); i++ ) { 311 for (i=0; i<list.count(); i++ ) {
311 bool result = true; 312 bool result = true;
312 QString entry = folder+"/"+ list[i] ; 313 QString entry = folder+"/"+ list[i] ;
313 //qDebug("entry %s ",entry.latin1() ); 314 //qDebug("entry %s ",entry.latin1() );
314 315
315 QFileInfo fi ( entry ); 316 QFileInfo fi ( entry );
316 if ( fi.isFile() ) { 317 if ( fi.isFile() ) {
317 //qDebug("file %s ",entry.latin1() ); 318 //qDebug("file %s ",entry.latin1() );
318 result = QFile::remove ( entry ) ; 319 result = QFile::remove ( entry ) ;
319 } else { 320 } else {
320 //qDebug("dir %s ",entry.latin1()); 321 //qDebug("dir %s ",entry.latin1());
321 if ( list[i] != "." && list[i] != ".." ) 322 if ( list[i] != "." && list[i] != ".." )
322 result = rmDir( entry ); 323 result = rmDir( entry );
323 } 324 }
324 if ( ! result ) 325 if ( ! result )
325 return false; 326 return false;
326 } 327 }
327 //qDebug("removing... "); 328 //qDebug("removing... ");
328 return QDir::root().rmdir ( folder, true ); 329 return QDir::root().rmdir ( folder, true );
329} 330}
330int MHwrapper::deleteMbox(const FolderP&tfolder) 331int MHwrapper::deleteMbox(const FolderP&tfolder)
331{ 332{
332 init_storage(); 333 init_storage();
333 if (!m_storage) { 334 if (!m_storage) {
334 return 0; 335 return 0;
335 } 336 }
336 if (!tfolder) return 0; 337 if (!tfolder) return 0;
337 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 338 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
338 339
339 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 340 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
340 341
341 if (r != MAIL_NO_ERROR) { 342 if (r != MAIL_NO_ERROR) {
342 qDebug("error deleting mail box "); 343 qDebug("error deleting mail box ");
343 return 0; 344 return 0;
344 } 345 }
345 //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() ); 346 //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() );
346 if ( !rmDir( tfolder->getName() )) { 347 if ( !rmDir( tfolder->getName() )) {
347 qDebug("error deleteing folder %s ",tfolder->getName().latin1()); 348 qDebug("error deleteing folder %s ",tfolder->getName().latin1());
348 } 349 }
349 else 350 else
350 qDebug("mail box deleted %s ", tfolder->getName().latin1()); 351 qDebug("mail box deleted %s ", tfolder->getName().latin1());
351 return 1; 352 return 1;
352} 353}
353 354
354 355
355void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 356void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
356{ 357{
357 init_storage(); 358 init_storage();
358 if (!m_storage) { 359 if (!m_storage) {
359 return; 360 return;
360 } 361 }
361 target_stat.message_count = 0; 362 target_stat.message_count = 0;
362 target_stat.message_unseen = 0; 363 target_stat.message_unseen = 0;
363 target_stat.message_recent = 0; 364 target_stat.message_recent = 0;
364 QString f = buildPath(mailbox); 365 QString f = buildPath(mailbox);
365 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 366 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
366 &target_stat.message_recent,&target_stat.message_unseen); 367 &target_stat.message_recent,&target_stat.message_unseen);
367 if (r != MAIL_NO_ERROR) { 368 if (r != MAIL_NO_ERROR) {
368 Global::statusMessage(i18n("Error retrieving status")); 369 Global::statusMessage(i18n("Error retrieving status"));
369 } 370 }
370} 371}
371 372
372MAILLIB::ATYPE MHwrapper::getType()const 373MAILLIB::ATYPE MHwrapper::getType()const
373{ 374{
374 return MAILLIB::A_MH; 375 return MAILLIB::A_MH;
375} 376}
376 377
377const QString&MHwrapper::getName()const 378const QString&MHwrapper::getName()const
378{ 379{
379 return MHName; 380 return MHName;
380} 381}
381void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 382void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
382{ 383{
383 init_storage(); 384 init_storage();
384 if (!m_storage) { 385 if (!m_storage) {
385 return; 386 return;
386 } 387 }