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
@@ -1,1339 +1,1358 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h> 9#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h> 11#include <kglobal.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 18 : AbstractMail()
19{ 19{
20 account = a; 20 account = a;
21 m_imap = 0; 21 m_imap = 0;
22 m_Lastmbox = ""; 22 m_Lastmbox = "";
23 mCurrent = 0; 23 mCurrent = 0;
24 mMax = 0; 24 mMax = 0;
25} 25}
26 26
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
28{ 28{
29 logout(); 29 logout();
30} 30}
31 31
32/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
35{ 35{
36 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
38 } 38 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 41 m_Lastmbox = "";
42 return err; 42 return err;
43 } 43 }
44 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
45 return err; 45 return err;
46} 46}
47 47
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 49{
50 //qDebug("imap progress %d of %d ",current,maximum ); 50 //qDebug("imap progress %d of %d ",current,maximum );
51 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); 51 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
52 //qApp->processEvents() 52 //qApp->processEvents()
53 static int last = 0; 53 static int last = 0;
54 if ( last != current ) 54 if ( last != current )
55 IMAPwrapper::progress(); 55 IMAPwrapper::progress();
56 last = current; 56 last = current;
57} 57}
58void IMAPwrapper::progress( QString m ) 58void IMAPwrapper::progress( QString m )
59{ 59{
60 60
61 static QString mProgrMess; 61 static QString mProgrMess;
62 if ( m != QString::null ) { 62 if ( m != QString::null ) {
63 mProgrMess = m; 63 mProgrMess = m;
64 mCurrent = 1; 64 mCurrent = 1;
65 return; 65 return;
66 } 66 }
67 QString mess; 67 QString mess;
68 //qDebug("progress "); 68 //qDebug("progress ");
69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
71 Global::statusMessage(mess); 71 Global::statusMessage(mess);
72 //qDebug("Progress %s %s", mess.latin1(), m.latin1()); 72 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
73 qApp->processEvents(); 73 qApp->processEvents();
74} 74}
75bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
76{ 76{
77 int err; 77 int err;
78 bool try_tls = force_tls; 78 bool try_tls = force_tls;
79 mailimap_capability_data * cap_data = 0; 79 mailimap_capability_data * cap_data = 0;
80 80
81 err = mailimap_capability(m_imap,&cap_data); 81 err = mailimap_capability(m_imap,&cap_data);
82 if (err != MAILIMAP_NO_ERROR) { 82 if (err != MAILIMAP_NO_ERROR) {
83 Global::statusMessage("error getting capabilities!"); 83 Global::statusMessage("error getting capabilities!");
84 return false; 84 return false;
85 } 85 }
86 clistiter * cur; 86 clistiter * cur;
87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
88 struct mailimap_capability * cap; 88 struct mailimap_capability * cap;
89 cap = (struct mailimap_capability *)clist_content(cur); 89 cap = (struct mailimap_capability *)clist_content(cur);
90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
92 try_tls = true; 92 try_tls = true;
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 if (cap_data) { 97 if (cap_data) {
98 mailimap_capability_data_free(cap_data); 98 mailimap_capability_data_free(cap_data);
99 } 99 }
100 if (try_tls) { 100 if (try_tls) {
101 err = mailimap_starttls(m_imap); 101 err = mailimap_starttls(m_imap);
102 if (err != MAILIMAP_NO_ERROR && force_tls) { 102 if (err != MAILIMAP_NO_ERROR && force_tls) {
103 Global::statusMessage(i18n("Server has no TLS support!")); 103 Global::statusMessage(i18n("Server has no TLS support!"));
104 try_tls = false; 104 try_tls = false;
105 } else { 105 } else {
106 mailstream_low * low; 106 mailstream_low * low;
107 mailstream_low * new_low; 107 mailstream_low * new_low;
108 low = mailstream_get_low(m_imap->imap_stream); 108 low = mailstream_get_low(m_imap->imap_stream);
109 if (!low) { 109 if (!low) {
110 try_tls = false; 110 try_tls = false;
111 } else { 111 } else {
112 int fd = mailstream_low_get_fd(low); 112 int fd = mailstream_low_get_fd(low);
113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
114 mailstream_low_free(low); 114 mailstream_low_free(low);
115 mailstream_set_low(m_imap->imap_stream, new_low); 115 mailstream_set_low(m_imap->imap_stream, new_low);
116 } else { 116 } else {
117 try_tls = false; 117 try_tls = false;
118 } 118 }
119 } 119 }
120 } 120 }
121 } 121 }
122 return try_tls; 122 return try_tls;
123} 123}
124 124
125void IMAPwrapper::login() 125void IMAPwrapper::login()
126{ 126{
127 QString server, user, pass; 127 QString server, user, pass;
128 uint16_t port; 128 uint16_t port;
129 int err = MAILIMAP_NO_ERROR; 129 int err = MAILIMAP_NO_ERROR;
130 130
131 if (account->getOffline()) return; 131 if (account->getOffline()) return;
132 /* we are connected this moment */ 132 /* we are connected this moment */
133 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 133 /* TODO: setup a timer holding the line or if connection closed - delete the value */
134 if (m_imap) { 134 if (m_imap) {
135 err = mailimap_noop(m_imap); 135 err = mailimap_noop(m_imap);
136 if (err!=MAILIMAP_NO_ERROR) { 136 if (err!=MAILIMAP_NO_ERROR) {
137 logout(); 137 logout();
138 } else { 138 } else {
139 mailstream_flush(m_imap->imap_stream); 139 mailstream_flush(m_imap->imap_stream);
140 return; 140 return;
141 } 141 }
142 } 142 }
143 server = account->getServer(); 143 server = account->getServer();
144 port = account->getPort().toUInt(); 144 port = account->getPort().toUInt();
145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
147 login.show(); 147 login.show();
148 if ( QDialog::Accepted == login.exec() ) { 148 if ( QDialog::Accepted == login.exec() ) {
149 // ok 149 // ok
150 user = login.getUser(); 150 user = login.getUser();
151 pass = login.getPassword(); 151 pass = login.getPassword();
152 } else { 152 } else {
153 // cancel 153 // cancel
154 return; 154 return;
155 } 155 }
156 } else { 156 } else {
157 user = account->getUser(); 157 user = account->getUser();
158 pass = account->getPassword(); 158 pass = account->getPassword();
159 } 159 }
160 160
161 m_imap = mailimap_new( 20, &imap_progress ); 161 m_imap = mailimap_new( 20, &imap_progress );
162 162
163 /* connect */ 163 /* connect */
164 bool ssl = false; 164 bool ssl = false;
165 bool try_tls = false; 165 bool try_tls = false;
166 bool force_tls = false; 166 bool force_tls = false;
167 167
168 if ( account->ConnectionType() == 2 ) { 168 if ( account->ConnectionType() == 2 ) {
169 ssl = true; 169 ssl = true;
170 } 170 }
171 if (account->ConnectionType()==1) { 171 if (account->ConnectionType()==1) {
172 force_tls = true; 172 force_tls = true;
173 } 173 }
174 174
175 if ( ssl ) { 175 if ( ssl ) {
176 qDebug("using ssl "); 176 qDebug("using ssl ");
177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
178 qDebug("back "); 178 qDebug("back ");
179 } else { 179 } else {
180 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 180 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
181 } 181 }
182 182
183 if ( err != MAILIMAP_NO_ERROR && 183 if ( err != MAILIMAP_NO_ERROR &&
184 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 184 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
185 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 185 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
186 QString failure = ""; 186 QString failure = "";
187 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 187 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
188 failure="Connection refused"; 188 failure="Connection refused";
189 } else { 189 } else {
190 failure="Unknown failure"; 190 failure="Unknown failure";
191 } 191 }
192 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); 192 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
193 mailimap_free( m_imap ); 193 mailimap_free( m_imap );
194 m_imap = 0; 194 m_imap = 0;
195 return; 195 return;
196 } 196 }
197 197
198 if (!ssl) { 198 if (!ssl) {
199 try_tls = start_tls(force_tls); 199 try_tls = start_tls(force_tls);
200 } 200 }
201 201
202 bool ok = true; 202 bool ok = true;
203 if (force_tls && !try_tls) { 203 if (force_tls && !try_tls) {
204 Global::statusMessage(i18n("Server has no TLS support!")); 204 Global::statusMessage(i18n("Server has no TLS support!"));
205 ok = false; 205 ok = false;
206 } 206 }
207 207
208 208
209 /* login */ 209 /* login */
210 210
211 if (ok) { 211 if (ok) {
212 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 212 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
213 if ( err != MAILIMAP_NO_ERROR ) { 213 if ( err != MAILIMAP_NO_ERROR ) {
214 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); 214 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
215 ok = false; 215 ok = false;
216 } 216 }
217 } 217 }
218 if (!ok) { 218 if (!ok) {
219 err = mailimap_close( m_imap ); 219 err = mailimap_close( m_imap );
220 mailimap_free( m_imap ); 220 mailimap_free( m_imap );
221 m_imap = 0; 221 m_imap = 0;
222 } 222 }
223} 223}
224 224
225void IMAPwrapper::logout() 225void IMAPwrapper::logout()
226{ 226{
227 int err = MAILIMAP_NO_ERROR; 227 int err = MAILIMAP_NO_ERROR;
228 if (!m_imap) return; 228 if (!m_imap) return;
229 err = mailimap_logout( m_imap ); 229 err = mailimap_logout( m_imap );
230 err = mailimap_close( m_imap ); 230 err = mailimap_close( m_imap );
231 mailimap_free( m_imap ); 231 mailimap_free( m_imap );
232 m_imap = 0; 232 m_imap = 0;
233 m_Lastmbox = ""; 233 m_Lastmbox = "";
234} 234}
235 235
236void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 236void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
237{ 237{
238 238
239 int tryAgain = 1; 239 int tryAgain = 1;
240 while ( tryAgain >= 0 ) { 240 while ( tryAgain >= 0 ) {
241 int err = MAILIMAP_NO_ERROR; 241 int err = MAILIMAP_NO_ERROR;
242 clist *result = 0; 242 clist *result = 0;
243 clistcell *current; 243 clistcell *current;
244 mailimap_fetch_type *fetchType = 0; 244 mailimap_fetch_type *fetchType = 0;
245 mailimap_set *set = 0; 245 mailimap_set *set = 0;
246 246
247 login(); 247 login();
248 if (!m_imap) { 248 if (!m_imap) {
249 return; 249 return;
250 } 250 }
251 /* select mailbox READONLY for operations */ 251 /* select mailbox READONLY for operations */
252 err = selectMbox(mailbox); 252 err = selectMbox(mailbox);
253 if ( err != MAILIMAP_NO_ERROR ) { 253 if ( err != MAILIMAP_NO_ERROR ) {
254 return; 254 return;
255 } 255 }
256 256
257 int last = m_imap->imap_selection_info->sel_exists; 257 int last = m_imap->imap_selection_info->sel_exists;
258 258
259 if (last == 0) { 259 if (last == 0) {
260 Global::statusMessage(i18n("Mailbox has no mails")); 260 Global::statusMessage(i18n("Mailbox has no mails"));
261 return; 261 return;
262 } else { 262 } else {
263 } 263 }
264 progress( i18n("Fetch ")); 264 progress( i18n("Fetch "));
265 mMax = last; 265 mMax = last;
266 //qDebug("last %d ", last); 266 //qDebug("last %d ", last);
267 Global::statusMessage(i18n("Fetching header list")); 267 Global::statusMessage(i18n("Fetching header list"));
268 qApp->processEvents(); 268 qApp->processEvents();
269 /* the range has to start at 1!!! not with 0!!!! */ 269 /* the range has to start at 1!!! not with 0!!!! */
270 //LR the access to web.de imap server is no working with value 1 270 //LR the access to web.de imap server is no working with value 1
271 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 271 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
272 set = mailimap_set_new_interval( tryAgain, last ); 272 set = mailimap_set_new_interval( tryAgain, last );
273 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 273 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
277 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 277 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
278 278
279 err = mailimap_fetch( m_imap, set, fetchType, &result ); 279 err = mailimap_fetch( m_imap, set, fetchType, &result );
280 mailimap_set_free( set ); 280 mailimap_set_free( set );
281 mailimap_fetch_type_free( fetchType ); 281 mailimap_fetch_type_free( fetchType );
282 282
283 QString date,subject,from; 283 QString date,subject,from;
284 284
285 if ( err == MAILIMAP_NO_ERROR ) { 285 if ( err == MAILIMAP_NO_ERROR ) {
286 tryAgain = -1; 286 tryAgain = -1;
287 mailimap_msg_att * msg_att; 287 mailimap_msg_att * msg_att;
288 int i = 0; 288 int i = 0;
289 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 289 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
290 ++i; 290 ++i;
291 //qDebug("iii %d ",i); 291 //qDebug("iii %d ",i);
292 msg_att = (mailimap_msg_att*)current->data; 292 msg_att = (mailimap_msg_att*)current->data;
293 RecMail*m = parse_list_result(msg_att); 293 RecMail*m = parse_list_result(msg_att);
294 if (m) { 294 if (m) {
295 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 295 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
296 m->setNumber(i); 296 m->setNumber(i);
297 m->setMbox(mailbox); 297 m->setMbox(mailbox);
298 m->setWrapper(this); 298 m->setWrapper(this);
299 target.append(m); 299 target.append(m);
300 } 300 }
301 } 301 }
302 } 302 }
303 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); 303 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
304 } else { 304 } else {
305 --tryAgain; 305 --tryAgain;
306 --tryAgain;//disabled tryagain by adding this line 306 --tryAgain;//disabled tryagain by adding this line
307 if ( tryAgain < 0 ) 307 if ( tryAgain < 0 )
308 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); 308 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
309 else 309 else
310 qDebug("try again... "); 310 qDebug("try again... ");
311 } 311 }
312 312
313 if (result) mailimap_fetch_list_free(result); 313 if (result) mailimap_fetch_list_free(result);
314 } 314 }
315} 315}
316 316
317QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 317QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
318{ 318{
319 const char *path, *mask; 319 const char *path, *mask;
320 int err = MAILIMAP_NO_ERROR; 320 int err = MAILIMAP_NO_ERROR;
321 clist *result = 0; 321 clist *result = 0;
322 clistcell *current = 0; 322 clistcell *current = 0;
323 clistcell*cur_flag = 0; 323 clistcell*cur_flag = 0;
324 mailimap_mbx_list_flags*bflags = 0; 324 mailimap_mbx_list_flags*bflags = 0;
325 325
326 QValueList<FolderP>* folders = new QValueList<FolderP>(); 326 QValueList<FolderP>* folders = new QValueList<FolderP>();
327 login(); 327 login();
328 if (!m_imap) { 328 if (!m_imap) {
329 return folders; 329 return folders;
330 } 330 }
331 331
332/* 332/*
333 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 333 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
334 * We must not forget to filter them out in next loop! 334 * We must not forget to filter them out in next loop!
335 * it seems like ugly code. and yes - it is ugly code. but the best way. 335 * it seems like ugly code. and yes - it is ugly code. but the best way.
336 */ 336 */
337 Global::statusMessage(i18n("Fetching folder list")); 337 Global::statusMessage(i18n("Fetching folder list"));
338 qApp->processEvents(); 338 qApp->processEvents();
339 QString temp; 339 QString temp;
340 mask = "INBOX" ; 340 mask = "INBOX" ;
341 mailimap_mailbox_list *list; 341 mailimap_mailbox_list *list;
342 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 342 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
343 QString del; 343 QString del;
344 bool selectable = true; 344 bool selectable = true;
345 bool no_inferiors = false; 345 bool no_inferiors = false;
346 if ( err == MAILIMAP_NO_ERROR ) { 346 if ( err == MAILIMAP_NO_ERROR ) {
347 current = result->first; 347 current = result->first;
348 for ( int i = result->count; i > 0; i-- ) { 348 for ( int i = result->count; i > 0; i-- ) {
349 list = (mailimap_mailbox_list *) current->data; 349 list = (mailimap_mailbox_list *) current->data;
350 // it is better use the deep copy mechanism of qt itself 350 // it is better use the deep copy mechanism of qt itself
351 // instead of using strdup! 351 // instead of using strdup!
352 temp = list->mb_name; 352 temp = list->mb_name;
353 del = list->mb_delimiter; 353 del = list->mb_delimiter;
354 current = current->next; 354 current = current->next;
355 if ( (bflags = list->mb_flag) ) { 355 if ( (bflags = list->mb_flag) ) {
356 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 356 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
357 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 357 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
358 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 358 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
359 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 359 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
360 no_inferiors = true; 360 no_inferiors = true;
361 } 361 }
362 } 362 }
363 } 363 }
364 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 364 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
365 } 365 }
366 } else { 366 } else {
367 qDebug("error fetching folders: "); 367 qDebug("error fetching folders: ");
368 368
369 } 369 }
370 mailimap_list_result_free( result ); 370 mailimap_list_result_free( result );
371 371
372/* 372/*
373 * second stage - get the other then inbox folders 373 * second stage - get the other then inbox folders
374 */ 374 */
375 mask = "*" ; 375 mask = "*" ;
376 path = account->getPrefix().latin1(); 376 path = account->getPrefix().latin1();
377 if (!path) path = ""; 377 if (!path) path = "";
378 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 378 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
379 if ( err == MAILIMAP_NO_ERROR ) { 379 if ( err == MAILIMAP_NO_ERROR ) {
380 current = result->first; 380 current = result->first;
381 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 381 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
382 no_inferiors = false; 382 no_inferiors = false;
383 list = (mailimap_mailbox_list *) current->data; 383 list = (mailimap_mailbox_list *) current->data;
384 // it is better use the deep copy mechanism of qt itself 384 // it is better use the deep copy mechanism of qt itself
385 // instead of using strdup! 385 // instead of using strdup!
386 temp = list->mb_name; 386 temp = list->mb_name;
387 if (temp.lower()=="inbox") 387 if (temp.lower()=="inbox")
388 continue; 388 continue;
389 if (temp.lower()==account->getPrefix().lower()) 389 if (temp.lower()==account->getPrefix().lower())
390 continue; 390 continue;
391 if ( (bflags = list->mb_flag) ) { 391 if ( (bflags = list->mb_flag) ) {
392 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 392 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
393 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 393 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
394 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 394 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
395 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 395 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
396 no_inferiors = true; 396 no_inferiors = true;
397 } 397 }
398 } 398 }
399 } 399 }
400 del = list->mb_delimiter; 400 del = list->mb_delimiter;
401 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 401 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
402 } 402 }
403 } else { 403 } else {
404 qDebug("error fetching folders "); 404 qDebug("error fetching folders ");
405 405
406 } 406 }
407 if (result) mailimap_list_result_free( result ); 407 if (result) mailimap_list_result_free( result );
408 return folders; 408 return folders;
409} 409}
410 410
411RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 411RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
412{ 412{
413 RecMail * m = 0; 413 RecMail * m = 0;
414 mailimap_msg_att_item *item=0; 414 mailimap_msg_att_item *item=0;
415 clistcell *current,*c,*cf; 415 clistcell *current,*c,*cf;
416 mailimap_msg_att_dynamic*flist; 416 mailimap_msg_att_dynamic*flist;
417 mailimap_flag_fetch*cflag; 417 mailimap_flag_fetch*cflag;
418 int size; 418 int size;
419 QBitArray mFlags(7); 419 QBitArray mFlags(7);
420 QStringList addresslist; 420 QStringList addresslist;
421 421
422 if (!m_att) { 422 if (!m_att) {
423 return m; 423 return m;
424 } 424 }
425 m = new RecMail(); 425 m = new RecMail();
426 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 426 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
427 current = c; 427 current = c;
428 size = 0; 428 size = 0;
429 item = (mailimap_msg_att_item*)current->data; 429 item = (mailimap_msg_att_item*)current->data;
430 if ( !item ) 430 if ( !item )
431 continue; 431 continue;
432 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 432 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
433 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 433 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
434 if (!flist || !flist->att_list) { 434 if (!flist || !flist->att_list) {
435 continue; 435 continue;
436 } 436 }
437 cf = flist->att_list->first; 437 cf = flist->att_list->first;
438 if( ! cf ) 438 if( ! cf )
439 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 439 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
440 cflag = (mailimap_flag_fetch*)cf->data; 440 cflag = (mailimap_flag_fetch*)cf->data;
441 if( ! cflag ) 441 if( ! cflag )
442 qDebug("imap:not cflag "); 442 qDebug("imap:not cflag ");
443 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 443 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
444 switch (cflag->fl_flag->fl_type) { 444 switch (cflag->fl_flag->fl_type) {
445 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 445 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
446 mFlags.setBit(FLAG_ANSWERED); 446 mFlags.setBit(FLAG_ANSWERED);
447 break; 447 break;
448 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 448 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
449 mFlags.setBit(FLAG_FLAGGED); 449 mFlags.setBit(FLAG_FLAGGED);
450 break; 450 break;
451 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 451 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
452 mFlags.setBit(FLAG_DELETED); 452 mFlags.setBit(FLAG_DELETED);
453 break; 453 break;
454 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 454 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
455 mFlags.setBit(FLAG_SEEN); 455 mFlags.setBit(FLAG_SEEN);
456 break; 456 break;
457 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 457 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
458 mFlags.setBit(FLAG_DRAFT); 458 mFlags.setBit(FLAG_DRAFT);
459 break; 459 break;
460 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 460 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
461 break; 461 break;
462 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 462 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
463 break; 463 break;
464 default: 464 default:
465 break; 465 break;
466 } 466 }
467 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 467 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
468 mFlags.setBit(FLAG_RECENT); 468 mFlags.setBit(FLAG_RECENT);
469 } 469 }
470 } 470 }
471 continue; 471 continue;
472 } 472 }
473 if ( item->att_data.att_static == NULL ) 473 if ( item->att_data.att_static == NULL )
474 continue; 474 continue;
475 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 475 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
476 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 476 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
477 if ( head == NULL ) 477 if ( head == NULL )
478 continue; 478 continue;
479 if ( head->env_date != NULL ) { 479 if ( head->env_date != NULL ) {
480 m->setDate(head->env_date); 480 m->setDate(head->env_date);
481 //struct mailimf_date_time result; 481 //struct mailimf_date_time result;
482 struct mailimf_date_time* date;// = &result; 482 struct mailimf_date_time* date;// = &result;
483 struct mailimf_date_time **re = &date; 483 struct mailimf_date_time **re = &date;
484 size_t length = m->getDate().length(); 484 size_t length = m->getDate().length();
485 size_t index = 0; 485 size_t index = 0;
486 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { 486 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) {
487 QDateTime dt = Genericwrapper::parseDateTime( date ); 487 QDateTime dt = Genericwrapper::parseDateTime( date );
488 QString ret; 488 QString ret;
489 if ( dt.date() == QDate::currentDate () ) 489 if ( dt.date() == QDate::currentDate () )
490 ret = KGlobal::locale()->formatTime( dt.time(),true); 490 ret = KGlobal::locale()->formatTime( dt.time(),true);
491 else { 491 else {
492 ret = KGlobal::locale()->formatDateTime( dt,true,true); 492 ret = KGlobal::locale()->formatDateTime( dt,true,true);
493 } 493 }
494 m->setDate( ret ); 494 m->setDate( ret );
495 char tmp[20]; 495 char tmp[20];
496 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 496 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
497 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); 497 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
498 //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); 498 //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date);
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 // }
1011 //#endif 1030 //#endif
1012 //deleteMail( mail); 1031 //deleteMail( mail);
1013 ++iii; 1032 ++iii;
1014 } 1033 }
1015 //qDebug("Deleting imap mails... "); 1034 //qDebug("Deleting imap mails... ");
1016 err = mailimap_expunge(m_imap); 1035 err = mailimap_expunge(m_imap);
1017 if (err != MAILIMAP_NO_ERROR) { 1036 if (err != MAILIMAP_NO_ERROR) {
1018 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1037 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1019 } 1038 }
1020} 1039}
1021void IMAPwrapper::deleteMail(const RecMailP&mail) 1040void IMAPwrapper::deleteMail(const RecMailP&mail)
1022{ 1041{
1023 mailimap_flag_list*flist; 1042 mailimap_flag_list*flist;
1024 mailimap_set *set; 1043 mailimap_set *set;
1025 mailimap_store_att_flags * store_flags; 1044 mailimap_store_att_flags * store_flags;
1026 int err; 1045 int err;
1027 login(); 1046 login();
1028 if (!m_imap) { 1047 if (!m_imap) {
1029 return; 1048 return;
1030 } 1049 }
1031 err = selectMbox(mail->getMbox()); 1050 err = selectMbox(mail->getMbox());
1032 if ( err != MAILIMAP_NO_ERROR ) { 1051 if ( err != MAILIMAP_NO_ERROR ) {
1033 return; 1052 return;
1034 } 1053 }
1035 flist = mailimap_flag_list_new_empty(); 1054 flist = mailimap_flag_list_new_empty();
1036 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1055 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1037 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1056 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1038 set = mailimap_set_new_single(mail->getNumber()); 1057 set = mailimap_set_new_single(mail->getNumber());
1039 err = mailimap_store(m_imap,set,store_flags); 1058 err = mailimap_store(m_imap,set,store_flags);
1040 mailimap_set_free( set ); 1059 mailimap_set_free( set );
1041 mailimap_store_att_flags_free(store_flags); 1060 mailimap_store_att_flags_free(store_flags);
1042 1061
1043 if (err != MAILIMAP_NO_ERROR) { 1062 if (err != MAILIMAP_NO_ERROR) {
1044 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1063 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1045 return; 1064 return;
1046 } 1065 }
1047 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1066 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1048 /* should we realy do that at this moment? */ 1067 /* should we realy do that at this moment? */
1049 1068
1050 err = mailimap_expunge(m_imap); 1069 err = mailimap_expunge(m_imap);
1051 if (err != MAILIMAP_NO_ERROR) { 1070 if (err != MAILIMAP_NO_ERROR) {
1052 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1071 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1053 } 1072 }
1054 //qDebug("IMAPwrapper::deleteMail 2"); 1073 //qDebug("IMAPwrapper::deleteMail 2");
1055 1074
1056} 1075}
1057 1076
1058void IMAPwrapper::answeredMail(const RecMailP&mail) 1077void IMAPwrapper::answeredMail(const RecMailP&mail)
1059{ 1078{
1060 mailimap_flag_list*flist; 1079 mailimap_flag_list*flist;
1061 mailimap_set *set; 1080 mailimap_set *set;
1062 mailimap_store_att_flags * store_flags; 1081 mailimap_store_att_flags * store_flags;
1063 int err; 1082 int err;
1064 login(); 1083 login();
1065 if (!m_imap) { 1084 if (!m_imap) {
1066 return; 1085 return;
1067 } 1086 }
1068 err = selectMbox(mail->getMbox()); 1087 err = selectMbox(mail->getMbox());
1069 if ( err != MAILIMAP_NO_ERROR ) { 1088 if ( err != MAILIMAP_NO_ERROR ) {
1070 return; 1089 return;
1071 } 1090 }
1072 flist = mailimap_flag_list_new_empty(); 1091 flist = mailimap_flag_list_new_empty();
1073 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1092 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1074 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1093 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1075 set = mailimap_set_new_single(mail->getNumber()); 1094 set = mailimap_set_new_single(mail->getNumber());
1076 err = mailimap_store(m_imap,set,store_flags); 1095 err = mailimap_store(m_imap,set,store_flags);
1077 mailimap_set_free( set ); 1096 mailimap_set_free( set );
1078 mailimap_store_att_flags_free(store_flags); 1097 mailimap_store_att_flags_free(store_flags);
1079 1098
1080 if (err != MAILIMAP_NO_ERROR) { 1099 if (err != MAILIMAP_NO_ERROR) {
1081 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1100 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1082 return; 1101 return;
1083 } 1102 }
1084} 1103}
1085 1104
1086QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1105QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
1087{ 1106{
1088 QString body(""); 1107 QString body("");
1089 encodedString*res = fetchRawPart(mail,path,internal_call); 1108 encodedString*res = fetchRawPart(mail,path,internal_call);
1090 encodedString*r = decode_String(res,enc); 1109 encodedString*r = decode_String(res,enc);
1091 delete res; 1110 delete res;
1092 if (r) { 1111 if (r) {
1093 if (r->Length()>0) { 1112 if (r->Length()>0) {
1094 body = r->Content(); 1113 body = r->Content();
1095 } 1114 }
1096 delete r; 1115 delete r;
1097 } 1116 }
1098 return body; 1117 return body;
1099} 1118}
1100 1119
1101QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1120QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1102{ 1121{
1103 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1122 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1104} 1123}
1105 1124
1106encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1125encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1107{ 1126{
1108 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1127 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1109 encodedString*r = decode_String(res,part->Encoding()); 1128 encodedString*r = decode_String(res,part->Encoding());
1110 delete res; 1129 delete res;
1111 return r; 1130 return r;
1112} 1131}
1113 1132
1114encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1133encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1115{ 1134{
1116 return fetchRawPart(mail,part->Positionlist(),false); 1135 return fetchRawPart(mail,part->Positionlist(),false);
1117} 1136}
1118 1137
1119int IMAPwrapper::deleteAllMail(const FolderP&folder) 1138int IMAPwrapper::deleteAllMail(const FolderP&folder)
1120{ 1139{
1121 login(); 1140 login();
1122 if (!m_imap) { 1141 if (!m_imap) {
1123 return 0; 1142 return 0;
1124 } 1143 }
1125 mailimap_flag_list*flist; 1144 mailimap_flag_list*flist;
1126 mailimap_set *set; 1145 mailimap_set *set;
1127 mailimap_store_att_flags * store_flags; 1146 mailimap_store_att_flags * store_flags;
1128 int err = selectMbox(folder->getName()); 1147 int err = selectMbox(folder->getName());
1129 if ( err != MAILIMAP_NO_ERROR ) { 1148 if ( err != MAILIMAP_NO_ERROR ) {
1130 return 0; 1149 return 0;
1131 } 1150 }
1132 1151
1133 int last = m_imap->imap_selection_info->sel_exists; 1152 int last = m_imap->imap_selection_info->sel_exists;
1134 if (last == 0) { 1153 if (last == 0) {
1135 Global::statusMessage(i18n("Mailbox has no mails!")); 1154 Global::statusMessage(i18n("Mailbox has no mails!"));
1136 return 0; 1155 return 0;
1137 } 1156 }
1138 flist = mailimap_flag_list_new_empty(); 1157 flist = mailimap_flag_list_new_empty();
1139 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1158 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1140 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1159 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1141 set = mailimap_set_new_interval( 1, last ); 1160 set = mailimap_set_new_interval( 1, last );
1142 err = mailimap_store(m_imap,set,store_flags); 1161 err = mailimap_store(m_imap,set,store_flags);
1143 mailimap_set_free( set ); 1162 mailimap_set_free( set );
1144 mailimap_store_att_flags_free(store_flags); 1163 mailimap_store_att_flags_free(store_flags);
1145 if (err != MAILIMAP_NO_ERROR) { 1164 if (err != MAILIMAP_NO_ERROR) {
1146 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1165 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1147 return 0; 1166 return 0;
1148 } 1167 }
1149 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1168 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1150 /* should we realy do that at this moment? */ 1169 /* should we realy do that at this moment? */
1151 err = mailimap_expunge(m_imap); 1170 err = mailimap_expunge(m_imap);
1152 if (err != MAILIMAP_NO_ERROR) { 1171 if (err != MAILIMAP_NO_ERROR) {
1153 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1172 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1154 return 0; 1173 return 0;
1155 } 1174 }
1156 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1175 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1157 return 1; 1176 return 1;
1158} 1177}
1159 1178
1160int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1179int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1161{ 1180{
1162 if (folder.length()==0) return 0; 1181 if (folder.length()==0) return 0;
1163 login(); 1182 login();
1164 if (!m_imap) {return 0;} 1183 if (!m_imap) {return 0;}
1165 QString pre = account->getPrefix(); 1184 QString pre = account->getPrefix();
1166 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1185 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1167 pre+=delemiter; 1186 pre+=delemiter;
1168 } 1187 }
1169 if (parentfolder) { 1188 if (parentfolder) {
1170 pre += parentfolder->getDisplayName()+delemiter; 1189 pre += parentfolder->getDisplayName()+delemiter;
1171 } 1190 }
1172 pre+=folder; 1191 pre+=folder;
1173 if (getsubfolder) { 1192 if (getsubfolder) {
1174 if (delemiter.length()>0) { 1193 if (delemiter.length()>0) {
1175 pre+=delemiter; 1194 pre+=delemiter;
1176 } else { 1195 } else {
1177 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); 1196 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
1178 return 0; 1197 return 0;
1179 } 1198 }
1180 } 1199 }
1181 // odebug << "Creating " << pre.latin1() << "" << oendl; 1200 // odebug << "Creating " << pre.latin1() << "" << oendl;
1182 int res = mailimap_create(m_imap,pre.latin1()); 1201 int res = mailimap_create(m_imap,pre.latin1());
1183 if (res != MAILIMAP_NO_ERROR) { 1202 if (res != MAILIMAP_NO_ERROR) {
1184 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1203 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1185 return 0; 1204 return 0;
1186 } 1205 }
1187 return 1; 1206 return 1;
1188} 1207}
1189 1208
1190int IMAPwrapper::deleteMbox(const FolderP&folder) 1209int IMAPwrapper::deleteMbox(const FolderP&folder)
1191{ 1210{
1192 if (!folder) return 0; 1211 if (!folder) return 0;
1193 login(); 1212 login();
1194 if (!m_imap) {return 0;} 1213 if (!m_imap) {return 0;}
1195 int res = mailimap_delete(m_imap,folder->getName()); 1214 int res = mailimap_delete(m_imap,folder->getName());
1196 if (res != MAILIMAP_NO_ERROR) { 1215 if (res != MAILIMAP_NO_ERROR) {
1197 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1216 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1198 return 0; 1217 return 0;
1199 } 1218 }
1200 return 1; 1219 return 1;
1201} 1220}
1202 1221
1203void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1222void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1204{ 1223{
1205 mailimap_status_att_list * att_list =0; 1224 mailimap_status_att_list * att_list =0;
1206 mailimap_mailbox_data_status * status=0; 1225 mailimap_mailbox_data_status * status=0;
1207 clistiter * cur = 0; 1226 clistiter * cur = 0;
1208 int r = 0; 1227 int r = 0;
1209 target_stat.message_count = 0; 1228 target_stat.message_count = 0;
1210 target_stat.message_unseen = 0; 1229 target_stat.message_unseen = 0;
1211 target_stat.message_recent = 0; 1230 target_stat.message_recent = 0;
1212 login(); 1231 login();
1213 if (!m_imap) { 1232 if (!m_imap) {
1214 return; 1233 return;
1215 } 1234 }
1216 att_list = mailimap_status_att_list_new_empty(); 1235 att_list = mailimap_status_att_list_new_empty();
1217 if (!att_list) return; 1236 if (!att_list) return;
1218 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1237 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1219 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1238 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1220 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1239 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1221 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1240 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1222 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1241 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1223 for (cur = clist_begin(status->st_info_list); 1242 for (cur = clist_begin(status->st_info_list);
1224 cur != NULL ; cur = clist_next(cur)) { 1243 cur != NULL ; cur = clist_next(cur)) {
1225 mailimap_status_info * status_info; 1244 mailimap_status_info * status_info;
1226 status_info = (mailimap_status_info *)clist_content(cur); 1245 status_info = (mailimap_status_info *)clist_content(cur);
1227 switch (status_info->st_att) { 1246 switch (status_info->st_att) {
1228 case MAILIMAP_STATUS_ATT_MESSAGES: 1247 case MAILIMAP_STATUS_ATT_MESSAGES:
1229 target_stat.message_count = status_info->st_value; 1248 target_stat.message_count = status_info->st_value;
1230 break; 1249 break;
1231 case MAILIMAP_STATUS_ATT_RECENT: 1250 case MAILIMAP_STATUS_ATT_RECENT:
1232 target_stat.message_recent = status_info->st_value; 1251 target_stat.message_recent = status_info->st_value;
1233 break; 1252 break;
1234 case MAILIMAP_STATUS_ATT_UNSEEN: 1253 case MAILIMAP_STATUS_ATT_UNSEEN:
1235 target_stat.message_unseen = status_info->st_value; 1254 target_stat.message_unseen = status_info->st_value;
1236 break; 1255 break;
1237 } 1256 }
1238 } 1257 }
1239 } else { 1258 } else {
1240 // odebug << "Error retrieving status" << oendl; 1259 // odebug << "Error retrieving status" << oendl;
1241 } 1260 }
1242 if (status) mailimap_mailbox_data_status_free(status); 1261 if (status) mailimap_mailbox_data_status_free(status);
1243 if (att_list) mailimap_status_att_list_free(att_list); 1262 if (att_list) mailimap_status_att_list_free(att_list);
1244} 1263}
1245 1264
1246void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1265void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1247{ 1266{
1248 login(); 1267 login();
1249 if (!m_imap) return; 1268 if (!m_imap) return;
1250 if (!msg) return; 1269 if (!msg) return;
1251 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1270 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1252 if (r != MAILIMAP_NO_ERROR) { 1271 if (r != MAILIMAP_NO_ERROR) {
1253 Global::statusMessage("Error storing mail!"); 1272 Global::statusMessage("Error storing mail!");
1254 } 1273 }
1255} 1274}
1256 1275
1257MAILLIB::ATYPE IMAPwrapper::getType()const 1276MAILLIB::ATYPE IMAPwrapper::getType()const
1258{ 1277{
1259 return account->getType(); 1278 return account->getType();
1260} 1279}
1261 1280
1262const QString&IMAPwrapper::getName()const 1281const QString&IMAPwrapper::getName()const
1263{ 1282{
1264 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1283 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1265 return account->getAccountName(); 1284 return account->getAccountName();
1266} 1285}
1267 1286
1268encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1287encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1269{ 1288{
1270 // dummy 1289 // dummy
1271 QValueList<int> path; 1290 QValueList<int> path;
1272 return fetchRawPart(mail,path,false); 1291 return fetchRawPart(mail,path,false);
1273} 1292}
1274 1293
1275void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1294void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1276 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1295 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1277{ 1296{
1278 if (targetWrapper != this || maxSizeInKb > 0 ) { 1297 if (targetWrapper != this || maxSizeInKb > 0 ) {
1279 mMax = 0; 1298 mMax = 0;
1280 progress( i18n("Copy")); 1299 progress( i18n("Copy"));
1281 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1300 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1282 //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1301 //qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1283 // odebug << "Using generic" << oendl; 1302 // odebug << "Using generic" << oendl;
1284 return; 1303 return;
1285 } 1304 }
1286 mailimap_set *set = 0; 1305 mailimap_set *set = 0;
1287 login(); 1306 login();
1288 if (!m_imap) { 1307 if (!m_imap) {
1289 return; 1308 return;
1290 } 1309 }
1291 int err = selectMbox(fromFolder->getName()); 1310 int err = selectMbox(fromFolder->getName());
1292 if ( err != MAILIMAP_NO_ERROR ) { 1311 if ( err != MAILIMAP_NO_ERROR ) {
1293 return; 1312 return;
1294 } 1313 }
1295 Global::statusMessage( i18n("Copying mails on server...") ); 1314 Global::statusMessage( i18n("Copying mails on server...") );
1296 int last = m_imap->imap_selection_info->sel_exists; 1315 int last = m_imap->imap_selection_info->sel_exists;
1297 set = mailimap_set_new_interval( 1, last ); 1316 set = mailimap_set_new_interval( 1, last );
1298 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1317 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1299 mailimap_set_free( set ); 1318 mailimap_set_free( set );
1300 if ( err != MAILIMAP_NO_ERROR ) { 1319 if ( err != MAILIMAP_NO_ERROR ) {
1301 QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); 1320 QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response);
1302 Global::statusMessage(error_msg); 1321 Global::statusMessage(error_msg);
1303 // odebug << error_msg << oendl; 1322 // odebug << error_msg << oendl;
1304 return; 1323 return;
1305 } 1324 }
1306 if (moveit) { 1325 if (moveit) {
1307 deleteAllMail(fromFolder); 1326 deleteAllMail(fromFolder);
1308 } 1327 }
1309} 1328}
1310 1329
1311void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1330void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1312{ 1331{
1313 if (targetWrapper != this) { 1332 if (targetWrapper != this) {
1314 // odebug << "Using generic" << oendl; 1333 // odebug << "Using generic" << oendl;
1315 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1334 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1316 return; 1335 return;
1317 } 1336 }
1318 mailimap_set *set = 0; 1337 mailimap_set *set = 0;
1319 login(); 1338 login();
1320 if (!m_imap) { 1339 if (!m_imap) {
1321 return; 1340 return;
1322 } 1341 }
1323 int err = selectMbox(mail->getMbox()); 1342 int err = selectMbox(mail->getMbox());
1324 if ( err != MAILIMAP_NO_ERROR ) { 1343 if ( err != MAILIMAP_NO_ERROR ) {
1325 return; 1344 return;
1326 } 1345 }
1327 set = mailimap_set_new_single(mail->getNumber()); 1346 set = mailimap_set_new_single(mail->getNumber());
1328 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1347 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1329 mailimap_set_free( set ); 1348 mailimap_set_free( set );
1330 if ( err != MAILIMAP_NO_ERROR ) { 1349 if ( err != MAILIMAP_NO_ERROR ) {
1331 QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); 1350 QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response);
1332 Global::statusMessage(error_msg); 1351 Global::statusMessage(error_msg);
1333 // odebug << error_msg << oendl; 1352 // odebug << error_msg << oendl;
1334 return; 1353 return;
1335 } 1354 }
1336 if (moveit) { 1355 if (moveit) {
1337 deleteMail(mail); 1356 deleteMail(mail);
1338 } 1357 }
1339} 1358}
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,450 +1,451 @@
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 }
387 if (targetWrapper != this) { 388 if (targetWrapper != this) {
388 qDebug("Using generic "); 389 qDebug("Using generic ");
389 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 390 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
390 return; 391 return;
391 } 392 }
392 qDebug("Using internal routines for move/copy "); 393 qDebug("Using internal routines for move/copy ");
393 QString tf = buildPath(targetFolder); 394 QString tf = buildPath(targetFolder);
394 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 395 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
395 if (r != MAIL_NO_ERROR) { 396 if (r != MAIL_NO_ERROR) {
396 qDebug("Error selecting source mailbox "); 397 qDebug("Error selecting source mailbox ");
397 return; 398 return;
398 } 399 }
399 if (moveit) { 400 if (moveit) {
400 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 401 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
401 } else { 402 } else {
402 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 403 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
403 } 404 }
404 if (r != MAIL_NO_ERROR) { 405 if (r != MAIL_NO_ERROR) {
405 qDebug("Error copy/moving mail internal "); 406 qDebug("Error copy/moving mail internal ");
406 } 407 }
407} 408}
408 409
409void MHwrapper::mvcpAllMails(const FolderP&fromFolder, 410void MHwrapper::mvcpAllMails(const FolderP&fromFolder,
410 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 411 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
411{ 412{
412 init_storage(); 413 init_storage();
413 if (!m_storage) { 414 if (!m_storage) {
414 return; 415 return;
415 } 416 }
416 if (targetWrapper != this) { 417 if (targetWrapper != this) {
417 qDebug("Using generic "); 418 qDebug("Using generic ");
418 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 419 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
419 return; 420 return;
420 } 421 }
421 if (!fromFolder) return; 422 if (!fromFolder) return;
422 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); 423 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
423 if (r!=MAIL_NO_ERROR) { 424 if (r!=MAIL_NO_ERROR) {
424 qDebug("error selecting source folder! "); 425 qDebug("error selecting source folder! ");
425 return; 426 return;
426 } 427 }
427 QString tf = buildPath(targetFolder); 428 QString tf = buildPath(targetFolder);
428 mailmessage_list*l=0; 429 mailmessage_list*l=0;
429 r = mailsession_get_messages_list(m_storage->sto_session,&l); 430 r = mailsession_get_messages_list(m_storage->sto_session,&l);
430 if (r != MAIL_NO_ERROR) { 431 if (r != MAIL_NO_ERROR) {
431 qDebug("Error message list "); 432 qDebug("Error message list ");
432 } 433 }
433 unsigned j = 0; 434 unsigned j = 0;
434 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { 435 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
435 mailmessage * msg; 436 mailmessage * msg;
436 msg = (mailmessage*)carray_get(l->msg_tab, i); 437 msg = (mailmessage*)carray_get(l->msg_tab, i);
437 j = msg->msg_index; 438 j = msg->msg_index;
438 if (moveit) { 439 if (moveit) {
439 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); 440 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
440 } else { 441 } else {
441 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); 442 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
442 } 443 }
443 if (r != MAIL_NO_ERROR) { 444 if (r != MAIL_NO_ERROR) {
444 qDebug("Error copy/moving mail interna "); 445 qDebug("Error copy/moving mail interna ");
445 446
446 break; 447 break;
447 } 448 }
448 } 449 }
449 if (l) mailmessage_list_free(l); 450 if (l) mailmessage_list_free(l);
450} 451}