summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp30
-rw-r--r--kmicromail/libmailwrapper/abstractmail.h12
-rw-r--r--kmicromail/libmailwrapper/generatemail.cpp6
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.cpp14
-rw-r--r--kmicromail/libmailwrapper/genericwrapper.h6
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp28
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.h14
-rw-r--r--kmicromail/libmailwrapper/libmailwrapper.pro8
-rw-r--r--kmicromail/libmailwrapper/logindialog.cpp2
-rw-r--r--kmicromail/libmailwrapper/logindialog.h2
-rw-r--r--kmicromail/libmailwrapper/mailtypes.cpp10
-rw-r--r--kmicromail/libmailwrapper/mailtypes.h14
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.cpp14
-rw-r--r--kmicromail/libmailwrapper/mailwrapper.h6
-rw-r--r--kmicromail/libmailwrapper/mboxwrapper.cpp14
-rw-r--r--kmicromail/libmailwrapper/mboxwrapper.h10
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp12
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.h8
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.cpp12
-rw-r--r--kmicromail/libmailwrapper/nntpwrapper.h6
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp20
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h8
-rw-r--r--kmicromail/libmailwrapper/sendmailprogress.cpp2
-rw-r--r--kmicromail/libmailwrapper/settings.cpp10
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp6
25 files changed, 159 insertions, 115 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 870985e..746d2ae 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,282 +1,284 @@
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 <q3progressbar.h>
12#include <qapplication.h> 12#include <qapplication.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14//Added by qt3to4:
15#include <Q3ValueList>
14#include <klocale.h> 16#include <klocale.h>
15#include <kdecore/kstandarddirs.h> 17#include <kdecore/kstandarddirs.h>
16#include <qfile.h> 18#include <qfile.h>
17#include <qtextstream.h> 19#include <q3textstream.h>
18#include <stdlib.h> 20#include <stdlib.h>
19#include <libetpan/mailmime_content.h> 21#include <libetpan/mailmime_content.h>
20#include <libetpan/mailmime.h> 22#include <libetpan/mailmime.h>
21 23
22using namespace Opie::Core; 24using namespace Opie::Core;
23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 25AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
24{ 26{
25 return new IMAPwrapper(a); 27 return new IMAPwrapper(a);
26} 28}
27 29
28AbstractMail* AbstractMail::getWrapper(POP3account *a) 30AbstractMail* AbstractMail::getWrapper(POP3account *a)
29{ 31{
30 return new POP3wrapper(a); 32 return new POP3wrapper(a);
31} 33}
32 34
33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 35AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
34{ 36{
35 return new NNTPwrapper(a); 37 return new NNTPwrapper(a);
36} 38}
37 39
38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 40AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
39{ 41{
40 return new MHwrapper(a,name); 42 return new MHwrapper(a,name);
41} 43}
42 44
43AbstractMail* AbstractMail::getWrapper(Account*a) 45AbstractMail* AbstractMail::getWrapper(Account*a)
44{ 46{
45 if (!a) return 0; 47 if (!a) return 0;
46 switch (a->getType()) { 48 switch (a->getType()) {
47 case MAILLIB::A_IMAP: 49 case MAILLIB::A_IMAP:
48 return new IMAPwrapper((IMAPaccount*)a); 50 return new IMAPwrapper((IMAPaccount*)a);
49 break; 51 break;
50 case MAILLIB::A_POP3: 52 case MAILLIB::A_POP3:
51 return new POP3wrapper((POP3account*)a); 53 return new POP3wrapper((POP3account*)a);
52 break; 54 break;
53 case MAILLIB::A_NNTP: 55 case MAILLIB::A_NNTP:
54 return new NNTPwrapper((NNTPaccount*)a); 56 return new NNTPwrapper((NNTPaccount*)a);
55 break; 57 break;
56 default: 58 default:
57 return 0; 59 return 0;
58 } 60 }
59} 61}
60 62
61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 63encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
62{ 64{
63 // odebug << "Decode string start" << oendl; 65 // odebug << "Decode string start" << oendl;
64 char*result_text; 66 char*result_text;
65 size_t index = 0; 67 size_t index = 0;
66 /* reset for recursive use! */ 68 /* reset for recursive use! */
67 size_t target_length = 0; 69 size_t target_length = 0;
68 result_text = 0; 70 result_text = 0;
69 int mimetype = MAILMIME_MECHANISM_7BIT; 71 int mimetype = MAILMIME_MECHANISM_7BIT;
70 if (enc.lower()=="quoted-printable") { 72 if (enc.lower()=="quoted-printable") {
71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 73 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
72 } else if (enc.lower()=="base64") { 74 } else if (enc.lower()=="base64") {
73 mimetype = MAILMIME_MECHANISM_BASE64; 75 mimetype = MAILMIME_MECHANISM_BASE64;
74 } else if (enc.lower()=="8bit") { 76 } else if (enc.lower()=="8bit") {
75 mimetype = MAILMIME_MECHANISM_8BIT; 77 mimetype = MAILMIME_MECHANISM_8BIT;
76 } else if (enc.lower()=="binary") { 78 } else if (enc.lower()=="binary") {
77 mimetype = MAILMIME_MECHANISM_BINARY; 79 mimetype = MAILMIME_MECHANISM_BINARY;
78 } 80 }
79 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 81 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
80 &result_text,&target_length); 82 &result_text,&target_length);
81 83
82 encodedString* result = new encodedString(); 84 encodedString* result = new encodedString();
83 if (err == MAILIMF_NO_ERROR) { 85 if (err == MAILIMF_NO_ERROR) {
84 result->setContent(result_text,target_length); 86 result->setContent(result_text,target_length);
85 } 87 }
86 //odebug << "Decode string finished" << oendl; 88 //odebug << "Decode string finished" << oendl;
87 return result; 89 return result;
88} 90}
89 91
90QString AbstractMail::convert_String(const char*text) 92QString AbstractMail::convert_String(const char*text)
91{ 93{
92 size_t index = 0; 94 size_t index = 0;
93 char*res = 0; 95 char*res = 0;
94 int err = MAILIMF_NO_ERROR; 96 int err = MAILIMF_NO_ERROR;
95 97
96 QString result(text); 98 QString result(text);
97 //qDebug("convert_String %s ", text); 99 //qDebug("convert_String %s ", text);
98 //err = mailmime_encoded_phrase_parse("iso-8859-1", 100 //err = mailmime_encoded_phrase_parse("iso-8859-1",
99 // text, strlen(text),&index, "iso-8859-1",&res); 101 // text, strlen(text),&index, "iso-8859-1",&res);
100 err = mailmime_encoded_phrase_parse("iso-8859-1", 102 err = mailmime_encoded_phrase_parse("iso-8859-1",
101 text, strlen(text),&index, "utf-8",&res); 103 text, strlen(text),&index, "utf-8",&res);
102 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 104 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
103 result = QString::fromUtf8(res); 105 result = QString::fromUtf8(res);
104 } 106 }
105 //qDebug("convert_String:%s ",result.latin1() ); 107 //qDebug("convert_String:%s ",result.latin1() );
106 if (res) free(res); 108 if (res) free(res);
107 return result; 109 return result;
108} 110}
109 111
110/* cp & paste from launcher */ 112/* cp & paste from launcher */
111QString AbstractMail::gen_attachment_id() 113QString AbstractMail::gen_attachment_id()
112{ 114{
113 QFile file( "/proc/sys/kernel/random/uuid" ); 115 QFile file( "/proc/sys/kernel/random/uuid" );
114 if (!file.open(IO_ReadOnly ) ) 116 if (!file.open(QIODevice::ReadOnly ) )
115 return QString::null; 117 return QString::null;
116 118
117 QTextStream stream(&file); 119 Q3TextStream stream(&file);
118 120
119 return "{" + stream.read().stripWhiteSpace() + "}"; 121 return "{" + stream.read().stripWhiteSpace() + "}";
120} 122}
121 123
122int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 124int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
123{ 125{
124 return 0; 126 return 0;
125} 127}
126 128
127QString AbstractMail::defaultLocalfolder() 129QString AbstractMail::defaultLocalfolder()
128{ 130{
129 // QString f = getenv( "HOME" ); 131 // QString f = getenv( "HOME" );
130 QString f = locateLocal( "data", "kopiemail/localmail"); 132 QString f = locateLocal( "data", "kopiemail/localmail");
131 // f += "/Applications/opiemail/localmail"; 133 // f += "/Applications/opiemail/localmail";
132 return f; 134 return f;
133} 135}
134 136
135QString AbstractMail::draftFolder() 137QString AbstractMail::draftFolder()
136{ 138{
137 return QString("Drafts"); 139 return QString("Drafts");
138} 140}
139 141
140/* temporary - will be removed when implemented in all classes */ 142/* temporary - will be removed when implemented in all classes */
141void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 143void AbstractMail::deleteMails(const QString &,const Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &)
142{ 144{
143} 145}
144void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 146void AbstractMail::deleteMailList(const Q3ValueList<RecMailP>&target)
145{ 147{
146 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 148 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
147 // this is currently re-implemented in pop3wrapper and imapwrapper 149 // this is currently re-implemented in pop3wrapper and imapwrapper
148 int iii = 0; 150 int iii = 0;
149 int count = target.count(); 151 int count = target.count();
150 QProgressBar wid ( count ); 152 Q3ProgressBar wid ( count );
151 wid.setCaption( i18n("Deleting ...")); 153 wid.setCaption( i18n("Deleting ..."));
152 wid.show(); 154 wid.show();
153 while (iii < count ) { 155 while (iii < count ) {
154 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 156 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
155 wid.setProgress( iii ); 157 wid.setProgress( iii );
156 wid.raise(); 158 wid.raise();
157 qApp->processEvents(); 159 qApp->processEvents();
158 RecMailP mail = (*target.at( iii )); 160 RecMailP mail = (*target.at( iii ));
159 deleteMail(mail); 161 deleteMail(mail);
160 ++iii; 162 ++iii;
161 } 163 }
162} 164}
163 165
164void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) 166void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
165{ 167{
166 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); 168 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
167 // get local folder 169 // get local folder
168 Account * acc = getAccount(); 170 Account * acc = getAccount();
169 if ( !acc ) return; 171 if ( !acc ) return;
170 QString lfName = acc->getLocalFolder(); 172 QString lfName = acc->getLocalFolder();
171 if ( lfName.isEmpty() ) 173 if ( lfName.isEmpty() )
172 lfName = acc->getAccountName(); 174 lfName = acc->getAccountName();
173 // create local folder 175 // create local folder
174 if ( !targetMail->createMbox(lfName)) 176 if ( !targetMail->createMbox(lfName))
175 { 177 {
176 QMessageBox::critical(0,i18n("Error creating new Folder"), 178 QMessageBox::critical(0,i18n("Error creating new Folder"),
177 i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); 179 i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
178 return; 180 return;
179 } 181 }
180 QValueList<RecMailP> t; 182 Q3ValueList<RecMailP> t;
181 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); 183 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
182 if ( t.count() == 0 ) { 184 if ( t.count() == 0 ) {
183 qDebug("There are no new messages %s", fromFolder->getName().latin1()); 185 qDebug("There are no new messages %s", fromFolder->getName().latin1());
184 Global::statusMessage(i18n("There are no new messages")); 186 Global::statusMessage(i18n("There are no new messages"));
185 return; 187 return;
186 } 188 }
187 Global::statusMessage(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); 189 Global::statusMessage(i18n("%1 :Downloading mails..."). arg(acc->getAccountName()));
188 qDebug(i18n("%1 :Downloading mails..."). arg(acc->getAccountName())); 190 qDebug(i18n("%1 :Downloading mails..."). arg(acc->getAccountName()));
189 qApp->processEvents(); 191 qApp->processEvents();
190 QValueList<RecMailP> e; 192 Q3ValueList<RecMailP> e;
191 targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); 193 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
192 //qDebug("target has mails %d ", e.count()); 194 //qDebug("target has mails %d ", e.count());
193 QValueList<RecMailP> n; 195 Q3ValueList<RecMailP> n;
194 int iii = 0; 196 int iii = 0;
195 int count = t.count(); 197 int count = t.count();
196 while (iii < count ) { 198 while (iii < count ) {
197 RecMailP r = (*t.at( iii )); 199 RecMailP r = (*t.at( iii ));
198 bool found = false; 200 bool found = false;
199 int jjj = 0; 201 int jjj = 0;
200 int countE = e.count(); 202 int countE = e.count();
201 while (jjj < countE ) { 203 while (jjj < countE ) {
202 RecMailP re = (*e.at( jjj )); 204 RecMailP re = (*e.at( jjj ));
203 if ( re->isEqual(r) ) { 205 if ( re->isEqual(r) ) {
204 found = true; 206 found = true;
205 break; 207 break;
206 } 208 }
207 ++jjj; 209 ++jjj;
208 } 210 }
209 if ( !found ) { 211 if ( !found ) {
210 //qDebug("AAAdate *%s* ", r->isodate.latin1() ); 212 //qDebug("AAAdate *%s* ", r->isodate.latin1() );
211 n.append( r ); 213 n.append( r );
212 } 214 }
213 ++iii; 215 ++iii;
214 } 216 }
215 qDebug("Downloaded %d messages ",n.count() ); 217 qDebug("Downloaded %d messages ",n.count() );
216 if ( n.count() == 0 ) { 218 if ( n.count() == 0 ) {
217 Global::statusMessage(i18n("There are no new messages")); 219 Global::statusMessage(i18n("There are no new messages"));
218 return; 220 return;
219 } 221 }
220 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); 222 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
221 Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count())); 223 Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count()));
222 224
223#if 0 225#if 0
224 QValueList<RecMailP> t; 226 Q3ValueList<RecMailP> t;
225 listMessages(fromFolder->getName(),t, maxSizeInKb); 227 listMessages(fromFolder->getName(),t, maxSizeInKb);
226 mvcpMailList( t,targetFolder,targetWrapper,moveit); 228 mvcpMailList( t,targetFolder,targetWrapper,moveit);
227#endif 229#endif
228 230
229} 231}
230void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 232void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
231 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 233 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
232{ 234{
233 QValueList<RecMailP> t; 235 Q3ValueList<RecMailP> t;
234 listMessages(fromFolder->getName(),t, maxSizeInKb); 236 listMessages(fromFolder->getName(),t, maxSizeInKb);
235 mvcpMailList( t,targetFolder,targetWrapper,moveit); 237 mvcpMailList( t,targetFolder,targetWrapper,moveit);
236 238
237} 239}
238void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 240void AbstractMail::mvcpMailList(const Q3ValueList<RecMailP>& t,
239 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 241 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
240{ 242{
241 encodedString*st = 0; 243 encodedString*st = 0;
242 int iii = 0; 244 int iii = 0;
243 int count = t.count(); 245 int count = t.count();
244 if ( count == 0 ) 246 if ( count == 0 )
245 return; 247 return;
246 // wel, processevents is qite strange, we need a widget for getting 248 // wel, processevents is qite strange, we need a widget for getting
247 // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye 249 // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye
248 250
249 QProgressBar wid ( count ); 251 Q3ProgressBar wid ( count );
250 wid.setCaption( i18n("Copying...")); 252 wid.setCaption( i18n("Copying..."));
251 wid.show(); 253 wid.show();
252 while (iii < count ) { 254 while (iii < count ) {
253 Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count)); 255 Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count));
254 wid.setProgress( iii ); 256 wid.setProgress( iii );
255 wid.raise(); 257 wid.raise();
256 qApp->processEvents(); 258 qApp->processEvents();
257 RecMailP r = (*t.at( iii )); 259 RecMailP r = (*t.at( iii ));
258 st = fetchRawBody(r); 260 st = fetchRawBody(r);
259 if (st) { 261 if (st) {
260 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 262 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
261 delete st; 263 delete st;
262 } 264 }
263 ++iii; 265 ++iii;
264 } 266 }
265 if (moveit) { 267 if (moveit) {
266 deleteMailList( t ); 268 deleteMailList( t );
267 //deleteAllMail(fromFolder); 269 //deleteAllMail(fromFolder);
268 } 270 }
269} 271}
270 272
271void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 273void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
272{ 274{
273 encodedString*st = 0; 275 encodedString*st = 0;
274 st = fetchRawBody(mail); 276 st = fetchRawBody(mail);
275 if (st) { 277 if (st) {
276 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 278 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
277 delete st; 279 delete st;
278 } 280 }
279 if (moveit) { 281 if (moveit) {
280 deleteMail(mail); 282 deleteMail(mail);
281 } 283 }
282} 284}
diff --git a/kmicromail/libmailwrapper/abstractmail.h b/kmicromail/libmailwrapper/abstractmail.h
index 2069ca1..f606b1f 100644
--- a/kmicromail/libmailwrapper/abstractmail.h
+++ b/kmicromail/libmailwrapper/abstractmail.h
@@ -1,81 +1,83 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __abstract_mail_ 2#ifndef __abstract_mail_
3#define __abstract_mail_ 3#define __abstract_mail_
4 4
5#include "maildefines.h" 5#include "maildefines.h"
6 6
7#include "settings.h" 7#include "settings.h"
8 8
9#include <qobject.h> 9#include <qobject.h>
10//Added by qt3to4:
11#include <Q3ValueList>
10#include <opie2/osmartpointer.h> 12#include <opie2/osmartpointer.h>
11#include "mailtypes.h" 13#include "mailtypes.h"
12 14
13 15
14#include "mailwrapper.h" 16#include "mailwrapper.h"
15 17
16class IMAPwrapper; 18class IMAPwrapper;
17class POP3wrapper; 19class POP3wrapper;
18class Folder; 20class Folder;
19class encodedString; 21class encodedString;
20struct folderStat; 22struct folderStat;
21 23
22class AbstractMail:public QObject 24class AbstractMail:public QObject
23{ 25{
24 Q_OBJECT 26 Q_OBJECT
25public: 27public:
26 AbstractMail(){}; 28 AbstractMail(){};
27 virtual ~AbstractMail(){} 29 virtual ~AbstractMail(){}
28 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0; 30 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders()=0;
29 virtual void listMessages(const QString & mailbox,QValueList<RecMailP>&target, int sizeInKb = 0 )=0; 31 virtual void listMessages(const QString & mailbox,Q3ValueList<RecMailP>&target, int sizeInKb = 0 )=0;
30 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; 32 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0;
31 virtual RecBodyP fetchBody(const RecMailP&mail)=0; 33 virtual RecBodyP fetchBody(const RecMailP&mail)=0;
32 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0; 34 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part)=0;
33 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0; 35 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part)=0;
34 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0; 36 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part)=0;
35 virtual encodedString* fetchRawBody(const RecMailP&mail)=0; 37 virtual encodedString* fetchRawBody(const RecMailP&mail)=0;
36 38
37 virtual void deleteMail(const RecMailP&mail)=0; 39 virtual void deleteMail(const RecMailP&mail)=0;
38 virtual void deleteMailList(const QValueList<RecMailP>&target); 40 virtual void deleteMailList(const Q3ValueList<RecMailP>&target);
39 virtual void answeredMail(const RecMailP&mail)=0; 41 virtual void answeredMail(const RecMailP&mail)=0;
40 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0; 42 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&)=0;
41 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> >&target); 43 virtual void deleteMails(const QString & FolderName,const Q3ValueList<Opie::Core::OSmartPointer<RecMail> >&target);
42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0; 44 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&)=0;
43 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0; 45 virtual void storeMessage(const char*msg,size_t length, const QString&folder)=0;
44 void downloadNewMails(const FolderP&fromFolder,AbstractMail*targetWrapper ); 46 void downloadNewMails(const FolderP&fromFolder,AbstractMail*targetWrapper );
45 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 47 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
46 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0); 48 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int sizeInKb = 0);
47 virtual void mvcpMailList(const QValueList<RecMailP>& t, 49 virtual void mvcpMailList(const Q3ValueList<RecMailP>& t,
48 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 50 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
49 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 51 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
50 52
51 virtual void cleanMimeCache(){}; 53 virtual void cleanMimeCache(){};
52 /* mail box methods */ 54 /* mail box methods */
53 /* parameter is the box to create. 55 /* parameter is the box to create.
54 * if the implementing subclass has prefixes, 56 * if the implementing subclass has prefixes,
55 * them has to be appended automatic. 57 * them has to be appended automatic.
56 */ 58 */
57 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 59 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
58 const QString& delemiter="/",bool getsubfolder=false); 60 const QString& delemiter="/",bool getsubfolder=false);
59 virtual void logout()=0; 61 virtual void logout()=0;
60 62
61 virtual Account* getAccount() = 0; 63 virtual Account* getAccount() = 0;
62 64
63 static AbstractMail* getWrapper(IMAPaccount *a); 65 static AbstractMail* getWrapper(IMAPaccount *a);
64 static AbstractMail* getWrapper(POP3account *a); 66 static AbstractMail* getWrapper(POP3account *a);
65 static AbstractMail* getWrapper(NNTPaccount *a); 67 static AbstractMail* getWrapper(NNTPaccount *a);
66 /* mbox only! */ 68 /* mbox only! */
67 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders"); 69 static AbstractMail* getWrapper(const QString&a,const QString&name="Local Folders");
68 static AbstractMail* getWrapper(Account*a); 70 static AbstractMail* getWrapper(Account*a);
69 71
70 static QString defaultLocalfolder(); 72 static QString defaultLocalfolder();
71 static QString draftFolder(); 73 static QString draftFolder();
72 74
73 virtual MAILLIB::ATYPE getType()const=0; 75 virtual MAILLIB::ATYPE getType()const=0;
74 virtual const QString&getName()const=0; 76 virtual const QString&getName()const=0;
75 77
76protected: 78protected:
77 static encodedString*decode_String(const encodedString*text,const QString&enc); 79 static encodedString*decode_String(const encodedString*text,const QString&enc);
78 static QString convert_String(const char*text); 80 static QString convert_String(const char*text);
79 static QString gen_attachment_id(); 81 static QString gen_attachment_id();
80}; 82};
81#endif 83#endif
diff --git a/kmicromail/libmailwrapper/generatemail.cpp b/kmicromail/libmailwrapper/generatemail.cpp
index 2d213fe..ddad21b 100644
--- a/kmicromail/libmailwrapper/generatemail.cpp
+++ b/kmicromail/libmailwrapper/generatemail.cpp
@@ -1,467 +1,469 @@
1#include "generatemail.h" 1#include "generatemail.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3 3
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5 5
6//#include <qt.h> 6//#include <qt.h>
7 7
8#include <stdlib.h> 8#include <stdlib.h>
9#include <qfileinfo.h> 9#include <qfileinfo.h>
10//Added by qt3to4:
11#include <Q3CString>
10 12
11using namespace Opie::Core; 13using namespace Opie::Core;
12const char* Generatemail::USER_AGENT="KOpieMail 33 1/3"; 14const char* Generatemail::USER_AGENT="KOpieMail 33 1/3";
13 15
14Generatemail::Generatemail() 16Generatemail::Generatemail()
15{ 17{
16 mCharset = "iso-8859-1"; 18 mCharset = "iso-8859-1";
17} 19}
18 20
19Generatemail::~Generatemail() 21Generatemail::~Generatemail()
20{ 22{
21} 23}
22 24
23void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) { 25void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
24 clistiter *it, *it2; 26 clistiter *it, *it2;
25 27
26 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) { 28 for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
27 mailimf_address *addr; 29 mailimf_address *addr;
28 addr = (mailimf_address *) it->data; 30 addr = (mailimf_address *) it->data;
29 31
30 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) { 32 if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
31 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL ); 33 esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
32 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) { 34 } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
33 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list; 35 clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
34 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) { 36 for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
35 mailimf_mailbox *mbox; 37 mailimf_mailbox *mbox;
36 mbox = (mailimf_mailbox *) it2->data; 38 mbox = (mailimf_mailbox *) it2->data;
37 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL ); 39 esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
38 } 40 }
39 } 41 }
40 } 42 }
41} 43}
42 44
43char *Generatemail::getFrom( mailimf_field *ffrom) { 45char *Generatemail::getFrom( mailimf_field *ffrom) {
44 char *from = NULL; 46 char *from = NULL;
45 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM) 47 if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
46 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) { 48 && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
47 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list; 49 clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
48 clistiter *it; 50 clistiter *it;
49 for ( it = clist_begin( cl ); it; it = it->next ) { 51 for ( it = clist_begin( cl ); it; it = it->next ) {
50 mailimf_mailbox *mb = (mailimf_mailbox *) it->data; 52 mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
51 from = strdup( mb->mb_addr_spec ); 53 from = strdup( mb->mb_addr_spec );
52 } 54 }
53 } 55 }
54 56
55 return from; 57 return from;
56} 58}
57 59
58char *Generatemail::getFrom( mailmime *mail ) { 60char *Generatemail::getFrom( mailmime *mail ) {
59 /* no need to delete - its just a pointer to structure content */ 61 /* no need to delete - its just a pointer to structure content */
60 mailimf_field *ffrom = 0; 62 mailimf_field *ffrom = 0;
61 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM ); 63 ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
62 return getFrom(ffrom); 64 return getFrom(ffrom);
63} 65}
64 66
65mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) { 67mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
66 mailimf_field *field; 68 mailimf_field *field;
67 clistiter *it; 69 clistiter *it;
68 70
69 it = clist_begin( fields->fld_list ); 71 it = clist_begin( fields->fld_list );
70 while ( it ) { 72 while ( it ) {
71 field = (mailimf_field *) it->data; 73 field = (mailimf_field *) it->data;
72 if ( field->fld_type == type ) { 74 if ( field->fld_type == type ) {
73 return field; 75 return field;
74 } 76 }
75 it = it->next; 77 it = it->next;
76 } 78 }
77 79
78 return NULL; 80 return NULL;
79} 81}
80 82
81mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) { 83mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
82 mailimf_address_list *addresses; 84 mailimf_address_list *addresses;
83 85
84 if ( addr.isEmpty() ) 86 if ( addr.isEmpty() )
85 return NULL; 87 return NULL;
86 88
87 addresses = mailimf_address_list_new_empty(); 89 addresses = mailimf_address_list_new_empty();
88 90
89 bool literal_open = false; 91 bool literal_open = false;
90 unsigned int startpos = 0; 92 unsigned int startpos = 0;
91 QStringList list; 93 QStringList list;
92 QString s; 94 QString s;
93 unsigned int i = 0; 95 unsigned int i = 0;
94 for (; i < addr.length();++i) { 96 for (; i < addr.length();++i) {
95 switch (addr[i]) { 97 switch (addr[i]) {
96 case '\"': 98 case '\"':
97 literal_open = !literal_open; 99 literal_open = !literal_open;
98 break; 100 break;
99 case ',': 101 case ',':
100 if (!literal_open) { 102 if (!literal_open) {
101 s = addr.mid(startpos,i-startpos); 103 s = addr.mid(startpos,i-startpos);
102 if (!s.isEmpty()) { 104 if (!s.isEmpty()) {
103 list.append(s); 105 list.append(s);
104 } 106 }
105 // !!!! this is a MUST BE! 107 // !!!! this is a MUST BE!
106 startpos = ++i; 108 startpos = ++i;
107 } 109 }
108 break; 110 break;
109 default: 111 default:
110 break; 112 break;
111 } 113 }
112 } 114 }
113 s = addr.mid(startpos,i-startpos); 115 s = addr.mid(startpos,i-startpos);
114 if (!s.isEmpty()) { 116 if (!s.isEmpty()) {
115 list.append(s); 117 list.append(s);
116 } 118 }
117 QStringList::Iterator it; 119 QStringList::Iterator it;
118 for ( it = list.begin(); it != list.end(); it++ ) { 120 for ( it = list.begin(); it != list.end(); it++ ) {
119 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() ); 121 int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
120 if ( err != MAILIMF_NO_ERROR ) { 122 if ( err != MAILIMF_NO_ERROR ) {
121 qDebug(" Error parsing"); // *it 123 qDebug(" Error parsing"); // *it
122 } else { 124 } else {
123 } 125 }
124 } 126 }
125 return addresses; 127 return addresses;
126} 128}
127 129
128mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) { 130mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
129 mailmime * filePart = 0; 131 mailmime * filePart = 0;
130 mailmime_fields * fields = 0; 132 mailmime_fields * fields = 0;
131 mailmime_content * content = 0; 133 mailmime_content * content = 0;
132 mailmime_parameter * param = 0; 134 mailmime_parameter * param = 0;
133 char*name = 0; 135 char*name = 0;
134 char*file = 0; 136 char*file = 0;
135 int err; 137 int err;
136 int pos = filename.findRev( '/' ); 138 int pos = filename.findRev( '/' );
137 139
138 if (filename.length()>0) { 140 if (filename.length()>0) {
139 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 141 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
140 name = strdup( tmp.latin1() ); // just filename 142 name = strdup( tmp.latin1() ); // just filename
141 file = strdup( filename.latin1() ); // full name with path 143 file = strdup( filename.latin1() ); // full name with path
142 } 144 }
143 145
144 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 146 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
145 int mechanism = MAILMIME_MECHANISM_BASE64; 147 int mechanism = MAILMIME_MECHANISM_BASE64;
146 148
147 if ( mimetype.startsWith( "text/" ) ) { 149 if ( mimetype.startsWith( "text/" ) ) {
148 param = mailmime_parameter_new( strdup( "charset" ), 150 param = mailmime_parameter_new( strdup( "charset" ),
149 strdup( mCharset.latin1() ) ); 151 strdup( mCharset.latin1() ) );
150 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 152 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
151 } 153 }
152 154
153 fields = mailmime_fields_new_filename( 155 fields = mailmime_fields_new_filename(
154 disptype, name, 156 disptype, name,
155 mechanism ); 157 mechanism );
156 content = mailmime_content_new_with_str( (char*)mimetype.latin1() ); 158 content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
157 if (content!=0 && fields != 0) { 159 if (content!=0 && fields != 0) {
158 if (param) { 160 if (param) {
159 clist_append(content->ct_parameters,param); 161 clist_append(content->ct_parameters,param);
160 param = 0; 162 param = 0;
161 } 163 }
162 if (filename.length()>0) { 164 if (filename.length()>0) {
163 QFileInfo f(filename); 165 QFileInfo f(filename);
164 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1())); 166 param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
165 clist_append(content->ct_parameters,param); 167 clist_append(content->ct_parameters,param);
166 param = 0; 168 param = 0;
167 } 169 }
168 filePart = mailmime_new_empty( content, fields ); 170 filePart = mailmime_new_empty( content, fields );
169 } 171 }
170 if (filePart) { 172 if (filePart) {
171 if (filename.length()>0) { 173 if (filename.length()>0) {
172 err = mailmime_set_body_file( filePart, file ); 174 err = mailmime_set_body_file( filePart, file );
173 } else { 175 } else {
174 err = mailmime_set_body_text(filePart,strdup( TextContent.utf8().data()),TextContent.utf8().length()); 176 err = mailmime_set_body_text(filePart,strdup( TextContent.utf8().data()),TextContent.utf8().length());
175 //err = mailmime_set_body_text(filePart,strdup( TextContent.latin1()),TextContent.length()); 177 //err = mailmime_set_body_text(filePart,strdup( TextContent.latin1()),TextContent.length());
176 } 178 }
177 if (err != MAILIMF_NO_ERROR) { 179 if (err != MAILIMF_NO_ERROR) {
178 qDebug("Error setting body with file "); 180 qDebug("Error setting body with file ");
179 mailmime_free( filePart ); 181 mailmime_free( filePart );
180 filePart = 0; 182 filePart = 0;
181 } 183 }
182 } 184 }
183 185
184 if (!filePart) { 186 if (!filePart) {
185 if ( param != NULL ) { 187 if ( param != NULL ) {
186 mailmime_parameter_free( param ); 188 mailmime_parameter_free( param );
187 } 189 }
188 if (content) { 190 if (content) {
189 mailmime_content_free( content ); 191 mailmime_content_free( content );
190 } 192 }
191 if (fields) { 193 if (fields) {
192 mailmime_fields_free( fields ); 194 mailmime_fields_free( fields );
193 } else { 195 } else {
194 if (name) { 196 if (name) {
195 free( name ); 197 free( name );
196 } 198 }
197 if (file) { 199 if (file) {
198 free( file ); 200 free( file );
199 } 201 }
200 } 202 }
201 } 203 }
202 return filePart; // Success :) 204 return filePart; // Success :)
203 205
204} 206}
205 207
206void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) { 208void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
207 const Attachment *it; 209 const Attachment *it;
208 unsigned int count = files.count(); 210 unsigned int count = files.count();
209 for ( unsigned int i = 0; i < count; ++i ) { 211 for ( unsigned int i = 0; i < count; ++i ) {
210 mailmime *filePart; 212 mailmime *filePart;
211 int err; 213 int err;
212 it = ((QList<Attachment>)files).at(i); 214 it = ((QList<Attachment>)files).at(i);
213 215
214 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" ); 216 filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
215 if ( filePart == NULL ) { 217 if ( filePart == NULL ) {
216 continue; 218 continue;
217 } 219 }
218 err = mailmime_smart_add_part( message, filePart ); 220 err = mailmime_smart_add_part( message, filePart );
219 if ( err != MAILIMF_NO_ERROR ) { 221 if ( err != MAILIMF_NO_ERROR ) {
220 mailmime_free( filePart ); 222 mailmime_free( filePart );
221 } 223 }
222 } 224 }
223} 225}
224 226
225mailmime *Generatemail::buildTxtPart(const QString&str ) { 227mailmime *Generatemail::buildTxtPart(const QString&str ) {
226 mailmime *txtPart; 228 mailmime *txtPart;
227 mailmime_fields *fields; 229 mailmime_fields *fields;
228 mailmime_content *content; 230 mailmime_content *content;
229 mailmime_parameter *param; 231 mailmime_parameter *param;
230 int err; 232 int err;
231 QCString __str; 233 Q3CString __str;
232 //qDebug(" Generatemail::buildTxtPart %s", str.latin1()); 234 //qDebug(" Generatemail::buildTxtPart %s", str.latin1());
233 param = mailmime_parameter_new( strdup( "charset" ), 235 param = mailmime_parameter_new( strdup( "charset" ),
234 strdup( mCharset.latin1() ) ); 236 strdup( mCharset.latin1() ) );
235 if ( param == NULL ) 237 if ( param == NULL )
236 goto err_free; 238 goto err_free;
237 239
238 content = mailmime_content_new_with_str( "text/plain" ); 240 content = mailmime_content_new_with_str( "text/plain" );
239 if ( content == NULL ) 241 if ( content == NULL )
240 goto err_free_param; 242 goto err_free_param;
241 243
242 err = clist_append( content->ct_parameters, param ); 244 err = clist_append( content->ct_parameters, param );
243 if ( err != MAILIMF_NO_ERROR ) 245 if ( err != MAILIMF_NO_ERROR )
244 goto err_free_content; 246 goto err_free_content;
245 247
246 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT); 248 fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
247 if ( fields == NULL ) 249 if ( fields == NULL )
248 goto err_free_content; 250 goto err_free_content;
249 251
250 txtPart = mailmime_new_empty( content, fields ); 252 txtPart = mailmime_new_empty( content, fields );
251 if ( txtPart == NULL ) 253 if ( txtPart == NULL )
252 goto err_free_fields; 254 goto err_free_fields;
253 { 255 {
254 //__str = str.utf8(); 256 //__str = str.utf8();
255 __str = QCString (str.latin1()); 257 __str = Q3CString (str.latin1());
256 err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() ); 258 err = mailmime_set_body_text( txtPart, strdup(__str.data()), __str.length() );
257 } 259 }
258 if ( err != MAILIMF_NO_ERROR ) 260 if ( err != MAILIMF_NO_ERROR )
259 goto err_free_txtPart; 261 goto err_free_txtPart;
260 262
261 return txtPart; // Success :) 263 return txtPart; // Success :)
262 264
263err_free_txtPart: 265err_free_txtPart:
264 mailmime_free( txtPart ); 266 mailmime_free( txtPart );
265err_free_fields: 267err_free_fields:
266 mailmime_fields_free( fields ); 268 mailmime_fields_free( fields );
267err_free_content: 269err_free_content:
268 mailmime_content_free( content ); 270 mailmime_content_free( content );
269err_free_param: 271err_free_param:
270 mailmime_parameter_free( param ); 272 mailmime_parameter_free( param );
271err_free: 273err_free:
272 ; 274 ;
273 275
274 return NULL; // Error :( 276 return NULL; // Error :(
275} 277}
276 278
277mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) { 279mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
278 return mailimf_mailbox_new( strdup( name.latin1() ), 280 return mailimf_mailbox_new( strdup( name.latin1() ),
279 strdup( mail.latin1() ) ); 281 strdup( mail.latin1() ) );
280} 282}
281 283
282mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail ) 284mailimf_fields *Generatemail::createImfFields(const Opie::Core::OSmartPointer<Mail>&mail )
283{ 285{
284 mailimf_fields *fields = NULL; 286 mailimf_fields *fields = NULL;
285 mailimf_field *xmailer = NULL; 287 mailimf_field *xmailer = NULL;
286 mailimf_mailbox *sender=0,*fromBox=0; 288 mailimf_mailbox *sender=0,*fromBox=0;
287 mailimf_mailbox_list *from=0; 289 mailimf_mailbox_list *from=0;
288 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0; 290 mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
289 clist*in_reply_to = 0; 291 clist*in_reply_to = 0;
290 char *subject = strdup( mail->getSubject().latin1() ); 292 char *subject = strdup( mail->getSubject().latin1() );
291 int err; 293 int err;
292 int res = 1; 294 int res = 1;
293 295
294 sender = newMailbox( mail->getName(), mail->getMail() ); 296 sender = newMailbox( mail->getName(), mail->getMail() );
295 if ( sender == NULL ) { 297 if ( sender == NULL ) {
296 res = 0; 298 res = 0;
297 } 299 }
298 300
299 if (res) { 301 if (res) {
300 fromBox = newMailbox( mail->getName(), mail->getMail() ); 302 fromBox = newMailbox( mail->getName(), mail->getMail() );
301 } 303 }
302 if ( fromBox == NULL ) { 304 if ( fromBox == NULL ) {
303 res = 0; 305 res = 0;
304 } 306 }
305 307
306 if (res) { 308 if (res) {
307 from = mailimf_mailbox_list_new_empty(); 309 from = mailimf_mailbox_list_new_empty();
308 } 310 }
309 if ( from == NULL ) { 311 if ( from == NULL ) {
310 res = 0; 312 res = 0;
311 } 313 }
312 314
313 if (res && from) { 315 if (res && from) {
314 err = mailimf_mailbox_list_add( from, fromBox ); 316 err = mailimf_mailbox_list_add( from, fromBox );
315 if ( err != MAILIMF_NO_ERROR ) { 317 if ( err != MAILIMF_NO_ERROR ) {
316 res = 0; 318 res = 0;
317 } 319 }
318 } 320 }
319 321
320 if (res) to = parseAddresses( mail->getTo() ); 322 if (res) to = parseAddresses( mail->getTo() );
321 if (res) cc = parseAddresses( mail->getCC() ); 323 if (res) cc = parseAddresses( mail->getCC() );
322 if (res) bcc = parseAddresses( mail->getBCC() ); 324 if (res) bcc = parseAddresses( mail->getBCC() );
323 if (res) reply = parseAddresses( mail->getReply() ); 325 if (res) reply = parseAddresses( mail->getReply() );
324 326
325 if (res && mail->Inreply().count()>0) { 327 if (res && mail->Inreply().count()>0) {
326 in_reply_to = clist_new(); 328 in_reply_to = clist_new();
327 char*c_reply; 329 char*c_reply;
328 unsigned int nsize = 0; 330 unsigned int nsize = 0;
329 for (QStringList::ConstIterator it=mail->Inreply().begin(); 331 for (QStringList::ConstIterator it=mail->Inreply().begin();
330 it != mail->Inreply().end();++it) { 332 it != mail->Inreply().end();++it) {
331 if ((*it).isEmpty()) 333 if ((*it).isEmpty())
332 continue; 334 continue;
333 QString h((*it)); 335 QString h((*it));
334 while (h.length()>0 && h[0]=='<') { 336 while (h.length()>0 && h[0]=='<') {
335 h.remove(0,1); 337 h.remove(0,1);
336 } 338 }
337 while (h.length()>0 && h[h.length()-1]=='>') { 339 while (h.length()>0 && h[h.length()-1]=='>') {
338 h.remove(h.length()-1,1); 340 h.remove(h.length()-1,1);
339 } 341 }
340 if (h.isEmpty()) continue; 342 if (h.isEmpty()) continue;
341 nsize = strlen(h.latin1()); 343 nsize = strlen(h.latin1());
342 /* yes! must be malloc! */ 344 /* yes! must be malloc! */
343 c_reply = (char*)malloc( (nsize+1)*sizeof(char)); 345 c_reply = (char*)malloc( (nsize+1)*sizeof(char));
344 memset(c_reply,0,nsize+1); 346 memset(c_reply,0,nsize+1);
345 memcpy(c_reply,h.latin1(),nsize); 347 memcpy(c_reply,h.latin1(),nsize);
346 clist_append(in_reply_to,c_reply); 348 clist_append(in_reply_to,c_reply);
347 } 349 }
348 } 350 }
349 351
350 if (res) { 352 if (res) {
351 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc, 353 fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
352 in_reply_to, NULL, subject ); 354 in_reply_to, NULL, subject );
353 if ( fields == NULL ) { 355 if ( fields == NULL ) {
354 res = 0; 356 res = 0;
355 } 357 }
356 } 358 }
357 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ), 359 if (res) xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
358 strdup( USER_AGENT ) ); 360 strdup( USER_AGENT ) );
359 if ( xmailer == NULL ) { 361 if ( xmailer == NULL ) {
360 res = 0; 362 res = 0;
361 } else { 363 } else {
362 err = mailimf_fields_add( fields, xmailer ); 364 err = mailimf_fields_add( fields, xmailer );
363 if ( err != MAILIMF_NO_ERROR ) { 365 if ( err != MAILIMF_NO_ERROR ) {
364 res = 0; 366 res = 0;
365 } 367 }
366 } 368 }
367 if (!res ) { 369 if (!res ) {
368 if (xmailer) { 370 if (xmailer) {
369 mailimf_field_free( xmailer ); 371 mailimf_field_free( xmailer );
370 xmailer = NULL; 372 xmailer = NULL;
371 } 373 }
372 if (fields) { 374 if (fields) {
373 mailimf_fields_free( fields ); 375 mailimf_fields_free( fields );
374 fields = NULL; 376 fields = NULL;
375 } else { 377 } else {
376 if (reply) 378 if (reply)
377 mailimf_address_list_free( reply ); 379 mailimf_address_list_free( reply );
378 if (bcc) 380 if (bcc)
379 mailimf_address_list_free( bcc ); 381 mailimf_address_list_free( bcc );
380 if (cc) 382 if (cc)
381 mailimf_address_list_free( cc ); 383 mailimf_address_list_free( cc );
382 if (to) 384 if (to)
383 mailimf_address_list_free( to ); 385 mailimf_address_list_free( to );
384 if (fromBox) { 386 if (fromBox) {
385 mailimf_mailbox_free( fromBox ); 387 mailimf_mailbox_free( fromBox );
386 } else if (from) { 388 } else if (from) {
387 mailimf_mailbox_list_free( from ); 389 mailimf_mailbox_list_free( from );
388 } 390 }
389 if (sender) { 391 if (sender) {
390 mailimf_mailbox_free( sender ); 392 mailimf_mailbox_free( sender );
391 } 393 }
392 if (subject) { 394 if (subject) {
393 free( subject ); 395 free( subject );
394 } 396 }
395 } 397 }
396 } 398 }
397 return fields; 399 return fields;
398} 400}
399 401
400mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) { 402mailmime *Generatemail::createMimeMail(const Opie::Core::OSmartPointer<Mail> &mail ) {
401 mailmime *message, *txtPart; 403 mailmime *message, *txtPart;
402 mailimf_fields *fields; 404 mailimf_fields *fields;
403 int err; 405 int err;
404 406
405 //LR disabled for now 407 //LR disabled for now
406 //mCharset = mail->getCharset().lower(); 408 //mCharset = mail->getCharset().lower();
407 fields = createImfFields( mail ); 409 fields = createImfFields( mail );
408 if ( fields == NULL ) 410 if ( fields == NULL )
409 goto err_free; 411 goto err_free;
410 412
411 message = mailmime_new_message_data( NULL ); 413 message = mailmime_new_message_data( NULL );
412 if ( message == NULL ) 414 if ( message == NULL )
413 goto err_free_fields; 415 goto err_free_fields;
414 416
415 mailmime_set_imf_fields( message, fields ); 417 mailmime_set_imf_fields( message, fields );
416 418
417 txtPart = buildTxtPart( mail->getMessage() ); 419 txtPart = buildTxtPart( mail->getMessage() );
418 420
419 if ( txtPart == NULL ) 421 if ( txtPart == NULL )
420 goto err_free_message; 422 goto err_free_message;
421 423
422 err = mailmime_smart_add_part( message, txtPart ); 424 err = mailmime_smart_add_part( message, txtPart );
423 if ( err != MAILIMF_NO_ERROR ) 425 if ( err != MAILIMF_NO_ERROR )
424 goto err_free_txtPart; 426 goto err_free_txtPart;
425 427
426 addFileParts( message, mail->getAttachments() ); 428 addFileParts( message, mail->getAttachments() );
427 429
428 return message; // Success :) 430 return message; // Success :)
429 431
430err_free_txtPart: 432err_free_txtPart:
431 mailmime_free( txtPart ); 433 mailmime_free( txtPart );
432err_free_message: 434err_free_message:
433 mailmime_free( message ); 435 mailmime_free( message );
434err_free_fields: 436err_free_fields:
435 mailimf_fields_free( fields ); 437 mailimf_fields_free( fields );
436err_free: 438err_free:
437 ; 439 ;
438 440
439 return NULL; // Error :( 441 return NULL; // Error :(
440} 442}
441 443
442clist *Generatemail::createRcptList( mailimf_fields *fields ) { 444clist *Generatemail::createRcptList( mailimf_fields *fields ) {
443 clist *rcptList; 445 clist *rcptList;
444 mailimf_field *field; 446 mailimf_field *field;
445 447
446 rcptList = esmtp_address_list_new(); 448 rcptList = esmtp_address_list_new();
447 449
448 field = getField( fields, MAILIMF_FIELD_TO ); 450 field = getField( fields, MAILIMF_FIELD_TO );
449 if ( field && (field->fld_type == MAILIMF_FIELD_TO) 451 if ( field && (field->fld_type == MAILIMF_FIELD_TO)
450 && field->fld_data.fld_to->to_addr_list ) { 452 && field->fld_data.fld_to->to_addr_list ) {
451 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list ); 453 addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
452 } 454 }
453 455
454 field = getField( fields, MAILIMF_FIELD_CC ); 456 field = getField( fields, MAILIMF_FIELD_CC );
455 if ( field && (field->fld_type == MAILIMF_FIELD_CC) 457 if ( field && (field->fld_type == MAILIMF_FIELD_CC)
456 && field->fld_data.fld_cc->cc_addr_list ) { 458 && field->fld_data.fld_cc->cc_addr_list ) {
457 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list ); 459 addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
458 } 460 }
459 461
460 field = getField( fields, MAILIMF_FIELD_BCC ); 462 field = getField( fields, MAILIMF_FIELD_BCC );
461 if ( field && (field->fld_type == MAILIMF_FIELD_BCC) 463 if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
462 && field->fld_data.fld_bcc->bcc_addr_list ) { 464 && field->fld_data.fld_bcc->bcc_addr_list ) {
463 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list ); 465 addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
464 } 466 }
465 467
466 return rcptList; 468 return rcptList;
467} 469}
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp
index 0b6adf7..633ab42 100644
--- a/kmicromail/libmailwrapper/genericwrapper.cpp
+++ b/kmicromail/libmailwrapper/genericwrapper.cpp
@@ -1,549 +1,551 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "genericwrapper.h" 2#include "genericwrapper.h"
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <kconfig.h> 6#include <kconfig.h>
7#include <kglobal.h> 7#include <kglobal.h>
8#include <kstandarddirs.h> 8#include <kstandarddirs.h>
9//Added by qt3to4:
10#include <Q3ValueList>
9 11
10 12
11using namespace Opie::Core; 13using namespace Opie::Core;
12Genericwrapper::Genericwrapper() 14Genericwrapper::Genericwrapper()
13 : AbstractMail() 15 : AbstractMail()
14{ 16{
15 bodyCache.clear(); 17 bodyCache.clear();
16 m_storage = 0; 18 m_storage = 0;
17 m_folder = 0; 19 m_folder = 0;
18} 20}
19 21
20Genericwrapper::~Genericwrapper() 22Genericwrapper::~Genericwrapper()
21{ 23{
22 if (m_folder) { 24 if (m_folder) {
23 mailfolder_free(m_folder); 25 mailfolder_free(m_folder);
24 } 26 }
25 if (m_storage) { 27 if (m_storage) {
26 mailstorage_free(m_storage); 28 mailstorage_free(m_storage);
27 } 29 }
28 cleanMimeCache(); 30 cleanMimeCache();
29} 31}
30const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date ) 32const QDateTime Genericwrapper::parseDateTime( mailimf_date_time *date )
31{ 33{
32 34
33 QDate da (date->dt_year,date->dt_month, date->dt_day ); 35 QDate da (date->dt_year,date->dt_month, date->dt_day );
34 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec ); 36 QTime ti ( date->dt_hour, date->dt_min, date->dt_sec );
35 QDateTime dt ( da ,ti ); 37 QDateTime dt ( da ,ti );
36 int addsec = -date->dt_zone*36; 38 int addsec = -date->dt_zone*36;
37 //qDebug("adsec1 %d ",addsec ); 39 //qDebug("adsec1 %d ",addsec );
38 dt = dt.addSecs( addsec ); 40 dt = dt.addSecs( addsec );
39 int off = KGlobal::locale()->localTimeOffset( dt ); 41 int off = KGlobal::locale()->localTimeOffset( dt );
40 //qDebug("adsec2 %d ",off*60 ); 42 //qDebug("adsec2 %d ",off*60 );
41 43
42 dt = dt.addSecs( off*60 ); 44 dt = dt.addSecs( off*60 );
43 return dt; 45 return dt;
44#if 0 46#if 0
45 QString ret; 47 QString ret;
46 if ( dt.date() == QDate::currentDate () ) 48 if ( dt.date() == QDate::currentDate () )
47 ret = KGlobal::locale()->formatTime( dt.time(),true); 49 ret = KGlobal::locale()->formatTime( dt.time(),true);
48 50
49 else { 51 else {
50 ret = KGlobal::locale()->formatDateTime( dt,true,true); 52 ret = KGlobal::locale()->formatDateTime( dt,true,true);
51 } 53 }
52#endif 54#endif
53#if 0 55#if 0
54 if ( off < 0 ) 56 if ( off < 0 )
55 ret += " -"; 57 ret += " -";
56 else 58 else
57 ret += " +"; 59 ret += " +";
58 ret += QString::number( off / 60 ); 60 ret += QString::number( off / 60 );
59 ret += "h"; 61 ret += "h";
60#endif 62#endif
61#if 0 63#if 0
62 char tmp[23]; 64 char tmp[23];
63 65
64 // snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 66 // 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 ); 67 // 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", 68 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 ); 69 date->dt_year,date->dt_month, date->dt_day, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
68 70
69 71
70 return QString( tmp ); 72 return QString( tmp );
71#endif 73#endif
72 //return ret; 74 //return ret;
73} 75}
74 76
75void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime) 77void Genericwrapper::fillSingleBody(RecPartP&target,mailmessage*,mailmime*mime)
76{ 78{
77 if (!mime) { 79 if (!mime) {
78 return; 80 return;
79 } 81 }
80 mailmime_field*field = 0; 82 mailmime_field*field = 0;
81 mailmime_single_fields fields; 83 mailmime_single_fields fields;
82 memset(&fields, 0, sizeof(struct mailmime_single_fields)); 84 memset(&fields, 0, sizeof(struct mailmime_single_fields));
83 if (mime->mm_mime_fields != NULL) { 85 if (mime->mm_mime_fields != NULL) {
84 mailmime_single_fields_init(&fields, mime->mm_mime_fields, 86 mailmime_single_fields_init(&fields, mime->mm_mime_fields,
85 mime->mm_content_type); 87 mime->mm_content_type);
86 } 88 }
87 89
88 mailmime_content*type = fields.fld_content; 90 mailmime_content*type = fields.fld_content;
89 clistcell*current; 91 clistcell*current;
90 if (!type) { 92 if (!type) {
91 target->setType("text"); 93 target->setType("text");
92 target->setSubtype("plain"); 94 target->setSubtype("plain");
93 } else { 95 } else {
94 target->setSubtype(type->ct_subtype); 96 target->setSubtype(type->ct_subtype);
95 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { 97 switch(type->ct_type->tp_data.tp_discrete_type->dt_type) {
96 case MAILMIME_DISCRETE_TYPE_TEXT: 98 case MAILMIME_DISCRETE_TYPE_TEXT:
97 target->setType("text"); 99 target->setType("text");
98 break; 100 break;
99 case MAILMIME_DISCRETE_TYPE_IMAGE: 101 case MAILMIME_DISCRETE_TYPE_IMAGE:
100 target->setType("image"); 102 target->setType("image");
101 break; 103 break;
102 case MAILMIME_DISCRETE_TYPE_AUDIO: 104 case MAILMIME_DISCRETE_TYPE_AUDIO:
103 target->setType("audio"); 105 target->setType("audio");
104 break; 106 break;
105 case MAILMIME_DISCRETE_TYPE_VIDEO: 107 case MAILMIME_DISCRETE_TYPE_VIDEO:
106 target->setType("video"); 108 target->setType("video");
107 break; 109 break;
108 case MAILMIME_DISCRETE_TYPE_APPLICATION: 110 case MAILMIME_DISCRETE_TYPE_APPLICATION:
109 target->setType("application"); 111 target->setType("application");
110 break; 112 break;
111 case MAILMIME_DISCRETE_TYPE_EXTENSION: 113 case MAILMIME_DISCRETE_TYPE_EXTENSION:
112 default: 114 default:
113 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { 115 if (type->ct_type->tp_data.tp_discrete_type->dt_extension) {
114 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); 116 target->setType(type->ct_type->tp_data.tp_discrete_type->dt_extension);
115 } 117 }
116 break; 118 break;
117 } 119 }
118 if (type->ct_parameters) { 120 if (type->ct_parameters) {
119 fillParameters(target,type->ct_parameters); 121 fillParameters(target,type->ct_parameters);
120 } 122 }
121 } 123 }
122 if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { 124 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)) { 125 for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) {
124 field = (mailmime_field*)current->data; 126 field = (mailmime_field*)current->data;
125 switch(field->fld_type) { 127 switch(field->fld_type) {
126 case MAILMIME_FIELD_TRANSFER_ENCODING: 128 case MAILMIME_FIELD_TRANSFER_ENCODING:
127 target->setEncoding(getencoding(field->fld_data.fld_encoding)); 129 target->setEncoding(getencoding(field->fld_data.fld_encoding));
128 break; 130 break;
129 case MAILMIME_FIELD_ID: 131 case MAILMIME_FIELD_ID:
130 target->setIdentifier(field->fld_data.fld_id); 132 target->setIdentifier(field->fld_data.fld_id);
131 break; 133 break;
132 case MAILMIME_FIELD_DESCRIPTION: 134 case MAILMIME_FIELD_DESCRIPTION:
133 target->setDescription(field->fld_data.fld_description); 135 target->setDescription(field->fld_data.fld_description);
134 break; 136 break;
135 default: 137 default:
136 break; 138 break;
137 } 139 }
138 } 140 }
139 } 141 }
140} 142}
141 143
142void Genericwrapper::fillParameters(RecPartP&target,clist*parameters) 144void Genericwrapper::fillParameters(RecPartP&target,clist*parameters)
143{ 145{
144 if (!parameters) {return;} 146 if (!parameters) {return;}
145 clistcell*current=0; 147 clistcell*current=0;
146 mailmime_parameter*param; 148 mailmime_parameter*param;
147 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { 149 for (current=clist_begin(parameters);current!=0;current=clist_next(current)) {
148 param = (mailmime_parameter*)current->data; 150 param = (mailmime_parameter*)current->data;
149 if (param) { 151 if (param) {
150 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 152 target->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
151 } 153 }
152 } 154 }
153} 155}
154 156
155QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) 157QString Genericwrapper::getencoding(mailmime_mechanism*aEnc)
156{ 158{
157 QString enc="7bit"; 159 QString enc="7bit";
158 if (!aEnc) return enc; 160 if (!aEnc) return enc;
159 switch(aEnc->enc_type) { 161 switch(aEnc->enc_type) {
160 case MAILMIME_MECHANISM_7BIT: 162 case MAILMIME_MECHANISM_7BIT:
161 enc = "7bit"; 163 enc = "7bit";
162 break; 164 break;
163 case MAILMIME_MECHANISM_8BIT: 165 case MAILMIME_MECHANISM_8BIT:
164 enc = "8bit"; 166 enc = "8bit";
165 break; 167 break;
166 case MAILMIME_MECHANISM_BINARY: 168 case MAILMIME_MECHANISM_BINARY:
167 enc = "binary"; 169 enc = "binary";
168 break; 170 break;
169 case MAILMIME_MECHANISM_QUOTED_PRINTABLE: 171 case MAILMIME_MECHANISM_QUOTED_PRINTABLE:
170 enc = "quoted-printable"; 172 enc = "quoted-printable";
171 break; 173 break;
172 case MAILMIME_MECHANISM_BASE64: 174 case MAILMIME_MECHANISM_BASE64:
173 enc = "base64"; 175 enc = "base64";
174 break; 176 break;
175 case MAILMIME_MECHANISM_TOKEN: 177 case MAILMIME_MECHANISM_TOKEN:
176 default: 178 default:
177 if (aEnc->enc_token) { 179 if (aEnc->enc_token) {
178 enc = QString(aEnc->enc_token); 180 enc = QString(aEnc->enc_token);
179 } 181 }
180 break; 182 break;
181 } 183 }
182 return enc; 184 return enc;
183} 185}
184 186
185void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) 187void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,Q3ValueList<int>recList,unsigned int current_rec,int current_count)
186{ 188{
187 if (current_rec >= 10) { 189 if (current_rec >= 10) {
188 ; // odebug << "too deep recursion!" << oendl; 190 ; // odebug << "too deep recursion!" << oendl;
189 } 191 }
190 if (!message || !mime) { 192 if (!message || !mime) {
191 return; 193 return;
192 } 194 }
193 int r; 195 int r;
194 char*data = 0; 196 char*data = 0;
195 size_t len; 197 size_t len;
196 clistiter * cur = 0; 198 clistiter * cur = 0;
197 QString b; 199 QString b;
198 RecPartP part = new RecPart(); 200 RecPartP part = new RecPart();
199 201
200 switch (mime->mm_type) { 202 switch (mime->mm_type) {
201 case MAILMIME_SINGLE: 203 case MAILMIME_SINGLE:
202 { 204 {
203 QValueList<int>countlist = recList; 205 Q3ValueList<int>countlist = recList;
204 countlist.append(current_count); 206 countlist.append(current_count);
205 r = mailmessage_fetch_section(message,mime,&data,&len); 207 r = mailmessage_fetch_section(message,mime,&data,&len);
206 part->setSize(len); 208 part->setSize(len);
207 part->setPositionlist(countlist); 209 part->setPositionlist(countlist);
208 b = gen_attachment_id(); 210 b = gen_attachment_id();
209 part->setIdentifier(b); 211 part->setIdentifier(b);
210 fillSingleBody(part,message,mime); 212 fillSingleBody(part,message,mime);
211 if (part->Type()=="text" && target->Bodytext().isNull()) { 213 if (part->Type()=="text" && target->Bodytext().isNull()) {
212 encodedString*rs = new encodedString(); 214 encodedString*rs = new encodedString();
213 rs->setContent(data,len); 215 rs->setContent(data,len);
214 encodedString*res = decode_String(rs,part->Encoding()); 216 encodedString*res = decode_String(rs,part->Encoding());
215 if (countlist.count()>2) { 217 if (countlist.count()>2) {
216 bodyCache[b]=rs; 218 bodyCache[b]=rs;
217 target->addPart(part); 219 target->addPart(part);
218 } else { 220 } else {
219 delete rs; 221 delete rs;
220 } 222 }
221 b = QString(res->Content()); 223 b = QString(res->Content());
222 delete res; 224 delete res;
223 size_t index = 0; 225 size_t index = 0;
224 char*resu = 0; 226 char*resu = 0;
225 int err = MAILIMF_NO_ERROR; 227 int err = MAILIMF_NO_ERROR;
226 QString charset = part->searchParamter( "charset"); 228 QString charset = part->searchParamter( "charset");
227 qDebug("CHARSET %s ",charset.latin1() ); 229 qDebug("CHARSET %s ",charset.latin1() );
228#if 0 230#if 0
229 if (false ) { 231 if (false ) {
230 //if ( !charset.isEmpty() ) { 232 //if ( !charset.isEmpty() ) {
231 target->setCharset( charset ); 233 target->setCharset( charset );
232 err = mailmime_encoded_phrase_parse(charset.latin1(), 234 err = mailmime_encoded_phrase_parse(charset.latin1(),
233 b.latin1(), b.length(),&index, "utf-8",&resu); 235 b.latin1(), b.length(),&index, "utf-8",&resu);
234 if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) { 236 if (err == MAILIMF_NO_ERROR && resu && strlen(resu)) {
235 //qDebug("res %d %s ", index, resu); 237 //qDebug("res %d %s ", index, resu);
236 b = QString::fromUtf8(resu); 238 b = QString::fromUtf8(resu);
237 } 239 }
238 if (resu) free(resu); 240 if (resu) free(resu);
239 } 241 }
240#endif 242#endif
241 target->setBodytext(b); 243 target->setBodytext(b);
242 target->setDescription(part); 244 target->setDescription(part);
243 } else { 245 } else {
244 bodyCache[b]=new encodedString(data,len); 246 bodyCache[b]=new encodedString(data,len);
245 target->addPart(part); 247 target->addPart(part);
246 } 248 }
247 } 249 }
248 break; 250 break;
249 case MAILMIME_MULTIPLE: 251 case MAILMIME_MULTIPLE:
250 { 252 {
251 unsigned int ccount = 1; 253 unsigned int ccount = 1;
252 mailmime*cbody=0; 254 mailmime*cbody=0;
253 QValueList<int>countlist = recList; 255 Q3ValueList<int>countlist = recList;
254 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { 256 for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
255 cbody = (mailmime*)clist_content(cur); 257 cbody = (mailmime*)clist_content(cur);
256 if (cbody->mm_type==MAILMIME_MULTIPLE) { 258 if (cbody->mm_type==MAILMIME_MULTIPLE) {
257 RecPartP targetPart = new RecPart(); 259 RecPartP targetPart = new RecPart();
258 targetPart->setType("multipart"); 260 targetPart->setType("multipart");
259 countlist.append(current_count); 261 countlist.append(current_count);
260 targetPart->setPositionlist(countlist); 262 targetPart->setPositionlist(countlist);
261 target->addPart(targetPart); 263 target->addPart(targetPart);
262 } 264 }
263 traverseBody(target,message, cbody,countlist,current_rec+1,ccount); 265 traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
264 if (cbody->mm_type==MAILMIME_MULTIPLE) { 266 if (cbody->mm_type==MAILMIME_MULTIPLE) {
265 countlist = recList; 267 countlist = recList;
266 } 268 }
267 ++ccount; 269 ++ccount;
268 } 270 }
269 } 271 }
270 break; 272 break;
271 case MAILMIME_MESSAGE: 273 case MAILMIME_MESSAGE:
272 { 274 {
273 QValueList<int>countlist = recList; 275 Q3ValueList<int>countlist = recList;
274 countlist.append(current_count); 276 countlist.append(current_count);
275 /* the own header is always at recursion 0 - we don't need that */ 277 /* the own header is always at recursion 0 - we don't need that */
276 if (current_rec > 0) { 278 if (current_rec > 0) {
277 part->setPositionlist(countlist); 279 part->setPositionlist(countlist);
278 r = mailmessage_fetch_section(message,mime,&data,&len); 280 r = mailmessage_fetch_section(message,mime,&data,&len);
279 part->setSize(len); 281 part->setSize(len);
280 part->setPositionlist(countlist); 282 part->setPositionlist(countlist);
281 b = gen_attachment_id(); 283 b = gen_attachment_id();
282 part->setIdentifier(b); 284 part->setIdentifier(b);
283 part->setType("message"); 285 part->setType("message");
284 part->setSubtype("rfc822"); 286 part->setSubtype("rfc822");
285 bodyCache[b]=new encodedString(data,len); 287 bodyCache[b]=new encodedString(data,len);
286 target->addPart(part); 288 target->addPart(part);
287 } 289 }
288 if (mime->mm_data.mm_message.mm_msg_mime != NULL) { 290 if (mime->mm_data.mm_message.mm_msg_mime != NULL) {
289 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); 291 traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1);
290 } 292 }
291 } 293 }
292 break; 294 break;
293 } 295 }
294} 296}
295 297
296RecBodyP Genericwrapper::parseMail( mailmessage * msg ) 298RecBodyP Genericwrapper::parseMail( mailmessage * msg )
297{ 299{
298 int err = MAILIMF_NO_ERROR; 300 int err = MAILIMF_NO_ERROR;
299 //mailmime_single_fields fields; 301 //mailmime_single_fields fields;
300 /* is bound to msg and will be freed there */ 302 /* is bound to msg and will be freed there */
301 mailmime * mime=0; 303 mailmime * mime=0;
302 RecBodyP body = new RecBody(); 304 RecBodyP body = new RecBody();
303 //memset(&fields, 0, sizeof(struct mailmime_single_fields)); 305 //memset(&fields, 0, sizeof(struct mailmime_single_fields));
304 err = mailmessage_get_bodystructure(msg,&mime); 306 err = mailmessage_get_bodystructure(msg,&mime);
305 QValueList<int>recList; 307 Q3ValueList<int>recList;
306 traverseBody(body,msg,mime,recList); 308 traverseBody(body,msg,mime,recList);
307 return body; 309 return body;
308} 310}
309 311
310 312
311QString Genericwrapper::parseAddressList( mailimf_address_list *list ) 313QString Genericwrapper::parseAddressList( mailimf_address_list *list )
312{ 314{
313 QString result( "" ); 315 QString result( "" );
314 316
315 bool first = true; 317 bool first = true;
316 if (list == 0) return result; 318 if (list == 0) return result;
317 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 319 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
318 mailimf_address *addr = (mailimf_address *) current->data; 320 mailimf_address *addr = (mailimf_address *) current->data;
319 321
320 if ( !first ) { 322 if ( !first ) {
321 result.append( "," ); 323 result.append( "," );
322 } else { 324 } else {
323 first = false; 325 first = false;
324 } 326 }
325 327
326 switch ( addr->ad_type ) { 328 switch ( addr->ad_type ) {
327 case MAILIMF_ADDRESS_MAILBOX: 329 case MAILIMF_ADDRESS_MAILBOX:
328 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 330 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
329 break; 331 break;
330 case MAILIMF_ADDRESS_GROUP: 332 case MAILIMF_ADDRESS_GROUP:
331 result.append( parseGroup( addr->ad_data.ad_group ) ); 333 result.append( parseGroup( addr->ad_data.ad_group ) );
332 break; 334 break;
333 default: 335 default:
334 ; // odebug << "Generic: unkown mailimf address type" << oendl; 336 ; // odebug << "Generic: unkown mailimf address type" << oendl;
335 break; 337 break;
336 } 338 }
337 } 339 }
338 340
339 return result; 341 return result;
340} 342}
341 343
342QString Genericwrapper::parseGroup( mailimf_group *group ) 344QString Genericwrapper::parseGroup( mailimf_group *group )
343{ 345{
344 QString result( "" ); 346 QString result( "" );
345 347
346 result.append( group->grp_display_name ); 348 result.append( group->grp_display_name );
347 result.append( ": " ); 349 result.append( ": " );
348 350
349 if ( group->grp_mb_list != NULL ) { 351 if ( group->grp_mb_list != NULL ) {
350 result.append( parseMailboxList( group->grp_mb_list ) ); 352 result.append( parseMailboxList( group->grp_mb_list ) );
351 } 353 }
352 354
353 result.append( ";" ); 355 result.append( ";" );
354 356
355 return result; 357 return result;
356} 358}
357 359
358QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) 360QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
359{ 361{
360 QString result( "" ); 362 QString result( "" );
361 363
362 if ( box->mb_display_name == NULL ) { 364 if ( box->mb_display_name == NULL ) {
363 result.append( convert_String(box->mb_addr_spec) ); 365 result.append( convert_String(box->mb_addr_spec) );
364 } else { 366 } else {
365 result.append( convert_String(box->mb_display_name) ); 367 result.append( convert_String(box->mb_display_name) );
366 result.append( " <" ); 368 result.append( " <" );
367 result.append( convert_String( box->mb_addr_spec) ); 369 result.append( convert_String( box->mb_addr_spec) );
368 result.append( ">" ); 370 result.append( ">" );
369 } 371 }
370 372
371 return result; 373 return result;
372} 374}
373 375
374QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) 376QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
375{ 377{
376 QString result( "" ); 378 QString result( "" );
377 379
378 bool first = true; 380 bool first = true;
379 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 381 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
380 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 382 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
381 383
382 if ( !first ) { 384 if ( !first ) {
383 result.append( "," ); 385 result.append( "," );
384 } else { 386 } else {
385 first = false; 387 first = false;
386 } 388 }
387 389
388 result.append( parseMailbox( box ) ); 390 result.append( parseMailbox( box ) );
389 } 391 }
390 392
391 return result; 393 return result;
392} 394}
393 395
394encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) 396encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part)
395{ 397{
396 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 398 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
397 if (it==bodyCache.end()) return new encodedString(); 399 if (it==bodyCache.end()) return new encodedString();
398 encodedString*t = decode_String(it.data(),part->Encoding()); 400 encodedString*t = decode_String(it.data(),part->Encoding());
399 return t; 401 return t;
400} 402}
401 403
402encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) 404encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part)
403{ 405{
404 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); 406 QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier());
405 if (it==bodyCache.end()) return new encodedString(); 407 if (it==bodyCache.end()) return new encodedString();
406 encodedString*t = it.data(); 408 encodedString*t = it.data();
407 return t; 409 return t;
408} 410}
409 411
410QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 412QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
411{ 413{
412 encodedString*t = fetchDecodedPart(mail,part); 414 encodedString*t = fetchDecodedPart(mail,part);
413 QString text=t->Content(); 415 QString text=t->Content();
414 delete t; 416 delete t;
415 return text; 417 return text;
416} 418}
417 419
418void Genericwrapper::cleanMimeCache() 420void Genericwrapper::cleanMimeCache()
419{ 421{
420 QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); 422 QMap<QString,encodedString*>::Iterator it = bodyCache.begin();
421 for (;it!=bodyCache.end();++it) { 423 for (;it!=bodyCache.end();++it) {
422 encodedString*t = it.data(); 424 encodedString*t = it.data();
423 //it.setValue(0); 425 //it.setValue(0);
424 if (t) delete t; 426 if (t) delete t;
425 } 427 }
426 bodyCache.clear(); 428 bodyCache.clear();
427 ; // odebug << "Genericwrapper: cache cleaned" << oendl; 429 ; // odebug << "Genericwrapper: cache cleaned" << oendl;
428} 430}
429 431
430QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) 432QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
431{ 433{
432 QStringList res; 434 QStringList res;
433 if (!in_replies || !in_replies->mid_list) return res; 435 if (!in_replies || !in_replies->mid_list) return res;
434 clistiter * current = 0; 436 clistiter * current = 0;
435 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { 437 for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
436 QString h((char*)current->data); 438 QString h((char*)current->data);
437 while (h.length()>0 && h[0]=='<') { 439 while (h.length()>0 && h[0]=='<') {
438 h.remove(0,1); 440 h.remove(0,1);
439 } 441 }
440 while (h.length()>0 && h[h.length()-1]=='>') { 442 while (h.length()>0 && h[h.length()-1]=='>') {
441 h.remove(h.length()-1,1); 443 h.remove(h.length()-1,1);
442 } 444 }
443 if (h.length()>0) { 445 if (h.length()>0) {
444 res.append(h); 446 res.append(h);
445 } 447 }
446 } 448 }
447 return res; 449 return res;
448} 450}
449 451
450void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) 452void Genericwrapper::parseList(Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb)
451{ 453{
452 int r; 454 int r;
453 mailmessage_list * env_list = 0; 455 mailmessage_list * env_list = 0;
454 r = mailsession_get_messages_list(session,&env_list); 456 r = mailsession_get_messages_list(session,&env_list);
455 if (r != MAIL_NO_ERROR) { 457 if (r != MAIL_NO_ERROR) {
456 ; // odebug << "Error message list" << oendl; 458 ; // odebug << "Error message list" << oendl;
457 return; 459 return;
458 } 460 }
459 r = mailsession_get_envelopes_list(session, env_list); 461 r = mailsession_get_envelopes_list(session, env_list);
460 if (r != MAIL_NO_ERROR) { 462 if (r != MAIL_NO_ERROR) {
461 ; // odebug << "Error filling message list" << oendl; 463 ; // odebug << "Error filling message list" << oendl;
462 if (env_list) { 464 if (env_list) {
463 mailmessage_list_free(env_list); 465 mailmessage_list_free(env_list);
464 } 466 }
465 return; 467 return;
466 } 468 }
467 mailimf_references * refs = 0; 469 mailimf_references * refs = 0;
468 mailimf_in_reply_to * in_replies = 0; 470 mailimf_in_reply_to * in_replies = 0;
469 uint32_t i = 0; 471 uint32_t i = 0;
470 for(; i < carray_count(env_list->msg_tab) ; ++i) { 472 for(; i < carray_count(env_list->msg_tab) ; ++i) {
471 mailmessage * msg; 473 mailmessage * msg;
472 QBitArray mFlags(7); 474 QBitArray mFlags(7);
473 msg = (mailmessage*)carray_get(env_list->msg_tab, i); 475 msg = (mailmessage*)carray_get(env_list->msg_tab, i);
474 if (msg->msg_fields == NULL) { 476 if (msg->msg_fields == NULL) {
475 //; // odebug << "could not fetch envelope of message " << i << "" << oendl; 477 //; // odebug << "could not fetch envelope of message " << i << "" << oendl;
476 continue; 478 continue;
477 } 479 }
478 RecMailP mail = new RecMail(); 480 RecMailP mail = new RecMail();
479 mail->setWrapper(this); 481 mail->setWrapper(this);
480 mail_flags * flag_result = 0; 482 mail_flags * flag_result = 0;
481 r = mailmessage_get_flags(msg,&flag_result); 483 r = mailmessage_get_flags(msg,&flag_result);
482 if (r == MAIL_ERROR_NOT_IMPLEMENTED) { 484 if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
483 mFlags.setBit(FLAG_SEEN); 485 mFlags.setBit(FLAG_SEEN);
484 } 486 }
485 mailimf_single_fields single_fields; 487 mailimf_single_fields single_fields;
486 mailimf_single_fields_init(&single_fields, msg->msg_fields); 488 mailimf_single_fields_init(&single_fields, msg->msg_fields);
487 mail->setMsgsize(msg->msg_size); 489 mail->setMsgsize(msg->msg_size);
488 mail->setFlags(mFlags); 490 mail->setFlags(mFlags);
489 mail->setMbox(mailbox); 491 mail->setMbox(mailbox);
490 mail->setNumber(msg->msg_index); 492 mail->setNumber(msg->msg_index);
491 if (single_fields.fld_subject) 493 if (single_fields.fld_subject)
492 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); 494 mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
493 if (single_fields.fld_from) { 495 if (single_fields.fld_from) {
494 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); 496 mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
495 } 497 }
496 if (!mbox_as_to) { 498 if (!mbox_as_to) {
497 if (single_fields.fld_to) 499 if (single_fields.fld_to)
498 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); 500 mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
499 } else { 501 } else {
500 mail->setTo(mailbox); 502 mail->setTo(mailbox);
501 } 503 }
502 if (single_fields.fld_cc) 504 if (single_fields.fld_cc)
503 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); 505 mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
504 if (single_fields.fld_bcc) 506 if (single_fields.fld_bcc)
505 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); 507 mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
506 if (single_fields.fld_orig_date) { 508 if (single_fields.fld_orig_date) {
507 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); 509 QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time );
508 QString ret; 510 QString ret;
509 if ( dt.date() == QDate::currentDate () ) 511 if ( dt.date() == QDate::currentDate () )
510 ret = KGlobal::locale()->formatTime( dt.time(),true); 512 ret = KGlobal::locale()->formatTime( dt.time(),true);
511 else { 513 else {
512 ret = KGlobal::locale()->formatDateTime( dt,true,true); 514 ret = KGlobal::locale()->formatDateTime( dt,true,true);
513 } 515 }
514 mail->setDate( ret ); 516 mail->setDate( ret );
515 char tmp[20]; 517 char tmp[20];
516 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 518 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
517 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); 519 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
518 //qDebug(" iso %s ", tmp); 520 //qDebug(" iso %s ", tmp);
519 mail->setIsoDate( QString( tmp ) ); 521 mail->setIsoDate( QString( tmp ) );
520 } 522 }
521 // crashes when accessing pop3 account? 523 // crashes when accessing pop3 account?
522 if (single_fields.fld_message_id) { 524 if (single_fields.fld_message_id) {
523 mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); 525 mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
524 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; 526 ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl;
525 } 527 }
526 if (single_fields.fld_reply_to) { 528 if (single_fields.fld_reply_to) {
527 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); 529 QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list);
528 if (t.count()>0) { 530 if (t.count()>0) {
529 mail->setReplyto(t[0]); 531 mail->setReplyto(t[0]);
530 } 532 }
531 } 533 }
532#if 0 534#if 0
533 refs = single_fields.fld_references; 535 refs = single_fields.fld_references;
534 if (refs && refs->mid_list && clist_count(refs->mid_list)) { 536 if (refs && refs->mid_list && clist_count(refs->mid_list)) {
535 char * text = (char*)refs->mid_list->first->data; 537 char * text = (char*)refs->mid_list->first->data;
536 mail->setReplyto(QString(text)); 538 mail->setReplyto(QString(text));
537 } 539 }
538#endif 540#endif
539 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && 541 if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
540 clist_count(single_fields.fld_in_reply_to->mid_list)) { 542 clist_count(single_fields.fld_in_reply_to->mid_list)) {
541 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); 543 mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
542 } 544 }
543 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) 545 if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 )
544 target.append(mail); 546 target.append(mail);
545 } 547 }
546 if (env_list) { 548 if (env_list) {
547 mailmessage_list_free(env_list); 549 mailmessage_list_free(env_list);
548 } 550 }
549} 551}
diff --git a/kmicromail/libmailwrapper/genericwrapper.h b/kmicromail/libmailwrapper/genericwrapper.h
index c35a6da..a50161d 100644
--- a/kmicromail/libmailwrapper/genericwrapper.h
+++ b/kmicromail/libmailwrapper/genericwrapper.h
@@ -1,68 +1,70 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __GENERIC_WRAPPER_H 2#ifndef __GENERIC_WRAPPER_H
3#define __GENERIC_WRAPPER_H 3#define __GENERIC_WRAPPER_H
4 4
5#include "abstractmail.h" 5#include "abstractmail.h"
6#include <qmap.h> 6#include <qmap.h>
7#include <qstring.h> 7#include <qstring.h>
8//Added by qt3to4:
9#include <Q3ValueList>
8#include <libetpan/clist.h> 10#include <libetpan/clist.h>
9 11
10class RecMail; 12class RecMail;
11class RecBody; 13class RecBody;
12class encodedString; 14class encodedString;
13struct mailpop3; 15struct mailpop3;
14struct mailmessage; 16struct mailmessage;
15struct mailmime; 17struct mailmime;
16struct mailmime_mechanism; 18struct mailmime_mechanism;
17struct mailimf_mailbox_list; 19struct mailimf_mailbox_list;
18struct mailimf_mailbox; 20struct mailimf_mailbox;
19struct mailimf_date_time; 21struct mailimf_date_time;
20struct mailimf_group; 22struct mailimf_group;
21struct mailimf_address_list; 23struct mailimf_address_list;
22struct mailsession; 24struct mailsession;
23struct mailstorage; 25struct mailstorage;
24struct mailfolder; 26struct mailfolder;
25struct mailimf_in_reply_to; 27struct mailimf_in_reply_to;
26 28
27/* this class hold just the funs shared between 29/* this class hold just the funs shared between
28 * mbox and pop3 (later mh, too) mail access. 30 * mbox and pop3 (later mh, too) mail access.
29 * it is not desigend to make a instance of it! 31 * it is not desigend to make a instance of it!
30 */ 32 */
31class Genericwrapper : public AbstractMail 33class Genericwrapper : public AbstractMail
32{ 34{
33 Q_OBJECT 35 Q_OBJECT
34public: 36public:
35 Genericwrapper(); 37 Genericwrapper();
36 virtual ~Genericwrapper(); 38 virtual ~Genericwrapper();
37 39
38 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 40 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
39 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 41 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
40 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 42 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
41 virtual void cleanMimeCache(); 43 virtual void cleanMimeCache();
42 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;} 44 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&){return 1;}
43 virtual void logout(){}; 45 virtual void logout(){};
44 virtual void storeMessage(const char*msg,size_t length, const QString&folder){}; 46 virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
45 static const QDateTime parseDateTime( mailimf_date_time *date ); 47 static const QDateTime parseDateTime( mailimf_date_time *date );
46 48
47protected: 49protected:
48 RecBodyP parseMail( mailmessage * msg ); 50 RecBodyP parseMail( mailmessage * msg );
49 QString parseMailboxList( mailimf_mailbox_list *list ); 51 QString parseMailboxList( mailimf_mailbox_list *list );
50 QString parseMailbox( mailimf_mailbox *box ); 52 QString parseMailbox( mailimf_mailbox *box );
51 QString parseGroup( mailimf_group *group ); 53 QString parseGroup( mailimf_group *group );
52 QString parseAddressList( mailimf_address_list *list ); 54 QString parseAddressList( mailimf_address_list *list );
53 55
54 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1); 56 void traverseBody(RecBodyP&target,mailmessage*message,mailmime*mime,Q3ValueList<int>recList,unsigned int current_rek=0,int current_count=1);
55 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime); 57 static void fillSingleBody(RecPartP&target,mailmessage*message,mailmime*mime);
56 static void fillParameters(RecPartP&target,clist*parameters); 58 static void fillParameters(RecPartP&target,clist*parameters);
57 static QString getencoding(mailmime_mechanism*aEnc); 59 static QString getencoding(mailmime_mechanism*aEnc);
58 virtual void parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false, int maxSizeInKb = 0); 60 virtual void parseList(Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false, int maxSizeInKb = 0);
59 QStringList parseInreplies(mailimf_in_reply_to * in_replies); 61 QStringList parseInreplies(mailimf_in_reply_to * in_replies);
60 62
61 QString msgTempName; 63 QString msgTempName;
62 unsigned int last_msg_id; 64 unsigned int last_msg_id;
63 QMap<QString,encodedString*> bodyCache; 65 QMap<QString,encodedString*> bodyCache;
64 mailstorage * m_storage; 66 mailstorage * m_storage;
65 mailfolder*m_folder; 67 mailfolder*m_folder;
66}; 68};
67 69
68#endif 70#endif
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 4f0c849..f73f4cc 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1370 +1,1372 @@
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//Added by qt3to4:
7#include <Q3ValueList>
6#include "imapwrapper.h" 8#include "imapwrapper.h"
7#include "mailtypes.h" 9#include "mailtypes.h"
8#include "logindialog.h" 10#include "logindialog.h"
9#include <qprogressbar.h> 11#include <q3progressbar.h>
10#include "genericwrapper.h" 12#include "genericwrapper.h"
11#include <kglobal.h> 13#include <kglobal.h>
12 14
13using namespace Opie::Core; 15using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 16int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 17int IMAPwrapper::mCurrent = 0;
16 18
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 19IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 20 : AbstractMail()
19{ 21{
20 account = a; 22 account = a;
21 m_imap = 0; 23 m_imap = 0;
22 m_Lastmbox = ""; 24 m_Lastmbox = "";
23 mCurrent = 0; 25 mCurrent = 0;
24 mMax = 0; 26 mMax = 0;
25} 27}
26 28
27IMAPwrapper::~IMAPwrapper() 29IMAPwrapper::~IMAPwrapper()
28{ 30{
29 logout(); 31 logout();
30} 32}
31 33
32/* to avoid to often select statements in loops etc. 34/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 35 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 36int IMAPwrapper::selectMbox(const QString&mbox)
35{ 37{
36 if (mbox == m_Lastmbox) { 38 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 39 return MAILIMAP_NO_ERROR;
38 } 40 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 41 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 42 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 43 m_Lastmbox = "";
42 return err; 44 return err;
43 } 45 }
44 m_Lastmbox = mbox; 46 m_Lastmbox = mbox;
45 return err; 47 return err;
46} 48}
47 49
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 50void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 51{
50 return; 52 return;
51 //qDebug("imap progress %d of %d ",current,maximum ); 53 //qDebug("imap progress %d of %d ",current,maximum );
52 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum)); 54 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
53 //qApp->processEvents() 55 //qApp->processEvents()
54 static unsigned int last = 0; 56 static unsigned int last = 0;
55 if ( last != current ) 57 if ( last != current )
56 IMAPwrapper::progress(); 58 IMAPwrapper::progress();
57 last = current; 59 last = current;
58} 60}
59void IMAPwrapper::progress( QString m ) 61void IMAPwrapper::progress( QString m )
60{ 62{
61 static QString mProgrMess; 63 static QString mProgrMess;
62 if ( m != QString::null ) { 64 if ( m != QString::null ) {
63 mProgrMess = m; 65 mProgrMess = m;
64 mCurrent = 1; 66 mCurrent = 1;
65 return; 67 return;
66 } 68 }
67 QString mess; 69 QString mess;
68 //qDebug("progress "); 70 //qDebug("progress ");
69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax); 71 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++); 72 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
71 Global::statusMessage(mess); 73 Global::statusMessage(mess);
72 //qDebug("Progress %s %s", mess.latin1(), m.latin1()); 74 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
73 qApp->processEvents(); 75 qApp->processEvents();
74} 76}
75bool IMAPwrapper::start_tls(bool force_tls) 77bool IMAPwrapper::start_tls(bool force_tls)
76{ 78{
77 int err; 79 int err;
78 bool try_tls = force_tls; 80 bool try_tls = force_tls;
79 mailimap_capability_data * cap_data = 0; 81 mailimap_capability_data * cap_data = 0;
80 82
81 err = mailimap_capability(m_imap,&cap_data); 83 err = mailimap_capability(m_imap,&cap_data);
82 if (err != MAILIMAP_NO_ERROR) { 84 if (err != MAILIMAP_NO_ERROR) {
83 Global::statusMessage("error getting capabilities!"); 85 Global::statusMessage("error getting capabilities!");
84 return false; 86 return false;
85 } 87 }
86 clistiter * cur; 88 clistiter * cur;
87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 89 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
88 struct mailimap_capability * cap; 90 struct mailimap_capability * cap;
89 cap = (struct mailimap_capability *)clist_content(cur); 91 cap = (struct mailimap_capability *)clist_content(cur);
90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 92 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 93 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
92 try_tls = true; 94 try_tls = true;
93 break; 95 break;
94 } 96 }
95 } 97 }
96 } 98 }
97 if (cap_data) { 99 if (cap_data) {
98 mailimap_capability_data_free(cap_data); 100 mailimap_capability_data_free(cap_data);
99 } 101 }
100 if (try_tls) { 102 if (try_tls) {
101 err = mailimap_starttls(m_imap); 103 err = mailimap_starttls(m_imap);
102 if (err != MAILIMAP_NO_ERROR && force_tls) { 104 if (err != MAILIMAP_NO_ERROR && force_tls) {
103 Global::statusMessage(i18n("Server has no TLS support!")); 105 Global::statusMessage(i18n("Server has no TLS support!"));
104 try_tls = false; 106 try_tls = false;
105 } else { 107 } else {
106 mailstream_low * low; 108 mailstream_low * low;
107 mailstream_low * new_low; 109 mailstream_low * new_low;
108 low = mailstream_get_low(m_imap->imap_stream); 110 low = mailstream_get_low(m_imap->imap_stream);
109 if (!low) { 111 if (!low) {
110 try_tls = false; 112 try_tls = false;
111 } else { 113 } else {
112 int fd = mailstream_low_get_fd(low); 114 int fd = mailstream_low_get_fd(low);
113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 115 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
114 mailstream_low_free(low); 116 mailstream_low_free(low);
115 mailstream_set_low(m_imap->imap_stream, new_low); 117 mailstream_set_low(m_imap->imap_stream, new_low);
116 } else { 118 } else {
117 try_tls = false; 119 try_tls = false;
118 } 120 }
119 } 121 }
120 } 122 }
121 } 123 }
122 return try_tls; 124 return try_tls;
123} 125}
124 126
125void IMAPwrapper::login(bool tryTLS) // = true) 127void IMAPwrapper::login(bool tryTLS) // = true)
126{ 128{
127 QString server, user, pass; 129 QString server, user, pass;
128 uint16_t port; 130 uint16_t port;
129 int err = MAILIMAP_NO_ERROR; 131 int err = MAILIMAP_NO_ERROR;
130 132
131 if (account->getOffline()) return; 133 if (account->getOffline()) return;
132 /* we are connected this moment */ 134 /* we are connected this moment */
133 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 135 /* TODO: setup a timer holding the line or if connection closed - delete the value */
134 if (m_imap) { 136 if (m_imap) {
135 err = mailimap_noop(m_imap); 137 err = mailimap_noop(m_imap);
136 if (err!=MAILIMAP_NO_ERROR) { 138 if (err!=MAILIMAP_NO_ERROR) {
137 logout(); 139 logout();
138 } else { 140 } else {
139 mailstream_flush(m_imap->imap_stream); 141 mailstream_flush(m_imap->imap_stream);
140 return; 142 return;
141 } 143 }
142 } 144 }
143 server = account->getServer(); 145 server = account->getServer();
144 port = account->getPort().toUInt(); 146 port = account->getPort().toUInt();
145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 147 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 148 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
147 login.show(); 149 login.show();
148 if ( QDialog::Accepted == login.exec() ) { 150 if ( QDialog::Accepted == login.exec() ) {
149 // ok 151 // ok
150 user = login.getUser(); 152 user = login.getUser();
151 pass = login.getPassword(); 153 pass = login.getPassword();
152 } else { 154 } else {
153 // cancel 155 // cancel
154 return; 156 return;
155 } 157 }
156 } else { 158 } else {
157 user = account->getUser(); 159 user = account->getUser();
158 pass = account->getPassword(); 160 pass = account->getPassword();
159 } 161 }
160 m_imap = mailimap_new( 20, &imap_progress ); 162 m_imap = mailimap_new( 20, &imap_progress );
161 163
162 /* connect */ 164 /* connect */
163 bool ssl = false; 165 bool ssl = false;
164 bool try_tls = false; 166 bool try_tls = false;
165 bool force_tls = false; 167 bool force_tls = false;
166 168
167 if ( account->ConnectionType() == 2 ) { 169 if ( account->ConnectionType() == 2 ) {
168 ssl = true; 170 ssl = true;
169 } 171 }
170 if (account->ConnectionType()==1) { 172 if (account->ConnectionType()==1) {
171 force_tls = true; 173 force_tls = true;
172 } 174 }
173 175
174 if ( ssl ) { 176 if ( ssl ) {
175 //qDebug("using ssl "); 177 //qDebug("using ssl ");
176 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 178 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
177 //qDebug("back "); 179 //qDebug("back ");
178 } else { 180 } else {
179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 181 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
180 } 182 }
181 183
182 if ( err != MAILIMAP_NO_ERROR && 184 if ( err != MAILIMAP_NO_ERROR &&
183 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 185 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 186 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
185 QString failure = ""; 187 QString failure = "";
186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 188 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
187 failure="Connection refused"; 189 failure="Connection refused";
188 } else { 190 } else {
189 failure="Unknown failure"; 191 failure="Unknown failure";
190 } 192 }
191 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); 193 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
192 mailimap_free( m_imap ); 194 mailimap_free( m_imap );
193 m_imap = 0; 195 m_imap = 0;
194 return; 196 return;
195 } 197 }
196 if ( tryTLS ) { 198 if ( tryTLS ) {
197 if (!ssl) { 199 if (!ssl) {
198 try_tls = start_tls(force_tls); 200 try_tls = start_tls(force_tls);
199 } 201 }
200 } 202 }
201 bool ok = true; 203 bool ok = true;
202 if (force_tls && !try_tls) { 204 if (force_tls && !try_tls) {
203 Global::statusMessage(i18n("Server has no TLS support!")); 205 Global::statusMessage(i18n("Server has no TLS support!"));
204 ok = false; 206 ok = false;
205 } 207 }
206 208
207 209
208 /* login */ 210 /* login */
209 211
210 if (ok) { 212 if (ok) {
211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 213 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
212 if ( err != MAILIMAP_NO_ERROR ) { 214 if ( err != MAILIMAP_NO_ERROR ) {
213 if ( tryTLS && !force_tls && !try_tls ) { 215 if ( tryTLS && !force_tls && !try_tls ) {
214 err = mailimap_close( m_imap ); 216 err = mailimap_close( m_imap );
215 mailimap_free( m_imap ); 217 mailimap_free( m_imap );
216 m_imap = 0; 218 m_imap = 0;
217 login( false ); 219 login( false );
218 return; 220 return;
219 } 221 }
220 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); 222 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
221 ok = false; 223 ok = false;
222 } 224 }
223 } 225 }
224 if (!ok) { 226 if (!ok) {
225 err = mailimap_close( m_imap ); 227 err = mailimap_close( m_imap );
226 mailimap_free( m_imap ); 228 mailimap_free( m_imap );
227 m_imap = 0; 229 m_imap = 0;
228 } 230 }
229} 231}
230 232
231void IMAPwrapper::logout() 233void IMAPwrapper::logout()
232{ 234{
233 int err = MAILIMAP_NO_ERROR; 235 int err = MAILIMAP_NO_ERROR;
234 if (!m_imap) return; 236 if (!m_imap) return;
235 err = mailimap_logout( m_imap ); 237 err = mailimap_logout( m_imap );
236 err = mailimap_close( m_imap ); 238 err = mailimap_close( m_imap );
237 mailimap_free( m_imap ); 239 mailimap_free( m_imap );
238 m_imap = 0; 240 m_imap = 0;
239 m_Lastmbox = ""; 241 m_Lastmbox = "";
240} 242}
241 243
242void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 244void IMAPwrapper::listMessages(const QString&mailbox,Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
243{ 245{
244 246
245 int tryAgain = 1; 247 int tryAgain = 1;
246 while ( tryAgain >= 0 ) { 248 while ( tryAgain >= 0 ) {
247 int err = MAILIMAP_NO_ERROR; 249 int err = MAILIMAP_NO_ERROR;
248 clist *result = 0; 250 clist *result = 0;
249 clistcell *current; 251 clistcell *current;
250 mailimap_fetch_type *fetchType = 0; 252 mailimap_fetch_type *fetchType = 0;
251 mailimap_set *set = 0; 253 mailimap_set *set = 0;
252 254
253 login(); 255 login();
254 if (!m_imap) { 256 if (!m_imap) {
255 return; 257 return;
256 } 258 }
257 /* select mailbox READONLY for operations */ 259 /* select mailbox READONLY for operations */
258 err = selectMbox(mailbox); 260 err = selectMbox(mailbox);
259 if ( err != MAILIMAP_NO_ERROR ) { 261 if ( err != MAILIMAP_NO_ERROR ) {
260 return; 262 return;
261 } 263 }
262 264
263 int last = m_imap->imap_selection_info->sel_exists; 265 int last = m_imap->imap_selection_info->sel_exists;
264 266
265 if (last == 0) { 267 if (last == 0) {
266 Global::statusMessage(i18n("Mailbox has no mails")); 268 Global::statusMessage(i18n("Mailbox has no mails"));
267 return; 269 return;
268 } else { 270 } else {
269 } 271 }
270 progress( i18n("Fetch ")); 272 progress( i18n("Fetch "));
271 mMax = last; 273 mMax = last;
272 //qDebug("last %d ", last); 274 //qDebug("last %d ", last);
273 Global::statusMessage(i18n("Fetching header list")); 275 Global::statusMessage(i18n("Fetching header list"));
274 qApp->processEvents(); 276 qApp->processEvents();
275 /* the range has to start at 1!!! not with 0!!!! */ 277 /* the range has to start at 1!!! not with 0!!!! */
276 //LR the access to web.de imap server is no working with value 1 278 //LR the access to web.de imap server is no working with value 1
277 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 279 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
278 set = mailimap_set_new_interval( tryAgain, last ); 280 set = mailimap_set_new_interval( tryAgain, last );
279 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 281 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
280 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 282 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
281 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 283 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
282 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 284 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
283 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 285 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
284 286
285 err = mailimap_fetch( m_imap, set, fetchType, &result ); 287 err = mailimap_fetch( m_imap, set, fetchType, &result );
286 mailimap_set_free( set ); 288 mailimap_set_free( set );
287 mailimap_fetch_type_free( fetchType ); 289 mailimap_fetch_type_free( fetchType );
288 290
289 QString date,subject,from; 291 QString date,subject,from;
290 292
291 if ( err == MAILIMAP_NO_ERROR ) { 293 if ( err == MAILIMAP_NO_ERROR ) {
292 tryAgain = -1; 294 tryAgain = -1;
293 mailimap_msg_att * msg_att; 295 mailimap_msg_att * msg_att;
294 int i = 0; 296 int i = 0;
295 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 297 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
296 ++i; 298 ++i;
297 //qDebug("iii %d ",i); 299 //qDebug("iii %d ",i);
298 msg_att = (mailimap_msg_att*)current->data; 300 msg_att = (mailimap_msg_att*)current->data;
299 RecMail*m = parse_list_result(msg_att); 301 RecMail*m = parse_list_result(msg_att);
300 if (m) { 302 if (m) {
301 if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) { 303 if ( maxSizeInKb == 0 || m->Msgsize()<=(unsigned int ) maxSizeInKb*1024 ) {
302 m->setNumber(i); 304 m->setNumber(i);
303 m->setMbox(mailbox); 305 m->setMbox(mailbox);
304 m->setWrapper(this); 306 m->setWrapper(this);
305 target.append(m); 307 target.append(m);
306 } 308 }
307 } 309 }
308 } 310 }
309 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count())); 311 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
310 } else { 312 } else {
311 --tryAgain; 313 --tryAgain;
312 --tryAgain;//disabled tryagain by adding this line 314 --tryAgain;//disabled tryagain by adding this line
313 if ( tryAgain < 0 ) 315 if ( tryAgain < 0 )
314 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response)); 316 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
315 else 317 else
316 qDebug("try again... "); 318 qDebug("try again... ");
317 } 319 }
318 320
319 if (result) mailimap_fetch_list_free(result); 321 if (result) mailimap_fetch_list_free(result);
320 } 322 }
321} 323}
322 324
323QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 325Q3ValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
324{ 326{
325 const char *path, *mask; 327 const char *path, *mask;
326 int err = MAILIMAP_NO_ERROR; 328 int err = MAILIMAP_NO_ERROR;
327 clist *result = 0; 329 clist *result = 0;
328 clistcell *current = 0; 330 clistcell *current = 0;
329 clistcell*cur_flag = 0; 331 clistcell*cur_flag = 0;
330 mailimap_mbx_list_flags*bflags = 0; 332 mailimap_mbx_list_flags*bflags = 0;
331 333
332 QValueList<FolderP>* folders = new QValueList<FolderP>(); 334 Q3ValueList<FolderP>* folders = new Q3ValueList<FolderP>();
333 login(); 335 login();
334 if (!m_imap) { 336 if (!m_imap) {
335 return folders; 337 return folders;
336 } 338 }
337 339
338/* 340/*
339 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 341 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
340 * We must not forget to filter them out in next loop! 342 * We must not forget to filter them out in next loop!
341 * it seems like ugly code. and yes - it is ugly code. but the best way. 343 * it seems like ugly code. and yes - it is ugly code. but the best way.
342 */ 344 */
343 Global::statusMessage(i18n("Fetching folder list")); 345 Global::statusMessage(i18n("Fetching folder list"));
344 qApp->processEvents(); 346 qApp->processEvents();
345 QString temp; 347 QString temp;
346 mask = "INBOX" ; 348 mask = "INBOX" ;
347 mailimap_mailbox_list *list; 349 mailimap_mailbox_list *list;
348 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 350 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
349 QString del; 351 QString del;
350 bool selectable = true; 352 bool selectable = true;
351 bool no_inferiors = false; 353 bool no_inferiors = false;
352 if ( err == MAILIMAP_NO_ERROR ) { 354 if ( err == MAILIMAP_NO_ERROR ) {
353 current = result->first; 355 current = result->first;
354 for ( int i = result->count; i > 0; i-- ) { 356 for ( int i = result->count; i > 0; i-- ) {
355 list = (mailimap_mailbox_list *) current->data; 357 list = (mailimap_mailbox_list *) current->data;
356 // it is better use the deep copy mechanism of qt itself 358 // it is better use the deep copy mechanism of qt itself
357 // instead of using strdup! 359 // instead of using strdup!
358 temp = list->mb_name; 360 temp = list->mb_name;
359 del = list->mb_delimiter; 361 del = list->mb_delimiter;
360 current = current->next; 362 current = current->next;
361 if ( (bflags = list->mb_flag) ) { 363 if ( (bflags = list->mb_flag) ) {
362 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 364 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
363 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 365 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
364 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 366 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
365 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 367 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
366 no_inferiors = true; 368 no_inferiors = true;
367 } 369 }
368 } 370 }
369 } 371 }
370 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 372 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
371 } 373 }
372 } else { 374 } else {
373 qDebug("error fetching folders: "); 375 qDebug("error fetching folders: ");
374 376
375 } 377 }
376 mailimap_list_result_free( result ); 378 mailimap_list_result_free( result );
377 379
378/* 380/*
379 * second stage - get the other then inbox folders 381 * second stage - get the other then inbox folders
380 */ 382 */
381 mask = "*" ; 383 mask = "*" ;
382 path = account->getPrefix().latin1(); 384 path = account->getPrefix().latin1();
383 if (!path) path = ""; 385 if (!path) path = "";
384 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 386 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
385 if ( err == MAILIMAP_NO_ERROR ) { 387 if ( err == MAILIMAP_NO_ERROR ) {
386 current = result->first; 388 current = result->first;
387 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 389 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
388 no_inferiors = false; 390 no_inferiors = false;
389 list = (mailimap_mailbox_list *) current->data; 391 list = (mailimap_mailbox_list *) current->data;
390 // it is better use the deep copy mechanism of qt itself 392 // it is better use the deep copy mechanism of qt itself
391 // instead of using strdup! 393 // instead of using strdup!
392 temp = list->mb_name; 394 temp = list->mb_name;
393 if (temp.lower()=="inbox") 395 if (temp.lower()=="inbox")
394 continue; 396 continue;
395 if (temp.lower()==account->getPrefix().lower()) 397 if (temp.lower()==account->getPrefix().lower())
396 continue; 398 continue;
397 if ( (bflags = list->mb_flag) ) { 399 if ( (bflags = list->mb_flag) ) {
398 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 400 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
399 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 401 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
400 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 402 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
401 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 403 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
402 no_inferiors = true; 404 no_inferiors = true;
403 } 405 }
404 } 406 }
405 } 407 }
406 del = list->mb_delimiter; 408 del = list->mb_delimiter;
407 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 409 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
408 } 410 }
409 } else { 411 } else {
410 qDebug("error fetching folders "); 412 qDebug("error fetching folders ");
411 413
412 } 414 }
413 if (result) mailimap_list_result_free( result ); 415 if (result) mailimap_list_result_free( result );
414 return folders; 416 return folders;
415} 417}
416 418
417RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 419RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
418{ 420{
419 RecMail * m = 0; 421 RecMail * m = 0;
420 mailimap_msg_att_item *item=0; 422 mailimap_msg_att_item *item=0;
421 clistcell *current,*c,*cf; 423 clistcell *current,*c,*cf;
422 mailimap_msg_att_dynamic*flist; 424 mailimap_msg_att_dynamic*flist;
423 mailimap_flag_fetch*cflag; 425 mailimap_flag_fetch*cflag;
424 int size = 0; 426 int size = 0;
425 QBitArray mFlags(7); 427 QBitArray mFlags(7);
426 QStringList addresslist; 428 QStringList addresslist;
427 429
428 if (!m_att) { 430 if (!m_att) {
429 return m; 431 return m;
430 } 432 }
431 m = new RecMail(); 433 m = new RecMail();
432 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 434 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
433 current = c; 435 current = c;
434 size = 0; 436 size = 0;
435 item = (mailimap_msg_att_item*)current->data; 437 item = (mailimap_msg_att_item*)current->data;
436 if ( !item ) 438 if ( !item )
437 continue; 439 continue;
438 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 440 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
439 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 441 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
440 if (!flist || !flist->att_list) { 442 if (!flist || !flist->att_list) {
441 continue; 443 continue;
442 } 444 }
443 cf = flist->att_list->first; 445 cf = flist->att_list->first;
444 if( cf ) { 446 if( cf ) {
445 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 447 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
446 cflag = (mailimap_flag_fetch*)cf->data; 448 cflag = (mailimap_flag_fetch*)cf->data;
447 if( ! cflag ) 449 if( ! cflag )
448 qDebug("imap:NO cflag "); 450 qDebug("imap:NO cflag ");
449 else { 451 else {
450 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 452 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
451 switch (cflag->fl_flag->fl_type) { 453 switch (cflag->fl_flag->fl_type) {
452 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 454 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
453 mFlags.setBit(FLAG_ANSWERED); 455 mFlags.setBit(FLAG_ANSWERED);
454 break; 456 break;
455 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 457 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
456 mFlags.setBit(FLAG_FLAGGED); 458 mFlags.setBit(FLAG_FLAGGED);
457 break; 459 break;
458 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 460 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
459 mFlags.setBit(FLAG_DELETED); 461 mFlags.setBit(FLAG_DELETED);
460 break; 462 break;
461 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 463 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
462 mFlags.setBit(FLAG_SEEN); 464 mFlags.setBit(FLAG_SEEN);
463 break; 465 break;
464 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 466 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
465 mFlags.setBit(FLAG_DRAFT); 467 mFlags.setBit(FLAG_DRAFT);
466 break; 468 break;
467 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 469 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
468 break; 470 break;
469 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 471 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
470 break; 472 break;
471 default: 473 default:
472 break; 474 break;
473 } 475 }
474 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 476 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
475 mFlags.setBit(FLAG_RECENT); 477 mFlags.setBit(FLAG_RECENT);
476 } 478 }
477 } 479 }
478 } 480 }
479 } 481 }
480 //qDebug(" continue"); 482 //qDebug(" continue");
481 continue; 483 continue;
482 } 484 }
483 if ( item->att_data.att_static == NULL ) 485 if ( item->att_data.att_static == NULL )
484 continue; 486 continue;
485 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 487 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
486 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 488 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
487 if ( head == NULL ) 489 if ( head == NULL )
488 continue; 490 continue;
489 if ( head->env_date != NULL ) { 491 if ( head->env_date != NULL ) {
490 m->setDate(head->env_date); 492 m->setDate(head->env_date);
491 //struct mailimf_date_time result; 493 //struct mailimf_date_time result;
492 struct mailimf_date_time* date;// = &result; 494 struct mailimf_date_time* date;// = &result;
493 struct mailimf_date_time **re = &date; 495 struct mailimf_date_time **re = &date;
494 size_t length = m->getDate().length(); 496 size_t length = m->getDate().length();
495 size_t index = 0; 497 size_t index = 0;
496 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) { 498 if ( mailimf_date_time_parse(head->env_date, length,&index, re ) == MAILIMF_NO_ERROR ) {
497 //qDebug("parseDateTime "); 499 //qDebug("parseDateTime ");
498 QDateTime dt = Genericwrapper::parseDateTime( date ); 500 QDateTime dt = Genericwrapper::parseDateTime( date );
499 QString ret; 501 QString ret;
500 if ( dt.date() == QDate::currentDate () ) 502 if ( dt.date() == QDate::currentDate () )
501 ret = KGlobal::locale()->formatTime( dt.time(),true); 503 ret = KGlobal::locale()->formatTime( dt.time(),true);
502 else { 504 else {
503 ret = KGlobal::locale()->formatDateTime( dt,true,true); 505 ret = KGlobal::locale()->formatDateTime( dt,true,true);
504 } 506 }
505 m->setDate( ret ); 507 m->setDate( ret );
506 char tmp[20]; 508 char tmp[20];
507 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", 509 snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i",
508 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); 510 dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() );
509 //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date); 511 //qDebug("%d iso %s %s ", date->dt_zone, tmp, head->env_date);
510 m->setIsoDate( QString( tmp ) ); 512 m->setIsoDate( QString( tmp ) );
511 mailimf_date_time_free ( date ); 513 mailimf_date_time_free ( date );
512 } else { 514 } else {
513 m->setIsoDate(head->env_date); 515 m->setIsoDate(head->env_date);
514 } 516 }
515 } 517 }
516 if ( head->env_subject != NULL ) 518 if ( head->env_subject != NULL )
517 m->setSubject(convert_String((const char*)head->env_subject)); 519 m->setSubject(convert_String((const char*)head->env_subject));
518 //m->setSubject(head->env_subject); 520 //m->setSubject(head->env_subject);
519 if (head->env_from!=NULL) { 521 if (head->env_from!=NULL) {
520 addresslist = address_list_to_stringlist(head->env_from->frm_list); 522 addresslist = address_list_to_stringlist(head->env_from->frm_list);
521 if (addresslist.count()) { 523 if (addresslist.count()) {
522 m->setFrom(addresslist.first()); 524 m->setFrom(addresslist.first());
523 } 525 }
524 } 526 }
525 if (head->env_to!=NULL) { 527 if (head->env_to!=NULL) {
526 addresslist = address_list_to_stringlist(head->env_to->to_list); 528 addresslist = address_list_to_stringlist(head->env_to->to_list);
527 m->setTo(addresslist); 529 m->setTo(addresslist);
528 } 530 }
529 if (head->env_cc!=NULL) { 531 if (head->env_cc!=NULL) {
530 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 532 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
531 m->setCC(addresslist); 533 m->setCC(addresslist);
532 } 534 }
533 if (head->env_bcc!=NULL) { 535 if (head->env_bcc!=NULL) {
534 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 536 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
535 m->setBcc(addresslist); 537 m->setBcc(addresslist);
536 } 538 }
537 /* reply to address, eg. email. */ 539 /* reply to address, eg. email. */
538 if (head->env_reply_to!=NULL) { 540 if (head->env_reply_to!=NULL) {
539 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 541 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
540 if (addresslist.count()) { 542 if (addresslist.count()) {
541 m->setReplyto(addresslist.first()); 543 m->setReplyto(addresslist.first());
542 } 544 }
543 } 545 }
544 if (head->env_in_reply_to!=NULL) { 546 if (head->env_in_reply_to!=NULL) {
545 QString h(head->env_in_reply_to); 547 QString h(head->env_in_reply_to);
546 while (h.length()>0 && h[0]=='<') { 548 while (h.length()>0 && h[0]=='<') {
547 h.remove(0,1); 549 h.remove(0,1);
548 } 550 }
549 while (h.length()>0 && h[h.length()-1]=='>') { 551 while (h.length()>0 && h[h.length()-1]=='>') {
550 h.remove(h.length()-1,1); 552 h.remove(h.length()-1,1);
551 } 553 }
552 if (h.length()>0) { 554 if (h.length()>0) {
553 m->setInreply(QStringList(h)); 555 m->setInreply(QStringList(h));
554 } 556 }
555 } 557 }
556 if (head->env_message_id != NULL) { 558 if (head->env_message_id != NULL) {
557 m->setMsgid(QString(head->env_message_id)); 559 m->setMsgid(QString(head->env_message_id));
558 } 560 }
559 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 561 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
560#if 0 562#if 0
561 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 563 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
562 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 564 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
563 qDebug("time %s ",da.toString().latin1() ); 565 qDebug("time %s ",da.toString().latin1() );
564#endif 566#endif
565 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 567 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
566 size = item->att_data.att_static->att_data.att_rfc822_size; 568 size = item->att_data.att_static->att_data.att_rfc822_size;
567 } 569 }
568 } 570 }
569 /* msg is already deleted */ 571 /* msg is already deleted */
570 if (mFlags.testBit(FLAG_DELETED) && m) { 572 if (mFlags.testBit(FLAG_DELETED) && m) {
571 delete m; 573 delete m;
572 m = 0; 574 m = 0;
573 } 575 }
574 if (m) { 576 if (m) {
575 m->setFlags(mFlags); 577 m->setFlags(mFlags);
576 m->setMsgsize(size); 578 m->setMsgsize(size);
577 } 579 }
578 return m; 580 return m;
579} 581}
580 582
581RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 583RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
582{ 584{
583 RecBodyP body = new RecBody(); 585 RecBodyP body = new RecBody();
584 const char *mb; 586 const char *mb;
585 int err = MAILIMAP_NO_ERROR; 587 int err = MAILIMAP_NO_ERROR;
586 clist *result = 0; 588 clist *result = 0;
587 clistcell *current; 589 clistcell *current;
588 mailimap_fetch_att *fetchAtt = 0; 590 mailimap_fetch_att *fetchAtt = 0;
589 mailimap_fetch_type *fetchType = 0; 591 mailimap_fetch_type *fetchType = 0;
590 mailimap_set *set = 0; 592 mailimap_set *set = 0;
591 mailimap_body*body_desc = 0; 593 mailimap_body*body_desc = 0;
592 594
593 mb = mail->getMbox().latin1(); 595 mb = mail->getMbox().latin1();
594 596
595 login(); 597 login();
596 if (!m_imap) { 598 if (!m_imap) {
597 return body; 599 return body;
598 } 600 }
599 err = selectMbox(mail->getMbox()); 601 err = selectMbox(mail->getMbox());
600 if ( err != MAILIMAP_NO_ERROR ) { 602 if ( err != MAILIMAP_NO_ERROR ) {
601 return body; 603 return body;
602 } 604 }
603 605
604 /* the range has to start at 1!!! not with 0!!!! */ 606 /* the range has to start at 1!!! not with 0!!!! */
605 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 607 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
606 fetchAtt = mailimap_fetch_att_new_bodystructure(); 608 fetchAtt = mailimap_fetch_att_new_bodystructure();
607 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 609 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
608 err = mailimap_fetch( m_imap, set, fetchType, &result ); 610 err = mailimap_fetch( m_imap, set, fetchType, &result );
609 mailimap_set_free( set ); 611 mailimap_set_free( set );
610 mailimap_fetch_type_free( fetchType ); 612 mailimap_fetch_type_free( fetchType );
611 613
612 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 614 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
613 mailimap_msg_att * msg_att; 615 mailimap_msg_att * msg_att;
614 msg_att = (mailimap_msg_att*)current->data; 616 msg_att = (mailimap_msg_att*)current->data;
615 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 617 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
616 QValueList<int> path; 618 Q3ValueList<int> path;
617 body_desc = item->att_data.att_static->att_data.att_body; 619 body_desc = item->att_data.att_static->att_data.att_body;
618 traverseBody(mail,body_desc,body,0,path); 620 traverseBody(mail,body_desc,body,0,path);
619 } else { 621 } else {
620 qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response ); 622 qDebug("error fetching body %d (%d): %s", err, MAILIMAP_NO_ERROR, m_imap->imap_response );
621 } 623 }
622 if (result) mailimap_fetch_list_free(result); 624 if (result) mailimap_fetch_list_free(result);
623 return body; 625 return body;
624} 626}
625 627
626QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 628QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
627{ 629{
628 QStringList l; 630 QStringList l;
629 QString from; 631 QString from;
630 bool named_from; 632 bool named_from;
631 clistcell *current = NULL; 633 clistcell *current = NULL;
632 mailimap_address * current_address=NULL; 634 mailimap_address * current_address=NULL;
633 if (!list) { 635 if (!list) {
634 return l; 636 return l;
635 } 637 }
636 unsigned int count = 0; 638 unsigned int count = 0;
637 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 639 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
638 from = ""; 640 from = "";
639 named_from = false; 641 named_from = false;
640 current_address=(mailimap_address*)current->data; 642 current_address=(mailimap_address*)current->data;
641 if (current_address->ad_personal_name){ 643 if (current_address->ad_personal_name){
642 from+=convert_String((const char*)current_address->ad_personal_name); 644 from+=convert_String((const char*)current_address->ad_personal_name);
643 from+=" "; 645 from+=" ";
644 named_from = true; 646 named_from = true;
645 } 647 }
646 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 648 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
647 from+="<"; 649 from+="<";
648 } 650 }
649 if (current_address->ad_mailbox_name) { 651 if (current_address->ad_mailbox_name) {
650 from+=QString(current_address->ad_mailbox_name); 652 from+=QString(current_address->ad_mailbox_name);
651 from+="@"; 653 from+="@";
652 } 654 }
653 if (current_address->ad_host_name) { 655 if (current_address->ad_host_name) {
654 from+=QString(current_address->ad_host_name); 656 from+=QString(current_address->ad_host_name);
655 } 657 }
656 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 658 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
657 from+=">"; 659 from+=">";
658 } 660 }
659 l.append(QString(from)); 661 l.append(QString(from));
660 if (++count > 99) { 662 if (++count > 99) {
661 break; 663 break;
662 } 664 }
663 } 665 }
664 return l; 666 return l;
665} 667}
666 668
667encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 669encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call)
668{ 670{
669 encodedString*res=new encodedString; 671 encodedString*res=new encodedString;
670 int err; 672 int err;
671 mailimap_fetch_type *fetchType; 673 mailimap_fetch_type *fetchType;
672 mailimap_set *set; 674 mailimap_set *set;
673 clistcell*current,*cur; 675 clistcell*current,*cur;
674 mailimap_section_part * section_part = 0; 676 mailimap_section_part * section_part = 0;
675 mailimap_section_spec * section_spec = 0; 677 mailimap_section_spec * section_spec = 0;
676 mailimap_section * section = 0; 678 mailimap_section * section = 0;
677 mailimap_fetch_att * fetch_att = 0; 679 mailimap_fetch_att * fetch_att = 0;
678 680
679 login(); 681 login();
680 if (!m_imap) { 682 if (!m_imap) {
681 return res; 683 return res;
682 } 684 }
683 if (!internal_call) { 685 if (!internal_call) {
684 err = selectMbox(mail->getMbox()); 686 err = selectMbox(mail->getMbox());
685 if ( err != MAILIMAP_NO_ERROR ) { 687 if ( err != MAILIMAP_NO_ERROR ) {
686 return res; 688 return res;
687 } 689 }
688 } 690 }
689 set = mailimap_set_new_single(mail->getNumber()); 691 set = mailimap_set_new_single(mail->getNumber());
690 692
691 clist*id_list = 0; 693 clist*id_list = 0;
692 694
693 /* if path == empty then its a request for the whole rfc822 mail and generates 695 /* if path == empty then its a request for the whole rfc822 mail and generates
694 a "fetch <id> (body[])" statement on imap server */ 696 a "fetch <id> (body[])" statement on imap server */
695 if (path.count()>0 ) { 697 if (path.count()>0 ) {
696 id_list = clist_new(); 698 id_list = clist_new();
697 for (unsigned j=0; j < path.count();++j) { 699 for (unsigned j=0; j < path.count();++j) {
698 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 700 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
699 *p_id = path[j]; 701 *p_id = path[j];
700 clist_append(id_list,p_id); 702 clist_append(id_list,p_id);
701 } 703 }
702 section_part = mailimap_section_part_new(id_list); 704 section_part = mailimap_section_part_new(id_list);
703 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 705 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
704 } 706 }
705 707
706 section = mailimap_section_new(section_spec); 708 section = mailimap_section_new(section_spec);
707 fetch_att = mailimap_fetch_att_new_body_section(section); 709 fetch_att = mailimap_fetch_att_new_body_section(section);
708 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 710 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
709 711
710 clist*result = 0; 712 clist*result = 0;
711 713
712 err = mailimap_fetch( m_imap, set, fetchType, &result ); 714 err = mailimap_fetch( m_imap, set, fetchType, &result );
713 mailimap_set_free( set ); 715 mailimap_set_free( set );
714 mailimap_fetch_type_free( fetchType ); 716 mailimap_fetch_type_free( fetchType );
715 717
716 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 718 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
717 mailimap_msg_att * msg_att; 719 mailimap_msg_att * msg_att;
718 msg_att = (mailimap_msg_att*)current->data; 720 msg_att = (mailimap_msg_att*)current->data;
719 mailimap_msg_att_item*msg_att_item; 721 mailimap_msg_att_item*msg_att_item;
720 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 722 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
721 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 723 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
722 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 724 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
723 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 725 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
724 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 726 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
725 /* detach - we take over the content */ 727 /* detach - we take over the content */
726 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 728 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
727 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 729 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
728 } 730 }
729 } 731 }
730 } 732 }
731 } else { 733 } else {
732 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 734 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
733 } 735 }
734 if (result) mailimap_fetch_list_free(result); 736 if (result) mailimap_fetch_list_free(result);
735 return res; 737 return res;
736} 738}
737 739
738/* current_recursion is for recursive calls. 740/* current_recursion is for recursive calls.
739 current_count means the position inside the internal loop! */ 741 current_count means the position inside the internal loop! */
740void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 742void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
741 int current_recursion,QValueList<int>recList,int current_count) 743 int current_recursion,Q3ValueList<int>recList,int current_count)
742{ 744{
743 if (!body || current_recursion>=10) { 745 if (!body || current_recursion>=10) {
744 return; 746 return;
745 } 747 }
746 switch (body->bd_type) { 748 switch (body->bd_type) {
747 case MAILIMAP_BODY_1PART: 749 case MAILIMAP_BODY_1PART:
748 { 750 {
749 QValueList<int>countlist = recList; 751 Q3ValueList<int>countlist = recList;
750 countlist.append(current_count); 752 countlist.append(current_count);
751 RecPartP currentPart = new RecPart(); 753 RecPartP currentPart = new RecPart();
752 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 754 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
753 QString id(""); 755 QString id("");
754 currentPart->setPositionlist(countlist); 756 currentPart->setPositionlist(countlist);
755 for (unsigned int j = 0; j < countlist.count();++j) { 757 for (unsigned int j = 0; j < countlist.count();++j) {
756 id+=(j>0?" ":""); 758 id+=(j>0?" ":"");
757 id+=QString("%1").arg(countlist[j]); 759 id+=QString("%1").arg(countlist[j]);
758 } 760 }
759 //odebug << "ID = " << id.latin1() << "" << oendl; 761 //odebug << "ID = " << id.latin1() << "" << oendl;
760 currentPart->setIdentifier(id); 762 currentPart->setIdentifier(id);
761 fillSinglePart(currentPart,part1); 763 fillSinglePart(currentPart,part1);
762 /* important: Check for is NULL 'cause a body can be empty! 764 /* important: Check for is NULL 'cause a body can be empty!
763 And we put it only into the mail if it is the FIRST part */ 765 And we put it only into the mail if it is the FIRST part */
764 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 766 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
765 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 767 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
766 768
767 size_t index = 0; 769 size_t index = 0;
768 char*res = 0; 770 char*res = 0;
769 int err = MAILIMF_NO_ERROR; 771 int err = MAILIMF_NO_ERROR;
770 772
771 QString charset = currentPart->searchParamter( "charset"); 773 QString charset = currentPart->searchParamter( "charset");
772 qDebug("CHARSET %s ",charset.latin1() ); 774 qDebug("CHARSET %s ",charset.latin1() );
773 if ( false ) { 775 if ( false ) {
774 //if ( !charset.isEmpty() ) { 776 //if ( !charset.isEmpty() ) {
775 target_body->setCharset( charset ); 777 target_body->setCharset( charset );
776 //err = mailmime_encoded_phrase_parse("iso-8859-1", 778 //err = mailmime_encoded_phrase_parse("iso-8859-1",
777 // text, strlen(text),&index, "iso-8859-1",&res); 779 // text, strlen(text),&index, "iso-8859-1",&res);
778 err = mailmime_encoded_phrase_parse(charset.latin1(), 780 err = mailmime_encoded_phrase_parse(charset.latin1(),
779 body_text.latin1(), body_text.length(),&index, "utf-8",&res); 781 body_text.latin1(), body_text.length(),&index, "utf-8",&res);
780 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 782 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
781 //qDebug("res %d %s ", index, res); 783 //qDebug("res %d %s ", index, res);
782 body_text = QString::fromUtf8(res); 784 body_text = QString::fromUtf8(res);
783 } 785 }
784 if (res) free(res); 786 if (res) free(res);
785 } 787 }
786 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() ); 788 //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
787 target_body->setDescription(currentPart); 789 target_body->setDescription(currentPart);
788 target_body->setBodytext(body_text); 790 target_body->setBodytext(body_text);
789 if (countlist.count()>1) { 791 if (countlist.count()>1) {
790 target_body->addPart(currentPart); 792 target_body->addPart(currentPart);
791 } 793 }
792 } else { 794 } else {
793 target_body->addPart(currentPart); 795 target_body->addPart(currentPart);
794 } 796 }
795 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 797 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
796 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 798 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
797 } 799 }
798 } 800 }
799 break; 801 break;
800 case MAILIMAP_BODY_MPART: 802 case MAILIMAP_BODY_MPART:
801 { 803 {
802 QValueList<int>countlist = recList; 804 Q3ValueList<int>countlist = recList;
803 clistcell*current=0; 805 clistcell*current=0;
804 mailimap_body*current_body=0; 806 mailimap_body*current_body=0;
805 unsigned int ccount = 1; 807 unsigned int ccount = 1;
806 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 808 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
807 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 809 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
808 current_body = (mailimap_body*)current->data; 810 current_body = (mailimap_body*)current->data;
809 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 811 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
810 RecPartP targetPart = new RecPart(); 812 RecPartP targetPart = new RecPart();
811 targetPart->setType("multipart"); 813 targetPart->setType("multipart");
812 fillMultiPart(targetPart,mailDescription); 814 fillMultiPart(targetPart,mailDescription);
813 countlist.append(current_count); 815 countlist.append(current_count);
814 targetPart->setPositionlist(countlist); 816 targetPart->setPositionlist(countlist);
815 target_body->addPart(targetPart); 817 target_body->addPart(targetPart);
816 QString id(""); 818 QString id("");
817 for (unsigned int j = 0; j < countlist.count();++j) { 819 for (unsigned int j = 0; j < countlist.count();++j) {
818 id+=(j>0?" ":""); 820 id+=(j>0?" ":"");
819 id+=QString("%1").arg(countlist[j]); 821 id+=QString("%1").arg(countlist[j]);
820 } 822 }
821 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 823 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
822 } 824 }
823 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 825 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
824 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 826 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
825 countlist = recList; 827 countlist = recList;
826 } 828 }
827 ++ccount; 829 ++ccount;
828 } 830 }
829 } 831 }
830 break; 832 break;
831 default: 833 default:
832 break; 834 break;
833 } 835 }
834} 836}
835 837
836void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 838void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
837{ 839{
838 if (!Description) { 840 if (!Description) {
839 return; 841 return;
840 } 842 }
841 switch (Description->bd_type) { 843 switch (Description->bd_type) {
842 case MAILIMAP_BODY_TYPE_1PART_TEXT: 844 case MAILIMAP_BODY_TYPE_1PART_TEXT:
843 target_part->setType("text"); 845 target_part->setType("text");
844 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 846 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
845 break; 847 break;
846 case MAILIMAP_BODY_TYPE_1PART_BASIC: 848 case MAILIMAP_BODY_TYPE_1PART_BASIC:
847 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 849 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
848 break; 850 break;
849 case MAILIMAP_BODY_TYPE_1PART_MSG: 851 case MAILIMAP_BODY_TYPE_1PART_MSG:
850 target_part->setType("message"); 852 target_part->setType("message");
851 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 853 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
852 break; 854 break;
853 default: 855 default:
854 break; 856 break;
855 } 857 }
856} 858}
857 859
858void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 860void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
859{ 861{
860 if (!which) { 862 if (!which) {
861 return; 863 return;
862 } 864 }
863 QString sub; 865 QString sub;
864 sub = which->bd_media_text; 866 sub = which->bd_media_text;
865 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 867 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
866 target_part->setSubtype(sub.lower()); 868 target_part->setSubtype(sub.lower());
867 target_part->setLines(which->bd_lines); 869 target_part->setLines(which->bd_lines);
868 fillBodyFields(target_part,which->bd_fields); 870 fillBodyFields(target_part,which->bd_fields);
869} 871}
870 872
871void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 873void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
872{ 874{
873 if (!which) { 875 if (!which) {
874 return; 876 return;
875 } 877 }
876 target_part->setSubtype("rfc822"); 878 target_part->setSubtype("rfc822");
877 //odebug << "Message part" << oendl; 879 //odebug << "Message part" << oendl;
878 /* we set this type to text/plain */ 880 /* we set this type to text/plain */
879 target_part->setLines(which->bd_lines); 881 target_part->setLines(which->bd_lines);
880 fillBodyFields(target_part,which->bd_fields); 882 fillBodyFields(target_part,which->bd_fields);
881} 883}
882 884
883void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 885void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
884{ 886{
885 if (!which) return; 887 if (!which) return;
886 QString sub = which->bd_media_subtype; 888 QString sub = which->bd_media_subtype;
887 target_part->setSubtype(sub.lower()); 889 target_part->setSubtype(sub.lower());
888 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 890 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
889 clistcell*cur = 0; 891 clistcell*cur = 0;
890 mailimap_single_body_fld_param*param=0; 892 mailimap_single_body_fld_param*param=0;
891 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 893 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
892 param = (mailimap_single_body_fld_param*)cur->data; 894 param = (mailimap_single_body_fld_param*)cur->data;
893 if (param) { 895 if (param) {
894 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 896 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
895 } 897 }
896 } 898 }
897 } 899 }
898} 900}
899 901
900void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 902void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
901{ 903{
902 if (!which) { 904 if (!which) {
903 return; 905 return;
904 } 906 }
905 QString type,sub; 907 QString type,sub;
906 switch (which->bd_media_basic->med_type) { 908 switch (which->bd_media_basic->med_type) {
907 case MAILIMAP_MEDIA_BASIC_APPLICATION: 909 case MAILIMAP_MEDIA_BASIC_APPLICATION:
908 type = "application"; 910 type = "application";
909 break; 911 break;
910 case MAILIMAP_MEDIA_BASIC_AUDIO: 912 case MAILIMAP_MEDIA_BASIC_AUDIO:
911 type = "audio"; 913 type = "audio";
912 break; 914 break;
913 case MAILIMAP_MEDIA_BASIC_IMAGE: 915 case MAILIMAP_MEDIA_BASIC_IMAGE:
914 type = "image"; 916 type = "image";
915 break; 917 break;
916 case MAILIMAP_MEDIA_BASIC_MESSAGE: 918 case MAILIMAP_MEDIA_BASIC_MESSAGE:
917 type = "message"; 919 type = "message";
918 break; 920 break;
919 case MAILIMAP_MEDIA_BASIC_VIDEO: 921 case MAILIMAP_MEDIA_BASIC_VIDEO:
920 type = "video"; 922 type = "video";
921 break; 923 break;
922 case MAILIMAP_MEDIA_BASIC_OTHER: 924 case MAILIMAP_MEDIA_BASIC_OTHER:
923 default: 925 default:
924 if (which->bd_media_basic->med_basic_type) { 926 if (which->bd_media_basic->med_basic_type) {
925 type = which->bd_media_basic->med_basic_type; 927 type = which->bd_media_basic->med_basic_type;
926 } else { 928 } else {
927 type = ""; 929 type = "";
928 } 930 }
929 break; 931 break;
930 } 932 }
931 if (which->bd_media_basic->med_subtype) { 933 if (which->bd_media_basic->med_subtype) {
932 sub = which->bd_media_basic->med_subtype; 934 sub = which->bd_media_basic->med_subtype;
933 } else { 935 } else {
934 sub = ""; 936 sub = "";
935 } 937 }
936 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 938 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
937 target_part->setType(type.lower()); 939 target_part->setType(type.lower());
938 target_part->setSubtype(sub.lower()); 940 target_part->setSubtype(sub.lower());
939 fillBodyFields(target_part,which->bd_fields); 941 fillBodyFields(target_part,which->bd_fields);
940} 942}
941 943
942void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 944void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
943{ 945{
944 if (!which) return; 946 if (!which) return;
945 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 947 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
946 clistcell*cur; 948 clistcell*cur;
947 mailimap_single_body_fld_param*param=0; 949 mailimap_single_body_fld_param*param=0;
948 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 950 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
949 param = (mailimap_single_body_fld_param*)cur->data; 951 param = (mailimap_single_body_fld_param*)cur->data;
950 if (param) { 952 if (param) {
951 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 953 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
952 } 954 }
953 } 955 }
954 } 956 }
955 mailimap_body_fld_enc*enc = which->bd_encoding; 957 mailimap_body_fld_enc*enc = which->bd_encoding;
956 QString encoding(""); 958 QString encoding("");
957 switch (enc->enc_type) { 959 switch (enc->enc_type) {
958 case MAILIMAP_BODY_FLD_ENC_7BIT: 960 case MAILIMAP_BODY_FLD_ENC_7BIT:
959 encoding = "7bit"; 961 encoding = "7bit";
960 break; 962 break;
961 case MAILIMAP_BODY_FLD_ENC_8BIT: 963 case MAILIMAP_BODY_FLD_ENC_8BIT:
962 encoding = "8bit"; 964 encoding = "8bit";
963 break; 965 break;
964 case MAILIMAP_BODY_FLD_ENC_BINARY: 966 case MAILIMAP_BODY_FLD_ENC_BINARY:
965 encoding="binary"; 967 encoding="binary";
966 break; 968 break;
967 case MAILIMAP_BODY_FLD_ENC_BASE64: 969 case MAILIMAP_BODY_FLD_ENC_BASE64:
968 encoding="base64"; 970 encoding="base64";
969 break; 971 break;
970 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 972 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
971 encoding="quoted-printable"; 973 encoding="quoted-printable";
972 break; 974 break;
973 case MAILIMAP_BODY_FLD_ENC_OTHER: 975 case MAILIMAP_BODY_FLD_ENC_OTHER:
974 default: 976 default:
975 if (enc->enc_value) { 977 if (enc->enc_value) {
976 char*t=enc->enc_value; 978 char*t=enc->enc_value;
977 encoding=QString(enc->enc_value); 979 encoding=QString(enc->enc_value);
978 enc->enc_value=0L; 980 enc->enc_value=0L;
979 free(t); 981 free(t);
980 } 982 }
981 } 983 }
982 if (which->bd_description) { 984 if (which->bd_description) {
983 target_part->setDescription(QString(which->bd_description)); 985 target_part->setDescription(QString(which->bd_description));
984 } 986 }
985 target_part->setEncoding(encoding); 987 target_part->setEncoding(encoding);
986 target_part->setSize(which->bd_size); 988 target_part->setSize(which->bd_size);
987} 989}
988void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 990void IMAPwrapper::deleteMailList(const Q3ValueList<RecMailP>&target)
989{ 991{
990 //#if 0 992 //#if 0
991 mailimap_flag_list*flist; 993 mailimap_flag_list*flist;
992 mailimap_set *set; 994 mailimap_set *set;
993 mailimap_store_att_flags * store_flags; 995 mailimap_store_att_flags * store_flags;
994 int err; 996 int err;
995 login(); 997 login();
996 //#endif 998 //#endif
997 if (!m_imap) { 999 if (!m_imap) {
998 return; 1000 return;
999 } 1001 }
1000 int iii = 0; 1002 int iii = 0;
1001 int count = target.count(); 1003 int count = target.count();
1002 // qDebug("imap remove count %d ", count); 1004 // qDebug("imap remove count %d ", count);
1003 1005
1004 1006
1005 mMax = count; 1007 mMax = count;
1006 progress( i18n("Delete")); 1008 progress( i18n("Delete"));
1007 1009
1008 QProgressBar wid ( count ); 1010 Q3ProgressBar wid ( count );
1009 wid.setCaption( i18n("Deleting ...")); 1011 wid.setCaption( i18n("Deleting ..."));
1010 wid.show(); 1012 wid.show();
1011 while (iii < count ) { 1013 while (iii < count ) {
1012 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 1014 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
1013 wid.setProgress( iii ); 1015 wid.setProgress( iii );
1014 wid.raise(); 1016 wid.raise();
1015 qApp->processEvents(); 1017 qApp->processEvents();
1016 RecMailP mail = (*target.at( iii )); 1018 RecMailP mail = (*target.at( iii ));
1017 //#if 0 1019 //#if 0
1018 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 1020 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
1019 err = selectMbox(mail->getMbox()); 1021 err = selectMbox(mail->getMbox());
1020 if ( err != MAILIMAP_NO_ERROR ) { 1022 if ( err != MAILIMAP_NO_ERROR ) {
1021 return; 1023 return;
1022 } 1024 }
1023 flist = mailimap_flag_list_new_empty(); 1025 flist = mailimap_flag_list_new_empty();
1024 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1026 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1025 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1027 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1026 set = mailimap_set_new_single(mail->getNumber()); 1028 set = mailimap_set_new_single(mail->getNumber());
1027 err = mailimap_store(m_imap,set,store_flags); 1029 err = mailimap_store(m_imap,set,store_flags);
1028 mailimap_set_free( set ); 1030 mailimap_set_free( set );
1029 mailimap_store_att_flags_free(store_flags); 1031 mailimap_store_att_flags_free(store_flags);
1030 1032
1031 if (err != MAILIMAP_NO_ERROR) { 1033 if (err != MAILIMAP_NO_ERROR) {
1032 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1034 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1033 return; 1035 return;
1034 } 1036 }
1035 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1037 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1036 /* should we realy do that at this moment? */ 1038 /* should we realy do that at this moment? */
1037 1039
1038 // err = mailimap_expunge(m_imap); 1040 // err = mailimap_expunge(m_imap);
1039 //if (err != MAILIMAP_NO_ERROR) { 1041 //if (err != MAILIMAP_NO_ERROR) {
1040 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1042 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1041 // } 1043 // }
1042 //#endif 1044 //#endif
1043 //deleteMail( mail); 1045 //deleteMail( mail);
1044 ++iii; 1046 ++iii;
1045 } 1047 }
1046 //qDebug("Deleting imap mails... "); 1048 //qDebug("Deleting imap mails... ");
1047 err = mailimap_expunge(m_imap); 1049 err = mailimap_expunge(m_imap);
1048 if (err != MAILIMAP_NO_ERROR) { 1050 if (err != MAILIMAP_NO_ERROR) {
1049 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response)); 1051 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1050 } 1052 }
1051} 1053}
1052void IMAPwrapper::deleteMail(const RecMailP&mail) 1054void IMAPwrapper::deleteMail(const RecMailP&mail)
1053{ 1055{
1054 mailimap_flag_list*flist; 1056 mailimap_flag_list*flist;
1055 mailimap_set *set; 1057 mailimap_set *set;
1056 mailimap_store_att_flags * store_flags; 1058 mailimap_store_att_flags * store_flags;
1057 int err; 1059 int err;
1058 login(); 1060 login();
1059 if (!m_imap) { 1061 if (!m_imap) {
1060 return; 1062 return;
1061 } 1063 }
1062 err = selectMbox(mail->getMbox()); 1064 err = selectMbox(mail->getMbox());
1063 if ( err != MAILIMAP_NO_ERROR ) { 1065 if ( err != MAILIMAP_NO_ERROR ) {
1064 return; 1066 return;
1065 } 1067 }
1066 flist = mailimap_flag_list_new_empty(); 1068 flist = mailimap_flag_list_new_empty();
1067 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1069 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1068 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1070 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1069 set = mailimap_set_new_single(mail->getNumber()); 1071 set = mailimap_set_new_single(mail->getNumber());
1070 err = mailimap_store(m_imap,set,store_flags); 1072 err = mailimap_store(m_imap,set,store_flags);
1071 mailimap_set_free( set ); 1073 mailimap_set_free( set );
1072 mailimap_store_att_flags_free(store_flags); 1074 mailimap_store_att_flags_free(store_flags);
1073 1075
1074 if (err != MAILIMAP_NO_ERROR) { 1076 if (err != MAILIMAP_NO_ERROR) {
1075 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1077 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1076 return; 1078 return;
1077 } 1079 }
1078 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1080 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1079 /* should we realy do that at this moment? */ 1081 /* should we realy do that at this moment? */
1080 1082
1081 err = mailimap_expunge(m_imap); 1083 err = mailimap_expunge(m_imap);
1082 if (err != MAILIMAP_NO_ERROR) { 1084 if (err != MAILIMAP_NO_ERROR) {
1083 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1085 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1084 } 1086 }
1085 //qDebug("IMAPwrapper::deleteMail 2"); 1087 //qDebug("IMAPwrapper::deleteMail 2");
1086 1088
1087} 1089}
1088 1090
1089void IMAPwrapper::answeredMail(const RecMailP&mail) 1091void IMAPwrapper::answeredMail(const RecMailP&mail)
1090{ 1092{
1091 mailimap_flag_list*flist; 1093 mailimap_flag_list*flist;
1092 mailimap_set *set; 1094 mailimap_set *set;
1093 mailimap_store_att_flags * store_flags; 1095 mailimap_store_att_flags * store_flags;
1094 int err; 1096 int err;
1095 login(); 1097 login();
1096 if (!m_imap) { 1098 if (!m_imap) {
1097 return; 1099 return;
1098 } 1100 }
1099 err = selectMbox(mail->getMbox()); 1101 err = selectMbox(mail->getMbox());
1100 if ( err != MAILIMAP_NO_ERROR ) { 1102 if ( err != MAILIMAP_NO_ERROR ) {
1101 return; 1103 return;
1102 } 1104 }
1103 flist = mailimap_flag_list_new_empty(); 1105 flist = mailimap_flag_list_new_empty();
1104 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1106 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1105 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1107 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1106 set = mailimap_set_new_single(mail->getNumber()); 1108 set = mailimap_set_new_single(mail->getNumber());
1107 err = mailimap_store(m_imap,set,store_flags); 1109 err = mailimap_store(m_imap,set,store_flags);
1108 mailimap_set_free( set ); 1110 mailimap_set_free( set );
1109 mailimap_store_att_flags_free(store_flags); 1111 mailimap_store_att_flags_free(store_flags);
1110 1112
1111 if (err != MAILIMAP_NO_ERROR) { 1113 if (err != MAILIMAP_NO_ERROR) {
1112 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1114 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1113 return; 1115 return;
1114 } 1116 }
1115} 1117}
1116 1118
1117QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1119QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call,const QString&enc)
1118{ 1120{
1119 QString body(""); 1121 QString body("");
1120 encodedString*res = fetchRawPart(mail,path,internal_call); 1122 encodedString*res = fetchRawPart(mail,path,internal_call);
1121 encodedString*r = decode_String(res,enc); 1123 encodedString*r = decode_String(res,enc);
1122 delete res; 1124 delete res;
1123 if (r) { 1125 if (r) {
1124 if (r->Length()>0) { 1126 if (r->Length()>0) {
1125 body = r->Content(); 1127 body = r->Content();
1126 } 1128 }
1127 delete r; 1129 delete r;
1128 } 1130 }
1129 return body; 1131 return body;
1130} 1132}
1131 1133
1132QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1134QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1133{ 1135{
1134 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1136 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1135} 1137}
1136 1138
1137encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1139encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1138{ 1140{
1139 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1141 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1140 encodedString*r = decode_String(res,part->Encoding()); 1142 encodedString*r = decode_String(res,part->Encoding());
1141 delete res; 1143 delete res;
1142 return r; 1144 return r;
1143} 1145}
1144 1146
1145encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1147encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1146{ 1148{
1147 return fetchRawPart(mail,part->Positionlist(),false); 1149 return fetchRawPart(mail,part->Positionlist(),false);
1148} 1150}
1149 1151
1150int IMAPwrapper::deleteAllMail(const FolderP&folder) 1152int IMAPwrapper::deleteAllMail(const FolderP&folder)
1151{ 1153{
1152 login(); 1154 login();
1153 if (!m_imap) { 1155 if (!m_imap) {
1154 return 0; 1156 return 0;
1155 } 1157 }
1156 mailimap_flag_list*flist; 1158 mailimap_flag_list*flist;
1157 mailimap_set *set; 1159 mailimap_set *set;
1158 mailimap_store_att_flags * store_flags; 1160 mailimap_store_att_flags * store_flags;
1159 int err = selectMbox(folder->getName()); 1161 int err = selectMbox(folder->getName());
1160 if ( err != MAILIMAP_NO_ERROR ) { 1162 if ( err != MAILIMAP_NO_ERROR ) {
1161 return 0; 1163 return 0;
1162 } 1164 }
1163 1165
1164 int last = m_imap->imap_selection_info->sel_exists; 1166 int last = m_imap->imap_selection_info->sel_exists;
1165 if (last == 0) { 1167 if (last == 0) {
1166 Global::statusMessage(i18n("Mailbox has no mails!")); 1168 Global::statusMessage(i18n("Mailbox has no mails!"));
1167 return 0; 1169 return 0;
1168 } 1170 }
1169 flist = mailimap_flag_list_new_empty(); 1171 flist = mailimap_flag_list_new_empty();
1170 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1172 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1171 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1173 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1172 set = mailimap_set_new_interval( 1, last ); 1174 set = mailimap_set_new_interval( 1, last );
1173 err = mailimap_store(m_imap,set,store_flags); 1175 err = mailimap_store(m_imap,set,store_flags);
1174 mailimap_set_free( set ); 1176 mailimap_set_free( set );
1175 mailimap_store_att_flags_free(store_flags); 1177 mailimap_store_att_flags_free(store_flags);
1176 if (err != MAILIMAP_NO_ERROR) { 1178 if (err != MAILIMAP_NO_ERROR) {
1177 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1179 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1178 return 0; 1180 return 0;
1179 } 1181 }
1180 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1182 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1181 /* should we realy do that at this moment? */ 1183 /* should we realy do that at this moment? */
1182 err = mailimap_expunge(m_imap); 1184 err = mailimap_expunge(m_imap);
1183 if (err != MAILIMAP_NO_ERROR) { 1185 if (err != MAILIMAP_NO_ERROR) {
1184 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response)); 1186 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1185 return 0; 1187 return 0;
1186 } 1188 }
1187 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1189 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1188 return 1; 1190 return 1;
1189} 1191}
1190 1192
1191int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1193int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1192{ 1194{
1193 if (folder.length()==0) return 0; 1195 if (folder.length()==0) return 0;
1194 login(); 1196 login();
1195 if (!m_imap) {return 0;} 1197 if (!m_imap) {return 0;}
1196 QString pre = account->getPrefix(); 1198 QString pre = account->getPrefix();
1197 if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) { 1199 if (delemiter.length()>0 && pre.findRev(delemiter)!=((int)pre.length())-1) {
1198 pre+=delemiter; 1200 pre+=delemiter;
1199 } 1201 }
1200 if (parentfolder) { 1202 if (parentfolder) {
1201 pre += parentfolder->getDisplayName()+delemiter; 1203 pre += parentfolder->getDisplayName()+delemiter;
1202 } 1204 }
1203 pre+=folder; 1205 pre+=folder;
1204 if (getsubfolder) { 1206 if (getsubfolder) {
1205 if (delemiter.length()>0) { 1207 if (delemiter.length()>0) {
1206 pre+=delemiter; 1208 pre+=delemiter;
1207 } else { 1209 } else {
1208 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre)); 1210 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
1209 return 0; 1211 return 0;
1210 } 1212 }
1211 } 1213 }
1212 // odebug << "Creating " << pre.latin1() << "" << oendl; 1214 // odebug << "Creating " << pre.latin1() << "" << oendl;
1213 int res = mailimap_create(m_imap,pre.latin1()); 1215 int res = mailimap_create(m_imap,pre.latin1());
1214 if (res != MAILIMAP_NO_ERROR) { 1216 if (res != MAILIMAP_NO_ERROR) {
1215 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1217 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1216 return 0; 1218 return 0;
1217 } 1219 }
1218 return 1; 1220 return 1;
1219} 1221}
1220 1222
1221int IMAPwrapper::deleteMbox(const FolderP&folder) 1223int IMAPwrapper::deleteMbox(const FolderP&folder)
1222{ 1224{
1223 if (!folder) return 0; 1225 if (!folder) return 0;
1224 login(); 1226 login();
1225 if (!m_imap) {return 0;} 1227 if (!m_imap) {return 0;}
1226 int res = mailimap_delete(m_imap,folder->getName()); 1228 int res = mailimap_delete(m_imap,folder->getName());
1227 if (res != MAILIMAP_NO_ERROR) { 1229 if (res != MAILIMAP_NO_ERROR) {
1228 Global::statusMessage(i18n("%1").arg(m_imap->imap_response)); 1230 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1229 return 0; 1231 return 0;
1230 } 1232 }
1231 return 1; 1233 return 1;
1232} 1234}
1233 1235
1234void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1236void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1235{ 1237{
1236 mailimap_status_att_list * att_list =0; 1238 mailimap_status_att_list * att_list =0;
1237 mailimap_mailbox_data_status * status=0; 1239 mailimap_mailbox_data_status * status=0;
1238 clistiter * cur = 0; 1240 clistiter * cur = 0;
1239 int r = 0; 1241 int r = 0;
1240 target_stat.message_count = 0; 1242 target_stat.message_count = 0;
1241 target_stat.message_unseen = 0; 1243 target_stat.message_unseen = 0;
1242 target_stat.message_recent = 0; 1244 target_stat.message_recent = 0;
1243 login(); 1245 login();
1244 if (!m_imap) { 1246 if (!m_imap) {
1245 return; 1247 return;
1246 } 1248 }
1247 att_list = mailimap_status_att_list_new_empty(); 1249 att_list = mailimap_status_att_list_new_empty();
1248 if (!att_list) return; 1250 if (!att_list) return;
1249 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1251 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1250 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1252 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1251 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1253 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1252 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1254 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1253 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1255 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1254 for (cur = clist_begin(status->st_info_list); 1256 for (cur = clist_begin(status->st_info_list);
1255 cur != NULL ; cur = clist_next(cur)) { 1257 cur != NULL ; cur = clist_next(cur)) {
1256 mailimap_status_info * status_info; 1258 mailimap_status_info * status_info;
1257 status_info = (mailimap_status_info *)clist_content(cur); 1259 status_info = (mailimap_status_info *)clist_content(cur);
1258 switch (status_info->st_att) { 1260 switch (status_info->st_att) {
1259 case MAILIMAP_STATUS_ATT_MESSAGES: 1261 case MAILIMAP_STATUS_ATT_MESSAGES:
1260 target_stat.message_count = status_info->st_value; 1262 target_stat.message_count = status_info->st_value;
1261 break; 1263 break;
1262 case MAILIMAP_STATUS_ATT_RECENT: 1264 case MAILIMAP_STATUS_ATT_RECENT:
1263 target_stat.message_recent = status_info->st_value; 1265 target_stat.message_recent = status_info->st_value;
1264 break; 1266 break;
1265 case MAILIMAP_STATUS_ATT_UNSEEN: 1267 case MAILIMAP_STATUS_ATT_UNSEEN:
1266 target_stat.message_unseen = status_info->st_value; 1268 target_stat.message_unseen = status_info->st_value;
1267 break; 1269 break;
1268 } 1270 }
1269 } 1271 }
1270 } else { 1272 } else {
1271 // odebug << "Error retrieving status" << oendl; 1273 // odebug << "Error retrieving status" << oendl;
1272 } 1274 }
1273 if (status) mailimap_mailbox_data_status_free(status); 1275 if (status) mailimap_mailbox_data_status_free(status);
1274 if (att_list) mailimap_status_att_list_free(att_list); 1276 if (att_list) mailimap_status_att_list_free(att_list);
1275} 1277}
1276 1278
1277void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1279void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1278{ 1280{
1279 login(); 1281 login();
1280 if (!m_imap) return; 1282 if (!m_imap) return;
1281 if (!msg) return; 1283 if (!msg) return;
1282 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1284 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1283 if (r != MAILIMAP_NO_ERROR) { 1285 if (r != MAILIMAP_NO_ERROR) {
1284 Global::statusMessage("Error storing mail!"); 1286 Global::statusMessage("Error storing mail!");
1285 } 1287 }
1286} 1288}
1287 1289
1288MAILLIB::ATYPE IMAPwrapper::getType()const 1290MAILLIB::ATYPE IMAPwrapper::getType()const
1289{ 1291{
1290 return account->getType(); 1292 return account->getType();
1291} 1293}
1292 1294
1293const QString&IMAPwrapper::getName()const 1295const QString&IMAPwrapper::getName()const
1294{ 1296{
1295 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1297 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1296 return account->getAccountName(); 1298 return account->getAccountName();
1297} 1299}
1298 1300
1299encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1301encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1300{ 1302{
1301 // dummy 1303 // dummy
1302 QValueList<int> path; 1304 Q3ValueList<int> path;
1303 return fetchRawPart(mail,path,false); 1305 return fetchRawPart(mail,path,false);
1304} 1306}
1305 1307
1306void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1308void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1307 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1309 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1308{ 1310{
1309 if (targetWrapper != this || maxSizeInKb > 0 ) { 1311 if (targetWrapper != this || maxSizeInKb > 0 ) {
1310 mMax = 0; 1312 mMax = 0;
1311 progress( i18n("Copy")); 1313 progress( i18n("Copy"));
1312 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1314 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1313 //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1315 //qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1314 // odebug << "Using generic" << oendl; 1316 // odebug << "Using generic" << oendl;
1315 return; 1317 return;
1316 } 1318 }
1317 mailimap_set *set = 0; 1319 mailimap_set *set = 0;
1318 login(); 1320 login();
1319 if (!m_imap) { 1321 if (!m_imap) {
1320 return; 1322 return;
1321 } 1323 }
1322 int err = selectMbox(fromFolder->getName()); 1324 int err = selectMbox(fromFolder->getName());
1323 if ( err != MAILIMAP_NO_ERROR ) { 1325 if ( err != MAILIMAP_NO_ERROR ) {
1324 return; 1326 return;
1325 } 1327 }
1326 Global::statusMessage( i18n("Copying mails on server...") ); 1328 Global::statusMessage( i18n("Copying mails on server...") );
1327 int last = m_imap->imap_selection_info->sel_exists; 1329 int last = m_imap->imap_selection_info->sel_exists;
1328 set = mailimap_set_new_interval( 1, last ); 1330 set = mailimap_set_new_interval( 1, last );
1329 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1331 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1330 mailimap_set_free( set ); 1332 mailimap_set_free( set );
1331 if ( err != MAILIMAP_NO_ERROR ) { 1333 if ( err != MAILIMAP_NO_ERROR ) {
1332 QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response); 1334 QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response);
1333 Global::statusMessage(error_msg); 1335 Global::statusMessage(error_msg);
1334 // odebug << error_msg << oendl; 1336 // odebug << error_msg << oendl;
1335 return; 1337 return;
1336 } 1338 }
1337 if (moveit) { 1339 if (moveit) {
1338 deleteAllMail(fromFolder); 1340 deleteAllMail(fromFolder);
1339 } 1341 }
1340} 1342}
1341 1343
1342void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1344void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1343{ 1345{
1344 if (targetWrapper != this) { 1346 if (targetWrapper != this) {
1345 // odebug << "Using generic" << oendl; 1347 // odebug << "Using generic" << oendl;
1346 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1348 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1347 return; 1349 return;
1348 } 1350 }
1349 mailimap_set *set = 0; 1351 mailimap_set *set = 0;
1350 login(); 1352 login();
1351 if (!m_imap) { 1353 if (!m_imap) {
1352 return; 1354 return;
1353 } 1355 }
1354 int err = selectMbox(mail->getMbox()); 1356 int err = selectMbox(mail->getMbox());
1355 if ( err != MAILIMAP_NO_ERROR ) { 1357 if ( err != MAILIMAP_NO_ERROR ) {
1356 return; 1358 return;
1357 } 1359 }
1358 set = mailimap_set_new_single(mail->getNumber()); 1360 set = mailimap_set_new_single(mail->getNumber());
1359 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1361 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1360 mailimap_set_free( set ); 1362 mailimap_set_free( set );
1361 if ( err != MAILIMAP_NO_ERROR ) { 1363 if ( err != MAILIMAP_NO_ERROR ) {
1362 QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response); 1364 QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response);
1363 Global::statusMessage(error_msg); 1365 Global::statusMessage(error_msg);
1364 // odebug << error_msg << oendl; 1366 // odebug << error_msg << oendl;
1365 return; 1367 return;
1366 } 1368 }
1367 if (moveit) { 1369 if (moveit) {
1368 deleteMail(mail); 1370 deleteMail(mail);
1369 } 1371 }
1370} 1372}
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h
index 31c60a8..d3d3ecd 100644
--- a/kmicromail/libmailwrapper/imapwrapper.h
+++ b/kmicromail/libmailwrapper/imapwrapper.h
@@ -1,85 +1,87 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __IMAPWRAPPER 2#ifndef __IMAPWRAPPER
3#define __IMAPWRAPPER 3#define __IMAPWRAPPER
4 4
5#include <qlist.h> 5#include <qlist.h>
6//Added by qt3to4:
7#include <Q3ValueList>
6#include "mailwrapper.h" 8#include "mailwrapper.h"
7#include "abstractmail.h" 9#include "abstractmail.h"
8#include <libetpan/clist.h> 10#include <libetpan/clist.h>
9 11
10struct mailimap; 12struct mailimap;
11struct mailimap_body; 13struct mailimap_body;
12struct mailimap_body_type_1part; 14struct mailimap_body_type_1part;
13struct mailimap_body_type_text; 15struct mailimap_body_type_text;
14struct mailimap_body_type_basic; 16struct mailimap_body_type_basic;
15struct mailimap_body_type_msg; 17struct mailimap_body_type_msg;
16struct mailimap_body_type_mpart; 18struct mailimap_body_type_mpart;
17struct mailimap_body_fields; 19struct mailimap_body_fields;
18struct mailimap_msg_att; 20struct mailimap_msg_att;
19class encodedString; 21class encodedString;
20 22
21class IMAPwrapper : public AbstractMail 23class IMAPwrapper : public AbstractMail
22{ 24{
23 Q_OBJECT 25 Q_OBJECT
24public: 26public:
25 IMAPwrapper( IMAPaccount *a ); 27 IMAPwrapper( IMAPaccount *a );
26 virtual ~IMAPwrapper(); 28 virtual ~IMAPwrapper();
27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 29 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0); 30 virtual void listMessages(const QString & mailbox,Q3ValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0);
29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 31 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
30 32
31 virtual void deleteMail(const RecMailP&mail); 33 virtual void deleteMail(const RecMailP&mail);
32 void deleteMailList(const QValueList<RecMailP>&target); 34 void deleteMailList(const Q3ValueList<RecMailP>&target);
33 virtual void answeredMail(const RecMailP&mail); 35 virtual void answeredMail(const RecMailP&mail);
34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); 36 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder);
35 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 37 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 38 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); 39 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0);
38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 40 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
39 41
40 virtual RecBodyP fetchBody(const RecMailP&mail); 42 virtual RecBodyP fetchBody(const RecMailP&mail);
41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 43 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 44 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 45 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
44 virtual encodedString* fetchRawBody(const RecMailP&mail); 46 virtual encodedString* fetchRawBody(const RecMailP&mail);
45 47
46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 48 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
47 const QString& delemiter="/",bool getsubfolder=false); 49 const QString& delemiter="/",bool getsubfolder=false);
48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); 50 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder);
49 51
50 static void imap_progress( size_t current, size_t maximum ); 52 static void imap_progress( size_t current, size_t maximum );
51 53
52 virtual void logout(); 54 virtual void logout();
53 virtual MAILLIB::ATYPE getType()const; 55 virtual MAILLIB::ATYPE getType()const;
54 virtual const QString&getName()const; 56 virtual const QString&getName()const;
55 virtual Account* getAccount() { return account; }; 57 virtual Account* getAccount() { return account; };
56 58
57protected: 59protected:
58 RecMail*parse_list_result(mailimap_msg_att*); 60 RecMail*parse_list_result(mailimap_msg_att*);
59 void login(bool tryTLS = true); 61 void login(bool tryTLS = true);
60 bool start_tls(bool force=true); 62 bool start_tls(bool force=true);
61 63
62 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 64 virtual QString fetchTextPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call=false,const QString&enc="");
63 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); 65 virtual encodedString*fetchRawPart(const RecMailP&mail,const Q3ValueList<int>&path,bool internal_call);
64 int selectMbox(const QString&mbox); 66 int selectMbox(const QString&mbox);
65 67
66 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); 68 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description);
67 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); 69 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which);
68 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); 70 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which);
69 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); 71 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which);
70 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); 72 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which);
71 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 73 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,Q3ValueList<int>recList,int current_count=1);
72 74
73 /* just helpers */ 75 /* just helpers */
74 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); 76 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which);
75 static QStringList address_list_to_stringlist(clist*list); 77 static QStringList address_list_to_stringlist(clist*list);
76 78
77 static void progress(QString mess = QString::null); 79 static void progress(QString mess = QString::null);
78 static int mCurrent; 80 static int mCurrent;
79 static int mMax; 81 static int mMax;
80 IMAPaccount *account; 82 IMAPaccount *account;
81 mailimap *m_imap; 83 mailimap *m_imap;
82 QString m_Lastmbox; 84 QString m_Lastmbox;
83}; 85};
84 86
85#endif 87#endif
diff --git a/kmicromail/libmailwrapper/libmailwrapper.pro b/kmicromail/libmailwrapper/libmailwrapper.pro
index 646630b..6b595ab 100644
--- a/kmicromail/libmailwrapper/libmailwrapper.pro
+++ b/kmicromail/libmailwrapper/libmailwrapper.pro
@@ -1,65 +1,71 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3 3
4HEADERS = mailwrapper.h \ 4HEADERS = mailwrapper.h \
5 imapwrapper.h \ 5 imapwrapper.h \
6 mailtypes.h \ 6 mailtypes.h \
7 pop3wrapper.h \ 7 pop3wrapper.h \
8 abstractmail.h \ 8 abstractmail.h \
9 smtpwrapper.h \ 9 smtpwrapper.h \
10 genericwrapper.h \ 10 genericwrapper.h \
11 mboxwrapper.h \ 11 mboxwrapper.h \
12 settings.h \ 12 settings.h \
13 logindialog.h \ 13 logindialog.h \
14 sendmailprogress.h \ 14 sendmailprogress.h \
15 statusmail.h \ 15 statusmail.h \
16 mhwrapper.h \ 16 mhwrapper.h \
17 nntpwrapper.h \ 17 nntpwrapper.h \
18 generatemail.h \ 18 generatemail.h \
19 storemail.h \ 19 storemail.h \
20 ../qpe/global.h 20 ../qpe/global.h
21 21
22SOURCES = imapwrapper.cpp \ 22SOURCES = imapwrapper.cpp \
23 mailwrapper.cpp \ 23 mailwrapper.cpp \
24 mailtypes.cpp \ 24 mailtypes.cpp \
25 pop3wrapper.cpp \ 25 pop3wrapper.cpp \
26 abstractmail.cpp \ 26 abstractmail.cpp \
27 smtpwrapper.cpp \ 27 smtpwrapper.cpp \
28 genericwrapper.cpp \ 28 genericwrapper.cpp \
29 mboxwrapper.cpp \ 29 mboxwrapper.cpp \
30 settings.cpp \ 30 settings.cpp \
31 logindialog.cpp \ 31 logindialog.cpp \
32 sendmailprogress.cpp \ 32 sendmailprogress.cpp \
33 statusmail.cpp \ 33 statusmail.cpp \
34 mhwrapper.cpp \ 34 mhwrapper.cpp \
35 nntpwrapper.cpp \ 35 nntpwrapper.cpp \
36 generatemail.cpp \ 36 generatemail.cpp \
37 storemail.cpp \ 37 storemail.cpp \
38 ../qpe/qdialog_hacked.cpp \ 38 ../qpe/qdialog_hacked.cpp \
39 ../qpe/global.cpp 39 ../qpe/global.cpp
40 40
41INTERFACES = logindialogui.ui \ 41#The following line was changed from INTERFACES to FORMS3 by qt3to4
42FORMS3 = logindialogui.ui \
42 sendmailprogressui.ui 43 sendmailprogressui.ui
43 44
44INCLUDEPATH += ../qpe .. ../../microkde ../../microkde/kdecore ../../libetpan/include 45INCLUDEPATH += ../qpe .. ../../microkde ../../microkde/kdecore ../../libetpan/include
45LIBS += -lssl -lcrypto 46LIBS += -lssl -lcrypto
46 47
47#-lqpe -letpan 48#-lqpe -letpan
48 49
49DESTDIR = ../../bin 50DESTDIR = ../../bin
50TARGET = micromailwrapper 51TARGET = micromailwrapper
51 52
52DEFINES += DESKTOP_VERSION 53DEFINES += DESKTOP_VERSION
53unix : { 54unix : {
54OBJECTS_DIR = obj/unix 55OBJECTS_DIR = obj/unix
55MOC_DIR = moc/unix 56MOC_DIR = moc/unix
56} 57}
57win32: { 58win32: {
58DEFINES += _WIN32_ 59DEFINES += _WIN32_
59LIBS += mfc71u.lib 60LIBS += mfc71u.lib
60QMAKE_LINK += /NODEFAULTLIB:LIBC 61QMAKE_LINK += /NODEFAULTLIB:LIBC
61#QMAKE_LINK += /NODEFAULTLIB:MSVCRT 62#QMAKE_LINK += /NODEFAULTLIB:MSVCRT
62#QMAKE_LINK += /NODEFAULTLIB:uafxcw.lib 63#QMAKE_LINK += /NODEFAULTLIB:uafxcw.lib
63OBJECTS_DIR = obj/win 64OBJECTS_DIR = obj/win
64MOC_DIR = moc/win 65MOC_DIR = moc/win
65} 66}
67#The following line was inserted by qt3to4
68QT += xml qt3support
69#The following line was inserted by qt3to4
70CONFIG += uic3
71
diff --git a/kmicromail/libmailwrapper/logindialog.cpp b/kmicromail/libmailwrapper/logindialog.cpp
index 31b75d0..d1f4b5d 100644
--- a/kmicromail/libmailwrapper/logindialog.cpp
+++ b/kmicromail/libmailwrapper/logindialog.cpp
@@ -1,33 +1,33 @@
1#include <qlineedit.h> 1#include <qlineedit.h>
2 2
3#include "logindialog.h" 3#include "logindialog.h"
4 4
5 5
6 6
7//using namespace Opie::Core; 7//using namespace Opie::Core;
8 8
9LoginDialog::LoginDialog(const QString&user,const QString&pass, QWidget *parent, const char *name, bool modal, WFlags flags ) 9LoginDialog::LoginDialog(const QString&user,const QString&pass, QWidget *parent, const char *name, bool modal, Qt::WFlags flags )
10 : LoginDialogUI( parent, name, modal, flags ) 10 : LoginDialogUI( parent, name, modal, flags )
11{ 11{
12 userLine->setText( (user.isEmpty()?QString(""):user) ); 12 userLine->setText( (user.isEmpty()?QString(""):user) );
13 passLine->setText( (pass.isEmpty()?QString(""):pass) ); 13 passLine->setText( (pass.isEmpty()?QString(""):pass) );
14 _user = user; 14 _user = user;
15 _pass = pass; 15 _pass = pass;
16 16
17 if ( user.isEmpty() ) { 17 if ( user.isEmpty() ) {
18 userLine->setFocus(); 18 userLine->setFocus();
19 } else { 19 } else {
20 passLine->setFocus(); 20 passLine->setFocus();
21 } 21 }
22} 22}
23 23
24void LoginDialog::accept() 24void LoginDialog::accept()
25{ 25{
26 //_user.replace( 0, _user.length(), userLine->text() ); 26 //_user.replace( 0, _user.length(), userLine->text() );
27 //_pass.replace( 0, _pass.length(), passLine->text() ); 27 //_pass.replace( 0, _pass.length(), passLine->text() );
28 _user = userLine->text(); 28 _user = userLine->text();
29 _pass = passLine->text(); 29 _pass = passLine->text();
30 30
31 //odebug << "User im accept: |" << _user.latin1() << "|" << oendl; 31 //odebug << "User im accept: |" << _user.latin1() << "|" << oendl;
32 QDialog::accept(); 32 QDialog::accept();
33} 33}
diff --git a/kmicromail/libmailwrapper/logindialog.h b/kmicromail/libmailwrapper/logindialog.h
index f406f2c..a18daa5 100644
--- a/kmicromail/libmailwrapper/logindialog.h
+++ b/kmicromail/libmailwrapper/logindialog.h
@@ -1,23 +1,23 @@
1#ifndef LOGINDIALOG_H 1#ifndef LOGINDIALOG_H
2#define LOGINDIALOG_H 2#define LOGINDIALOG_H
3 3
4#include "logindialogui.h" 4#include "logindialogui.h"
5 5
6class LoginDialog : public LoginDialogUI 6class LoginDialog : public LoginDialogUI
7{ 7{
8 Q_OBJECT 8 Q_OBJECT
9 9
10public: 10public:
11 LoginDialog(const QString&user,const QString&pass, QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags flags = 0 ); 11 LoginDialog(const QString&user,const QString&pass, QWidget *parent = 0, const char *name = 0, bool modal = false, Qt::WFlags flags = 0 );
12 QString getUser() { return _user; } 12 QString getUser() { return _user; }
13 QString getPassword() { return _pass; } 13 QString getPassword() { return _pass; }
14 14
15protected slots: 15protected slots:
16 void accept(); 16 void accept();
17 17
18private: 18private:
19 QString _user, _pass; 19 QString _user, _pass;
20 20
21}; 21};
22 22
23#endif 23#endif
diff --git a/kmicromail/libmailwrapper/mailtypes.cpp b/kmicromail/libmailwrapper/mailtypes.cpp
index 70a0ab5..84ccf9f 100644
--- a/kmicromail/libmailwrapper/mailtypes.cpp
+++ b/kmicromail/libmailwrapper/mailtypes.cpp
@@ -1,457 +1,459 @@
1#include "mailtypes.h" 1#include "mailtypes.h"
2 2
3//#include <opie2/odebug.h> 3//#include <opie2/odebug.h>
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6//Added by qt3to4:
7#include <Q3ValueList>
6 8
7using namespace Opie::Core; 9using namespace Opie::Core;
8RecMail::RecMail() 10RecMail::RecMail()
9 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7) 11 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
10{ 12{
11 init(); 13 init();
12} 14}
13 15
14RecMail::RecMail(const RecMail&old) 16RecMail::RecMail(const RecMail&old)
15 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7) 17 :Opie::Core::ORefCount(),subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
16{ 18{
17 init(); 19 init();
18 copy_old(old); 20 copy_old(old);
19 // odebug << "Copy constructor RecMail" << oendl; 21 // odebug << "Copy constructor RecMail" << oendl;
20} 22}
21 23
22RecMail::~RecMail() 24RecMail::~RecMail()
23{ 25{
24 wrapper = 0; 26 wrapper = 0;
25} 27}
26static bool stringCompareRec( const QString& s1, const QString& s2 ) 28static bool stringCompareRec( const QString& s1, const QString& s2 )
27{ 29{
28 if ( s1.isEmpty() && s2.isEmpty() ) 30 if ( s1.isEmpty() && s2.isEmpty() )
29 return true; 31 return true;
30 return s1 == s2; 32 return s1 == s2;
31} 33}
32#if 0 34#if 0
33QString RecMail::MsgsizeString() const 35QString RecMail::MsgsizeString() const
34{ 36{
35 37
36 double s = msg_size; 38 double s = msg_size;
37 int w = 0; 39 int w = 0;
38 s/=1024; 40 s/=1024;
39 if (s>999.0) { 41 if (s>999.0) {
40 s/=1024.0; 42 s/=1024.0;
41 ++w; 43 ++w;
42 } 44 }
43 QString fsize = QString::number( s, 'f', 2 ); 45 QString fsize = QString::number( s, 'f', 2 );
44 if ( w == 0 ) { 46 if ( w == 0 ) {
45 fsize += "kB" ; 47 fsize += "kB" ;
46 } else 48 } else
47 fsize += "MB" ; 49 fsize += "MB" ;
48 return fsize; 50 return fsize;
49} 51}
50#endif 52#endif
51bool RecMail::isEqual( RecMail* r1 ) 53bool RecMail::isEqual( RecMail* r1 )
52{ 54{
53 if ( !stringCompareRec( isodate, r1->isodate ) ) { 55 if ( !stringCompareRec( isodate, r1->isodate ) ) {
54 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1()); 56 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1());
55 return false; 57 return false;
56 } 58 }
57 if ( !stringCompareRec( subject.left(40), r1->subject.left(40) ) ) { 59 if ( !stringCompareRec( subject.left(40), r1->subject.left(40) ) ) {
58 //qDebug("sub *%s* *%s*", subject.latin1(), r1->subject.latin1()); 60 //qDebug("sub *%s* *%s*", subject.latin1(), r1->subject.latin1());
59 return false; 61 return false;
60 } 62 }
61 63
62 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1()); 64 //qDebug("date *%s* *%s* ", isodate.latin1(), r1->isodate.latin1());
63 if ( !stringCompareRec( from.left(40), r1->from.left(40)) ) { 65 if ( !stringCompareRec( from.left(40), r1->from.left(40)) ) {
64 if ( r1->from.find ( from ) < 0 ) { 66 if ( r1->from.find ( from ) < 0 ) {
65 if ( !stringCompareRec( from.simplifyWhiteSpace ().left(40), r1->from.simplifyWhiteSpace ().left(40)) ) { 67 if ( !stringCompareRec( from.simplifyWhiteSpace ().left(40), r1->from.simplifyWhiteSpace ().left(40)) ) {
66 //qDebug("from *%s* *%s* ", from.left(40).latin1(), r1->from.left(20).latin1()); 68 //qDebug("from *%s* *%s* ", from.left(40).latin1(), r1->from.left(20).latin1());
67 return false; 69 return false;
68 } 70 }
69 } 71 }
70 } 72 }
71 73
72 return true; 74 return true;
73} 75}
74void RecMail::copy_old(const RecMail&old) 76void RecMail::copy_old(const RecMail&old)
75{ 77{
76 subject = old.subject; 78 subject = old.subject;
77 date = old.date; 79 date = old.date;
78 mbox = old.mbox; 80 mbox = old.mbox;
79 msg_id = old.msg_id; 81 msg_id = old.msg_id;
80 msg_size = old.msg_size; 82 msg_size = old.msg_size;
81 msg_number = old.msg_number; 83 msg_number = old.msg_number;
82 from = old.from; 84 from = old.from;
83 msg_flags = old.msg_flags; 85 msg_flags = old.msg_flags;
84 to = old.to; 86 to = old.to;
85 cc = old.cc; 87 cc = old.cc;
86 bcc = old.bcc; 88 bcc = old.bcc;
87 wrapper = old.wrapper; 89 wrapper = old.wrapper;
88 in_reply_to = old.in_reply_to; 90 in_reply_to = old.in_reply_to;
89 references = old.references; 91 references = old.references;
90 replyto = old.replyto; 92 replyto = old.replyto;
91} 93}
92 94
93void RecMail::init() 95void RecMail::init()
94{ 96{
95 to.clear(); 97 to.clear();
96 cc.clear(); 98 cc.clear();
97 bcc.clear(); 99 bcc.clear();
98 in_reply_to.clear(); 100 in_reply_to.clear();
99 references.clear(); 101 references.clear();
100 wrapper = 0; 102 wrapper = 0;
101} 103}
102 104
103void RecMail::setWrapper(AbstractMail*awrapper) 105void RecMail::setWrapper(AbstractMail*awrapper)
104{ 106{
105 wrapper = awrapper; 107 wrapper = awrapper;
106} 108}
107 109
108AbstractMail* RecMail::Wrapper() 110AbstractMail* RecMail::Wrapper()
109{ 111{
110 return wrapper; 112 return wrapper;
111} 113}
112 114
113void RecMail::setTo(const QStringList&list) 115void RecMail::setTo(const QStringList&list)
114{ 116{
115 to = list; 117 to = list;
116} 118}
117 119
118const QStringList&RecMail::To()const 120const QStringList&RecMail::To()const
119{ 121{
120 return to; 122 return to;
121} 123}
122 124
123void RecMail::setCC(const QStringList&list) 125void RecMail::setCC(const QStringList&list)
124{ 126{
125 cc = list; 127 cc = list;
126} 128}
127 129
128const QStringList&RecMail::CC()const 130const QStringList&RecMail::CC()const
129{ 131{
130 return cc; 132 return cc;
131} 133}
132 134
133void RecMail::setBcc(const QStringList&list) 135void RecMail::setBcc(const QStringList&list)
134{ 136{
135 bcc = list; 137 bcc = list;
136} 138}
137 139
138const QStringList& RecMail::Bcc()const 140const QStringList& RecMail::Bcc()const
139{ 141{
140 return bcc; 142 return bcc;
141} 143}
142 144
143void RecMail::setInreply(const QStringList&list) 145void RecMail::setInreply(const QStringList&list)
144{ 146{
145 in_reply_to = list; 147 in_reply_to = list;
146} 148}
147 149
148const QStringList& RecMail::Inreply()const 150const QStringList& RecMail::Inreply()const
149{ 151{
150 return in_reply_to; 152 return in_reply_to;
151} 153}
152 154
153void RecMail::setReferences(const QStringList&list) 155void RecMail::setReferences(const QStringList&list)
154{ 156{
155 references = list; 157 references = list;
156} 158}
157 159
158const QStringList& RecMail::References()const 160const QStringList& RecMail::References()const
159{ 161{
160 return references; 162 return references;
161} 163}
162 164
163RecPart::RecPart() 165RecPart::RecPart()
164 : Opie::Core::ORefCount(), 166 : Opie::Core::ORefCount(),
165 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 167 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
166{ 168{
167 m_Parameters.clear(); 169 m_Parameters.clear();
168 m_poslist.clear(); 170 m_poslist.clear();
169} 171}
170 172
171RecPart::RecPart(const RecPart&old) 173RecPart::RecPart(const RecPart&old)
172 : Opie::Core::ORefCount(), 174 : Opie::Core::ORefCount(),
173 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0) 175 m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_description(""),m_lines(0),m_size(0)
174{ 176{
175 m_type = old.m_type; 177 m_type = old.m_type;
176 m_subtype = old.m_subtype; 178 m_subtype = old.m_subtype;
177 m_identifier = old.m_identifier; 179 m_identifier = old.m_identifier;
178 m_encoding = old.m_encoding; 180 m_encoding = old.m_encoding;
179 m_description = old.m_description; 181 m_description = old.m_description;
180 m_lines = old.m_lines; 182 m_lines = old.m_lines;
181 m_size = old.m_size; 183 m_size = old.m_size;
182 m_Parameters = old.m_Parameters; 184 m_Parameters = old.m_Parameters;
183 m_poslist = old.m_poslist; 185 m_poslist = old.m_poslist;
184 // odebug << "RecPart copy constructor" << oendl; 186 // odebug << "RecPart copy constructor" << oendl;
185} 187}
186 188
187RecPart::~RecPart() 189RecPart::~RecPart()
188{ 190{
189} 191}
190 192
191void RecPart::setSize(unsigned int size) 193void RecPart::setSize(unsigned int size)
192{ 194{
193 m_size = size; 195 m_size = size;
194} 196}
195 197
196const unsigned int RecPart::Size()const 198const unsigned int RecPart::Size()const
197{ 199{
198 return m_size; 200 return m_size;
199} 201}
200 202
201void RecPart::setLines(unsigned int lines) 203void RecPart::setLines(unsigned int lines)
202{ 204{
203 m_lines = lines; 205 m_lines = lines;
204} 206}
205 207
206const unsigned int RecPart::Lines()const 208const unsigned int RecPart::Lines()const
207{ 209{
208 return m_lines; 210 return m_lines;
209} 211}
210 212
211const QString& RecPart::Type()const 213const QString& RecPart::Type()const
212{ 214{
213 return m_type; 215 return m_type;
214} 216}
215 217
216void RecPart::setType(const QString&type) 218void RecPart::setType(const QString&type)
217{ 219{
218 m_type = type; 220 m_type = type;
219} 221}
220 222
221const QString& RecPart::Subtype()const 223const QString& RecPart::Subtype()const
222{ 224{
223 return m_subtype; 225 return m_subtype;
224} 226}
225 227
226void RecPart::setSubtype(const QString&subtype) 228void RecPart::setSubtype(const QString&subtype)
227{ 229{
228 m_subtype = subtype; 230 m_subtype = subtype;
229} 231}
230 232
231const QString& RecPart::Identifier()const 233const QString& RecPart::Identifier()const
232{ 234{
233 return m_identifier; 235 return m_identifier;
234} 236}
235 237
236void RecPart::setIdentifier(const QString&identifier) 238void RecPart::setIdentifier(const QString&identifier)
237{ 239{
238 m_identifier = identifier; 240 m_identifier = identifier;
239} 241}
240 242
241const QString& RecPart::Encoding()const 243const QString& RecPart::Encoding()const
242{ 244{
243 return m_encoding; 245 return m_encoding;
244} 246}
245 247
246void RecPart::setEncoding(const QString&encoding) 248void RecPart::setEncoding(const QString&encoding)
247{ 249{
248 m_encoding = encoding; 250 m_encoding = encoding;
249} 251}
250 252
251const QString& RecPart::Description()const 253const QString& RecPart::Description()const
252{ 254{
253 return m_description; 255 return m_description;
254} 256}
255 257
256void RecPart::setDescription(const QString&desc) 258void RecPart::setDescription(const QString&desc)
257{ 259{
258 m_description = desc; 260 m_description = desc;
259} 261}
260 262
261void RecPart::setParameters(const part_plist_t&list) 263void RecPart::setParameters(const part_plist_t&list)
262{ 264{
263 m_Parameters = list; 265 m_Parameters = list;
264} 266}
265 267
266const part_plist_t& RecPart::Parameters()const 268const part_plist_t& RecPart::Parameters()const
267{ 269{
268 return m_Parameters; 270 return m_Parameters;
269} 271}
270 272
271void RecPart::addParameter(const QString&key,const QString&value) 273void RecPart::addParameter(const QString&key,const QString&value)
272{ 274{
273 m_Parameters[key]=value; 275 m_Parameters[key]=value;
274} 276}
275 277
276const QString RecPart::searchParamter(const QString&key)const 278const QString RecPart::searchParamter(const QString&key)const
277{ 279{
278 QString value(""); 280 QString value("");
279 part_plist_t::ConstIterator it = m_Parameters.find(key); 281 part_plist_t::ConstIterator it = m_Parameters.find(key);
280 if (it != m_Parameters.end()) { 282 if (it != m_Parameters.end()) {
281 value = it.data(); 283 value = it.data();
282 } 284 }
283 return value; 285 return value;
284} 286}
285 287
286void RecPart::setPositionlist(const QValueList<int>&poslist) 288void RecPart::setPositionlist(const Q3ValueList<int>&poslist)
287{ 289{
288 m_poslist = poslist; 290 m_poslist = poslist;
289} 291}
290 292
291const QValueList<int>& RecPart::Positionlist()const 293const Q3ValueList<int>& RecPart::Positionlist()const
292{ 294{
293 return m_poslist; 295 return m_poslist;
294} 296}
295 297
296RecBody::RecBody() 298RecBody::RecBody()
297 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart()) 299 : Opie::Core::ORefCount(),m_BodyText(),m_description(new RecPart())
298{ 300{
299 m_PartsList.clear(); 301 m_PartsList.clear();
300} 302}
301 303
302RecBody::RecBody(const RecBody&old) 304RecBody::RecBody(const RecBody&old)
303 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart()) 305 :Opie::Core::ORefCount(),m_BodyText(),m_PartsList(),m_description(new RecPart())
304{ 306{
305 m_BodyText = old.m_BodyText; 307 m_BodyText = old.m_BodyText;
306 m_PartsList = old.m_PartsList; 308 m_PartsList = old.m_PartsList;
307 m_description = old.m_description; 309 m_description = old.m_description;
308 mCharset = old.mCharset; 310 mCharset = old.mCharset;
309 // odebug << "Recbody copy constructor" << oendl; 311 // odebug << "Recbody copy constructor" << oendl;
310} 312}
311 313
312RecBody::~RecBody() 314RecBody::~RecBody()
313{ 315{
314} 316}
315 317
316void RecBody::setBodytext(const QString&bodyText) 318void RecBody::setBodytext(const QString&bodyText)
317{ 319{
318 m_BodyText = bodyText; 320 m_BodyText = bodyText;
319} 321}
320 322
321const QString& RecBody::Bodytext()const 323const QString& RecBody::Bodytext()const
322{ 324{
323 return m_BodyText; 325 return m_BodyText;
324} 326}
325 327
326void RecBody::setParts(const QValueList<RecPartP>&parts) 328void RecBody::setParts(const Q3ValueList<RecPartP>&parts)
327{ 329{
328 m_PartsList.clear(); 330 m_PartsList.clear();
329 m_PartsList = parts; 331 m_PartsList = parts;
330} 332}
331 333
332const QValueList<RecPartP>& RecBody::Parts()const 334const Q3ValueList<RecPartP>& RecBody::Parts()const
333{ 335{
334 return m_PartsList; 336 return m_PartsList;
335} 337}
336 338
337void RecBody::addPart(const RecPartP& part) 339void RecBody::addPart(const RecPartP& part)
338{ 340{
339 m_PartsList.append(part); 341 m_PartsList.append(part);
340} 342}
341 343
342void RecBody::setDescription(const RecPartP&des) 344void RecBody::setDescription(const RecPartP&des)
343{ 345{
344 m_description = des; 346 m_description = des;
345} 347}
346 348
347const RecPartP& RecBody::Description()const 349const RecPartP& RecBody::Description()const
348{ 350{
349 return m_description; 351 return m_description;
350} 352}
351 353
352void RecBody::setCharset(const QString& str) 354void RecBody::setCharset(const QString& str)
353{ 355{
354 mCharset = str; 356 mCharset = str;
355} 357}
356 358
357QString RecBody::getCharset()const 359QString RecBody::getCharset()const
358{ 360{
359 return mCharset; 361 return mCharset;
360} 362}
361 363
362/* handling encoded content */ 364/* handling encoded content */
363encodedString::encodedString() 365encodedString::encodedString()
364{ 366{
365 init(); 367 init();
366} 368}
367 369
368encodedString::encodedString(const char*nContent,unsigned int nSize) 370encodedString::encodedString(const char*nContent,unsigned int nSize)
369{ 371{
370 init(); 372 init();
371 setContent(nContent,nSize); 373 setContent(nContent,nSize);
372} 374}
373 375
374encodedString::encodedString(char*nContent,unsigned int nSize) 376encodedString::encodedString(char*nContent,unsigned int nSize)
375{ 377{
376 init(); 378 init();
377 setContent(nContent,nSize); 379 setContent(nContent,nSize);
378} 380}
379 381
380encodedString::encodedString(const encodedString&old) 382encodedString::encodedString(const encodedString&old)
381{ 383{
382 init(); 384 init();
383 copy_old(old); 385 copy_old(old);
384 // odebug << "encodedeString: copy constructor!" << oendl; 386 // odebug << "encodedeString: copy constructor!" << oendl;
385} 387}
386 388
387encodedString& encodedString::operator=(const encodedString&old) 389encodedString& encodedString::operator=(const encodedString&old)
388{ 390{
389 init(); 391 init();
390 copy_old(old); 392 copy_old(old);
391 // odebug << "encodedString: assign operator!" << oendl; 393 // odebug << "encodedString: assign operator!" << oendl;
392 return *this; 394 return *this;
393} 395}
394 396
395encodedString::~encodedString() 397encodedString::~encodedString()
396{ 398{
397 clean(); 399 clean();
398} 400}
399 401
400void encodedString::init() 402void encodedString::init()
401{ 403{
402 content = 0; 404 content = 0;
403 size = 0; 405 size = 0;
404} 406}
405 407
406void encodedString::clean() 408void encodedString::clean()
407{ 409{
408 if (content) { 410 if (content) {
409 free(content); 411 free(content);
410 } 412 }
411 content = 0; 413 content = 0;
412 size = 0; 414 size = 0;
413} 415}
414 416
415void encodedString::copy_old(const encodedString&old) 417void encodedString::copy_old(const encodedString&old)
416{ 418{
417 clean(); 419 clean();
418 if (old.size>0 && old.content) { 420 if (old.size>0 && old.content) {
419 content = (char*)malloc(old.size*sizeof(char)); 421 content = (char*)malloc(old.size*sizeof(char));
420 memcpy(content,old.content,size); 422 memcpy(content,old.content,size);
421 size = old.size; 423 size = old.size;
422 } 424 }
423} 425}
424 426
425const char*encodedString::Content()const 427const char*encodedString::Content()const
426{ 428{
427 return content; 429 return content;
428} 430}
429 431
430const int encodedString::Length()const 432const int encodedString::Length()const
431{ 433{
432 return size; 434 return size;
433} 435}
434 436
435void encodedString::setContent(const char*nContent,int nSize) 437void encodedString::setContent(const char*nContent,int nSize)
436{ 438{
437 if (nSize>0 && nContent) { 439 if (nSize>0 && nContent) {
438 content = (char*)malloc(nSize*sizeof(char)); 440 content = (char*)malloc(nSize*sizeof(char));
439 memcpy(content,nContent,nSize); 441 memcpy(content,nContent,nSize);
440 size = nSize; 442 size = nSize;
441 } 443 }
442} 444}
443 445
444void encodedString::setContent(char*nContent,int nSize) 446void encodedString::setContent(char*nContent,int nSize)
445{ 447{
446 content = nContent; 448 content = nContent;
447 size = nSize; 449 size = nSize;
448} 450}
449 451
450folderStat&folderStat::operator=(const folderStat&old) 452folderStat&folderStat::operator=(const folderStat&old)
451{ 453{
452 message_count = old.message_count; 454 message_count = old.message_count;
453 message_unseen = old.message_unseen; 455 message_unseen = old.message_unseen;
454 message_recent = old.message_recent; 456 message_recent = old.message_recent;
455 return *this; 457 return *this;
456} 458}
457 459
diff --git a/kmicromail/libmailwrapper/mailtypes.h b/kmicromail/libmailwrapper/mailtypes.h
index 97f10d7..ac7f8da 100644
--- a/kmicromail/libmailwrapper/mailtypes.h
+++ b/kmicromail/libmailwrapper/mailtypes.h
@@ -1,227 +1,227 @@
1#ifndef __MAIL_TYPES_H 1#ifndef __MAIL_TYPES_H
2#define __MAIL_TYPES_H 2#define __MAIL_TYPES_H
3 3
4#define FLAG_ANSWERED 0 4#define FLAG_ANSWERED 0
5#define FLAG_FLAGGED 1 5#define FLAG_FLAGGED 1
6#define FLAG_DELETED 2 6#define FLAG_DELETED 2
7#define FLAG_SEEN 3 7#define FLAG_SEEN 3
8#define FLAG_DRAFT 4 8#define FLAG_DRAFT 4
9#define FLAG_RECENT 5 9#define FLAG_RECENT 5
10 10
11#include <opie2/osmartpointer.h> 11#include <opie2/osmartpointer.h>
12 12
13#include <qbitarray.h> 13#include <qbitarray.h>
14#include <qstring.h> 14#include <qstring.h>
15#include <qstringlist.h> 15#include <qstringlist.h>
16#include <qmap.h> 16#include <qmap.h>
17#include <qvaluelist.h> 17#include <q3valuelist.h>
18 18
19class AbstractMail; 19class AbstractMail;
20/* a class to describe mails in a mailbox */ 20/* a class to describe mails in a mailbox */
21/* Attention! 21/* Attention!
22 From programmers point of view it would make sense to 22 From programmers point of view it would make sense to
23 store the mail body into this class, too. 23 store the mail body into this class, too.
24 But: not from the point of view of the device. 24 But: not from the point of view of the device.
25 Mailbodies can be real large. So we request them when 25 Mailbodies can be real large. So we request them when
26 needed from the mail-wrapper class direct from the server itself 26 needed from the mail-wrapper class direct from the server itself
27 (imap) or from a file-based cache (pop3?) 27 (imap) or from a file-based cache (pop3?)
28 So there is no interface "const QString&body()" but you should 28 So there is no interface "const QString&body()" but you should
29 make a request to the mailwrapper with this class as parameter to 29 make a request to the mailwrapper with this class as parameter to
30 get the body. Same words for the attachments. 30 get the body. Same words for the attachments.
31*/ 31*/
32class RecMail:public Opie::Core::ORefCount 32class RecMail:public Opie::Core::ORefCount
33{ 33{
34public: 34public:
35 RecMail(); 35 RecMail();
36 RecMail(const RecMail&old); 36 RecMail(const RecMail&old);
37 virtual ~RecMail(); 37 virtual ~RecMail();
38 bool isEqual( RecMail* r1 ); 38 bool isEqual( RecMail* r1 );
39 39
40 const unsigned int getNumber()const{return msg_number;} 40 const unsigned int getNumber()const{return msg_number;}
41 void setNumber(unsigned int number){msg_number=number;} 41 void setNumber(unsigned int number){msg_number=number;}
42 const QString&getDate()const{ return date; } 42 const QString&getDate()const{ return date; }
43 void setDate( const QString&a ) { date = a; } 43 void setDate( const QString&a ) { date = a; }
44 const QString&getIsoDate()const{ return isodate; } 44 const QString&getIsoDate()const{ return isodate; }
45 void setIsoDate( const QString&a ) { isodate = a; } 45 void setIsoDate( const QString&a ) { isodate = a; }
46 const QString&getFrom()const{ return from; } 46 const QString&getFrom()const{ return from; }
47 void setFrom( const QString&a ) { from = a; } 47 void setFrom( const QString&a ) { from = a; }
48 const QString&getSubject()const { return subject; } 48 const QString&getSubject()const { return subject; }
49 void setSubject( const QString&s ) { subject = s; } 49 void setSubject( const QString&s ) { subject = s; }
50 const QString&getMbox()const{return mbox;} 50 const QString&getMbox()const{return mbox;}
51 void setMbox(const QString&box){mbox = box;} 51 void setMbox(const QString&box){mbox = box;}
52 void setMsgid(const QString&id){msg_id=id;} 52 void setMsgid(const QString&id){msg_id=id;}
53 const QString&Msgid()const{return msg_id;} 53 const QString&Msgid()const{return msg_id;}
54 void setReplyto(const QString&reply){replyto=reply;} 54 void setReplyto(const QString&reply){replyto=reply;}
55 const QString&Replyto()const{return replyto;} 55 const QString&Replyto()const{return replyto;}
56 void setMsgsize(unsigned int size){msg_size = size;} 56 void setMsgsize(unsigned int size){msg_size = size;}
57 const unsigned int Msgsize()const{return msg_size;} 57 const unsigned int Msgsize()const{return msg_size;}
58 const QString MsgsizeString()const { 58 const QString MsgsizeString()const {
59 double s = msg_size; 59 double s = msg_size;
60 int w = 0; 60 int w = 0;
61 s/=1024; 61 s/=1024;
62 if (s>999.0) { 62 if (s>999.0) {
63 s/=1024.0; 63 s/=1024.0;
64 ++w; 64 ++w;
65 } 65 }
66 QString fsize = QString::number( s, 'f', 2 ); 66 QString fsize = QString::number( s, 'f', 2 );
67 if ( w == 0 ) { 67 if ( w == 0 ) {
68 fsize += "kB" ; 68 fsize += "kB" ;
69 } else 69 } else
70 fsize += "MB" ; 70 fsize += "MB" ;
71 return fsize; 71 return fsize;
72 }; 72 };
73 void setTo(const QStringList&list); 73 void setTo(const QStringList&list);
74 const QStringList&To()const; 74 const QStringList&To()const;
75 void setCC(const QStringList&list); 75 void setCC(const QStringList&list);
76 const QStringList&CC()const; 76 const QStringList&CC()const;
77 void setBcc(const QStringList&list); 77 void setBcc(const QStringList&list);
78 const QStringList&Bcc()const; 78 const QStringList&Bcc()const;
79 void setInreply(const QStringList&list); 79 void setInreply(const QStringList&list);
80 const QStringList&Inreply()const; 80 const QStringList&Inreply()const;
81 void setReferences(const QStringList&list); 81 void setReferences(const QStringList&list);
82 const QStringList&References()const; 82 const QStringList&References()const;
83 83
84 const QBitArray&getFlags()const{return msg_flags;} 84 const QBitArray&getFlags()const{return msg_flags;}
85 void setFlags(const QBitArray&flags){msg_flags = flags;} 85 void setFlags(const QBitArray&flags){msg_flags = flags;}
86 86
87 void setWrapper(AbstractMail*wrapper); 87 void setWrapper(AbstractMail*wrapper);
88 AbstractMail* Wrapper(); 88 AbstractMail* Wrapper();
89 // public for debugging 89 // public for debugging
90 QString subject,date,isodate,from,mbox,msg_id,replyto; 90 QString subject,date,isodate,from,mbox,msg_id,replyto;
91 91
92protected: 92protected:
93 //QString subject,date,isodate,from,mbox,msg_id,replyto; 93 //QString subject,date,isodate,from,mbox,msg_id,replyto;
94 unsigned int msg_number,msg_size; 94 unsigned int msg_number,msg_size;
95 QBitArray msg_flags; 95 QBitArray msg_flags;
96 QStringList to,cc,bcc,in_reply_to,references; 96 QStringList to,cc,bcc,in_reply_to,references;
97 AbstractMail*wrapper; 97 AbstractMail*wrapper;
98 void init(); 98 void init();
99 void copy_old(const RecMail&old); 99 void copy_old(const RecMail&old);
100}; 100};
101 101
102typedef Opie::Core::OSmartPointer<RecMail> RecMailP; 102typedef Opie::Core::OSmartPointer<RecMail> RecMailP;
103typedef QMap<QString,QString> part_plist_t; 103typedef QMap<QString,QString> part_plist_t;
104 104
105class RecPart:public Opie::Core::ORefCount 105class RecPart:public Opie::Core::ORefCount
106{ 106{
107protected: 107protected:
108 QString m_type,m_subtype,m_identifier,m_encoding,m_description; 108 QString m_type,m_subtype,m_identifier,m_encoding,m_description;
109 unsigned int m_lines,m_size; 109 unsigned int m_lines,m_size;
110 part_plist_t m_Parameters; 110 part_plist_t m_Parameters;
111 /* describes the position in the mail */ 111 /* describes the position in the mail */
112 QValueList<int> m_poslist; 112 Q3ValueList<int> m_poslist;
113 113
114public: 114public:
115 RecPart(); 115 RecPart();
116 RecPart(const RecPart&); 116 RecPart(const RecPart&);
117 virtual ~RecPart(); 117 virtual ~RecPart();
118 118
119 const QString&Type()const; 119 const QString&Type()const;
120 void setType(const QString&type); 120 void setType(const QString&type);
121 const QString&Subtype()const; 121 const QString&Subtype()const;
122 void setSubtype(const QString&subtype); 122 void setSubtype(const QString&subtype);
123 const QString&Identifier()const; 123 const QString&Identifier()const;
124 void setIdentifier(const QString&identifier); 124 void setIdentifier(const QString&identifier);
125 const QString&Encoding()const; 125 const QString&Encoding()const;
126 void setEncoding(const QString&encoding); 126 void setEncoding(const QString&encoding);
127 const QString&Description()const; 127 const QString&Description()const;
128 void setDescription(const QString&desc); 128 void setDescription(const QString&desc);
129 void setLines(unsigned int lines); 129 void setLines(unsigned int lines);
130 const unsigned int Lines()const; 130 const unsigned int Lines()const;
131 void setSize(unsigned int size); 131 void setSize(unsigned int size);
132 const unsigned int Size()const; 132 const unsigned int Size()const;
133 133
134 134
135 void setParameters(const part_plist_t&list); 135 void setParameters(const part_plist_t&list);
136 const part_plist_t&Parameters()const; 136 const part_plist_t&Parameters()const;
137 void addParameter(const QString&key,const QString&value); 137 void addParameter(const QString&key,const QString&value);
138 const QString searchParamter(const QString&key)const; 138 const QString searchParamter(const QString&key)const;
139 void setPositionlist(const QValueList<int>&poslist); 139 void setPositionlist(const Q3ValueList<int>&poslist);
140 const QValueList<int>& Positionlist()const; 140 const Q3ValueList<int>& Positionlist()const;
141}; 141};
142 142
143typedef Opie::Core::OSmartPointer<RecPart> RecPartP; 143typedef Opie::Core::OSmartPointer<RecPart> RecPartP;
144 144
145class RecBody:public Opie::Core::ORefCount 145class RecBody:public Opie::Core::ORefCount
146{ 146{
147protected: 147protected:
148 QString m_BodyText; 148 QString m_BodyText;
149 QString mCharset; 149 QString mCharset;
150 QValueList<RecPartP> m_PartsList; 150 Q3ValueList<RecPartP> m_PartsList;
151 RecPartP m_description; 151 RecPartP m_description;
152 152
153public: 153public:
154 RecBody(); 154 RecBody();
155 RecBody(const RecBody&old); 155 RecBody(const RecBody&old);
156 virtual ~RecBody(); 156 virtual ~RecBody();
157 void setBodytext(const QString&); 157 void setBodytext(const QString&);
158 const QString& Bodytext()const; 158 const QString& Bodytext()const;
159 void setCharset(const QString&); 159 void setCharset(const QString&);
160 QString getCharset()const; 160 QString getCharset()const;
161 161
162 void setDescription(const RecPartP&des); 162 void setDescription(const RecPartP&des);
163 const RecPartP& Description()const; 163 const RecPartP& Description()const;
164 164
165 void setParts(const QValueList<RecPartP>&parts); 165 void setParts(const Q3ValueList<RecPartP>&parts);
166 const QValueList<RecPartP>& Parts()const; 166 const Q3ValueList<RecPartP>& Parts()const;
167 void addPart(const RecPartP&part); 167 void addPart(const RecPartP&part);
168}; 168};
169 169
170typedef Opie::Core::OSmartPointer<RecBody> RecBodyP; 170typedef Opie::Core::OSmartPointer<RecBody> RecBodyP;
171 171
172class encodedString 172class encodedString
173{ 173{
174public: 174public:
175 encodedString(); 175 encodedString();
176 /* 176 /*
177 creates an new content string. 177 creates an new content string.
178 it makes a deep copy of it! 178 it makes a deep copy of it!
179 */ 179 */
180 encodedString(const char*nContent,unsigned int length); 180 encodedString(const char*nContent,unsigned int length);
181 /* 181 /*
182 Take over the nContent. Means: it will just copy the pointer, not the content. 182 Take over the nContent. Means: it will just copy the pointer, not the content.
183 so make sure: No one else frees the string, the string has allocated with 183 so make sure: No one else frees the string, the string has allocated with
184 malloc for compatibility with c-based libs 184 malloc for compatibility with c-based libs
185 */ 185 */
186 encodedString(char*nContent,unsigned int nSize); 186 encodedString(char*nContent,unsigned int nSize);
187 /* copy construkor - makes ALWAYS a deep copy!!!! */ 187 /* copy construkor - makes ALWAYS a deep copy!!!! */
188 encodedString(const encodedString&old); 188 encodedString(const encodedString&old);
189 /* assign operator - makes ALWAYS a deep copy!!!! */ 189 /* assign operator - makes ALWAYS a deep copy!!!! */
190 encodedString& operator=(const encodedString&old); 190 encodedString& operator=(const encodedString&old);
191 /* destructor - cleans the content */ 191 /* destructor - cleans the content */
192 virtual ~encodedString(); 192 virtual ~encodedString();
193 193
194 /* returns a pointer to the content - do not delete yoursel! */ 194 /* returns a pointer to the content - do not delete yoursel! */
195 const char*Content()const; 195 const char*Content()const;
196 /* returns the lengths of the content 'cause it must not be a null-terminated string! */ 196 /* returns the lengths of the content 'cause it must not be a null-terminated string! */
197 const int Length()const; 197 const int Length()const;
198 198
199 /* 199 /*
200 makes a deep copy of nContent! 200 makes a deep copy of nContent!
201 */ 201 */
202 void setContent(const char*nContent,int nSize); 202 void setContent(const char*nContent,int nSize);
203 /* 203 /*
204 Take over the nContent. Means: it will just copy the pointer, not the content. 204 Take over the nContent. Means: it will just copy the pointer, not the content.
205 so make sure: No one else frees the string, the string has allocated with 205 so make sure: No one else frees the string, the string has allocated with
206 malloc for compatibility with c-based libs 206 malloc for compatibility with c-based libs
207 */ 207 */
208 void setContent(char*nContent,int nSize); 208 void setContent(char*nContent,int nSize);
209 209
210protected: 210protected:
211 char * content; 211 char * content;
212 unsigned int size; 212 unsigned int size;
213 213
214 void init(); 214 void init();
215 void copy_old(const encodedString&old); 215 void copy_old(const encodedString&old);
216 void clean(); 216 void clean();
217}; 217};
218 218
219struct folderStat 219struct folderStat
220{ 220{
221 unsigned int message_count; 221 unsigned int message_count;
222 unsigned int message_unseen; 222 unsigned int message_unseen;
223 unsigned int message_recent; 223 unsigned int message_recent;
224 folderStat&operator=(const folderStat&old); 224 folderStat&operator=(const folderStat&old);
225}; 225};
226 226
227#endif 227#endif
diff --git a/kmicromail/libmailwrapper/mailwrapper.cpp b/kmicromail/libmailwrapper/mailwrapper.cpp
index 2ee1ab3..9c299e8 100644
--- a/kmicromail/libmailwrapper/mailwrapper.cpp
+++ b/kmicromail/libmailwrapper/mailwrapper.cpp
@@ -1,181 +1,183 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8//Added by qt3to4:
9#include <Q3CString>
8 10
9#include "mailwrapper.h" 11#include "mailwrapper.h"
10//#include "logindialog.h" 12//#include "logindialog.h"
11//#include "defines.h" 13//#include "defines.h"
12 14
13#define UNDEFINED 64 15#define UNDEFINED 64
14#define MAXLINE 76 16#define MAXLINE 76
15#define UTF16MASK 0x03FFUL 17#define UTF16MASK 0x03FFUL
16#define UTF16SHIFT 10 18#define UTF16SHIFT 10
17#define UTF16BASE 0x10000UL 19#define UTF16BASE 0x10000UL
18#define UTF16HIGHSTART 0xD800UL 20#define UTF16HIGHSTART 0xD800UL
19#define UTF16HIGHEND 0xDBFFUL 21#define UTF16HIGHEND 0xDBFFUL
20#define UTF16LOSTART 0xDC00UL 22#define UTF16LOSTART 0xDC00UL
21#define UTF16LOEND 0xDFFFUL 23#define UTF16LOEND 0xDFFFUL
22 24
23 25
24using namespace Opie::Core; 26using namespace Opie::Core;
25Attachment::Attachment( QString lnk ) 27Attachment::Attachment( QString lnk )
26{ 28{
27 doc = lnk; 29 doc = lnk;
28 size = QFileInfo( doc ).size(); 30 size = QFileInfo( doc ).size();
29 mPix = SmallIcon( "files" ); 31 mPix = SmallIcon( "files" );
30} 32}
31 33
32Folder::Folder(const QString&tmp_name, const QString&sep ) 34Folder::Folder(const QString&tmp_name, const QString&sep )
33{ 35{
34 name = tmp_name; 36 name = tmp_name;
35 nameDisplay = name; 37 nameDisplay = name;
36 separator = sep; 38 separator = sep;
37 prefix = ""; 39 prefix = "";
38} 40}
39 41
40Folder::~Folder() 42Folder::~Folder()
41{ 43{
42} 44}
43 45
44const QString& Folder::Separator()const 46const QString& Folder::Separator()const
45{ 47{
46 return separator; 48 return separator;
47} 49}
48 50
49IMAPFolder::IMAPFolder(const QString&t_name,const QString&sep, bool select,bool no_inf, const QString&aprefix ) 51IMAPFolder::IMAPFolder(const QString&t_name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
50 : Folder( t_name,sep ),m_MaySelect(select),m_NoInferior(no_inf) 52 : Folder( t_name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
51{ 53{
52 // Decode IMAP foldername 54 // Decode IMAP foldername
53 nameDisplay = IMAPFolder::decodeFolderName( t_name ); 55 nameDisplay = IMAPFolder::decodeFolderName( t_name );
54 name = nameDisplay ; 56 name = nameDisplay ;
55 /* 57 /*
56 odebug << "folder " + name + " - displayed as " + nameDisplay << oendl; 58 odebug << "folder " + name + " - displayed as " + nameDisplay << oendl;
57 */ 59 */
58 prefix = aprefix; 60 prefix = aprefix;
59 61
60 if (prefix.length()>0) { 62 if (prefix.length()>0) {
61 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) { 63 if (nameDisplay.startsWith(prefix) && nameDisplay.length()>prefix.length()) {
62 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length()); 64 nameDisplay=nameDisplay.right(nameDisplay.length()-prefix.length());
63 } 65 }
64 } 66 }
65} 67}
66 68
67IMAPFolder::~IMAPFolder() 69IMAPFolder::~IMAPFolder()
68{ 70{
69} 71}
70 72
71static unsigned char base64chars[] = 73static unsigned char base64chars[] =
72 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; 74 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
73 75
74/** 76/**
75 * Decodes base64 encoded parts of the imapfolder name 77 * Decodes base64 encoded parts of the imapfolder name
76 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc 78 * Code taken from kde cvs: kdebase/kioslave/imap4/rfcdecoder.cc
77 */ 79 */
78QString IMAPFolder::decodeFolderName( const QString &name ) 80QString IMAPFolder::decodeFolderName( const QString &name )
79{ 81{
80 unsigned char c, i, bitcount; 82 unsigned char c, i, bitcount;
81 unsigned long ucs4, utf16, bitbuf; 83 unsigned long ucs4, utf16, bitbuf;
82 unsigned char base64[256], utf8[6]; 84 unsigned char base64[256], utf8[6];
83 unsigned long srcPtr = 0; 85 unsigned long srcPtr = 0;
84 QCString dst = ""; 86 Q3CString dst = "";
85 QCString src = name.ascii(); 87 Q3CString src = name.ascii();
86 88
87 /* initialize modified base64 decoding table */ 89 /* initialize modified base64 decoding table */
88 memset(base64, UNDEFINED, sizeof(base64)); 90 memset(base64, UNDEFINED, sizeof(base64));
89 for (i = 0; i < sizeof(base64chars); ++i) { 91 for (i = 0; i < sizeof(base64chars); ++i) {
90 base64[(int)base64chars[i]] = i; 92 base64[(int)base64chars[i]] = i;
91 } 93 }
92 94
93 /* loop until end of string */ 95 /* loop until end of string */
94 while (srcPtr < src.length ()) { 96 while (srcPtr < src.length ()) {
95 c = src[srcPtr++]; 97 c = src.at(srcPtr++);
96 /* deal with literal characters and &- */ 98 /* deal with literal characters and &- */
97 if (c != '&' || src[srcPtr] == '-') { 99 if (c != '&' || src.at(srcPtr) == '-') {
98 /* encode literally */ 100 /* encode literally */
99 dst += c; 101 dst += c;
100 /* skip over the '-' if this is an &- sequence */ 102 /* skip over the '-' if this is an &- sequence */
101 if (c == '&') 103 if (c == '&')
102 srcPtr++; 104 srcPtr++;
103 } else { 105 } else {
104 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */ 106 /* convert modified UTF-7 -> UTF-16 -> UCS-4 -> UTF-8 -> HEX */
105 bitbuf = 0; 107 bitbuf = 0;
106 bitcount = 0; 108 bitcount = 0;
107 ucs4 = 0; 109 ucs4 = 0;
108 while ((c = base64[(unsigned char) src[srcPtr]]) != UNDEFINED) { 110 while ((c = base64[(unsigned char) src.at(srcPtr)]) != UNDEFINED) {
109 ++srcPtr; 111 ++srcPtr;
110 bitbuf = (bitbuf << 6) | c; 112 bitbuf = (bitbuf << 6) | c;
111 bitcount += 6; 113 bitcount += 6;
112 /* enough bits for a UTF-16 character? */ 114 /* enough bits for a UTF-16 character? */
113 if (bitcount >= 16) { 115 if (bitcount >= 16) {
114 bitcount -= 16; 116 bitcount -= 16;
115 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff; 117 utf16 = (bitcount ? bitbuf >> bitcount : bitbuf) & 0xffff;
116 /* convert UTF16 to UCS4 */ 118 /* convert UTF16 to UCS4 */
117 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) { 119 if (utf16 >= UTF16HIGHSTART && utf16 <= UTF16HIGHEND) {
118 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT; 120 ucs4 = (utf16 - UTF16HIGHSTART) << UTF16SHIFT;
119 continue; 121 continue;
120 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) { 122 } else if (utf16 >= UTF16LOSTART && utf16 <= UTF16LOEND) {
121 ucs4 += utf16 - UTF16LOSTART + UTF16BASE; 123 ucs4 += utf16 - UTF16LOSTART + UTF16BASE;
122 } else { 124 } else {
123 ucs4 = utf16; 125 ucs4 = utf16;
124 } 126 }
125 /* convert UTF-16 range of UCS4 to UTF-8 */ 127 /* convert UTF-16 range of UCS4 to UTF-8 */
126 if (ucs4 <= 0x7fUL) { 128 if (ucs4 <= 0x7fUL) {
127 utf8[0] = ucs4; 129 utf8[0] = ucs4;
128 i = 1; 130 i = 1;
129 } else if (ucs4 <= 0x7ffUL) { 131 } else if (ucs4 <= 0x7ffUL) {
130 utf8[0] = 0xc0 | (ucs4 >> 6); 132 utf8[0] = 0xc0 | (ucs4 >> 6);
131 utf8[1] = 0x80 | (ucs4 & 0x3f); 133 utf8[1] = 0x80 | (ucs4 & 0x3f);
132 i = 2; 134 i = 2;
133 } else if (ucs4 <= 0xffffUL) { 135 } else if (ucs4 <= 0xffffUL) {
134 utf8[0] = 0xe0 | (ucs4 >> 12); 136 utf8[0] = 0xe0 | (ucs4 >> 12);
135 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f); 137 utf8[1] = 0x80 | ((ucs4 >> 6) & 0x3f);
136 utf8[2] = 0x80 | (ucs4 & 0x3f); 138 utf8[2] = 0x80 | (ucs4 & 0x3f);
137 i = 3; 139 i = 3;
138 } else { 140 } else {
139 utf8[0] = 0xf0 | (ucs4 >> 18); 141 utf8[0] = 0xf0 | (ucs4 >> 18);
140 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f); 142 utf8[1] = 0x80 | ((ucs4 >> 12) & 0x3f);
141 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f); 143 utf8[2] = 0x80 | ((ucs4 >> 6) & 0x3f);
142 utf8[3] = 0x80 | (ucs4 & 0x3f); 144 utf8[3] = 0x80 | (ucs4 & 0x3f);
143 i = 4; 145 i = 4;
144 } 146 }
145 /* copy it */ 147 /* copy it */
146 for (c = 0; c < i; ++c) { 148 for (c = 0; c < i; ++c) {
147 dst += utf8[c]; 149 dst += utf8[c];
148 } 150 }
149 } 151 }
150 } 152 }
151 /* skip over trailing '-' in modified UTF-7 encoding */ 153 /* skip over trailing '-' in modified UTF-7 encoding */
152 if (src[srcPtr] == '-') 154 if (src.at(srcPtr) == '-')
153 ++srcPtr; 155 ++srcPtr;
154 } 156 }
155 } 157 }
156 158
157 return QString::fromUtf8( dst.data() ); 159 return QString::fromUtf8( dst.data() );
158} 160}
159 161
160Mail::Mail() 162Mail::Mail()
161 :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("") 163 :Opie::Core::ORefCount(),name(""), mail(""), to(""), cc(""), bcc(""), reply(""), subject(""), message("")
162{ 164{
163} 165}
164 166
165MHFolder::MHFolder(const QString&disp_name,const QString&mbox) 167MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
166 : Folder( disp_name,"/" ) 168 : Folder( disp_name,"/" )
167{ 169{
168 separator = "/"; 170 separator = "/";
169 name = mbox; 171 name = mbox;
170 if (!disp_name.startsWith("/") && disp_name.length()>0) 172 if (!disp_name.startsWith("/") && disp_name.length()>0)
171 name+="/"; 173 name+="/";
172 name+=disp_name; 174 name+=disp_name;
173 if (disp_name.length()==0) { 175 if (disp_name.length()==0) {
174 nameDisplay = separator; 176 nameDisplay = separator;
175 } 177 }
176 prefix = mbox; 178 prefix = mbox;
177} 179}
178 180
179MHFolder::~MHFolder() 181MHFolder::~MHFolder()
180{ 182{
181} 183}
diff --git a/kmicromail/libmailwrapper/mailwrapper.h b/kmicromail/libmailwrapper/mailwrapper.h
index 3e8b51f..bebabf4 100644
--- a/kmicromail/libmailwrapper/mailwrapper.h
+++ b/kmicromail/libmailwrapper/mailwrapper.h
@@ -1,131 +1,133 @@
1#ifndef MAILWRAPPER_H 1#ifndef MAILWRAPPER_H
2#define MAILWRAPPER_H 2#define MAILWRAPPER_H
3 3
4//#include <qpe/applnk.h> 4//#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <qfileinfo.h> 8#include <qfileinfo.h>
9//Added by qt3to4:
10#include <QPixmap>
9#include <kiconloader.h> 11#include <kiconloader.h>
10 12
11#include "settings.h" 13#include "settings.h"
12 14
13#include <opie2/osmartpointer.h> 15#include <opie2/osmartpointer.h>
14/* 16/*
15class Attachment 17class Attachment
16{ 18{
17public: 19public:
18 Attachment( DocLnk lnk ); 20 Attachment( DocLnk lnk );
19 virtual ~Attachment(){} 21 virtual ~Attachment(){}
20 const QString getFileName()const{ return doc.file(); } 22 const QString getFileName()const{ return doc.file(); }
21 const QString getName()const{ return doc.name(); } 23 const QString getName()const{ return doc.name(); }
22 const QString getMimeType()const{ return doc.type(); } 24 const QString getMimeType()const{ return doc.type(); }
23 const QPixmap getPixmap()const{ return doc.pixmap(); } 25 const QPixmap getPixmap()const{ return doc.pixmap(); }
24 const int getSize()const { return size; } 26 const int getSize()const { return size; }
25 DocLnk getDocLnk() { return doc; } 27 DocLnk getDocLnk() { return doc; }
26 28
27protected: 29protected:
28 DocLnk doc; 30 DocLnk doc;
29 int size; 31 int size;
30 32
31}; 33};
32*/ 34*/
33 35
34class Attachment 36class Attachment
35{ 37{
36public: 38public:
37 Attachment( QString lnk ); 39 Attachment( QString lnk );
38 virtual ~Attachment(){} 40 virtual ~Attachment(){}
39 const QString getFileName()const{ return doc; } 41 const QString getFileName()const{ return doc; }
40 const QString getName()const{ return QFileInfo( doc ).baseName (); } 42 const QString getName()const{ return QFileInfo( doc ).baseName (); }
41 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); } 43 const QString getMimeType()const{ return QFileInfo( doc ).extension(false); }
42 const QPixmap getPixmap()const{ return mPix; } 44 const QPixmap getPixmap()const{ return mPix; }
43 const int getSize()const { return size; } 45 const int getSize()const { return size; }
44 QString getDocLnk() { return doc; } 46 QString getDocLnk() { return doc; }
45 47
46protected: 48protected:
47 QPixmap mPix; 49 QPixmap mPix;
48 QString doc; 50 QString doc;
49 int size; 51 int size;
50 52
51}; 53};
52 54
53class Mail:public Opie::Core::ORefCount 55class Mail:public Opie::Core::ORefCount
54{ 56{
55public: 57public:
56 Mail(); 58 Mail();
57 /* Possible that this destructor must not be declared virtual 59 /* Possible that this destructor must not be declared virtual
58 * 'cause it seems that it will never have some child classes. 60 * 'cause it seems that it will never have some child classes.
59 * in this case this object will not get a virtual table -> memory and 61 * in this case this object will not get a virtual table -> memory and
60 * speed will be a little bit better? 62 * speed will be a little bit better?
61 */ 63 */
62 virtual ~Mail(){} 64 virtual ~Mail(){}
63 void addAttachment( Attachment *att ) { attList.append( att ); } 65 void addAttachment( Attachment *att ) { attList.append( att ); }
64 const QList<Attachment>& getAttachments()const { return attList; } 66 const QList<Attachment*>& getAttachments()const { return attList; }
65 void removeAttachment( Attachment *att ) { attList.remove( att ); } 67 void removeAttachment( Attachment *att ) { attList.remove( att ); }
66 const QString&getName()const { return name; } 68 const QString&getName()const { return name; }
67 void setName( QString s ) { name = s; } 69 void setName( QString s ) { name = s; }
68 const QString&getMail()const{ return mail; } 70 const QString&getMail()const{ return mail; }
69 void setMail( const QString&s ) { mail = s; } 71 void setMail( const QString&s ) { mail = s; }
70 const QString&getTo()const{ return to; } 72 const QString&getTo()const{ return to; }
71 void setTo( const QString&s ) { to = s; } 73 void setTo( const QString&s ) { to = s; }
72 const QString&getCC()const{ return cc; } 74 const QString&getCC()const{ return cc; }
73 void setCC( const QString&s ) { cc = s; } 75 void setCC( const QString&s ) { cc = s; }
74 const QString&getBCC()const { return bcc; } 76 const QString&getBCC()const { return bcc; }
75 void setBCC( const QString&s ) { bcc = s; } 77 void setBCC( const QString&s ) { bcc = s; }
76 const QString&getMessage()const { return message; } 78 const QString&getMessage()const { return message; }
77 void setMessage( const QString&s ) { message = s; } 79 void setMessage( const QString&s ) { message = s; }
78 const QString&getSubject()const { return subject; } 80 const QString&getSubject()const { return subject; }
79 void setSubject( const QString&s ) { subject = s; } 81 void setSubject( const QString&s ) { subject = s; }
80 const QString&getReply()const{ return reply; } 82 const QString&getReply()const{ return reply; }
81 void setReply( const QString&a ) { reply = a; } 83 void setReply( const QString&a ) { reply = a; }
82 void setInreply(const QStringList&list){m_in_reply_to = list;} 84 void setInreply(const QStringList&list){m_in_reply_to = list;}
83 const QStringList&Inreply()const{return m_in_reply_to;} 85 const QStringList&Inreply()const{return m_in_reply_to;}
84 86
85 void setCharset( const QString&a ) { charset= a; } 87 void setCharset( const QString&a ) { charset= a; }
86 const QString& getCharset() const { return charset; } 88 const QString& getCharset() const { return charset; }
87 89
88private: 90private:
89 QList<Attachment> attList; 91 QList<Attachment*> attList;
90 QString name, mail, to, cc, bcc, reply, subject, message, charset; 92 QString name, mail, to, cc, bcc, reply, subject, message, charset;
91 QStringList m_in_reply_to; 93 QStringList m_in_reply_to;
92}; 94};
93 95
94class Folder:public Opie::Core::ORefCount 96class Folder:public Opie::Core::ORefCount
95{ 97{
96public: 98public:
97 Folder( const QString&init_name,const QString&sep ); 99 Folder( const QString&init_name,const QString&sep );
98 virtual ~Folder(); 100 virtual ~Folder();
99 const QString&getDisplayName()const { return nameDisplay; } 101 const QString&getDisplayName()const { return nameDisplay; }
100 const QString&getName()const { return name; } 102 const QString&getName()const { return name; }
101 const QString&getPrefix()const{return prefix; } 103 const QString&getPrefix()const{return prefix; }
102 virtual bool may_select()const{return true;} 104 virtual bool may_select()const{return true;}
103 virtual bool no_inferior()const{return true;} 105 virtual bool no_inferior()const{return true;}
104 const QString&Separator()const; 106 const QString&Separator()const;
105 107
106protected: 108protected:
107 QString nameDisplay, name, separator,prefix; 109 QString nameDisplay, name, separator,prefix;
108}; 110};
109 111
110typedef Opie::Core::OSmartPointer<Folder> FolderP; 112typedef Opie::Core::OSmartPointer<Folder> FolderP;
111 113
112class MHFolder : public Folder 114class MHFolder : public Folder
113{ 115{
114public: 116public:
115 MHFolder(const QString&disp_name,const QString&mbox); 117 MHFolder(const QString&disp_name,const QString&mbox);
116 virtual ~MHFolder(); 118 virtual ~MHFolder();
117}; 119};
118 120
119class IMAPFolder : public Folder 121class IMAPFolder : public Folder
120{ 122{
121 public: 123 public:
122 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); 124 IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" );
123 virtual ~IMAPFolder(); 125 virtual ~IMAPFolder();
124 virtual bool may_select()const{return m_MaySelect;} 126 virtual bool may_select()const{return m_MaySelect;}
125 virtual bool no_inferior()const{return m_NoInferior;} 127 virtual bool no_inferior()const{return m_NoInferior;}
126 static QString decodeFolderName( const QString &name ); 128 static QString decodeFolderName( const QString &name );
127 private: 129 private:
128 bool m_MaySelect,m_NoInferior; 130 bool m_MaySelect,m_NoInferior;
129}; 131};
130 132
131#endif 133#endif
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp
index 87f8c8a..888cae2 100644
--- a/kmicromail/libmailwrapper/mboxwrapper.cpp
+++ b/kmicromail/libmailwrapper/mboxwrapper.cpp
@@ -1,340 +1,342 @@
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//Added by qt3to4:
7#include <Q3ValueList>
6#include <stdlib.h> 8#include <stdlib.h>
7#include <klocale.h> 9#include <klocale.h>
8 10
9 11
10#include <qpe/global.h> 12#include <qpe/global.h>
11 13
12using namespace Opie::Core; 14using namespace Opie::Core;
13MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) 15MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name)
14 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) 16 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name)
15{ 17{
16 QDir dir(MBOXPath); 18 QDir dir(MBOXPath);
17 if (!dir.exists()) { 19 if (!dir.exists()) {
18 dir.mkdir(MBOXPath); 20 dir.mkdir(MBOXPath);
19 } 21 }
20} 22}
21 23
22MBOXwrapper::~MBOXwrapper() 24MBOXwrapper::~MBOXwrapper()
23{ 25{
24} 26}
25 27
26void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) 28void MBOXwrapper::listMessages(const QString & mailbox, Q3ValueList<RecMailP> &target )
27{ 29{
28 mailstorage*storage = mailstorage_new(NULL); 30 mailstorage*storage = mailstorage_new(NULL);
29 QString p = MBOXPath+"/"; 31 QString p = MBOXPath+"/";
30 p+=mailbox; 32 p+=mailbox;
31 33
32 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 34 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
33 mailfolder*folder; 35 mailfolder*folder;
34 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 36 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
35 r = mailfolder_connect(folder); 37 r = mailfolder_connect(folder);
36 if (r != MAIL_NO_ERROR) { 38 if (r != MAIL_NO_ERROR) {
37 //odebug << "Error initializing mbox" << oendl; 39 //odebug << "Error initializing mbox" << oendl;
38 mailfolder_free(folder); 40 mailfolder_free(folder);
39 mailstorage_free(storage); 41 mailstorage_free(storage);
40 return; 42 return;
41 } 43 }
42 44
43 parseList(target,folder->fld_session,mailbox); 45 parseList(target,folder->fld_session,mailbox);
44 46
45 mailfolder_disconnect(folder); 47 mailfolder_disconnect(folder);
46 mailfolder_free(folder); 48 mailfolder_free(folder);
47 mailstorage_free(storage); 49 mailstorage_free(storage);
48 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); 50 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count()));
49} 51}
50 52
51QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() 53Q3ValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders()
52{ 54{
53 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 55 Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >();
54 QDir dir(MBOXPath); 56 QDir dir(MBOXPath);
55 if (!dir.exists()) return folders; 57 if (!dir.exists()) return folders;
56 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 58 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
57 QStringList entries = dir.entryList(); 59 QStringList entries = dir.entryList();
58 QStringList::ConstIterator it = entries.begin(); 60 QStringList::ConstIterator it = entries.begin();
59 for (;it!=entries.end();++it) { 61 for (;it!=entries.end();++it) {
60 FolderP inb=new Folder(*it,"/"); 62 FolderP inb=new Folder(*it,"/");
61 folders->append(inb); 63 folders->append(inb);
62 } 64 }
63 return folders; 65 return folders;
64} 66}
65 67
66void MBOXwrapper::deleteMail(const RecMailP & mail) 68void MBOXwrapper::deleteMail(const RecMailP & mail)
67{ 69{
68 mailstorage*storage = mailstorage_new(NULL); 70 mailstorage*storage = mailstorage_new(NULL);
69 QString p = MBOXPath+"/"; 71 QString p = MBOXPath+"/";
70 p+=mail->getMbox(); 72 p+=mail->getMbox();
71 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 73 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
72 mailfolder*folder; 74 mailfolder*folder;
73 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 75 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
74 r = mailfolder_connect(folder); 76 r = mailfolder_connect(folder);
75 if (r != MAIL_NO_ERROR) { 77 if (r != MAIL_NO_ERROR) {
76 ; // << "Error initializing mbox" << oendl; 78 ; // << "Error initializing mbox" << oendl;
77 mailfolder_free(folder); 79 mailfolder_free(folder);
78 mailstorage_free(storage); 80 mailstorage_free(storage);
79 return; 81 return;
80 } 82 }
81 r = mailsession_remove_message(folder->fld_session,mail->getNumber()); 83 r = mailsession_remove_message(folder->fld_session,mail->getNumber());
82 if (r != MAIL_NO_ERROR) { 84 if (r != MAIL_NO_ERROR) {
83 ; // << "error deleting mail" << oendl; 85 ; // << "error deleting mail" << oendl;
84 } 86 }
85 mailfolder_free(folder); 87 mailfolder_free(folder);
86 mailstorage_free(storage); 88 mailstorage_free(storage);
87} 89}
88 90
89void MBOXwrapper::answeredMail(const RecMailP&) 91void MBOXwrapper::answeredMail(const RecMailP&)
90{ 92{
91} 93}
92 94
93RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) 95RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail )
94{ 96{
95 RecBodyP body = new RecBody(); 97 RecBodyP body = new RecBody();
96 mailstorage*storage = mailstorage_new(NULL); 98 mailstorage*storage = mailstorage_new(NULL);
97 QString p = MBOXPath+"/"; 99 QString p = MBOXPath+"/";
98 p+=mail->getMbox(); 100 p+=mail->getMbox();
99 mailmessage * msg; 101 mailmessage * msg;
100 char*data=0; 102 char*data=0;
101 size_t size; 103 size_t size;
102 104
103 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 105 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
104 mailfolder*folder; 106 mailfolder*folder;
105 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 107 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
106 r = mailfolder_connect(folder); 108 r = mailfolder_connect(folder);
107 if (r != MAIL_NO_ERROR) { 109 if (r != MAIL_NO_ERROR) {
108 ; // << "Error initializing mbox" << oendl; 110 ; // << "Error initializing mbox" << oendl;
109 mailfolder_free(folder); 111 mailfolder_free(folder);
110 mailstorage_free(storage); 112 mailstorage_free(storage);
111 return body; 113 return body;
112 } 114 }
113 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 115 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
114 if (r != MAIL_NO_ERROR) { 116 if (r != MAIL_NO_ERROR) {
115 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 117 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
116 mailfolder_free(folder); 118 mailfolder_free(folder);
117 mailstorage_free(storage); 119 mailstorage_free(storage);
118 return body; 120 return body;
119 } 121 }
120 r = mailmessage_fetch(msg,&data,&size); 122 r = mailmessage_fetch(msg,&data,&size);
121 if (r != MAIL_NO_ERROR) { 123 if (r != MAIL_NO_ERROR) {
122 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 124 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
123 mailfolder_free(folder); 125 mailfolder_free(folder);
124 mailstorage_free(storage); 126 mailstorage_free(storage);
125 mailmessage_free(msg); 127 mailmessage_free(msg);
126 return body; 128 return body;
127 } 129 }
128 qDebug("MBOXwrapper::fetchBody "); 130 qDebug("MBOXwrapper::fetchBody ");
129 body = parseMail(msg); 131 body = parseMail(msg);
130 mailmessage_fetch_result_free(msg,data); 132 mailmessage_fetch_result_free(msg,data);
131 mailfolder_free(folder); 133 mailfolder_free(folder);
132 mailstorage_free(storage); 134 mailstorage_free(storage);
133 135
134 return body; 136 return body;
135} 137}
136 138
137void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 139void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
138{ 140{
139 ; // << "MBOX " << current << " von " << maximum << "" << oendl; 141 ; // << "MBOX " << current << " von " << maximum << "" << oendl;
140} 142}
141 143
142int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) 144int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool )
143{ 145{
144 QString p = MBOXPath+"/"; 146 QString p = MBOXPath+"/";
145 p+=folder; 147 p+=folder;
146 QFileInfo fi(p); 148 QFileInfo fi(p);
147 if (fi.exists()) { 149 if (fi.exists()) {
148 Global::statusMessage(i18n("Mailbox exists.")); 150 Global::statusMessage(i18n("Mailbox exists."));
149 return 0; 151 return 0;
150 } 152 }
151 mailmbox_folder*f = 0; 153 mailmbox_folder*f = 0;
152 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 154 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
153 Global::statusMessage(i18n("Error init folder")); 155 Global::statusMessage(i18n("Error init folder"));
154 return 0; 156 return 0;
155 } 157 }
156 if (f) mailmbox_done(f); 158 if (f) mailmbox_done(f);
157 return 1; 159 return 1;
158} 160}
159 161
160void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 162void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
161{ 163{
162 QString p = MBOXPath+"/"; 164 QString p = MBOXPath+"/";
163 p+=folder; 165 p+=folder;
164 mailmbox_folder*f = 0; 166 mailmbox_folder*f = 0;
165 int r = mailmbox_init(p.latin1(),0,1,0,&f); 167 int r = mailmbox_init(p.latin1(),0,1,0,&f);
166 if (r != MAIL_NO_ERROR) { 168 if (r != MAIL_NO_ERROR) {
167 Global::statusMessage(i18n("Error init folder")); 169 Global::statusMessage(i18n("Error init folder"));
168 return; 170 return;
169 } 171 }
170 r = mailmbox_append_message(f,msg,length); 172 r = mailmbox_append_message(f,msg,length);
171 if (r != MAIL_NO_ERROR) { 173 if (r != MAIL_NO_ERROR) {
172 Global::statusMessage(i18n("Error writing to message folder")); 174 Global::statusMessage(i18n("Error writing to message folder"));
173 } 175 }
174 mailmbox_done(f); 176 mailmbox_done(f);
175} 177}
176 178
177encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) 179encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail)
178{ 180{
179 RecBody body; 181 RecBody body;
180 mailstorage*storage = mailstorage_new(NULL); 182 mailstorage*storage = mailstorage_new(NULL);
181 QString p = MBOXPath+"/"; 183 QString p = MBOXPath+"/";
182 p+=mail->getMbox(); 184 p+=mail->getMbox();
183 mailmessage * msg; 185 mailmessage * msg;
184 char*data=0; 186 char*data=0;
185 size_t size; 187 size_t size;
186 188
187 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 189 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
188 mailfolder*folder; 190 mailfolder*folder;
189 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 191 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
190 r = mailfolder_connect(folder); 192 r = mailfolder_connect(folder);
191 if (r != MAIL_NO_ERROR) { 193 if (r != MAIL_NO_ERROR) {
192 Global::statusMessage(i18n("Error initializing mbox")); 194 Global::statusMessage(i18n("Error initializing mbox"));
193 mailfolder_free(folder); 195 mailfolder_free(folder);
194 mailstorage_free(storage); 196 mailstorage_free(storage);
195 return 0; 197 return 0;
196 } 198 }
197 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 199 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
198 if (r != MAIL_NO_ERROR) { 200 if (r != MAIL_NO_ERROR) {
199 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 201 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
200 mailfolder_free(folder); 202 mailfolder_free(folder);
201 mailstorage_free(storage); 203 mailstorage_free(storage);
202 return 0; 204 return 0;
203 } 205 }
204 r = mailmessage_fetch(msg,&data,&size); 206 r = mailmessage_fetch(msg,&data,&size);
205 if (r != MAIL_NO_ERROR) { 207 if (r != MAIL_NO_ERROR) {
206 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 208 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
207 mailfolder_free(folder); 209 mailfolder_free(folder);
208 mailstorage_free(storage); 210 mailstorage_free(storage);
209 mailmessage_free(msg); 211 mailmessage_free(msg);
210 return 0; 212 return 0;
211 } 213 }
212 encodedString*result = new encodedString(data,size); 214 encodedString*result = new encodedString(data,size);
213 215
214 mailfolder_free(folder); 216 mailfolder_free(folder);
215 mailstorage_free(storage); 217 mailstorage_free(storage);
216 mailmessage_free(msg); 218 mailmessage_free(msg);
217 return result; 219 return result;
218} 220}
219 221
220void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 222void MBOXwrapper::deleteMails(const QString & mailbox,const Q3ValueList<RecMailP> &target)
221{ 223{
222 QString p = MBOXPath+"/"; 224 QString p = MBOXPath+"/";
223 p+=mailbox; 225 p+=mailbox;
224 mailmbox_folder*f = 0; 226 mailmbox_folder*f = 0;
225 int r = mailmbox_init(p.latin1(),0,1,0,&f); 227 int r = mailmbox_init(p.latin1(),0,1,0,&f);
226 if (r != MAIL_NO_ERROR) { 228 if (r != MAIL_NO_ERROR) {
227 ; // << "Error init folder" << oendl; 229 ; // << "Error init folder" << oendl;
228 return; 230 return;
229 } 231 }
230 deleteMails(f,target); 232 deleteMails(f,target);
231 mailmbox_done(f); 233 mailmbox_done(f);
232} 234}
233 235
234void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) 236void MBOXwrapper::deleteMails(mailmbox_folder*f,const Q3ValueList<RecMailP> &target)
235{ 237{
236 if (!f) return; 238 if (!f) return;
237 int r; 239 int r;
238 QValueList<RecMailP>::ConstIterator it; 240 Q3ValueList<RecMailP>::ConstIterator it;
239 for (it=target.begin(); it != target.end();++it) { 241 for (it=target.begin(); it != target.end();++it) {
240 r = mailmbox_delete_msg(f,(*it)->getNumber()); 242 r = mailmbox_delete_msg(f,(*it)->getNumber());
241 if (r!=MAILMBOX_NO_ERROR) { 243 if (r!=MAILMBOX_NO_ERROR) {
242 ; // << "error delete mail" << oendl; 244 ; // << "error delete mail" << oendl;
243 } 245 }
244 } 246 }
245 r = mailmbox_expunge(f); 247 r = mailmbox_expunge(f);
246 if (r != MAILMBOX_NO_ERROR) { 248 if (r != MAILMBOX_NO_ERROR) {
247 ; // << "error expunge mailbox" << oendl; 249 ; // << "error expunge mailbox" << oendl;
248 } 250 }
249} 251}
250 252
251int MBOXwrapper::deleteAllMail(const FolderP&tfolder) 253int MBOXwrapper::deleteAllMail(const FolderP&tfolder)
252{ 254{
253 if (!tfolder) return 0; 255 if (!tfolder) return 0;
254 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 256 QString p = MBOXPath+"/"+tfolder->getDisplayName();
255 int res = 1; 257 int res = 1;
256 258
257 mailfolder*folder = 0; 259 mailfolder*folder = 0;
258 mailmessage_list*l=0; 260 mailmessage_list*l=0;
259 mailstorage*storage = mailstorage_new(NULL); 261 mailstorage*storage = mailstorage_new(NULL);
260 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 262 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
261 if (r != MAIL_NO_ERROR) { 263 if (r != MAIL_NO_ERROR) {
262 Global::statusMessage(i18n("Error initializing mbox")); 264 Global::statusMessage(i18n("Error initializing mbox"));
263 res = 0; 265 res = 0;
264 } 266 }
265 if (res) { 267 if (res) {
266 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 268 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
267 r = mailfolder_connect(folder); 269 r = mailfolder_connect(folder);
268 if (r != MAIL_NO_ERROR) { 270 if (r != MAIL_NO_ERROR) {
269 Global::statusMessage(i18n("Error initializing mbox")); 271 Global::statusMessage(i18n("Error initializing mbox"));
270 res = 0; 272 res = 0;
271 } 273 }
272 } 274 }
273 if (res) { 275 if (res) {
274 r = mailsession_get_messages_list(folder->fld_session,&l); 276 r = mailsession_get_messages_list(folder->fld_session,&l);
275 if (r != MAIL_NO_ERROR) { 277 if (r != MAIL_NO_ERROR) {
276 ; // << "Error message list" << oendl; 278 ; // << "Error message list" << oendl;
277 res=0; 279 res=0;
278 } 280 }
279 } 281 }
280 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 282 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
281 r = mailsession_remove_message(folder->fld_session,i+1); 283 r = mailsession_remove_message(folder->fld_session,i+1);
282 if (r != MAIL_NO_ERROR) { 284 if (r != MAIL_NO_ERROR) {
283 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 285 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
284 res = 0; 286 res = 0;
285 break; 287 break;
286 } 288 }
287 } 289 }
288 if (l) mailmessage_list_free(l); 290 if (l) mailmessage_list_free(l);
289 if (folder) mailfolder_free(folder); 291 if (folder) mailfolder_free(folder);
290 if (storage) mailstorage_free(storage); 292 if (storage) mailstorage_free(storage);
291 return res; 293 return res;
292} 294}
293 295
294int MBOXwrapper::deleteMbox(const FolderP&tfolder) 296int MBOXwrapper::deleteMbox(const FolderP&tfolder)
295{ 297{
296 if (!tfolder) return 0; 298 if (!tfolder) return 0;
297 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 299 QString p = MBOXPath+"/"+tfolder->getDisplayName();
298 QFile fi(p); 300 QFile fi(p);
299 if (!fi.exists()) { 301 if (!fi.exists()) {
300 Global::statusMessage(i18n("Mailbox doesn't exist.")); 302 Global::statusMessage(i18n("Mailbox doesn't exist."));
301 return 0; 303 return 0;
302 } 304 }
303 if (!fi.remove()) { 305 if (!fi.remove()) {
304 Global::statusMessage(i18n("Error deleting Mailbox.")); 306 Global::statusMessage(i18n("Error deleting Mailbox."));
305 return 0; 307 return 0;
306 } 308 }
307 return 1; 309 return 1;
308} 310}
309 311
310void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 312void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
311{ 313{
312 mailfolder*folder = 0; 314 mailfolder*folder = 0;
313 mailstorage*storage = mailstorage_new(NULL); 315 mailstorage*storage = mailstorage_new(NULL);
314 target_stat.message_count = 0; 316 target_stat.message_count = 0;
315 target_stat.message_unseen = 0; 317 target_stat.message_unseen = 0;
316 target_stat.message_recent = 0; 318 target_stat.message_recent = 0;
317 QString p = MBOXPath+"/"+mailbox; 319 QString p = MBOXPath+"/"+mailbox;
318 QFile fi(p); 320 QFile fi(p);
319 if (!fi.exists()) { 321 if (!fi.exists()) {
320 Global::statusMessage(i18n("Mailbox doesn't exist.")); 322 Global::statusMessage(i18n("Mailbox doesn't exist."));
321 return; 323 return;
322 } 324 }
323 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 325 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
324 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 326 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
325 r = mailfolder_connect(folder); 327 r = mailfolder_connect(folder);
326 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 328 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
327 &target_stat.message_recent,&target_stat.message_unseen); 329 &target_stat.message_recent,&target_stat.message_unseen);
328 if (folder) mailfolder_free(folder); 330 if (folder) mailfolder_free(folder);
329 if (storage) mailstorage_free(storage); 331 if (storage) mailstorage_free(storage);
330} 332}
331 333
332MAILLIB::ATYPE MBOXwrapper::getType()const 334MAILLIB::ATYPE MBOXwrapper::getType()const
333{ 335{
334 return MAILLIB::A_MBOX; 336 return MAILLIB::A_MBOX;
335} 337}
336 338
337const QString&MBOXwrapper::getName()const 339const QString&MBOXwrapper::getName()const
338{ 340{
339 return MBOXName; 341 return MBOXName;
340} 342}
diff --git a/kmicromail/libmailwrapper/mboxwrapper.h b/kmicromail/libmailwrapper/mboxwrapper.h
index d03940f..e658a71 100644
--- a/kmicromail/libmailwrapper/mboxwrapper.h
+++ b/kmicromail/libmailwrapper/mboxwrapper.h
@@ -1,47 +1,49 @@
1#ifndef __MBOX_WRAPPER_H 1#ifndef __MBOX_WRAPPER_H
2#define __MBOX_WRAPPER_H 2#define __MBOX_WRAPPER_H
3 3
4#include "genericwrapper.h" 4#include "genericwrapper.h"
5#include <qstring.h> 5#include <qstring.h>
6//Added by qt3to4:
7#include <Q3ValueList>
6 8
7class encodedString; 9class encodedString;
8struct mailmbox_folder; 10struct mailmbox_folder;
9 11
10class MBOXwrapper : public Genericwrapper 12class MBOXwrapper : public Genericwrapper
11{ 13{
12 Q_OBJECT 14 Q_OBJECT
13 15
14public: 16public:
15 MBOXwrapper(const QString & dir,const QString&name); 17 MBOXwrapper(const QString & dir,const QString&name);
16 virtual ~MBOXwrapper(); 18 virtual ~MBOXwrapper();
17 19
18 virtual void listMessages(const QString & mailbox, QValueList<RecMailP>&target ); 20 virtual void listMessages(const QString & mailbox, Q3ValueList<RecMailP>&target );
19 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 21 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
20 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 22 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
21 23
22 virtual void deleteMail(const RecMailP&mail); 24 virtual void deleteMail(const RecMailP&mail);
23 virtual void answeredMail(const RecMailP&mail); 25 virtual void answeredMail(const RecMailP&mail);
24 26
25 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 27 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
26 const QString&d="",bool s=false); 28 const QString&d="",bool s=false);
27 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
28 30
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 31 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30 32
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 33 virtual RecBodyP fetchBody( const RecMailP &mail );
32 static void mbox_progress( size_t current, size_t maximum ); 34 static void mbox_progress( size_t current, size_t maximum );
33 35
34 virtual encodedString* fetchRawBody(const RecMailP&mail); 36 virtual encodedString* fetchRawBody(const RecMailP&mail);
35 virtual void deleteMails(const QString & FolderName,const QValueList<RecMailP> &target); 37 virtual void deleteMails(const QString & FolderName,const Q3ValueList<RecMailP> &target);
36 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 38 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
37 virtual MAILLIB::ATYPE getType()const; 39 virtual MAILLIB::ATYPE getType()const;
38 virtual const QString&getName()const; 40 virtual const QString&getName()const;
39 virtual Account* getAccount() { return 0; }; 41 virtual Account* getAccount() { return 0; };
40 42
41protected: 43protected:
42 static void deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target); 44 static void deleteMails(mailmbox_folder*f,const Q3ValueList<RecMailP> &target);
43 QString MBOXPath; 45 QString MBOXPath;
44 QString MBOXName; 46 QString MBOXName;
45}; 47};
46 48
47#endif 49#endif
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index 787e85d..4cd7a94 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -1,458 +1,460 @@
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//Added by qt3to4:
9#include <Q3ValueList>
8#include <stdlib.h> 10#include <stdlib.h>
9#include <qpe/global.h> 11#include <qpe/global.h>
10#include <klocale.h> 12#include <klocale.h>
11#include <kglobal.h> 13#include <kglobal.h>
12//#include <opie2/odebug.h> 14//#include <opie2/odebug.h>
13 15
14using namespace Opie::Core; 16using namespace Opie::Core;
15MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 17MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
16 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 18 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
17{ 19{
18 if (MHPath.length()>0) { 20 if (MHPath.length()>0) {
19 if (MHPath[MHPath.length()-1]=='/') { 21 if (MHPath[MHPath.length()-1]=='/') {
20 MHPath=MHPath.left(MHPath.length()-1); 22 MHPath=MHPath.left(MHPath.length()-1);
21 } 23 }
22 //odebug << MHPath << oendl; 24 //odebug << MHPath << oendl;
23 QDir dir(MHPath); 25 QDir dir(MHPath);
24 if (!dir.exists()) { 26 if (!dir.exists()) {
25 dir.mkdir(MHPath); 27 dir.mkdir(MHPath);
26 } 28 }
27 init_storage(); 29 init_storage();
28 } 30 }
29} 31}
30 32
31void MHwrapper::init_storage() 33void MHwrapper::init_storage()
32{ 34{
33 int r; 35 int r;
34 QString pre = MHPath; 36 QString pre = MHPath;
35 if (!m_storage) { 37 if (!m_storage) {
36 m_storage = mailstorage_new(NULL); 38 m_storage = mailstorage_new(NULL);
37 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 39 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
38 if (r != MAIL_NO_ERROR) { 40 if (r != MAIL_NO_ERROR) {
39 qDebug(" error init storage "); 41 qDebug(" error init storage ");
40 mailstorage_free(m_storage); 42 mailstorage_free(m_storage);
41 m_storage = 0; 43 m_storage = 0;
42 return; 44 return;
43 } 45 }
44 } 46 }
45 r = mailstorage_connect(m_storage); 47 r = mailstorage_connect(m_storage);
46 if (r!=MAIL_NO_ERROR) { 48 if (r!=MAIL_NO_ERROR) {
47 qDebug("error connecting storage "); 49 qDebug("error connecting storage ");
48 mailstorage_free(m_storage); 50 mailstorage_free(m_storage);
49 m_storage = 0; 51 m_storage = 0;
50 } 52 }
51} 53}
52 54
53void MHwrapper::clean_storage() 55void MHwrapper::clean_storage()
54{ 56{
55 if (m_storage) { 57 if (m_storage) {
56 mailstorage_disconnect(m_storage); 58 mailstorage_disconnect(m_storage);
57 mailstorage_free(m_storage); 59 mailstorage_free(m_storage);
58 m_storage = 0; 60 m_storage = 0;
59 } 61 }
60} 62}
61 63
62MHwrapper::~MHwrapper() 64MHwrapper::~MHwrapper()
63{ 65{
64 clean_storage(); 66 clean_storage();
65} 67}
66 68
67void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 69void MHwrapper::listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
68{ 70{
69 init_storage(); 71 init_storage();
70 if (!m_storage) { 72 if (!m_storage) {
71 return; 73 return;
72 } 74 }
73 QString f = buildPath(mailbox); 75 QString f = buildPath(mailbox);
74 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 76 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
75 if (r!=MAIL_NO_ERROR) { 77 if (r!=MAIL_NO_ERROR) {
76 qDebug("listMessages: error selecting folder! "); 78 qDebug("listMessages: error selecting folder! ");
77 return; 79 return;
78 } 80 }
79 parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); 81 parseList(target,m_storage->sto_session,f, false, maxSizeInKb );
80 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); 82 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count()));
81} 83}
82 84
83QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() 85Q3ValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders()
84{ 86{
85 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 87 Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >();
86 /* this is needed! */ 88 /* this is needed! */
87 if (m_storage) mailstorage_disconnect(m_storage); 89 if (m_storage) mailstorage_disconnect(m_storage);
88 init_storage(); 90 init_storage();
89 if (!m_storage) { 91 if (!m_storage) {
90 return folders; 92 return folders;
91 } 93 }
92 mail_list*flist = 0; 94 mail_list*flist = 0;
93 clistcell*current=0; 95 clistcell*current=0;
94 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 96 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
95 if (r != MAIL_NO_ERROR || !flist) { 97 if (r != MAIL_NO_ERROR || !flist) {
96 qDebug("error getting folder list "); 98 qDebug("error getting folder list ");
97 return folders; 99 return folders;
98 } 100 }
99 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 101 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
100 QString t = (char*)current->data; 102 QString t = (char*)current->data;
101 t.replace(0,MHPath.length(),""); 103 t.replace(0,MHPath.length(),"");
102 folders->append(new MHFolder(t,MHPath)); 104 folders->append(new MHFolder(t,MHPath));
103 } 105 }
104 mail_list_free(flist); 106 mail_list_free(flist);
105 return folders; 107 return folders;
106} 108}
107 109
108void MHwrapper::deleteMail(const RecMailP&mail) 110void MHwrapper::deleteMail(const RecMailP&mail)
109{ 111{
110 init_storage(); 112 init_storage();
111 if (!m_storage) { 113 if (!m_storage) {
112 return; 114 return;
113 } 115 }
114 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 116 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
115 if (r!=MAIL_NO_ERROR) { 117 if (r!=MAIL_NO_ERROR) {
116 qDebug("error selecting folder! "); 118 qDebug("error selecting folder! ");
117 return; 119 return;
118 } 120 }
119 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); 121 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
120 if (r != MAIL_NO_ERROR) { 122 if (r != MAIL_NO_ERROR) {
121 qDebug("error deleting mail "); 123 qDebug("error deleting mail ");
122 } 124 }
123} 125}
124 126
125void MHwrapper::answeredMail(const RecMailP&) 127void MHwrapper::answeredMail(const RecMailP&)
126{ 128{
127} 129}
128 130
129RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) 131RecBodyP MHwrapper::fetchBody( const RecMailP &mail )
130{ 132{
131 qDebug("MHwrapper::fetchBody "); 133 qDebug("MHwrapper::fetchBody ");
132 RecBodyP body = new RecBody(); 134 RecBodyP body = new RecBody();
133 init_storage(); 135 init_storage();
134 if (!m_storage) { 136 if (!m_storage) {
135 return body; 137 return body;
136 } 138 }
137 mailmessage * msg; 139 mailmessage * msg;
138 char*data=0; 140 char*data=0;
139 141
140 /* mail should hold the complete path! */ 142 /* mail should hold the complete path! */
141 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 143 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
142 if (r != MAIL_NO_ERROR) { 144 if (r != MAIL_NO_ERROR) {
143 return body; 145 return body;
144 } 146 }
145 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 147 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
146 if (r != MAIL_NO_ERROR) { 148 if (r != MAIL_NO_ERROR) {
147 qDebug("Error fetching mail "); 149 qDebug("Error fetching mail ");
148 150
149 return body; 151 return body;
150 } 152 }
151 body = parseMail(msg); 153 body = parseMail(msg);
152 mailmessage_fetch_result_free(msg,data); 154 mailmessage_fetch_result_free(msg,data);
153 return body; 155 return body;
154} 156}
155 157
156void MHwrapper::mbox_progress( size_t current, size_t maximum ) 158void MHwrapper::mbox_progress( size_t current, size_t maximum )
157{ 159{
158 qDebug("MBox Progress %d of %d",current,maximum ); 160 qDebug("MBox Progress %d of %d",current,maximum );
159 //odebug << "MH " << current << " von " << maximum << "" << oendl; 161 //odebug << "MH " << current << " von " << maximum << "" << oendl;
160} 162}
161 163
162QString MHwrapper::buildPath(const QString&p) 164QString MHwrapper::buildPath(const QString&p)
163{ 165{
164 QString f=""; 166 QString f="";
165 if (p.length()==0||p=="/") 167 if (p.length()==0||p=="/")
166 return MHPath; 168 return MHPath;
167 if (!p.startsWith(MHPath)) { 169 if (!p.startsWith(MHPath)) {
168 f+=MHPath; 170 f+=MHPath;
169 } 171 }
170 if (!p.startsWith("/")) { 172 if (!p.startsWith("/")) {
171 f+="/"; 173 f+="/";
172 } 174 }
173 f+=p; 175 f+=p;
174 return f; 176 return f;
175} 177}
176 178
177int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool ) 179int MHwrapper::createMbox(const QString&folder,const FolderP&pfolder,const QString&,bool )
178{ 180{
179 181
180 QString f; 182 QString f;
181 if (!pfolder) { 183 if (!pfolder) {
182 // toplevel folder 184 // toplevel folder
183 f = buildPath(folder); 185 f = buildPath(folder);
184 } else { 186 } else {
185 f = pfolder->getName(); 187 f = pfolder->getName();
186 f+="/"; 188 f+="/";
187 f+=folder; 189 f+=folder;
188 } 190 }
189 QFileInfo fi ( f ); 191 QFileInfo fi ( f );
190 if ( fi. exists () ) { 192 if ( fi. exists () ) {
191 qDebug("folder exists "); 193 qDebug("folder exists ");
192 return 1; 194 return 1;
193 } 195 }
194 qDebug("creating folder ---%s--- ",f.latin1() ); 196 qDebug("creating folder ---%s--- ",f.latin1() );
195 init_storage(); 197 init_storage();
196 if (!m_storage) { 198 if (!m_storage) {
197 return 0; 199 return 0;
198 } 200 }
199 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 201 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
200 if (r != MAIL_NO_ERROR) { 202 if (r != MAIL_NO_ERROR) {
201 qDebug("error %d creating folder %s", r, f.latin1()); 203 qDebug("error %d creating folder %s", r, f.latin1());
202 return 0; 204 return 0;
203 } 205 }
204 return 1; 206 return 1;
205} 207}
206 208
207void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 209void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
208{ 210{
209 init_storage(); 211 init_storage();
210 if (!m_storage) { 212 if (!m_storage) {
211 return; 213 return;
212 } 214 }
213 QString f = buildPath(Folder); 215 QString f = buildPath(Folder);
214 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 216 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
215 if (r!=MAIL_NO_ERROR) { 217 if (r!=MAIL_NO_ERROR) {
216 qDebug("error selecting folder %d", r); 218 qDebug("error selecting folder %d", r);
217 return; 219 return;
218 } 220 }
219 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 221 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
220 if (r!=MAIL_NO_ERROR) { 222 if (r!=MAIL_NO_ERROR) {
221 if ( r != MAIL_ERROR_APPEND ) 223 if ( r != MAIL_ERROR_APPEND )
222 qDebug("error storing mail %d", r); 224 qDebug("error storing mail %d", r);
223 } 225 }
224 return; 226 return;
225} 227}
226 228
227encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) 229encodedString* MHwrapper::fetchRawBody(const RecMailP&mail)
228{ 230{
229 encodedString*result = 0; 231 encodedString*result = 0;
230 init_storage(); 232 init_storage();
231 if (!m_storage) { 233 if (!m_storage) {
232 return result; 234 return result;
233 } 235 }
234 mailmessage * msg = 0; 236 mailmessage * msg = 0;
235 char*data=0; 237 char*data=0;
236 size_t size; 238 size_t size;
237 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 239 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
238 if (r!=MAIL_NO_ERROR) { 240 if (r!=MAIL_NO_ERROR) {
239 qDebug("error selecting folder! "); 241 qDebug("error selecting folder! ");
240 return result; 242 return result;
241 } 243 }
242 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 244 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
243 if (r != MAIL_NO_ERROR) { 245 if (r != MAIL_NO_ERROR) {
244 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 246 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
245 return 0; 247 return 0;
246 } 248 }
247 r = mailmessage_fetch(msg,&data,&size); 249 r = mailmessage_fetch(msg,&data,&size);
248 if (r != MAIL_NO_ERROR) { 250 if (r != MAIL_NO_ERROR) {
249 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); 251 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
250 if (msg) mailmessage_free(msg); 252 if (msg) mailmessage_free(msg);
251 return 0; 253 return 0;
252 } 254 }
253 result = new encodedString(data,size); 255 result = new encodedString(data,size);
254 if (msg) mailmessage_free(msg); 256 if (msg) mailmessage_free(msg);
255 return result; 257 return result;
256} 258}
257 259
258void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 260void MHwrapper::deleteMails(const QString & mailbox,const Q3ValueList<RecMailP> &target)
259{ 261{
260 QString f = buildPath(mailbox); 262 QString f = buildPath(mailbox);
261 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 263 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
262 if (r!=MAIL_NO_ERROR) { 264 if (r!=MAIL_NO_ERROR) {
263 qDebug("deleteMails: error selecting folder! "); 265 qDebug("deleteMails: error selecting folder! ");
264 return; 266 return;
265 } 267 }
266 QValueList<RecMailP>::ConstIterator it; 268 Q3ValueList<RecMailP>::ConstIterator it;
267 for (it=target.begin(); it!=target.end();++it) { 269 for (it=target.begin(); it!=target.end();++it) {
268 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); 270 r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber());
269 if (r != MAIL_NO_ERROR) { 271 if (r != MAIL_NO_ERROR) {
270 qDebug("error deleting mail "); 272 qDebug("error deleting mail ");
271 break; 273 break;
272 } 274 }
273 } 275 }
274} 276}
275 277
276int MHwrapper::deleteAllMail(const FolderP&tfolder) 278int MHwrapper::deleteAllMail(const FolderP&tfolder)
277{ 279{
278 init_storage(); 280 init_storage();
279 if (!m_storage) { 281 if (!m_storage) {
280 return 0; 282 return 0;
281 } 283 }
282 int res = 1; 284 int res = 1;
283 if (!tfolder) return 0; 285 if (!tfolder) return 0;
284 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 286 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
285 if (r!=MAIL_NO_ERROR) { 287 if (r!=MAIL_NO_ERROR) {
286 qDebug("error selecting folder! "); 288 qDebug("error selecting folder! ");
287 return 0; 289 return 0;
288 } 290 }
289 mailmessage_list*l=0; 291 mailmessage_list*l=0;
290 r = mailsession_get_messages_list(m_storage->sto_session,&l); 292 r = mailsession_get_messages_list(m_storage->sto_session,&l);
291 if (r != MAIL_NO_ERROR) { 293 if (r != MAIL_NO_ERROR) {
292 qDebug("Error message list "); 294 qDebug("Error message list ");
293 res = 0; 295 res = 0;
294 } 296 }
295 unsigned j = 0; 297 unsigned j = 0;
296 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 298 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
297 mailmessage * msg; 299 mailmessage * msg;
298 msg = (mailmessage*)carray_get(l->msg_tab, i); 300 msg = (mailmessage*)carray_get(l->msg_tab, i);
299 j = msg->msg_index; 301 j = msg->msg_index;
300 r = mailsession_remove_message(m_storage->sto_session,j); 302 r = mailsession_remove_message(m_storage->sto_session,j);
301 if (r != MAIL_NO_ERROR) { 303 if (r != MAIL_NO_ERROR) {
302 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 304 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
303 res = 0; 305 res = 0;
304 break; 306 break;
305 } 307 }
306 } 308 }
307 if (l) mailmessage_list_free(l); 309 if (l) mailmessage_list_free(l);
308 return res; 310 return res;
309} 311}
310bool MHwrapper::rmDir(QString folder) // absolute path! 312bool MHwrapper::rmDir(QString folder) // absolute path!
311{ 313{
312 QDir dir ( folder ); 314 QDir dir ( folder );
313 if ( !dir.exists() ) 315 if ( !dir.exists() )
314 return false; 316 return false;
315 int i; 317 int i;
316 // qDebug("rmdir %s ",folder.latin1()); 318 // qDebug("rmdir %s ",folder.latin1());
317 QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden ); 319 QStringList list = dir.entryList(QDir::Dirs|QDir::Files|QDir::NoSymLinks|QDir::Hidden );
318 for (i=0; i<list.count(); i++ ) { 320 for (i=0; i<list.count(); i++ ) {
319 bool result = true; 321 bool result = true;
320 QString entry = folder+"/"+ list[i] ; 322 QString entry = folder+"/"+ list[i] ;
321 //qDebug("entry %s ",entry.latin1() ); 323 //qDebug("entry %s ",entry.latin1() );
322 324
323 QFileInfo fi ( entry ); 325 QFileInfo fi ( entry );
324 if ( fi.isFile() ) { 326 if ( fi.isFile() ) {
325 //qDebug("file %s ",entry.latin1() ); 327 //qDebug("file %s ",entry.latin1() );
326 result = QFile::remove ( entry ) ; 328 result = QFile::remove ( entry ) ;
327 } else { 329 } else {
328 //qDebug("dir %s ",entry.latin1()); 330 //qDebug("dir %s ",entry.latin1());
329 if ( list[i] != "." && list[i] != ".." ) 331 if ( list[i] != "." && list[i] != ".." )
330 result = rmDir( entry ); 332 result = rmDir( entry );
331 } 333 }
332 if ( ! result ) 334 if ( ! result )
333 return false; 335 return false;
334 } 336 }
335 //qDebug("removing... "); 337 //qDebug("removing... ");
336 return QDir::root().rmdir ( folder, true ); 338 return QDir::root().rmdir ( folder, true );
337} 339}
338int MHwrapper::deleteMbox(const FolderP&tfolder) 340int MHwrapper::deleteMbox(const FolderP&tfolder)
339{ 341{
340 init_storage(); 342 init_storage();
341 if (!m_storage) { 343 if (!m_storage) {
342 return 0; 344 return 0;
343 } 345 }
344 if (!tfolder) return 0; 346 if (!tfolder) return 0;
345 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; 347 if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0;
346 348
347 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 349 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
348 350
349 if (r != MAIL_NO_ERROR) { 351 if (r != MAIL_NO_ERROR) {
350 qDebug("error deleting mail box "); 352 qDebug("error deleting mail box ");
351 return 0; 353 return 0;
352 } 354 }
353 //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() ); 355 //qDebug("*****************\ndel %s %s ", delDir.latin1(),tfolder->getName().latin1() );
354 if ( !rmDir( tfolder->getName() )) { 356 if ( !rmDir( tfolder->getName() )) {
355 qDebug("error deleteing folder %s ",tfolder->getName().latin1()); 357 qDebug("error deleteing folder %s ",tfolder->getName().latin1());
356 } 358 }
357 else 359 else
358 qDebug("mail box deleted %s ", tfolder->getName().latin1()); 360 qDebug("mail box deleted %s ", tfolder->getName().latin1());
359 return 1; 361 return 1;
360} 362}
361 363
362 364
363void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 365void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
364{ 366{
365 init_storage(); 367 init_storage();
366 if (!m_storage) { 368 if (!m_storage) {
367 return; 369 return;
368 } 370 }
369 target_stat.message_count = 0; 371 target_stat.message_count = 0;
370 target_stat.message_unseen = 0; 372 target_stat.message_unseen = 0;
371 target_stat.message_recent = 0; 373 target_stat.message_recent = 0;
372 QString f = buildPath(mailbox); 374 QString f = buildPath(mailbox);
373 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 375 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
374 &target_stat.message_recent,&target_stat.message_unseen); 376 &target_stat.message_recent,&target_stat.message_unseen);
375 if (r != MAIL_NO_ERROR) { 377 if (r != MAIL_NO_ERROR) {
376 Global::statusMessage(i18n("Error retrieving status")); 378 Global::statusMessage(i18n("Error retrieving status"));
377 } 379 }
378} 380}
379 381
380MAILLIB::ATYPE MHwrapper::getType()const 382MAILLIB::ATYPE MHwrapper::getType()const
381{ 383{
382 return MAILLIB::A_MH; 384 return MAILLIB::A_MH;
383} 385}
384 386
385const QString&MHwrapper::getName()const 387const QString&MHwrapper::getName()const
386{ 388{
387 return MHName; 389 return MHName;
388} 390}
389void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 391void MHwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
390{ 392{
391 init_storage(); 393 init_storage();
392 if (!m_storage) { 394 if (!m_storage) {
393 return; 395 return;
394 } 396 }
395 if (targetWrapper != this) { 397 if (targetWrapper != this) {
396 qDebug("Using generic "); 398 qDebug("Using generic ");
397 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); 399 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
398 return; 400 return;
399 } 401 }
400 qDebug("Using internal routines for move/copy "); 402 qDebug("Using internal routines for move/copy ");
401 QString tf = buildPath(targetFolder); 403 QString tf = buildPath(targetFolder);
402 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 404 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
403 if (r != MAIL_NO_ERROR) { 405 if (r != MAIL_NO_ERROR) {
404 qDebug("Error selecting source mailbox "); 406 qDebug("Error selecting source mailbox ");
405 return; 407 return;
406 } 408 }
407 if (moveit) { 409 if (moveit) {
408 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 410 r = mailsession_move_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
409 } else { 411 } else {
410 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1()); 412 r = mailsession_copy_message(m_storage->sto_session,mail->getNumber(),(char*)tf.latin1());
411 } 413 }
412 if (r != MAIL_NO_ERROR) { 414 if (r != MAIL_NO_ERROR) {
413 qDebug("Error copy/moving mail internal "); 415 qDebug("Error copy/moving mail internal ");
414 } 416 }
415} 417}
416 418
417void MHwrapper::mvcpAllMails(const FolderP&fromFolder, 419void MHwrapper::mvcpAllMails(const FolderP&fromFolder,
418 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 420 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
419{ 421{
420 init_storage(); 422 init_storage();
421 if (!m_storage) { 423 if (!m_storage) {
422 return; 424 return;
423 } 425 }
424 if (targetWrapper != this) { 426 if (targetWrapper != this) {
425 qDebug("Using generic "); 427 qDebug("Using generic ");
426 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 428 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
427 return; 429 return;
428 } 430 }
429 if (!fromFolder) return; 431 if (!fromFolder) return;
430 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); 432 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
431 if (r!=MAIL_NO_ERROR) { 433 if (r!=MAIL_NO_ERROR) {
432 qDebug("error selecting source folder! "); 434 qDebug("error selecting source folder! ");
433 return; 435 return;
434 } 436 }
435 QString tf = buildPath(targetFolder); 437 QString tf = buildPath(targetFolder);
436 mailmessage_list*l=0; 438 mailmessage_list*l=0;
437 r = mailsession_get_messages_list(m_storage->sto_session,&l); 439 r = mailsession_get_messages_list(m_storage->sto_session,&l);
438 if (r != MAIL_NO_ERROR) { 440 if (r != MAIL_NO_ERROR) {
439 qDebug("Error message list "); 441 qDebug("Error message list ");
440 } 442 }
441 unsigned j = 0; 443 unsigned j = 0;
442 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { 444 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
443 mailmessage * msg; 445 mailmessage * msg;
444 msg = (mailmessage*)carray_get(l->msg_tab, i); 446 msg = (mailmessage*)carray_get(l->msg_tab, i);
445 j = msg->msg_index; 447 j = msg->msg_index;
446 if (moveit) { 448 if (moveit) {
447 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); 449 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
448 } else { 450 } else {
449 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); 451 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
450 } 452 }
451 if (r != MAIL_NO_ERROR) { 453 if (r != MAIL_NO_ERROR) {
452 qDebug("Error copy/moving mail interna "); 454 qDebug("Error copy/moving mail interna ");
453 455
454 break; 456 break;
455 } 457 }
456 } 458 }
457 if (l) mailmessage_list_free(l); 459 if (l) mailmessage_list_free(l);
458} 460}
diff --git a/kmicromail/libmailwrapper/mhwrapper.h b/kmicromail/libmailwrapper/mhwrapper.h
index 36a443a..6151ff1 100644
--- a/kmicromail/libmailwrapper/mhwrapper.h
+++ b/kmicromail/libmailwrapper/mhwrapper.h
@@ -1,59 +1,61 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __MH_WRAPPER_H 2#ifndef __MH_WRAPPER_H
3#define __MH_WRAPPER_H 3#define __MH_WRAPPER_H
4 4
5#include "maildefines.h" 5#include "maildefines.h"
6 6
7#include "genericwrapper.h" 7#include "genericwrapper.h"
8#include <qstring.h> 8#include <qstring.h>
9//Added by qt3to4:
10#include <Q3ValueList>
9 11
10class encodedString; 12class encodedString;
11struct mailmbox_folder; 13struct mailmbox_folder;
12class MHwrapper : public Genericwrapper 14class MHwrapper : public Genericwrapper
13{ 15{
14 Q_OBJECT 16 Q_OBJECT
15public: 17public:
16 MHwrapper(const QString & dir,const QString&name); 18 MHwrapper(const QString & dir,const QString&name);
17 virtual ~MHwrapper(); 19 virtual ~MHwrapper();
18 20
19 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
20 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 23 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22 24
23 virtual void deleteMail(const RecMailP&mail); 25 virtual void deleteMail(const RecMailP&mail);
24 virtual void answeredMail(const RecMailP&mail); 26 virtual void answeredMail(const RecMailP&mail);
25 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 27 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
26 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 28 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
27 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 29 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
28 30
29 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0, 31 virtual int createMbox(const QString&folder,const Opie::Core::OSmartPointer<Folder>&f=0,
30 const QString&d="",bool s=false); 32 const QString&d="",bool s=false);
31 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&); 33 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&);
32 34
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 36
35 virtual RecBodyP fetchBody( const RecMailP &mail ); 37 virtual RecBodyP fetchBody( const RecMailP &mail );
36 static void mbox_progress( size_t current, size_t maximum ); 38 static void mbox_progress( size_t current, size_t maximum );
37 39
38 virtual encodedString* fetchRawBody(const RecMailP&mail); 40 virtual encodedString* fetchRawBody(const RecMailP&mail);
39 virtual void deleteMails(const QString & FolderName,const QValueList<Opie::Core::OSmartPointer<RecMail> > &target); 41 virtual void deleteMails(const QString & FolderName,const Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target);
40 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 42 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
41 virtual MAILLIB::ATYPE getType()const; 43 virtual MAILLIB::ATYPE getType()const;
42 virtual const QString&getName()const; 44 virtual const QString&getName()const;
43 virtual Account* getAccount() { return 0; }; 45 virtual Account* getAccount() { return 0; };
44 46
45public slots: 47public slots:
46 48
47protected: 49protected:
48 QString buildPath(const QString&p); 50 QString buildPath(const QString&p);
49 QString MHPath; 51 QString MHPath;
50 QString MHName; 52 QString MHName;
51 53
52 void init_storage(); 54 void init_storage();
53 void clean_storage(); 55 void clean_storage();
54 bool rmDir(QString folderabspath); 56 bool rmDir(QString folderabspath);
55 57
56 bool removeMboxfailed; 58 bool removeMboxfailed;
57}; 59};
58 60
59#endif 61#endif
diff --git a/kmicromail/libmailwrapper/nntpwrapper.cpp b/kmicromail/libmailwrapper/nntpwrapper.cpp
index 93cd2b5..b328ecd 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.cpp
+++ b/kmicromail/libmailwrapper/nntpwrapper.cpp
@@ -1,281 +1,283 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "nntpwrapper.h" 2#include "nntpwrapper.h"
3#include "logindialog.h" 3#include "logindialog.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5 5
6#include <qfile.h> 6#include <qfile.h>
7//Added by qt3to4:
8#include <Q3ValueList>
7 9
8#include <stdlib.h> 10#include <stdlib.h>
9 11
10#include <libetpan/libetpan.h> 12#include <libetpan/libetpan.h>
11 13
12 14
13 15
14#define HARD_MSG_SIZE_LIMIT 5242880 16#define HARD_MSG_SIZE_LIMIT 5242880
15 17
16using namespace Opie::Core; 18using namespace Opie::Core;
17NNTPwrapper::NNTPwrapper( NNTPaccount *a ) 19NNTPwrapper::NNTPwrapper( NNTPaccount *a )
18: Genericwrapper() { 20: Genericwrapper() {
19 account = a; 21 account = a;
20 m_nntp = NULL; 22 m_nntp = NULL;
21 msgTempName = a->getFileName()+"_msg_cache"; 23 msgTempName = a->getFileName()+"_msg_cache";
22 last_msg_id = 0; 24 last_msg_id = 0;
23} 25}
24 26
25NNTPwrapper::~NNTPwrapper() { 27NNTPwrapper::~NNTPwrapper() {
26 logout(); 28 logout();
27 QFile msg_cache(msgTempName); 29 QFile msg_cache(msgTempName);
28 if (msg_cache.exists()) { 30 if (msg_cache.exists()) {
29 msg_cache.remove(); 31 msg_cache.remove();
30 } 32 }
31} 33}
32 34
33void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) { 35void NNTPwrapper::nntp_progress( size_t current, size_t maximum ) {
34 ; // << "NNTP: " << current << " of " << maximum << "" << oendl; 36 ; // << "NNTP: " << current << " of " << maximum << "" << oendl;
35} 37}
36 38
37 39
38RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) { 40RecBodyP NNTPwrapper::fetchBody( const RecMailP &mail ) {
39 int err = NEWSNNTP_NO_ERROR; 41 int err = NEWSNNTP_NO_ERROR;
40 char *message = 0; 42 char *message = 0;
41 size_t length = 0; 43 size_t length = 0;
42 44
43 RecBodyP body = new RecBody(); 45 RecBodyP body = new RecBody();
44 login(); 46 login();
45 if ( !m_nntp ) { 47 if ( !m_nntp ) {
46 return body; 48 return body;
47 } 49 }
48 50
49 mailmessage * mailmsg; 51 mailmessage * mailmsg;
50 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 52 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 ; // << "Message to large: " << mail->Msgsize() << "" << oendl; 53 ; // << "Message to large: " << mail->Msgsize() << "" << oendl;
52 return body; 54 return body;
53 } 55 }
54 56
55 QFile msg_cache(msgTempName); 57 QFile msg_cache(msgTempName);
56 58
57 cleanMimeCache(); 59 cleanMimeCache();
58 60
59 if (mail->getNumber()!=last_msg_id) { 61 if (mail->getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 62 if (msg_cache.exists()) {
61 msg_cache.remove(); 63 msg_cache.remove();
62 } 64 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 65 msg_cache.open(QIODevice::ReadWrite|QIODevice::Truncate);
64 last_msg_id = mail->getNumber(); 66 last_msg_id = mail->getNumber();
65 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); 67 err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 68 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 69 msg_cache.writeBlock(message,length);
68 } else { 70 } else {
69 QString msg=""; 71 QString msg="";
70 msg_cache.open(IO_ReadOnly); 72 msg_cache.open(QIODevice::ReadOnly);
71 message = new char[4096]; 73 message = new char[4096];
72 memset(message,0,4096); 74 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 75 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 76 msg+=message;
75 memset(message,0,4096); 77 memset(message,0,4096);
76 } 78 }
77 delete message; 79 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 80 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 81 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 82 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 83 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 84 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 85 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 86 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 87 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 88 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 89 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 90 msg_data->msg_length = strlen(message);
89 } 91 }
90 body = parseMail(mailmsg); 92 body = parseMail(mailmsg);
91 93
92 /* clean up */ 94 /* clean up */
93 if (mailmsg) 95 if (mailmsg)
94 mailmessage_free(mailmsg); 96 mailmessage_free(mailmsg);
95 if (message) 97 if (message)
96 free(message); 98 free(message);
97 99
98 return body; 100 return body;
99} 101}
100 102
101 103
102void NNTPwrapper::listMessages(const QString & which, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb) 104void NNTPwrapper::listMessages(const QString & which, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb)
103{ 105{
104 login(); 106 login();
105 if (!m_nntp) 107 if (!m_nntp)
106 return; 108 return;
107 uint32_t res_messages,res_recent,res_unseen; 109 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen); 110 mailsession_status_folder(m_nntp->sto_session,(char*)which.latin1(),&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_nntp->sto_session,which,true, maxSizeInKb); 111 parseList(target,m_nntp->sto_session,which,true, maxSizeInKb);
110} 112}
111 113
112void NNTPwrapper::login() 114void NNTPwrapper::login()
113{ 115{
114 if (account->getOffline()) 116 if (account->getOffline())
115 return; 117 return;
116 /* we'll hold the line */ 118 /* we'll hold the line */
117 if ( m_nntp != NULL ) 119 if ( m_nntp != NULL )
118 return; 120 return;
119 121
120 QString server; 122 QString server;
121 QString User,Pass; 123 QString User,Pass;
122 uint16_t port; 124 uint16_t port;
123 int err = NEWSNNTP_NO_ERROR; 125 int err = NEWSNNTP_NO_ERROR;
124 126
125 server = account->getServer(); 127 server = account->getServer();
126 port = account->getPort().toUInt(); 128 port = account->getPort().toUInt();
127 129
128 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) { 130 if ( ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) && account->getLogin() ) {
129 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 131 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
130 login.show(); 132 login.show();
131 if ( QDialog::Accepted == login.exec() ) { 133 if ( QDialog::Accepted == login.exec() ) {
132 // ok 134 // ok
133 User = login.getUser(); 135 User = login.getUser();
134 Pass = login.getPassword(); 136 Pass = login.getPassword();
135 } else { 137 } else {
136 // cancel 138 // cancel
137 ; // << "NNTP: Login canceled" << oendl; 139 ; // << "NNTP: Login canceled" << oendl;
138 return; 140 return;
139 } 141 }
140 } else { 142 } else {
141 User = account->getUser(); 143 User = account->getUser();
142 Pass = account->getPassword(); 144 Pass = account->getPassword();
143 } 145 }
144 146
145 // bool ssl = account->getSSL(); 147 // bool ssl = account->getSSL();
146 148
147 m_nntp=mailstorage_new(NULL); 149 m_nntp=mailstorage_new(NULL);
148 150
149 int conntypeset = account->ConnectionType(); 151 int conntypeset = account->ConnectionType();
150 int conntype = 0; 152 int conntype = 0;
151 if ( conntypeset == 3 ) { 153 if ( conntypeset == 3 ) {
152 conntype = CONNECTION_TYPE_COMMAND; 154 conntype = CONNECTION_TYPE_COMMAND;
153 } else if ( conntypeset == 2 ) { 155 } else if ( conntypeset == 2 ) {
154 conntype = CONNECTION_TYPE_TLS; 156 conntype = CONNECTION_TYPE_TLS;
155 } else if ( conntypeset == 1 ) { 157 } else if ( conntypeset == 1 ) {
156 conntype = CONNECTION_TYPE_STARTTLS; 158 conntype = CONNECTION_TYPE_STARTTLS;
157 } else if ( conntypeset == 0 ) { 159 } else if ( conntypeset == 0 ) {
158 conntype = CONNECTION_TYPE_TRY_STARTTLS; 160 conntype = CONNECTION_TYPE_TRY_STARTTLS;
159 } 161 }
160 162
161 nntp_mailstorage_init(m_nntp,(char*)server.latin1(), port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN, 163 nntp_mailstorage_init(m_nntp,(char*)server.latin1(), port, NULL, CONNECTION_TYPE_PLAIN, NNTP_AUTH_TYPE_PLAIN,
162 (char*)User.latin1(),(char*)Pass.latin1(),0,0,0); 164 (char*)User.latin1(),(char*)Pass.latin1(),0,0,0);
163 165
164 err = mailstorage_connect( m_nntp ); 166 err = mailstorage_connect( m_nntp );
165 167
166 if (err != NEWSNNTP_NO_ERROR) { 168 if (err != NEWSNNTP_NO_ERROR) {
167 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 169 ; // << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 // Global::statusMessage(tr("Error initializing folder")); 170 // Global::statusMessage(tr("Error initializing folder"));
169 mailstorage_free(m_nntp); 171 mailstorage_free(m_nntp);
170 m_nntp = 0; 172 m_nntp = 0;
171 173
172 } else { 174 } else {
173 mailsession * session = m_nntp->sto_session; 175 mailsession * session = m_nntp->sto_session;
174 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 176 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
175 news->nntp_progr_fun = &nntp_progress; 177 news->nntp_progr_fun = &nntp_progress;
176 } 178 }
177 179
178} 180}
179 181
180void NNTPwrapper::logout() 182void NNTPwrapper::logout()
181{ 183{
182 int err = NEWSNNTP_NO_ERROR; 184 int err = NEWSNNTP_NO_ERROR;
183 if ( m_nntp == NULL ) 185 if ( m_nntp == NULL )
184 return; 186 return;
185 mailstorage_free(m_nntp); 187 mailstorage_free(m_nntp);
186 m_nntp = 0; 188 m_nntp = 0;
187} 189}
188 190
189QValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() { 191Q3ValueList<Opie::Core::OSmartPointer<Folder> >* NNTPwrapper::listFolders() {
190 192
191 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 193 Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >();
192 QStringList groups; 194 QStringList groups;
193 if (account) { 195 if (account) {
194 groups = account->getGroups(); 196 groups = account->getGroups();
195 } 197 }
196 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { 198 for ( QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
197 folders->append(new Folder((*it),".")); 199 folders->append(new Folder((*it),"."));
198 } 200 }
199 return folders; 201 return folders;
200} 202}
201 203
202/* we made this method in raw nntp access of etpan and not via generic interface 204/* we made this method in raw nntp access of etpan and not via generic interface
203 * 'cause in that case there will be doubled copy operations. eg. the etpan would 205 * 'cause in that case there will be doubled copy operations. eg. the etpan would
204 * copy that stuff into its own structures and we must copy it into useable c++ 206 * copy that stuff into its own structures and we must copy it into useable c++
205 * structures for our frontend. this would not make sense, so it is better to reimplement 207 * structures for our frontend. this would not make sense, so it is better to reimplement
206 * the stuff from generic interface of etpan but copy it direct to qt classes. 208 * the stuff from generic interface of etpan but copy it direct to qt classes.
207 */ 209 */
208QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) { 210QStringList NNTPwrapper::listAllNewsgroups(const QString&mask) {
209 login(); 211 login();
210 QStringList res; 212 QStringList res;
211 clist *result = 0; 213 clist *result = 0;
212 clistcell *current = 0; 214 clistcell *current = 0;
213 newsnntp_group_description *group; 215 newsnntp_group_description *group;
214 216
215 if ( m_nntp ) { 217 if ( m_nntp ) {
216 mailsession * session = m_nntp->sto_session; 218 mailsession * session = m_nntp->sto_session;
217 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session; 219 newsnntp * news = ( ( nntp_session_state_data * )session->sess_data )->nntp_session;
218 int err = NEWSNNTP_NO_ERROR; 220 int err = NEWSNNTP_NO_ERROR;
219 if (mask.isEmpty()) { 221 if (mask.isEmpty()) {
220 err = newsnntp_list(news, &result); 222 err = newsnntp_list(news, &result);
221 } else { 223 } else {
222 /* taken from generic wrapper of etpan */ 224 /* taken from generic wrapper of etpan */
223 QString nmask = mask+".*"; 225 QString nmask = mask+".*";
224 err = newsnntp_list_active(news, nmask.latin1(), &result); 226 err = newsnntp_list_active(news, nmask.latin1(), &result);
225 } 227 }
226 if ( err == NEWSNNTP_NO_ERROR && result) { 228 if ( err == NEWSNNTP_NO_ERROR && result) {
227 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) { 229 for ( current=clist_begin(result);current!=NULL;current=clist_next(current) ) {
228 group = ( newsnntp_group_description* ) current->data; 230 group = ( newsnntp_group_description* ) current->data;
229 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue; 231 if (!group||!group->grp_name||strlen(group->grp_name)==0) continue;
230 res.append(group->grp_name); 232 res.append(group->grp_name);
231 } 233 }
232 } 234 }
233 } 235 }
234 if (result) { 236 if (result) {
235 newsnntp_list_free(result); 237 newsnntp_list_free(result);
236 } 238 }
237 return res; 239 return res;
238} 240}
239 241
240void NNTPwrapper::answeredMail(const RecMailP&) {} 242void NNTPwrapper::answeredMail(const RecMailP&) {}
241 243
242void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) { 244void NNTPwrapper::statusFolder(folderStat&target_stat,const QString&) {
243 login(); 245 login();
244 target_stat.message_count = 0; 246 target_stat.message_count = 0;
245 target_stat.message_unseen = 0; 247 target_stat.message_unseen = 0;
246 target_stat.message_recent = 0; 248 target_stat.message_recent = 0;
247 if (!m_nntp) 249 if (!m_nntp)
248 return; 250 return;
249 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count, 251 int r = mailsession_status_folder(m_nntp->sto_session,0,&target_stat.message_count,
250 &target_stat.message_recent,&target_stat.message_unseen); 252 &target_stat.message_recent,&target_stat.message_unseen);
251} 253}
252 254
253 255
254encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) { 256encodedString* NNTPwrapper::fetchRawBody(const RecMailP&mail) {
255 char*target=0; 257 char*target=0;
256 size_t length=0; 258 size_t length=0;
257 encodedString*res = 0; 259 encodedString*res = 0;
258 mailmessage * mailmsg = 0; 260 mailmessage * mailmsg = 0;
259 int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg); 261 int err = mailsession_get_message(m_nntp->sto_session, mail->getNumber(), &mailmsg);
260 err = mailmessage_fetch(mailmsg,&target,&length); 262 err = mailmessage_fetch(mailmsg,&target,&length);
261 if (mailmsg) 263 if (mailmsg)
262 mailmessage_free(mailmsg); 264 mailmessage_free(mailmsg);
263 if (target) { 265 if (target) {
264 res = new encodedString(target,length); 266 res = new encodedString(target,length);
265 } 267 }
266 return res; 268 return res;
267} 269}
268 270
269MAILLIB::ATYPE NNTPwrapper::getType()const { 271MAILLIB::ATYPE NNTPwrapper::getType()const {
270 return account->getType(); 272 return account->getType();
271} 273}
272 274
273const QString&NNTPwrapper::getName()const{ 275const QString&NNTPwrapper::getName()const{
274 return account->getAccountName(); 276 return account->getAccountName();
275} 277}
276 278
277void NNTPwrapper::deleteMail(const RecMailP&) { 279void NNTPwrapper::deleteMail(const RecMailP&) {
278} 280}
279 281
280int NNTPwrapper::deleteAllMail(const FolderP&) { 282int NNTPwrapper::deleteAllMail(const FolderP&) {
281} 283}
diff --git a/kmicromail/libmailwrapper/nntpwrapper.h b/kmicromail/libmailwrapper/nntpwrapper.h
index 8c54f12..7c8e671 100644
--- a/kmicromail/libmailwrapper/nntpwrapper.h
+++ b/kmicromail/libmailwrapper/nntpwrapper.h
@@ -1,50 +1,52 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __NNTPWRAPPER 2#ifndef __NNTPWRAPPER
3#define __NNTPWRAPPER 3#define __NNTPWRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8//Added by qt3to4:
9#include <Q3ValueList>
8#include <libetpan/clist.h> 10#include <libetpan/clist.h>
9 11
10class encodedString; 12class encodedString;
11struct mailstorage; 13struct mailstorage;
12struct mailfolder; 14struct mailfolder;
13 15
14class NNTPwrapper : public Genericwrapper 16class NNTPwrapper : public Genericwrapper
15{ 17{
16 18
17 Q_OBJECT 19 Q_OBJECT
18 20
19public: 21public:
20 NNTPwrapper( NNTPaccount *a ); 22 NNTPwrapper( NNTPaccount *a );
21 virtual ~NNTPwrapper(); 23 virtual ~NNTPwrapper();
22 24
23 /* mailbox will be ignored */ 25 /* mailbox will be ignored */
24 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 26 virtual void listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
25 /* should only get the subscribed one */ 27 /* should only get the subscribed one */
26 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 28 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
27 /* mailbox will be ignored */ 29 /* mailbox will be ignored */
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 30 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 QStringList listAllNewsgroups(const QString&mask = QString::null); 31 QStringList listAllNewsgroups(const QString&mask = QString::null);
30 virtual void deleteMail(const RecMailP&mail); 32 virtual void deleteMail(const RecMailP&mail);
31 virtual void answeredMail(const RecMailP&mail); 33 virtual void answeredMail(const RecMailP&mail);
32 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
33 35
34 virtual RecBodyP fetchBody( const RecMailP &mail ); 36 virtual RecBodyP fetchBody( const RecMailP &mail );
35 virtual encodedString* fetchRawBody(const RecMailP&mail); 37 virtual encodedString* fetchRawBody(const RecMailP&mail);
36 virtual void logout(); 38 virtual void logout();
37 virtual MAILLIB::ATYPE getType()const; 39 virtual MAILLIB::ATYPE getType()const;
38 virtual const QString&getName()const; 40 virtual const QString&getName()const;
39 static void nntp_progress( size_t current, size_t maximum ); 41 static void nntp_progress( size_t current, size_t maximum );
40 virtual Account* getAccount() { return account; }; 42 virtual Account* getAccount() { return account; };
41 43
42protected: 44protected:
43 void login(); 45 void login();
44 NNTPaccount *account; 46 NNTPaccount *account;
45 mailstorage* m_nntp; 47 mailstorage* m_nntp;
46 48
47 49
48}; 50};
49 51
50#endif 52#endif
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 2888f7c..ebeed71 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,303 +1,305 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mailtypes.h" 4#include "mailtypes.h"
5#include "logindialog.h" 5#include "logindialog.h"
6#include <libetpan/libetpan.h> 6#include <libetpan/libetpan.h>
7 7
8#include <klocale.h> 8#include <klocale.h>
9 9
10#include <qpe/global.h> 10#include <qpe/global.h>
11#include <qfile.h> 11#include <qfile.h>
12#include <qprogressbar.h> 12#include <q3progressbar.h>
13#include <qapplication.h> 13#include <qapplication.h>
14//Added by qt3to4:
15#include <Q3ValueList>
14 16
15/* we don't fetch messages larger than 5 MB */ 17/* we don't fetch messages larger than 5 MB */
16#define HARD_MSG_SIZE_LIMIT 5242880 18#define HARD_MSG_SIZE_LIMIT 5242880
17 19
18using namespace Opie::Core; 20using namespace Opie::Core;
19POP3wrapper::POP3wrapper( POP3account *a ) 21POP3wrapper::POP3wrapper( POP3account *a )
20: Genericwrapper() { 22: Genericwrapper() {
21 account = a; 23 account = a;
22 m_pop3 = NULL; 24 m_pop3 = NULL;
23 msgTempName = a->getFileName()+"_msg_cache"; 25 msgTempName = a->getFileName()+"_msg_cache";
24 last_msg_id = 0; 26 last_msg_id = 0;
25} 27}
26 28
27POP3wrapper::~POP3wrapper() { 29POP3wrapper::~POP3wrapper() {
28 logout(); 30 logout();
29 QFile msg_cache(msgTempName); 31 QFile msg_cache(msgTempName);
30 if (msg_cache.exists()) { 32 if (msg_cache.exists()) {
31 msg_cache.remove(); 33 msg_cache.remove();
32 } 34 }
33} 35}
34 36
35void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 37void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
36 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 38 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
37} 39}
38 40
39RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 41RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
40 int err = MAILPOP3_NO_ERROR; 42 int err = MAILPOP3_NO_ERROR;
41 char *message = 0; 43 char *message = 0;
42 size_t length = 0; 44 size_t length = 0;
43 45
44 RecBodyP body = new RecBody(); 46 RecBodyP body = new RecBody();
45 47
46 login(); 48 login();
47 if ( !m_pop3 ) { 49 if ( !m_pop3 ) {
48 return body; 50 return body;
49 } 51 }
50 52
51 mailmessage * mailmsg; 53 mailmessage * mailmsg;
52 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 54 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
53 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 55 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
54 return body; 56 return body;
55 } 57 }
56 58
57 QFile msg_cache(msgTempName); 59 QFile msg_cache(msgTempName);
58 60
59 cleanMimeCache(); 61 cleanMimeCache();
60 62
61 if (mail->getNumber()!=last_msg_id) { 63 if (mail->getNumber()!=last_msg_id) {
62 if (msg_cache.exists()) { 64 if (msg_cache.exists()) {
63 msg_cache.remove(); 65 msg_cache.remove();
64 } 66 }
65 msg_cache.open(IO_ReadWrite|IO_Truncate); 67 msg_cache.open(QIODevice::ReadWrite|QIODevice::Truncate);
66 last_msg_id = mail->getNumber(); 68 last_msg_id = mail->getNumber();
67 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 69 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
68 err = mailmessage_fetch(mailmsg,&message,&length); 70 err = mailmessage_fetch(mailmsg,&message,&length);
69 msg_cache.writeBlock(message,length); 71 msg_cache.writeBlock(message,length);
70 } else { 72 } else {
71 QString msg=""; 73 QString msg="";
72 msg_cache.open(IO_ReadOnly); 74 msg_cache.open(QIODevice::ReadOnly);
73 message = new char[4096]; 75 message = new char[4096];
74 memset(message,0,4096); 76 memset(message,0,4096);
75 while (msg_cache.readBlock(message,4095)>0) { 77 while (msg_cache.readBlock(message,4095)>0) {
76 msg+=message; 78 msg+=message;
77 memset(message,0,4096); 79 memset(message,0,4096);
78 } 80 }
79 delete message; 81 delete message;
80 message = (char*)malloc(msg.length()+1*sizeof(char)); 82 message = (char*)malloc(msg.length()+1*sizeof(char));
81 memset(message,0,msg.length()+1); 83 memset(message,0,msg.length()+1);
82 memcpy(message,msg.latin1(),msg.length()); 84 memcpy(message,msg.latin1(),msg.length());
83 /* transform to libetpan stuff */ 85 /* transform to libetpan stuff */
84 mailmsg = mailmessage_new(); 86 mailmsg = mailmessage_new();
85 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 87 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
86 generic_message_t * msg_data; 88 generic_message_t * msg_data;
87 msg_data = (generic_message_t *)mailmsg->msg_data; 89 msg_data = (generic_message_t *)mailmsg->msg_data;
88 msg_data->msg_fetched = 1; 90 msg_data->msg_fetched = 1;
89 msg_data->msg_message = message; 91 msg_data->msg_message = message;
90 msg_data->msg_length = strlen(message); 92 msg_data->msg_length = strlen(message);
91 } 93 }
92 body = parseMail(mailmsg); 94 body = parseMail(mailmsg);
93 95
94 /* clean up */ 96 /* clean up */
95 if (mailmsg) 97 if (mailmsg)
96 mailmessage_free(mailmsg); 98 mailmessage_free(mailmsg);
97 if (message) 99 if (message)
98 free(message); 100 free(message);
99 101
100 return body; 102 return body;
101} 103}
102 104
103void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 105void POP3wrapper::listMessages(const QString &, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
104{ 106{
105 login(); 107 login();
106 if (!m_pop3) 108 if (!m_pop3)
107 return; 109 return;
108 uint32_t res_messages,res_recent,res_unseen; 110 uint32_t res_messages,res_recent,res_unseen;
109 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 111 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
110 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 112 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
111 Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages)); 113 Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages));
112} 114}
113 115
114void POP3wrapper::login() 116void POP3wrapper::login()
115{ 117{
116 if (account->getOffline()) 118 if (account->getOffline())
117 return; 119 return;
118 /* we'll hold the line */ 120 /* we'll hold the line */
119 if ( m_pop3 != NULL ) 121 if ( m_pop3 != NULL )
120 return; 122 return;
121 123
122 QString server,user, pass; 124 QString server,user, pass;
123 uint16_t port; 125 uint16_t port;
124 int err = MAILPOP3_NO_ERROR; 126 int err = MAILPOP3_NO_ERROR;
125 127
126 server = account->getServer(); 128 server = account->getServer();
127 port = account->getPort().toUInt(); 129 port = account->getPort().toUInt();
128 130
129 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 131 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
130 qApp->processEvents(); 132 qApp->processEvents();
131 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 133 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
132 login.show(); 134 login.show();
133 if ( QDialog::Accepted == login.exec() ) { 135 if ( QDialog::Accepted == login.exec() ) {
134 // ok 136 // ok
135 user = login.getUser(); 137 user = login.getUser();
136 pass = login.getPassword(); 138 pass = login.getPassword();
137 } else { 139 } else {
138 // cancel 140 // cancel
139 ; // odebug << "POP3: Login canceled" << oendl; 141 ; // odebug << "POP3: Login canceled" << oendl;
140 return; 142 return;
141 } 143 }
142 } else { 144 } else {
143 user = account->getUser(); 145 user = account->getUser();
144 pass = account->getPassword(); 146 pass = account->getPassword();
145 } 147 }
146 // bool ssl = account->getSSL(); 148 // bool ssl = account->getSSL();
147 149
148 m_pop3=mailstorage_new(NULL); 150 m_pop3=mailstorage_new(NULL);
149 int conntypeset = account->ConnectionType(); 151 int conntypeset = account->ConnectionType();
150 int conntype = 0; 152 int conntype = 0;
151 if ( conntypeset == 3 ) { 153 if ( conntypeset == 3 ) {
152 conntype = CONNECTION_TYPE_COMMAND; 154 conntype = CONNECTION_TYPE_COMMAND;
153 } else if ( conntypeset == 2 ) { 155 } else if ( conntypeset == 2 ) {
154 conntype = CONNECTION_TYPE_TLS; 156 conntype = CONNECTION_TYPE_TLS;
155 } else if ( conntypeset == 1 ) { 157 } else if ( conntypeset == 1 ) {
156 conntype = CONNECTION_TYPE_STARTTLS; 158 conntype = CONNECTION_TYPE_STARTTLS;
157 } else if ( conntypeset == 0 ) { 159 } else if ( conntypeset == 0 ) {
158 conntype = CONNECTION_TYPE_TRY_STARTTLS; 160 conntype = CONNECTION_TYPE_TRY_STARTTLS;
159 } 161 }
160 162
161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 163 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
162 164
163 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 165 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
164 (char*)user.latin1(),(char*)pass.latin1(),0,0,0); 166 (char*)user.latin1(),(char*)pass.latin1(),0,0,0);
165 167
166 err = mailstorage_connect(m_pop3); 168 err = mailstorage_connect(m_pop3);
167 if (err != MAIL_NO_ERROR) { 169 if (err != MAIL_NO_ERROR) {
168 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 170 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
169 Global::statusMessage(i18n("Error %1 initializing folder").arg( err )); 171 Global::statusMessage(i18n("Error %1 initializing folder").arg( err ));
170 mailstorage_free(m_pop3); 172 mailstorage_free(m_pop3);
171 m_pop3 = 0; 173 m_pop3 = 0;
172 } else { 174 } else {
173 mailsession * session = m_pop3->sto_session; 175 mailsession * session = m_pop3->sto_session;
174 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 176 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
175 if (mail) { 177 if (mail) {
176 mail->pop3_progr_fun = &pop3_progress; 178 mail->pop3_progr_fun = &pop3_progress;
177 } 179 }
178 } 180 }
179} 181}
180 182
181void POP3wrapper::logout() 183void POP3wrapper::logout()
182{ 184{
183 if ( m_pop3 == NULL ) 185 if ( m_pop3 == NULL )
184 return; 186 return;
185 mailstorage_free(m_pop3); 187 mailstorage_free(m_pop3);
186 m_pop3 = 0; 188 m_pop3 = 0;
187} 189}
188 190
189 191
190QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 192Q3ValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
191 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 193 Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<FolderP>();
192 FolderP inb=new Folder("INBOX","/"); 194 FolderP inb=new Folder("INBOX","/");
193 folders->append(inb); 195 folders->append(inb);
194 return folders; 196 return folders;
195} 197}
196 198
197void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) 199void POP3wrapper::deleteMailList(const Q3ValueList<RecMailP>&target)
198{ 200{
199 login(); 201 login();
200 if (!m_pop3) 202 if (!m_pop3)
201 return; 203 return;
202 int iii = 0; 204 int iii = 0;
203 int count = target.count(); 205 int count = target.count();
204 206
205 QProgressBar wid ( count ); 207 Q3ProgressBar wid ( count );
206 wid.setCaption( i18n("Deleting ...")); 208 wid.setCaption( i18n("Deleting ..."));
207 wid.show(); 209 wid.show();
208 while (iii < count ) { 210 while (iii < count ) {
209 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); 211 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
210 wid.setProgress( iii ); 212 wid.setProgress( iii );
211 wid.raise(); 213 wid.raise();
212 qApp->processEvents(); 214 qApp->processEvents();
213 //qDebug("delete "); 215 //qDebug("delete ");
214 RecMailP mail = (*target.at( iii )); 216 RecMailP mail = (*target.at( iii ));
215 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 217 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
216 if (err != MAIL_NO_ERROR) { 218 if (err != MAIL_NO_ERROR) {
217 Global::statusMessage(i18n("Error deleting mail")); 219 Global::statusMessage(i18n("Error deleting mail"));
218 } 220 }
219 ++iii; 221 ++iii;
220 } 222 }
221} 223}
222void POP3wrapper::deleteMail(const RecMailP&mail) { 224void POP3wrapper::deleteMail(const RecMailP&mail) {
223 login(); 225 login();
224 if (!m_pop3) 226 if (!m_pop3)
225 return; 227 return;
226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 228 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
227 if (err != MAIL_NO_ERROR) { 229 if (err != MAIL_NO_ERROR) {
228 Global::statusMessage(i18n("error deleting mail")); 230 Global::statusMessage(i18n("error deleting mail"));
229 } 231 }
230} 232}
231 233
232void POP3wrapper::answeredMail(const RecMailP&) {} 234void POP3wrapper::answeredMail(const RecMailP&) {}
233 235
234int POP3wrapper::deleteAllMail(const FolderP&) { 236int POP3wrapper::deleteAllMail(const FolderP&) {
235 login(); 237 login();
236 if (!m_pop3) 238 if (!m_pop3)
237 return 0; 239 return 0;
238 int res = 1; 240 int res = 1;
239 241
240 uint32_t result = 0; 242 uint32_t result = 0;
241 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 243 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
242 if (err != MAIL_NO_ERROR) { 244 if (err != MAIL_NO_ERROR) {
243 Global::statusMessage(i18n("Error getting folder info")); 245 Global::statusMessage(i18n("Error getting folder info"));
244 return 0; 246 return 0;
245 } 247 }
246 248
247 249
248 250
249 QProgressBar wid ( result ); 251 Q3ProgressBar wid ( result );
250 wid.setCaption( i18n("Deleting ...")); 252 wid.setCaption( i18n("Deleting ..."));
251 wid.show(); 253 wid.show();
252 for (unsigned int i = 0; i < result; ++i) { 254 for (unsigned int i = 0; i < result; ++i) {
253 Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result)); 255 Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result));
254 wid.setProgress( i ); 256 wid.setProgress( i );
255 wid.raise(); 257 wid.raise();
256 qApp->processEvents(); 258 qApp->processEvents();
257 259
258 err = mailsession_remove_message(m_pop3->sto_session,i+1); 260 err = mailsession_remove_message(m_pop3->sto_session,i+1);
259 if (err != MAIL_NO_ERROR) { 261 if (err != MAIL_NO_ERROR) {
260 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); 262 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
261 res=0; 263 res=0;
262 } 264 }
263 break; 265 break;
264 } 266 }
265 return res; 267 return res;
266} 268}
267 269
268void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 270void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
269 login(); 271 login();
270 target_stat.message_count = 0; 272 target_stat.message_count = 0;
271 target_stat.message_unseen = 0; 273 target_stat.message_unseen = 0;
272 target_stat.message_recent = 0; 274 target_stat.message_recent = 0;
273 if (!m_pop3) 275 if (!m_pop3)
274 return; 276 return;
275 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 277 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
276 &target_stat.message_recent,&target_stat.message_unseen); 278 &target_stat.message_recent,&target_stat.message_unseen);
277 if (r != MAIL_NO_ERROR) { 279 if (r != MAIL_NO_ERROR) {
278 ; // odebug << "error getting folter status." << oendl; 280 ; // odebug << "error getting folter status." << oendl;
279 } 281 }
280} 282}
281 283
282encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 284encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
283 char*target=0; 285 char*target=0;
284 size_t length=0; 286 size_t length=0;
285 encodedString*res = 0; 287 encodedString*res = 0;
286 mailmessage * mailmsg = 0; 288 mailmessage * mailmsg = 0;
287 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 289 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
288 err = mailmessage_fetch(mailmsg,&target,&length); 290 err = mailmessage_fetch(mailmsg,&target,&length);
289 if (mailmsg) 291 if (mailmsg)
290 mailmessage_free(mailmsg); 292 mailmessage_free(mailmsg);
291 if (target) { 293 if (target) {
292 res = new encodedString(target,length); 294 res = new encodedString(target,length);
293 } 295 }
294 return res; 296 return res;
295} 297}
296 298
297MAILLIB::ATYPE POP3wrapper::getType()const { 299MAILLIB::ATYPE POP3wrapper::getType()const {
298 return account->getType(); 300 return account->getType();
299} 301}
300 302
301const QString&POP3wrapper::getName()const{ 303const QString&POP3wrapper::getName()const{
302 return account->getAccountName(); 304 return account->getAccountName();
303} 305}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index ebc2fc7..a077877 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,44 +1,46 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
3#define __POP3WRAPPER 3#define __POP3WRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8//Added by qt3to4:
9#include <Q3ValueList>
8 10
9class encodedString; 11class encodedString;
10struct mailstorage; 12struct mailstorage;
11struct mailfolder; 13struct mailfolder;
12 14
13class POP3wrapper : public Genericwrapper 15class POP3wrapper : public Genericwrapper
14{ 16{
15 Q_OBJECT 17 Q_OBJECT
16 18
17public: 19public:
18 POP3wrapper( POP3account *a ); 20 POP3wrapper( POP3account *a );
19 virtual ~POP3wrapper(); 21 virtual ~POP3wrapper();
20 /* mailbox will be ignored */ 22 /* mailbox will be ignored */
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 23 virtual void listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 24 virtual Q3ValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 /* mailbox will be ignored */ 25 /* mailbox will be ignored */
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 26 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 27
26 virtual void deleteMail(const RecMailP&mail); 28 virtual void deleteMail(const RecMailP&mail);
27 virtual void deleteMailList(const QValueList<RecMailP>&target); 29 virtual void deleteMailList(const Q3ValueList<RecMailP>&target);
28 virtual void answeredMail(const RecMailP&mail); 30 virtual void answeredMail(const RecMailP&mail);
29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 31 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
30 32
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 33 virtual RecBodyP fetchBody( const RecMailP &mail );
32 virtual encodedString* fetchRawBody(const RecMailP&mail); 34 virtual encodedString* fetchRawBody(const RecMailP&mail);
33 virtual void logout(); 35 virtual void logout();
34 virtual MAILLIB::ATYPE getType()const; 36 virtual MAILLIB::ATYPE getType()const;
35 virtual const QString&getName()const; 37 virtual const QString&getName()const;
36 static void pop3_progress( size_t current, size_t maximum ); 38 static void pop3_progress( size_t current, size_t maximum );
37 virtual Account* getAccount() { return account; }; 39 virtual Account* getAccount() { return account; };
38protected: 40protected:
39 void login(); 41 void login();
40 POP3account *account; 42 POP3account *account;
41 mailstorage*m_pop3; 43 mailstorage*m_pop3;
42}; 44};
43 45
44#endif 46#endif
diff --git a/kmicromail/libmailwrapper/sendmailprogress.cpp b/kmicromail/libmailwrapper/sendmailprogress.cpp
index 20dfe9b..6cd6409 100644
--- a/kmicromail/libmailwrapper/sendmailprogress.cpp
+++ b/kmicromail/libmailwrapper/sendmailprogress.cpp
@@ -1,48 +1,48 @@
1#include "sendmailprogress.h" 1#include "sendmailprogress.h"
2#include <qprogressbar.h> 2#include <q3progressbar.h>
3#include <qlabel.h> 3#include <qlabel.h>
4#include <klocale.h> 4#include <klocale.h>
5 5
6progressMailSend::progressMailSend(QWidget*parent, const char * name) 6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) 7 :progressMailSendUI(parent,name,true),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{ 8{
9} 9}
10 10
11progressMailSend::~progressMailSend() 11progressMailSend::~progressMailSend()
12{ 12{
13} 13}
14 14
15void progressMailSend::setMaxMails(unsigned int aMaxMails) 15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{ 16{
17 m_max_mail = aMaxMails; 17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails); 18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails(); 19 setMails();
20} 20}
21 21
22void progressMailSend::setCurrentMails(unsigned int aCurrent) 22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{ 23{
24 m_current_mail = aCurrent; 24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent); 25 allMailProgressBar->setProgress(aCurrent);
26 setMails(); 26 setMails();
27} 27}
28 28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) 29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{ 30{
31 m_current_single = aCurrent; 31 m_current_single = aCurrent;
32 m_max_single = aMax; 32 m_max_single = aMax;
33 setSingle(); 33 setSingle();
34} 34}
35 35
36void progressMailSend::setSingle() 36void progressMailSend::setSingle()
37{ 37{
38 QString text = QString(i18n("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); 38 QString text = QString(i18n("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text); 39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single); 40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single); 41 singleMailProgressBar->setProgress(m_current_single);
42} 42}
43 43
44void progressMailSend::setMails() 44void progressMailSend::setMails()
45{ 45{
46 QString text = QString(i18n("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail); 46 QString text = QString(i18n("Sending mail %1 of %2")).arg(m_current_mail+1).arg(m_max_mail);
47 allMailLabel->setText(text); 47 allMailLabel->setText(text);
48} 48}
diff --git a/kmicromail/libmailwrapper/settings.cpp b/kmicromail/libmailwrapper/settings.cpp
index 9436d43..fc01528 100644
--- a/kmicromail/libmailwrapper/settings.cpp
+++ b/kmicromail/libmailwrapper/settings.cpp
@@ -1,544 +1,544 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <qdir.h> 2#include <qdir.h>
3 3
4#include <qtextcodec.h> 4#include <qtextcodec.h>
5#include <qtextstream.h> 5#include <q3textstream.h>
6#include <qfile.h> 6#include <qfile.h>
7 7
8//#include <opie2/odebug.h> 8//#include <opie2/odebug.h>
9#include <kconfig.h> 9#include <kconfig.h>
10 10
11#include <kstandarddirs.h> 11#include <kstandarddirs.h>
12#include "settings.h" 12#include "settings.h"
13//#include "defines.h" 13//#include "defines.h"
14 14
15#define IMAP_PORT "143" 15#define IMAP_PORT "143"
16#define IMAP_SSL_PORT "993" 16#define IMAP_SSL_PORT "993"
17#define SMTP_PORT "25" 17#define SMTP_PORT "25"
18#define SMTP_SSL_PORT "465" 18#define SMTP_SSL_PORT "465"
19#define POP3_PORT "110" 19#define POP3_PORT "110"
20#define POP3_SSL_PORT "995" 20#define POP3_SSL_PORT "995"
21#define NNTP_PORT "119" 21#define NNTP_PORT "119"
22#define NNTP_SSL_PORT "563" 22#define NNTP_SSL_PORT "563"
23 23
24 24
25Settings::Settings() 25Settings::Settings()
26 : QObject() 26 : QObject()
27{ 27{
28 accounts.setAutoDelete( true ); ; 28 accounts.setAutoDelete( true ); ;
29 updateAccounts(); 29 updateAccounts();
30 //qDebug("++++++++++++++++++new settings "); 30 //qDebug("++++++++++++++++++new settings ");
31} 31}
32 32
33void Settings::checkDirectory() 33void Settings::checkDirectory()
34{ 34{
35 return; 35 return;
36 locateLocal("data", "kopiemail" ); 36 locateLocal("data", "kopiemail" );
37 /* 37 /*
38 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) { 38 if ( !QDir( (QString) getenv( "HOME" ) + "/Applications/opiemail/" ).exists() ) {
39 system( "mkdir -p $HOME/Applications/opiemail" ); 39 system( "mkdir -p $HOME/Applications/opiemail" );
40 qDebug("$HOME/Applications/opiemail created "); 40 qDebug("$HOME/Applications/opiemail created ");
41 } 41 }
42 */ 42 */
43} 43}
44 44
45QList<Account> Settings::getAccounts() 45QList<Account> Settings::getAccounts()
46{ 46{
47 return accounts; 47 return accounts;
48} 48}
49 49
50void Settings::addAccount( Account *account ) 50void Settings::addAccount( Account *account )
51{ 51{
52 accounts.append( account ); 52 accounts.append( account );
53} 53}
54 54
55void Settings::delAccount( Account *account ) 55void Settings::delAccount( Account *account )
56{ 56{
57 account->remove(); 57 account->remove();
58 accounts.remove( account ); 58 accounts.remove( account );
59} 59}
60 60
61void Settings::updateAccounts() 61void Settings::updateAccounts()
62{ 62{
63 accounts.clear(); 63 accounts.clear();
64 QDir dir( locateLocal("data", "kopiemail" ) ); 64 QDir dir( locateLocal("data", "kopiemail" ) );
65 QStringList::Iterator it; 65 QStringList::Iterator it;
66 66
67 QStringList imap = dir.entryList( "imap-*" ); 67 QStringList imap = dir.entryList( "imap-*" );
68 for ( it = imap.begin(); it != imap.end(); it++ ) { 68 for ( it = imap.begin(); it != imap.end(); it++ ) {
69 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") ); 69 IMAPaccount *account = new IMAPaccount( (*it).replace(0, 5, "") );
70 accounts.append( account ); 70 accounts.append( account );
71 } 71 }
72 72
73 QStringList pop3 = dir.entryList( "pop3-*" ); 73 QStringList pop3 = dir.entryList( "pop3-*" );
74 for ( it = pop3.begin(); it != pop3.end(); it++ ) { 74 for ( it = pop3.begin(); it != pop3.end(); it++ ) {
75 POP3account *account = new POP3account( (*it).replace(0, 5, "") ); 75 POP3account *account = new POP3account( (*it).replace(0, 5, "") );
76 accounts.append( account ); 76 accounts.append( account );
77 } 77 }
78 78
79 QStringList smtp = dir.entryList( "smtp-*" ); 79 QStringList smtp = dir.entryList( "smtp-*" );
80 for ( it = smtp.begin(); it != smtp.end(); it++ ) { 80 for ( it = smtp.begin(); it != smtp.end(); it++ ) {
81 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") ); 81 SMTPaccount *account = new SMTPaccount( (*it).replace(0, 5, "") );
82 accounts.append( account ); 82 accounts.append( account );
83 } 83 }
84 84
85 QStringList nntp = dir.entryList( "nntp-*" ); 85 QStringList nntp = dir.entryList( "nntp-*" );
86 for ( it = nntp.begin(); it != nntp.end(); it++ ) { 86 for ( it = nntp.begin(); it != nntp.end(); it++ ) {
87 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") ); 87 NNTPaccount *account = new NNTPaccount( (*it).replace(0, 5, "") );
88 accounts.append( account ); 88 accounts.append( account );
89 } 89 }
90 90
91 readAccounts(); 91 readAccounts();
92} 92}
93 93
94void Settings::saveAccounts() 94void Settings::saveAccounts()
95{ 95{
96 checkDirectory(); 96 checkDirectory();
97 Account *it; 97 Account *it;
98 98
99 for ( it = accounts.first(); it; it = accounts.next() ) { 99 for ( it = accounts.first(); it; it = accounts.next() ) {
100 it->save(); 100 it->save();
101 } 101 }
102} 102}
103 103
104void Settings::readAccounts() 104void Settings::readAccounts()
105{ 105{
106 checkDirectory(); 106 checkDirectory();
107 Account *it; 107 Account *it;
108 108
109 for ( it = accounts.first(); it; it = accounts.next() ) { 109 for ( it = accounts.first(); it; it = accounts.next() ) {
110 it->read(); 110 it->read();
111 } 111 }
112} 112}
113 113
114Account::Account() 114Account::Account()
115{ 115{
116 accountName = "changeMe"; 116 accountName = "changeMe";
117 type = MAILLIB::A_UNDEFINED; 117 type = MAILLIB::A_UNDEFINED;
118 ssl = false; 118 ssl = false;
119 connectionType = 1; 119 connectionType = 1;
120 offline = false; 120 offline = false;
121 maxMailSize = 0; 121 maxMailSize = 0;
122 leaveOnServer = false; 122 leaveOnServer = false;
123} 123}
124 124
125void Account::remove() 125void Account::remove()
126{ 126{
127 QFile file( getFileName() ); 127 QFile file( getFileName() );
128 file.remove(); 128 file.remove();
129} 129}
130 130
131void Account::setPasswordList(const QStringList &str) 131void Account::setPasswordList(const QStringList &str)
132{ 132{
133 password = ""; 133 password = "";
134 int i; 134 int i;
135 for ( i = 0; i < str.count() ; ++i ) { 135 for ( i = 0; i < str.count() ; ++i ) {
136 QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3))); 136 QChar c ( (str[i].toUInt()-131)/(str.count()- (i%3)));
137 password.append( c ); 137 password.append( c );
138 } 138 }
139 //qDebug("password %s ", password.latin1()); 139 //qDebug("password %s ", password.latin1());
140} 140}
141QStringList Account::getPasswordList() 141QStringList Account::getPasswordList()
142{ 142{
143 int i; 143 int i;
144 int len = password.length(); 144 int len = password.length();
145 QStringList str; 145 QStringList str;
146 146
147 for ( i = 0; i < len ; ++i ) { 147 for ( i = 0; i < len ; ++i ) {
148 int val = password.at(i).unicode()*(len-(i%3))+131; 148 int val = password.at(i).unicode()*(len-(i%3))+131;
149 str.append( QString::number( val ) ); 149 str.append( QString::number( val ) );
150 // qDebug("append %s ", str[i].latin1()); 150 // qDebug("append %s ", str[i].latin1());
151 } 151 }
152 return str; 152 return str;
153} 153}
154 154
155IMAPaccount::IMAPaccount() 155IMAPaccount::IMAPaccount()
156 : Account() 156 : Account()
157{ 157{
158 file = IMAPaccount::getUniqueFileName(); 158 file = IMAPaccount::getUniqueFileName();
159 accountName = "New IMAP Account"; 159 accountName = "New IMAP Account";
160 ssl = false; 160 ssl = false;
161 connectionType = 1; 161 connectionType = 1;
162 type = MAILLIB::A_IMAP; 162 type = MAILLIB::A_IMAP;
163 port = IMAP_PORT; 163 port = IMAP_PORT;
164} 164}
165 165
166IMAPaccount::IMAPaccount( QString filename ) 166IMAPaccount::IMAPaccount( QString filename )
167 : Account() 167 : Account()
168{ 168{
169 file = filename; 169 file = filename;
170 accountName = "New IMAP Account"; 170 accountName = "New IMAP Account";
171 ssl = false; 171 ssl = false;
172 connectionType = 1; 172 connectionType = 1;
173 type = MAILLIB::A_IMAP; 173 type = MAILLIB::A_IMAP;
174 port = IMAP_PORT; 174 port = IMAP_PORT;
175} 175}
176 176
177QString IMAPaccount::getUniqueFileName() 177QString IMAPaccount::getUniqueFileName()
178{ 178{
179 int num = 0; 179 int num = 0;
180 QString unique; 180 QString unique;
181 181
182 QDir dir( locateLocal("data", "kopiemail" ) ); 182 QDir dir( locateLocal("data", "kopiemail" ) );
183 183
184 QStringList imap = dir.entryList( "imap-*" ); 184 QStringList imap = dir.entryList( "imap-*" );
185 do { 185 do {
186 unique.setNum( num++ ); 186 unique.setNum( num++ );
187 } while ( imap.contains( "imap-" + unique ) > 0 ); 187 } while ( imap.contains( "imap-" + unique ) > 0 );
188 188
189 return unique; 189 return unique;
190} 190}
191 191
192void IMAPaccount::read() 192void IMAPaccount::read()
193{ 193{
194 KConfig *conf = new KConfig( getFileName() ); 194 KConfig *conf = new KConfig( getFileName() );
195 conf->setGroup( "IMAP Account" ); 195 conf->setGroup( "IMAP Account" );
196 accountName = conf->readEntry( "Account","" ); 196 accountName = conf->readEntry( "Account","" );
197 if (accountName.isNull()) accountName = ""; 197 if (accountName.isNull()) accountName = "";
198 server = conf->readEntry( "Server","" ); 198 server = conf->readEntry( "Server","" );
199 if (server.isNull()) server=""; 199 if (server.isNull()) server="";
200 port = conf->readEntry( "Port","" ); 200 port = conf->readEntry( "Port","" );
201 if (port.isNull()) port="143"; 201 if (port.isNull()) port="143";
202 connectionType = conf->readNumEntry( "ConnectionType" ); 202 connectionType = conf->readNumEntry( "ConnectionType" );
203 ssl = conf->readBoolEntry( "SSL",false ); 203 ssl = conf->readBoolEntry( "SSL",false );
204 user = conf->readEntry( "User","" ); 204 user = conf->readEntry( "User","" );
205 if (user.isNull()) user = ""; 205 if (user.isNull()) user = "";
206 //password = conf->readEntryCrypt( "Password","" ); 206 //password = conf->readEntryCrypt( "Password","" );
207 setPasswordList( conf->readListEntry( "FolderHistory")); 207 setPasswordList( conf->readListEntry( "FolderHistory"));
208 if (password.isNull()) password = ""; 208 if (password.isNull()) password = "";
209 prefix = conf->readEntry("MailPrefix",""); 209 prefix = conf->readEntry("MailPrefix","");
210 if (prefix.isNull()) prefix = ""; 210 if (prefix.isNull()) prefix = "";
211 offline = conf->readBoolEntry("Offline",false); 211 offline = conf->readBoolEntry("Offline",false);
212 localFolder = conf->readEntry( "LocalFolder" ); 212 localFolder = conf->readEntry( "LocalFolder" );
213 maxMailSize = conf->readNumEntry( "MaxSize",0 ); 213 maxMailSize = conf->readNumEntry( "MaxSize",0 );
214 int lf = conf->readNumEntry( "LastFetch",0 ); 214 int lf = conf->readNumEntry( "LastFetch",0 );
215 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 215 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
216 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); 216 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false);
217 if ( lf < 0 ) lf = 0; 217 if ( lf < 0 ) lf = 0;
218 lastFetch = dt.addSecs( lf ); 218 lastFetch = dt.addSecs( lf );
219 delete conf; 219 delete conf;
220} 220}
221 221
222void IMAPaccount::save() 222void IMAPaccount::save()
223{ 223{
224 224
225 Settings::checkDirectory(); 225 Settings::checkDirectory();
226 226
227 KConfig *conf = new KConfig( getFileName() ); 227 KConfig *conf = new KConfig( getFileName() );
228 conf->setGroup( "IMAP Account" ); 228 conf->setGroup( "IMAP Account" );
229 conf->writeEntry( "Account", accountName ); 229 conf->writeEntry( "Account", accountName );
230 conf->writeEntry( "Server", server ); 230 conf->writeEntry( "Server", server );
231 conf->writeEntry( "Port", port ); 231 conf->writeEntry( "Port", port );
232 conf->writeEntry( "SSL", ssl ); 232 conf->writeEntry( "SSL", ssl );
233 conf->writeEntry( "ConnectionType", connectionType ); 233 conf->writeEntry( "ConnectionType", connectionType );
234 conf->writeEntry( "User", user ); 234 conf->writeEntry( "User", user );
235 //conf->writeEntryCrypt( "Password", password ); 235 //conf->writeEntryCrypt( "Password", password );
236 conf->writeEntry( "FolderHistory",getPasswordList() ); 236 conf->writeEntry( "FolderHistory",getPasswordList() );
237 conf->writeEntry( "MailPrefix",prefix); 237 conf->writeEntry( "MailPrefix",prefix);
238 conf->writeEntry( "Offline",offline); 238 conf->writeEntry( "Offline",offline);
239 conf->writeEntry( "LocalFolder", localFolder ); 239 conf->writeEntry( "LocalFolder", localFolder );
240 conf->writeEntry( "MaxSize", maxMailSize ); 240 conf->writeEntry( "MaxSize", maxMailSize );
241 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 241 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
242 int lf = dt.secsTo ( lastFetch ); 242 int lf = dt.secsTo ( lastFetch );
243 conf->writeEntry( "LastFetch", lf ); 243 conf->writeEntry( "LastFetch", lf );
244 conf->writeEntry( "LeaveOnServer", leaveOnServer); 244 conf->writeEntry( "LeaveOnServer", leaveOnServer);
245 conf->sync(); 245 conf->sync();
246 delete conf; 246 delete conf;
247} 247}
248 248
249 249
250QString IMAPaccount::getFileName() 250QString IMAPaccount::getFileName()
251{ 251{
252 return locateLocal("data", "kopiemail" ) +"/imap-" + file; 252 return locateLocal("data", "kopiemail" ) +"/imap-" + file;
253} 253}
254 254
255POP3account::POP3account() 255POP3account::POP3account()
256 : Account() 256 : Account()
257{ 257{
258 file = POP3account::getUniqueFileName(); 258 file = POP3account::getUniqueFileName();
259 accountName = "New POP3 Account"; 259 accountName = "New POP3 Account";
260 ssl = false; 260 ssl = false;
261 connectionType = 1; 261 connectionType = 1;
262 type = MAILLIB::A_POP3; 262 type = MAILLIB::A_POP3;
263 port = POP3_PORT; 263 port = POP3_PORT;
264} 264}
265 265
266POP3account::POP3account( QString filename ) 266POP3account::POP3account( QString filename )
267 : Account() 267 : Account()
268{ 268{
269 file = filename; 269 file = filename;
270 accountName = "New POP3 Account"; 270 accountName = "New POP3 Account";
271 ssl = false; 271 ssl = false;
272 connectionType = 1; 272 connectionType = 1;
273 type = MAILLIB::A_POP3; 273 type = MAILLIB::A_POP3;
274 port = POP3_PORT; 274 port = POP3_PORT;
275} 275}
276 276
277QString POP3account::getUniqueFileName() 277QString POP3account::getUniqueFileName()
278{ 278{
279 int num = 0; 279 int num = 0;
280 QString unique; 280 QString unique;
281 281
282 QDir dir( locateLocal("data", "kopiemail" ) ); 282 QDir dir( locateLocal("data", "kopiemail" ) );
283 283
284 QStringList imap = dir.entryList( "pop3-*" ); 284 QStringList imap = dir.entryList( "pop3-*" );
285 do { 285 do {
286 unique.setNum( num++ ); 286 unique.setNum( num++ );
287 } while ( imap.contains( "pop3-" + unique ) > 0 ); 287 } while ( imap.contains( "pop3-" + unique ) > 0 );
288 288
289 return unique; 289 return unique;
290} 290}
291 291
292void POP3account::read() 292void POP3account::read()
293{ 293{
294 KConfig *conf = new KConfig( getFileName()); 294 KConfig *conf = new KConfig( getFileName());
295 conf->setGroup( "POP3 Account" ); 295 conf->setGroup( "POP3 Account" );
296 accountName = conf->readEntry( "Account" ); 296 accountName = conf->readEntry( "Account" );
297 server = conf->readEntry( "Server" ); 297 server = conf->readEntry( "Server" );
298 port = conf->readEntry( "Port" ); 298 port = conf->readEntry( "Port" );
299 ssl = conf->readBoolEntry( "SSL" ); 299 ssl = conf->readBoolEntry( "SSL" );
300 connectionType = conf->readNumEntry( "ConnectionType" ); 300 connectionType = conf->readNumEntry( "ConnectionType" );
301 user = conf->readEntry( "User" ); 301 user = conf->readEntry( "User" );
302 //password = conf->readEntryCrypt( "Password" ); 302 //password = conf->readEntryCrypt( "Password" );
303 setPasswordList( conf->readListEntry( "FolderHistory")); 303 setPasswordList( conf->readListEntry( "FolderHistory"));
304 offline = conf->readBoolEntry("Offline",false); 304 offline = conf->readBoolEntry("Offline",false);
305 localFolder = conf->readEntry( "LocalFolder" ); 305 localFolder = conf->readEntry( "LocalFolder" );
306 maxMailSize = conf->readNumEntry( "MaxSize",0 ); 306 maxMailSize = conf->readNumEntry( "MaxSize",0 );
307 int lf = conf->readNumEntry( "LastFetch",0 ); 307 int lf = conf->readNumEntry( "LastFetch",0 );
308 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 308 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
309 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false); 309 leaveOnServer = conf->readBoolEntry("LeaveOnServer",false);
310 lastFetch = dt.addSecs( lf ); 310 lastFetch = dt.addSecs( lf );
311 delete conf; 311 delete conf;
312} 312}
313 313
314void POP3account::save() 314void POP3account::save()
315{ 315{
316 Settings::checkDirectory(); 316 Settings::checkDirectory();
317 317
318 KConfig *conf = new KConfig( getFileName() ); 318 KConfig *conf = new KConfig( getFileName() );
319 conf->setGroup( "POP3 Account" ); 319 conf->setGroup( "POP3 Account" );
320 conf->writeEntry( "Account", accountName ); 320 conf->writeEntry( "Account", accountName );
321 conf->writeEntry( "Server", server ); 321 conf->writeEntry( "Server", server );
322 conf->writeEntry( "Port", port ); 322 conf->writeEntry( "Port", port );
323 conf->writeEntry( "SSL", ssl ); 323 conf->writeEntry( "SSL", ssl );
324 conf->writeEntry( "ConnectionType", connectionType ); 324 conf->writeEntry( "ConnectionType", connectionType );
325 conf->writeEntry( "User", user ); 325 conf->writeEntry( "User", user );
326 //conf->writeEntryCrypt( "Password", password ); 326 //conf->writeEntryCrypt( "Password", password );
327 conf->writeEntry( "FolderHistory",getPasswordList() ); 327 conf->writeEntry( "FolderHistory",getPasswordList() );
328 conf->writeEntry( "Offline",offline); 328 conf->writeEntry( "Offline",offline);
329 conf->writeEntry( "LocalFolder", localFolder ); 329 conf->writeEntry( "LocalFolder", localFolder );
330 conf->writeEntry( "MaxSize", maxMailSize ); 330 conf->writeEntry( "MaxSize", maxMailSize );
331 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) ); 331 QDateTime dt ( QDate ( 2004, 1, 1 ), QTime( 0,0,0) );
332 int lf = dt.secsTo ( lastFetch ); 332 int lf = dt.secsTo ( lastFetch );
333 conf->writeEntry( "LastFetch", lf ); 333 conf->writeEntry( "LastFetch", lf );
334 conf->writeEntry( "LeaveOnServer", leaveOnServer); 334 conf->writeEntry( "LeaveOnServer", leaveOnServer);
335 conf->sync(); 335 conf->sync();
336 delete conf; 336 delete conf;
337} 337}
338 338
339 339
340QString POP3account::getFileName() 340QString POP3account::getFileName()
341{ 341{
342 return locateLocal("data", "kopiemail" ) +"/pop3-" + file; 342 return locateLocal("data", "kopiemail" ) +"/pop3-" + file;
343} 343}
344 344
345SMTPaccount::SMTPaccount() 345SMTPaccount::SMTPaccount()
346 : Account() 346 : Account()
347{ 347{
348 file = SMTPaccount::getUniqueFileName(); 348 file = SMTPaccount::getUniqueFileName();
349 accountName = "New SMTP Account"; 349 accountName = "New SMTP Account";
350 ssl = false; 350 ssl = false;
351 connectionType = 1; 351 connectionType = 1;
352 login = false; 352 login = false;
353 useCC = false; 353 useCC = false;
354 useBCC = false; 354 useBCC = false;
355 useReply = false; 355 useReply = false;
356 type = MAILLIB::A_SMTP; 356 type = MAILLIB::A_SMTP;
357 port = SMTP_PORT; 357 port = SMTP_PORT;
358} 358}
359 359
360SMTPaccount::SMTPaccount( QString filename ) 360SMTPaccount::SMTPaccount( QString filename )
361 : Account() 361 : Account()
362{ 362{
363 file = filename; 363 file = filename;
364 accountName = "New SMTP Account"; 364 accountName = "New SMTP Account";
365 ssl = false; 365 ssl = false;
366 connectionType = 1; 366 connectionType = 1;
367 login = false; 367 login = false;
368 type = MAILLIB::A_SMTP; 368 type = MAILLIB::A_SMTP;
369 port = SMTP_PORT; 369 port = SMTP_PORT;
370} 370}
371 371
372QString SMTPaccount::getSignature() 372QString SMTPaccount::getSignature()
373{ 373{
374 QFileInfo fi ( signature ); 374 QFileInfo fi ( signature );
375 if ( ! fi.exists() ) 375 if ( ! fi.exists() )
376 return QString(); 376 return QString();
377 377
378 QFile file( signature ); 378 QFile file( signature );
379 if (!file.open( IO_ReadOnly ) ) { 379 if (!file.open( QIODevice::ReadOnly ) ) {
380 return QString(); 380 return QString();
381 381
382 } 382 }
383 QTextStream ts( &file ); 383 Q3TextStream ts( &file );
384 ts.setCodec( QTextCodec::codecForName("utf8") ); 384 ts.setCodec( QTextCodec::codecForName("utf8") );
385 QString text = ts.read(); 385 QString text = ts.read();
386 file.close(); 386 file.close();
387 387
388 return text; 388 return text;
389 389
390} 390}
391void SMTPaccount::setSignature( QString b ) 391void SMTPaccount::setSignature( QString b )
392{ 392{
393 393
394 QFileInfo fi ( signature ); 394 QFileInfo fi ( signature );
395 if ( ! fi.exists() ) { 395 if ( ! fi.exists() ) {
396 QString filedir( locateLocal("data", "kopiemail" ) ); 396 QString filedir( locateLocal("data", "kopiemail" ) );
397 signature = filedir+ "/" + getAccountName() +".sig"; 397 signature = filedir+ "/" + getAccountName() +".sig";
398 qDebug("new sig %s ", signature.latin1()); 398 qDebug("new sig %s ", signature.latin1());
399 save(); 399 save();
400 } 400 }
401 QFile fileIn( signature ); 401 QFile fileIn( signature );
402 if (!fileIn.open( IO_WriteOnly ) ) { 402 if (!fileIn.open( QIODevice::WriteOnly ) ) {
403 qDebug("OM: Cannot write signature file %s ", signature.latin1() ); 403 qDebug("OM: Cannot write signature file %s ", signature.latin1() );
404 return ; 404 return ;
405 } 405 }
406 QTextStream tsIn( &fileIn ); 406 Q3TextStream tsIn( &fileIn );
407 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 407 tsIn.setCodec( QTextCodec::codecForName("utf8") );
408 tsIn << b ; 408 tsIn << b ;
409 fileIn.close(); 409 fileIn.close();
410} 410}
411QString SMTPaccount::getUniqueFileName() 411QString SMTPaccount::getUniqueFileName()
412{ 412{
413 int num = 0; 413 int num = 0;
414 QString unique; 414 QString unique;
415 415
416 QDir dir( locateLocal("data", "kopiemail" ) ); 416 QDir dir( locateLocal("data", "kopiemail" ) );
417 417
418 QStringList imap = dir.entryList( "smtp-*" ); 418 QStringList imap = dir.entryList( "smtp-*" );
419 do { 419 do {
420 unique.setNum( num++ ); 420 unique.setNum( num++ );
421 } while ( imap.contains( "smtp-" + unique ) > 0 ); 421 } while ( imap.contains( "smtp-" + unique ) > 0 );
422 422
423 return unique; 423 return unique;
424} 424}
425 425
426void SMTPaccount::read() 426void SMTPaccount::read()
427{ 427{
428 KConfig *conf = new KConfig( getFileName() ); 428 KConfig *conf = new KConfig( getFileName() );
429 conf->setGroup( "SMTP Account" ); 429 conf->setGroup( "SMTP Account" );
430 accountName = conf->readEntry( "Account" ); 430 accountName = conf->readEntry( "Account" );
431 server = conf->readEntry( "Server" ); 431 server = conf->readEntry( "Server" );
432 port = conf->readEntry( "Port" ); 432 port = conf->readEntry( "Port" );
433 ssl = conf->readBoolEntry( "SSL" ); 433 ssl = conf->readBoolEntry( "SSL" );
434 connectionType = conf->readNumEntry( "ConnectionType" ); 434 connectionType = conf->readNumEntry( "ConnectionType" );
435 login = conf->readBoolEntry( "Login" ); 435 login = conf->readBoolEntry( "Login" );
436 user = conf->readEntry( "User" ); 436 user = conf->readEntry( "User" );
437 signature = conf->readEntry( "SigFile" ); 437 signature = conf->readEntry( "SigFile" );
438 setPasswordList( conf->readListEntry( "FolderHistory")); 438 setPasswordList( conf->readListEntry( "FolderHistory"));
439 delete conf; 439 delete conf;
440} 440}
441 441
442void SMTPaccount::save() 442void SMTPaccount::save()
443{ 443{
444 Settings::checkDirectory(); 444 Settings::checkDirectory();
445 445
446 KConfig *conf = new KConfig( getFileName() ); 446 KConfig *conf = new KConfig( getFileName() );
447 conf->setGroup( "SMTP Account" ); 447 conf->setGroup( "SMTP Account" );
448 conf->writeEntry( "Account", accountName ); 448 conf->writeEntry( "Account", accountName );
449 conf->writeEntry( "Server", server ); 449 conf->writeEntry( "Server", server );
450 conf->writeEntry( "Port", port ); 450 conf->writeEntry( "Port", port );
451 conf->writeEntry( "SSL", ssl ); 451 conf->writeEntry( "SSL", ssl );
452 conf->writeEntry( "ConnectionType", connectionType ); 452 conf->writeEntry( "ConnectionType", connectionType );
453 conf->writeEntry( "Login", login ); 453 conf->writeEntry( "Login", login );
454 conf->writeEntry( "User", user ); 454 conf->writeEntry( "User", user );
455 conf->writeEntry( "SigFile", signature ); 455 conf->writeEntry( "SigFile", signature );
456 //conf->writeEntryCrypt( "Password", password ); 456 //conf->writeEntryCrypt( "Password", password );
457 conf->writeEntry( "FolderHistory",getPasswordList() ); 457 conf->writeEntry( "FolderHistory",getPasswordList() );
458 conf->sync(); 458 conf->sync();
459 delete conf; 459 delete conf;
460} 460}
461 461
462 462
463QString SMTPaccount::getFileName() 463QString SMTPaccount::getFileName()
464{ 464{
465 return locateLocal("data", "kopiemail" ) +"/smtp-" + file; 465 return locateLocal("data", "kopiemail" ) +"/smtp-" + file;
466} 466}
467 467
468NNTPaccount::NNTPaccount() 468NNTPaccount::NNTPaccount()
469 : Account() 469 : Account()
470{ 470{
471 file = NNTPaccount::getUniqueFileName(); 471 file = NNTPaccount::getUniqueFileName();
472 accountName = "New NNTP Account"; 472 accountName = "New NNTP Account";
473 ssl = false; 473 ssl = false;
474 login = false; 474 login = false;
475 type = MAILLIB::A_NNTP; 475 type = MAILLIB::A_NNTP;
476 port = NNTP_PORT; 476 port = NNTP_PORT;
477} 477}
478 478
479NNTPaccount::NNTPaccount( QString filename ) 479NNTPaccount::NNTPaccount( QString filename )
480 : Account() 480 : Account()
481{ 481{
482 file = filename; 482 file = filename;
483 accountName = "New NNTP Account"; 483 accountName = "New NNTP Account";
484 ssl = false; 484 ssl = false;
485 login = false; 485 login = false;
486 type = MAILLIB::A_NNTP; 486 type = MAILLIB::A_NNTP;
487 port = NNTP_PORT; 487 port = NNTP_PORT;
488} 488}
489 489
490QString NNTPaccount::getUniqueFileName() 490QString NNTPaccount::getUniqueFileName()
491{ 491{
492 int num = 0; 492 int num = 0;
493 QString unique; 493 QString unique;
494 494
495 QDir dir( locateLocal("data", "kopiemail" ) ); 495 QDir dir( locateLocal("data", "kopiemail" ) );
496 496
497 QStringList imap = dir.entryList( "nntp-*" ); 497 QStringList imap = dir.entryList( "nntp-*" );
498 do { 498 do {
499 unique.setNum( num++ ); 499 unique.setNum( num++ );
500 } while ( imap.contains( "nntp-" + unique ) > 0 ); 500 } while ( imap.contains( "nntp-" + unique ) > 0 );
501 501
502 return unique; 502 return unique;
503} 503}
504 504
505void NNTPaccount::read() 505void NNTPaccount::read()
506{ 506{
507 KConfig *conf = new KConfig( getFileName() ); 507 KConfig *conf = new KConfig( getFileName() );
508 conf->setGroup( "NNTP Account" ); 508 conf->setGroup( "NNTP Account" );
509 accountName = conf->readEntry( "Account" ); 509 accountName = conf->readEntry( "Account" );
510 server = conf->readEntry( "Server" ); 510 server = conf->readEntry( "Server" );
511 port = conf->readEntry( "Port" ); 511 port = conf->readEntry( "Port" );
512 ssl = conf->readBoolEntry( "SSL" ); 512 ssl = conf->readBoolEntry( "SSL" );
513 login = conf->readBoolEntry( "Login" ); 513 login = conf->readBoolEntry( "Login" );
514 user = conf->readEntry( "User" ); 514 user = conf->readEntry( "User" );
515 //password = conf->readEntryCrypt( "Password" ); 515 //password = conf->readEntryCrypt( "Password" );
516 setPasswordList( conf->readListEntry( "FolderHistory")); 516 setPasswordList( conf->readListEntry( "FolderHistory"));
517 subscribedGroups = conf->readListEntry( "Subscribed"); 517 subscribedGroups = conf->readListEntry( "Subscribed");
518 delete conf; 518 delete conf;
519} 519}
520 520
521void NNTPaccount::save() 521void NNTPaccount::save()
522{ 522{
523 Settings::checkDirectory(); 523 Settings::checkDirectory();
524 524
525 KConfig *conf = new KConfig( getFileName() ); 525 KConfig *conf = new KConfig( getFileName() );
526 conf->setGroup( "NNTP Account" ); 526 conf->setGroup( "NNTP Account" );
527 conf->writeEntry( "Account", accountName ); 527 conf->writeEntry( "Account", accountName );
528 conf->writeEntry( "Server", server ); 528 conf->writeEntry( "Server", server );
529 conf->writeEntry( "Port", port ); 529 conf->writeEntry( "Port", port );
530 conf->writeEntry( "SSL", ssl ); 530 conf->writeEntry( "SSL", ssl );
531 conf->writeEntry( "Login", login ); 531 conf->writeEntry( "Login", login );
532 conf->writeEntry( "User", user ); 532 conf->writeEntry( "User", user );
533 //conf->writeEntryCrypt( "Password", password ); 533 //conf->writeEntryCrypt( "Password", password );
534 conf->writeEntry( "FolderHistory",getPasswordList() ); 534 conf->writeEntry( "FolderHistory",getPasswordList() );
535 conf->writeEntry( "Subscribed" , subscribedGroups ); 535 conf->writeEntry( "Subscribed" , subscribedGroups );
536 conf->sync(); 536 conf->sync();
537 delete conf; 537 delete conf;
538} 538}
539 539
540 540
541QString NNTPaccount::getFileName() 541QString NNTPaccount::getFileName()
542{ 542{
543 return locateLocal("data", "kopiemail" ) +"/nntp-" + file; 543 return locateLocal("data", "kopiemail" ) +"/nntp-" + file;
544} 544}
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp
index 7c813cc..2df55ff 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.cpp
+++ b/kmicromail/libmailwrapper/smtpwrapper.cpp
@@ -1,501 +1,503 @@
1#include "smtpwrapper.h" 1#include "smtpwrapper.h"
2#include "mailwrapper.h" 2#include "mailwrapper.h"
3#include "abstractmail.h" 3#include "abstractmail.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include "mailtypes.h" 5#include "mailtypes.h"
6#include "sendmailprogress.h" 6#include "sendmailprogress.h"
7 7
8//#include <opie2/odebug.h> 8//#include <opie2/odebug.h>
9//#include <qt.h> 9//#include <qt.h>
10#include <qapplication.h> 10#include <qapplication.h>
11#include <qmessagebox.h> 11#include <qmessagebox.h>
12//Added by qt3to4:
13#include <Q3ValueList>
12#include <stdlib.h> 14#include <stdlib.h>
13#ifndef DESKTOP_VERSION 15#ifndef DESKTOP_VERSION
14//#include <qpe/config.h> 16//#include <qpe/config.h>
15#include <qpe/qcopenvelope_qws.h> 17#include <qpe/qcopenvelope_qws.h>
16#endif 18#endif
17#include <libetpan/libetpan.h> 19#include <libetpan/libetpan.h>
18#include <klocale.h> 20#include <klocale.h>
19#include <kglobal.h> 21#include <kglobal.h>
20#include <kconfig.h> 22#include <kconfig.h>
21 23
22 24
23using namespace Opie::Core; 25using namespace Opie::Core;
24progressMailSend*SMTPwrapper::sendProgress = 0; 26progressMailSend*SMTPwrapper::sendProgress = 0;
25 27
26SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 28SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp )
27 : Generatemail() 29 : Generatemail()
28{ 30{
29 m_SmtpAccount = aSmtp; 31 m_SmtpAccount = aSmtp;
30 KConfig cfg( locateLocal("config", "kopiemailrc" ) ); 32 KConfig cfg( locateLocal("config", "kopiemailrc" ) );
31 cfg.setGroup( "Status" ); 33 cfg.setGroup( "Status" );
32 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 34 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
33 emit queuedMails( m_queuedMail ); 35 emit queuedMails( m_queuedMail );
34 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); 36 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) );
35 m_smtp = 0; 37 m_smtp = 0;
36} 38}
37 39
38SMTPwrapper::~SMTPwrapper() 40SMTPwrapper::~SMTPwrapper()
39{ 41{
40 disc_server(); 42 disc_server();
41} 43}
42 44
43void SMTPwrapper::emitQCop( int queued ) { 45void SMTPwrapper::emitQCop( int queued ) {
44#ifndef DESKTOP_VERSION 46#ifndef DESKTOP_VERSION
45 // LR : not used in kde-pim 47 // LR : not used in kde-pim
46 //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 48 //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
47 //env << queued; 49 //env << queued;
48#endif 50#endif
49} 51}
50 52
51QString SMTPwrapper::mailsmtpError( int errnum ) { 53QString SMTPwrapper::mailsmtpError( int errnum ) {
52 switch ( errnum ) { 54 switch ( errnum ) {
53 case MAILSMTP_NO_ERROR: 55 case MAILSMTP_NO_ERROR:
54 return i18n( "No error" ); 56 return i18n( "No error" );
55 case MAILSMTP_ERROR_UNEXPECTED_CODE: 57 case MAILSMTP_ERROR_UNEXPECTED_CODE:
56 return i18n( "Unexpected error code" ); 58 return i18n( "Unexpected error code" );
57 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 59 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
58 return i18n( "Service not available" ); 60 return i18n( "Service not available" );
59 case MAILSMTP_ERROR_STREAM: 61 case MAILSMTP_ERROR_STREAM:
60 return i18n( "Stream error" ); 62 return i18n( "Stream error" );
61 case MAILSMTP_ERROR_HOSTNAME: 63 case MAILSMTP_ERROR_HOSTNAME:
62 return i18n( "gethostname() failed" ); 64 return i18n( "gethostname() failed" );
63 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 65 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
64 return i18n( "Not implemented" ); 66 return i18n( "Not implemented" );
65 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 67 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
66 return i18n( "Error, action not taken" ); 68 return i18n( "Error, action not taken" );
67 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 69 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
68 return i18n( "Data exceeds storage allocation" ); 70 return i18n( "Data exceeds storage allocation" );
69 case MAILSMTP_ERROR_IN_PROCESSING: 71 case MAILSMTP_ERROR_IN_PROCESSING:
70 return i18n( "Error in processing" ); 72 return i18n( "Error in processing" );
71 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: 73 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
72 return i18n( "Starttls not supported" ); 74 return i18n( "Starttls not supported" );
73 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 75 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
74 // return i18n( "Insufficient system storage" ); 76 // return i18n( "Insufficient system storage" );
75 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 77 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
76 return i18n( "Mailbox unavailable" ); 78 return i18n( "Mailbox unavailable" );
77 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 79 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
78 return i18n( "Mailbox name not allowed" ); 80 return i18n( "Mailbox name not allowed" );
79 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 81 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
80 return i18n( "Bad command sequence" ); 82 return i18n( "Bad command sequence" );
81 case MAILSMTP_ERROR_USER_NOT_LOCAL: 83 case MAILSMTP_ERROR_USER_NOT_LOCAL:
82 return i18n( "User not local" ); 84 return i18n( "User not local" );
83 case MAILSMTP_ERROR_TRANSACTION_FAILED: 85 case MAILSMTP_ERROR_TRANSACTION_FAILED:
84 return i18n( "Transaction failed" ); 86 return i18n( "Transaction failed" );
85 case MAILSMTP_ERROR_MEMORY: 87 case MAILSMTP_ERROR_MEMORY:
86 return i18n( "Memory error" ); 88 return i18n( "Memory error" );
87 case MAILSMTP_ERROR_CONNECTION_REFUSED: 89 case MAILSMTP_ERROR_CONNECTION_REFUSED:
88 return i18n( "Connection refused" ); 90 return i18n( "Connection refused" );
89 default: 91 default:
90 return i18n( "Unknown error code" ); 92 return i18n( "Unknown error code" );
91 } 93 }
92} 94}
93 95
94 96
95void SMTPwrapper::progress( size_t current, size_t maximum ) { 97void SMTPwrapper::progress( size_t current, size_t maximum ) {
96 if (SMTPwrapper::sendProgress) { 98 if (SMTPwrapper::sendProgress) {
97 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 99 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
98 qApp->processEvents(); 100 qApp->processEvents();
99 } 101 }
100} 102}
101 103
102void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 104void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
103 if (!mail) 105 if (!mail)
104 return; 106 return;
105 QString localfolders = AbstractMail::defaultLocalfolder(); 107 QString localfolders = AbstractMail::defaultLocalfolder();
106 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 108 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
107 wrap->createMbox(box); 109 wrap->createMbox(box);
108 wrap->storeMessage(mail,length,box); 110 wrap->storeMessage(mail,length,box);
109 delete wrap; 111 delete wrap;
110} 112}
111 113
112bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { 114bool SMTPwrapper::smtpSend( mailmime *mail,bool later) {
113 clist *rcpts = 0; 115 clist *rcpts = 0;
114 char *from, *data; 116 char *from, *data;
115 size_t size; 117 size_t size;
116 118
117 from = data = 0; 119 from = data = 0;
118 120
119 mailmessage * msg = 0; 121 mailmessage * msg = 0;
120 msg = mime_message_init(mail); 122 msg = mime_message_init(mail);
121 mime_message_set_tmpdir(msg,getenv( "HOME" )); 123 mime_message_set_tmpdir(msg,getenv( "HOME" ));
122 int r = mailmessage_fetch(msg,&data,&size); 124 int r = mailmessage_fetch(msg,&data,&size);
123 mime_message_detach_mime(msg); 125 mime_message_detach_mime(msg);
124 mailmessage_free(msg); 126 mailmessage_free(msg);
125 if (r != MAIL_NO_ERROR || !data) { 127 if (r != MAIL_NO_ERROR || !data) {
126 if (data) 128 if (data)
127 free(data); 129 free(data);
128 qDebug("Error fetching mime... "); 130 qDebug("Error fetching mime... ");
129 return false; 131 return false;
130 } 132 }
131 msg = 0; 133 msg = 0;
132 if (later) { 134 if (later) {
133 storeMail(data,size,"Outgoing"); 135 storeMail(data,size,"Outgoing");
134 if (data) 136 if (data)
135 free( data ); 137 free( data );
136 KConfig cfg( locateLocal("config", "kopiemailrc" ) ); 138 KConfig cfg( locateLocal("config", "kopiemailrc" ) );
137 cfg.setGroup( "Status" ); 139 cfg.setGroup( "Status" );
138 cfg.writeEntry( "outgoing", ++m_queuedMail ); 140 cfg.writeEntry( "outgoing", ++m_queuedMail );
139 emit queuedMails( m_queuedMail ); 141 emit queuedMails( m_queuedMail );
140 return true; 142 return true;
141 } 143 }
142 from = getFrom( mail ); 144 from = getFrom( mail );
143 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 145 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
144 bool result = smtpSend(from,rcpts,data,size); 146 bool result = smtpSend(from,rcpts,data,size);
145 if (data) { 147 if (data) {
146 free(data); 148 free(data);
147 } 149 }
148 if (from) { 150 if (from) {
149 free(from); 151 free(from);
150 } 152 }
151 if (rcpts) 153 if (rcpts)
152 smtp_address_list_free( rcpts ); 154 smtp_address_list_free( rcpts );
153 return result; 155 return result;
154} 156}
155 157
156void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 158void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
157{ 159{
158 if (data) { 160 if (data) {
159 storeMail(data,size,"Sendfailed"); 161 storeMail(data,size,"Sendfailed");
160 } 162 }
161 if (failuremessage) { 163 if (failuremessage) {
162 QMessageBox::critical(0,i18n("Error sending mail"), 164 QMessageBox::critical(0,i18n("Error sending mail"),
163 failuremessage); 165 failuremessage);
164 } 166 }
165} 167}
166 168
167int SMTPwrapper::start_smtp_tls() 169int SMTPwrapper::start_smtp_tls()
168{ 170{
169 if (!m_smtp) { 171 if (!m_smtp) {
170 return MAILSMTP_ERROR_IN_PROCESSING; 172 return MAILSMTP_ERROR_IN_PROCESSING;
171 } 173 }
172 int err = mailesmtp_starttls(m_smtp); 174 int err = mailesmtp_starttls(m_smtp);
173 if (err != MAILSMTP_NO_ERROR) return err; 175 if (err != MAILSMTP_NO_ERROR) return err;
174 mailstream_low * low; 176 mailstream_low * low;
175 mailstream_low * new_low; 177 mailstream_low * new_low;
176 low = mailstream_get_low(m_smtp->stream); 178 low = mailstream_get_low(m_smtp->stream);
177 if (!low) { 179 if (!low) {
178 return MAILSMTP_ERROR_IN_PROCESSING; 180 return MAILSMTP_ERROR_IN_PROCESSING;
179 } 181 }
180 int fd = mailstream_low_get_fd(low); 182 int fd = mailstream_low_get_fd(low);
181 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 183 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
182 mailstream_low_free(low); 184 mailstream_low_free(low);
183 mailstream_set_low(m_smtp->stream, new_low); 185 mailstream_set_low(m_smtp->stream, new_low);
184 } else { 186 } else {
185 return MAILSMTP_ERROR_IN_PROCESSING; 187 return MAILSMTP_ERROR_IN_PROCESSING;
186 } 188 }
187 return err; 189 return err;
188} 190}
189 191
190void SMTPwrapper::connect_server() 192void SMTPwrapper::connect_server()
191{ 193{
192 QString server, user, pass; 194 QString server, user, pass;
193 bool ssl; 195 bool ssl;
194 uint16_t port; 196 uint16_t port;
195 ssl = false; 197 ssl = false;
196 bool try_tls = false; 198 bool try_tls = false;
197 bool force_tls=false; 199 bool force_tls=false;
198 QString failuretext = ""; 200 QString failuretext = "";
199 201
200 if (m_smtp || !m_SmtpAccount) { 202 if (m_smtp || !m_SmtpAccount) {
201 return; 203 return;
202 } 204 }
203 server = m_SmtpAccount->getServer(); 205 server = m_SmtpAccount->getServer();
204 if ( m_SmtpAccount->ConnectionType() == 3 ) { 206 if ( m_SmtpAccount->ConnectionType() == 3 ) {
205 ssl = true; 207 ssl = true;
206 try_tls = false; 208 try_tls = false;
207 } else if (m_SmtpAccount->ConnectionType() == 2) { 209 } else if (m_SmtpAccount->ConnectionType() == 2) {
208 force_tls = true; 210 force_tls = true;
209 try_tls = true; 211 try_tls = true;
210 } else if (m_SmtpAccount->ConnectionType() == 1) { 212 } else if (m_SmtpAccount->ConnectionType() == 1) {
211 try_tls = true; 213 try_tls = true;
212 } 214 }
213 int result = 1; 215 int result = 1;
214 port = m_SmtpAccount->getPort().toUInt(); 216 port = m_SmtpAccount->getPort().toUInt();
215 217
216 m_smtp = mailsmtp_new( 20, &progress ); 218 m_smtp = mailsmtp_new( 20, &progress );
217 if ( m_smtp == NULL ) { 219 if ( m_smtp == NULL ) {
218 /* no failure message cause this happens when problems with memory - than we 220 /* no failure message cause this happens when problems with memory - than we
219 we can not display any messagebox */ 221 we can not display any messagebox */
220 return; 222 return;
221 } 223 }
222 //m_smtp->auth = MAILSMTP_AUTH_LOGIN; 224 //m_smtp->auth = MAILSMTP_AUTH_LOGIN;
223 225
224 int err = MAILSMTP_NO_ERROR; 226 int err = MAILSMTP_NO_ERROR;
225 ; // odebug << "Servername " << server << " at port " << port << "" << oendl; 227 ; // odebug << "Servername " << server << " at port " << port << "" << oendl;
226 if ( ssl ) { 228 if ( ssl ) {
227 qDebug("smtp: ssl_connect "); 229 qDebug("smtp: ssl_connect ");
228 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); 230 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port );
229 } else { 231 } else {
230 ; // odebug << "No SSL session" << oendl; 232 ; // odebug << "No SSL session" << oendl;
231 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); 233 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port );
232 } 234 }
233 if ( err != MAILSMTP_NO_ERROR ) { 235 if ( err != MAILSMTP_NO_ERROR ) {
234 qDebug("Error init SMTP connection" ); 236 qDebug("Error init SMTP connection" );
235 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 237 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
236 result = 0; 238 result = 0;
237 } 239 }
238 240
239 qDebug("SMTP connection inited "); 241 qDebug("SMTP connection inited ");
240 /* switch to tls after init 'cause there it will send the ehlo */ 242 /* switch to tls after init 'cause there it will send the ehlo */
241 if (result) { 243 if (result) {
242 err = mailsmtp_init( m_smtp ); 244 err = mailsmtp_init( m_smtp );
243 if (err != MAILSMTP_NO_ERROR) { 245 if (err != MAILSMTP_NO_ERROR) {
244 result = 0; 246 result = 0;
245 qDebug("Error init SMTP connection "); 247 qDebug("Error init SMTP connection ");
246 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 248 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
247 } 249 }
248 } 250 }
249 if (result && try_tls) { 251 if (result && try_tls) {
250 qDebug("Smpt: Try TLS... "); 252 qDebug("Smpt: Try TLS... ");
251 err = start_smtp_tls(); 253 err = start_smtp_tls();
252 if (err != MAILSMTP_NO_ERROR) { 254 if (err != MAILSMTP_NO_ERROR) {
253 try_tls = false; 255 try_tls = false;
254 qDebug("Smpt: No TLS possible "); 256 qDebug("Smpt: No TLS possible ");
255 } else { 257 } else {
256 qDebug("Smpt: Using TLS "); 258 qDebug("Smpt: Using TLS ");
257 } 259 }
258 } 260 }
259 261
260 //qDebug("mailesmtp_ehlo %d ",err ); 262 //qDebug("mailesmtp_ehlo %d ",err );
261 if (!try_tls && force_tls) { 263 if (!try_tls && force_tls) {
262 result = 0; 264 result = 0;
263 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err)); 265 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err));
264 } 266 }
265 //LR 05-10-22 : qDebug("no elo any more "); 267 //LR 05-10-22 : qDebug("no elo any more ");
266 // if ( false /*mailesmtp_ehlo(m_smtp) != MAILSMTP_NO_ERROR */) { 268 // if ( false /*mailesmtp_ehlo(m_smtp) != MAILSMTP_NO_ERROR */) {
267// qDebug("Smpt: ehlo failed "); 269// qDebug("Smpt: ehlo failed ");
268// result = 0; 270// result = 0;
269// } 271// }
270// else { 272// else {
271 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN); 273 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN);
272 if ( m_smtp->auth & MAILSMTP_AUTH_LOGIN && m_smtp->auth & MAILSMTP_AUTH_PLAIN ) { 274 if ( m_smtp->auth & MAILSMTP_AUTH_LOGIN && m_smtp->auth & MAILSMTP_AUTH_PLAIN ) {
273 qDebug("Smpt: Using MAILSMTP_AUTH_LOGIN "); 275 qDebug("Smpt: Using MAILSMTP_AUTH_LOGIN ");
274 m_smtp->auth -= MAILSMTP_AUTH_PLAIN; 276 m_smtp->auth -= MAILSMTP_AUTH_PLAIN;
275 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN); 277 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN);
276 } 278 }
277 // } 279 // }
278 280
279 if (result==1 && m_SmtpAccount->getLogin() ) { 281 if (result==1 && m_SmtpAccount->getLogin() ) {
280 ; // odebug << "smtp with auth" << oendl; 282 ; // odebug << "smtp with auth" << oendl;
281 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 283 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
282 // get'em 284 // get'em
283 LoginDialog login( m_SmtpAccount->getUser(), 285 LoginDialog login( m_SmtpAccount->getUser(),
284 m_SmtpAccount->getPassword(), NULL, 0, true ); 286 m_SmtpAccount->getPassword(), NULL, 0, true );
285 login.show(); 287 login.show();
286 if ( QDialog::Accepted == login.exec() ) { 288 if ( QDialog::Accepted == login.exec() ) {
287 // ok 289 // ok
288 user = login.getUser(); 290 user = login.getUser();
289 pass = login.getPassword(); 291 pass = login.getPassword();
290 } else { 292 } else {
291 result = 0; 293 result = 0;
292 failuretext=i18n("Login aborted - \nstoring mail to localfolder"); 294 failuretext=i18n("Login aborted - \nstoring mail to localfolder");
293 } 295 }
294 } else { 296 } else {
295 user = m_SmtpAccount->getUser(); 297 user = m_SmtpAccount->getUser();
296 pass = m_SmtpAccount->getPassword(); 298 pass = m_SmtpAccount->getPassword();
297 } 299 }
298 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; 300 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl;
299 if (result) { 301 if (result) {
300 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); 302 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() );
301 if ( err == MAILSMTP_NO_ERROR ) { 303 if ( err == MAILSMTP_NO_ERROR ) {
302 qDebug("Smtp authentification ok "); 304 qDebug("Smtp authentification ok ");
303 } else { 305 } else {
304 failuretext = i18n("Authentification failed"); 306 failuretext = i18n("Authentification failed");
305 result = 0; 307 result = 0;
306 } 308 }
307 } 309 }
308 } 310 }
309 if ( result == 0 ) { 311 if ( result == 0 ) {
310 mailsmtp_free(m_smtp); 312 mailsmtp_free(m_smtp);
311 m_smtp = 0; 313 m_smtp = 0;
312 } 314 }
313} 315}
314 316
315void SMTPwrapper::disc_server() 317void SMTPwrapper::disc_server()
316{ 318{
317 if (m_smtp) { 319 if (m_smtp) {
318 mailsmtp_quit( m_smtp ); 320 mailsmtp_quit( m_smtp );
319 mailsmtp_free( m_smtp ); 321 mailsmtp_free( m_smtp );
320 m_smtp = 0; 322 m_smtp = 0;
321 } 323 }
322} 324}
323 325
324int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 326int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
325{ 327{
326 int err,result; 328 int err,result;
327 QString failuretext = ""; 329 QString failuretext = "";
328 330
329 connect_server(); 331 connect_server();
330 332
331 result = 1; 333 result = 1;
332 if (m_smtp) { 334 if (m_smtp) {
333 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 335 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
334 if ( err != MAILSMTP_NO_ERROR ) { 336 if ( err != MAILSMTP_NO_ERROR ) {
335 qDebug("Error sending mail"); 337 qDebug("Error sending mail");
336 failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err)); 338 failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err));
337 result = 0; 339 result = 0;
338 } 340 }
339 } else { 341 } else {
340 result = 0; 342 result = 0;
341 } 343 }
342 344
343 if (!result) { 345 if (!result) {
344 storeFailedMail(data,size,failuretext); 346 storeFailedMail(data,size,failuretext);
345 } else { 347 } else {
346 ; // odebug << "Mail sent." << oendl; 348 ; // odebug << "Mail sent." << oendl;
347 storeMail(data,size,"Sent"); 349 storeMail(data,size,"Sent");
348 } 350 }
349 return result; 351 return result;
350} 352}
351 353
352bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) 354bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later )
353{ 355{
354 mailmime * mimeMail; 356 mailmime * mimeMail;
355 bool result = true; 357 bool result = true;
356 mimeMail = createMimeMail(mail ); 358 mimeMail = createMimeMail(mail );
357 if ( mimeMail == 0 ) { 359 if ( mimeMail == 0 ) {
358 qDebug("SMTP wrapper:Error creating mail! "); 360 qDebug("SMTP wrapper:Error creating mail! ");
359 return false; 361 return false;
360 } else { 362 } else {
361 sendProgress = new progressMailSend(); 363 sendProgress = new progressMailSend();
362 sendProgress->show(); 364 sendProgress->show();
363 sendProgress->setMaxMails(1); 365 sendProgress->setMaxMails(1);
364 result = smtpSend( mimeMail,later); 366 result = smtpSend( mimeMail,later);
365 ; // odebug << "Clean up done" << oendl; 367 ; // odebug << "Clean up done" << oendl;
366 sendProgress->hide(); 368 sendProgress->hide();
367 delete sendProgress; 369 delete sendProgress;
368 sendProgress = 0; 370 sendProgress = 0;
369 mailmime_free( mimeMail ); 371 mailmime_free( mimeMail );
370 if ( m_smtp ) { 372 if ( m_smtp ) {
371 mailsmtp_free(m_smtp); 373 mailsmtp_free(m_smtp);
372 m_smtp = 0; 374 m_smtp = 0;
373 } 375 }
374 } 376 }
375 return result; 377 return result;
376} 378}
377 379
378int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { 380int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
379 size_t curTok = 0; 381 size_t curTok = 0;
380 mailimf_fields *fields = 0; 382 mailimf_fields *fields = 0;
381 mailimf_field*ffrom = 0; 383 mailimf_field*ffrom = 0;
382 clist *rcpts = 0; 384 clist *rcpts = 0;
383 char*from = 0; 385 char*from = 0;
384 int res = 0; 386 int res = 0;
385 387
386 encodedString * data = wrap->fetchRawBody(which); 388 encodedString * data = wrap->fetchRawBody(which);
387 if (!data) 389 if (!data)
388 return 0; 390 return 0;
389 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 391 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
390 if (err != MAILIMF_NO_ERROR) { 392 if (err != MAILIMF_NO_ERROR) {
391 delete data; 393 delete data;
392 delete wrap; 394 delete wrap;
393 return 0; 395 return 0;
394 } 396 }
395 397
396 rcpts = createRcptList( fields ); 398 rcpts = createRcptList( fields );
397 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 399 ffrom = getField(fields, MAILIMF_FIELD_FROM );
398 from = getFrom(ffrom); 400 from = getFrom(ffrom);
399 401
400 if (rcpts && from) { 402 if (rcpts && from) {
401 res = smtpSend(from,rcpts,data->Content(),data->Length()); 403 res = smtpSend(from,rcpts,data->Content(),data->Length());
402 } 404 }
403 if (fields) { 405 if (fields) {
404 mailimf_fields_free(fields); 406 mailimf_fields_free(fields);
405 fields = 0; 407 fields = 0;
406 } 408 }
407 if (data) { 409 if (data) {
408 delete data; 410 delete data;
409 } 411 }
410 if (from) { 412 if (from) {
411 free(from); 413 free(from);
412 } 414 }
413 if (rcpts) { 415 if (rcpts) {
414 smtp_address_list_free( rcpts ); 416 smtp_address_list_free( rcpts );
415 } 417 }
416 return res; 418 return res;
417} 419}
418 420
419/* this is a special fun */ 421/* this is a special fun */
420bool SMTPwrapper::flushOutbox() { 422bool SMTPwrapper::flushOutbox() {
421 bool returnValue = true; 423 bool returnValue = true;
422 424
423 ; // odebug << "Sending the queue" << oendl; 425 ; // odebug << "Sending the queue" << oendl;
424 if (!m_SmtpAccount) { 426 if (!m_SmtpAccount) {
425 ; // odebug << "No smtp account given" << oendl; 427 ; // odebug << "No smtp account given" << oendl;
426 return false; 428 return false;
427 } 429 }
428 430
429 bool reset_user_value = false; 431 bool reset_user_value = false;
430 QString localfolders = AbstractMail::defaultLocalfolder(); 432 QString localfolders = AbstractMail::defaultLocalfolder();
431 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 433 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
432 if (!wrap) { 434 if (!wrap) {
433 ; // odebug << "memory error" << oendl; 435 ; // odebug << "memory error" << oendl;
434 return false; 436 return false;
435 } 437 }
436 QString oldPw, oldUser; 438 QString oldPw, oldUser;
437 QValueList<RecMailP> mailsToSend; 439 Q3ValueList<RecMailP> mailsToSend;
438 QValueList<RecMailP> mailsToRemove; 440 Q3ValueList<RecMailP> mailsToRemove;
439 QString mbox("Outgoing"); 441 QString mbox("Outgoing");
440 wrap->listMessages(mbox,mailsToSend); 442 wrap->listMessages(mbox,mailsToSend);
441 if (mailsToSend.count()==0) { 443 if (mailsToSend.count()==0) {
442 delete wrap; 444 delete wrap;
443 ; // odebug << "No mails to send" << oendl; 445 ; // odebug << "No mails to send" << oendl;
444 return false; 446 return false;
445 } 447 }
446 448
447 oldPw = m_SmtpAccount->getPassword(); 449 oldPw = m_SmtpAccount->getPassword();
448 oldUser = m_SmtpAccount->getUser(); 450 oldUser = m_SmtpAccount->getUser();
449 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 451 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
450 // get'em 452 // get'em
451 QString user,pass; 453 QString user,pass;
452 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 454 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
453 login.show(); 455 login.show();
454 if ( QDialog::Accepted == login.exec() ) { 456 if ( QDialog::Accepted == login.exec() ) {
455 // ok 457 // ok
456 user = login.getUser().latin1(); 458 user = login.getUser().latin1();
457 pass = login.getPassword().latin1(); 459 pass = login.getPassword().latin1();
458 reset_user_value = true; 460 reset_user_value = true;
459 m_SmtpAccount->setUser(user); 461 m_SmtpAccount->setUser(user);
460 m_SmtpAccount->setPassword(pass); 462 m_SmtpAccount->setPassword(pass);
461 } else { 463 } else {
462 return true; 464 return true;
463 } 465 }
464 } 466 }
465 467
466 468
467 sendProgress = new progressMailSend(); 469 sendProgress = new progressMailSend();
468 sendProgress->show(); 470 sendProgress->show();
469 sendProgress->setMaxMails(mailsToSend.count()); 471 sendProgress->setMaxMails(mailsToSend.count());
470 472
471 while (returnValue && mailsToSend.count()>0) { 473 while (returnValue && mailsToSend.count()>0) {
472 if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { 474 if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) {
473 QMessageBox::critical(0,i18n("Error sending mail"), 475 QMessageBox::critical(0,i18n("Error sending mail"),
474 i18n("Error sending queued mail.\nBreaking.")); 476 i18n("Error sending queued mail.\nBreaking."));
475 returnValue = false; 477 returnValue = false;
476 } 478 }
477 mailsToRemove.append((*mailsToSend.begin())); 479 mailsToRemove.append((*mailsToSend.begin()));
478 mailsToSend.remove(mailsToSend.begin()); 480 mailsToSend.remove(mailsToSend.begin());
479 sendProgress->setCurrentMails(mailsToRemove.count()); 481 sendProgress->setCurrentMails(mailsToRemove.count());
480 } 482 }
481 if (reset_user_value) { 483 if (reset_user_value) {
482 m_SmtpAccount->setUser(oldUser); 484 m_SmtpAccount->setUser(oldUser);
483 m_SmtpAccount->setPassword(oldPw); 485 m_SmtpAccount->setPassword(oldPw);
484 } 486 }
485 487
486 KConfig cfg( locateLocal("config", "kopiemailrc" ) ); 488 KConfig cfg( locateLocal("config", "kopiemailrc" ) );
487 cfg.setGroup( "Status" ); 489 cfg.setGroup( "Status" );
488 m_queuedMail = mailsToSend.count(); 490 m_queuedMail = mailsToSend.count();
489 cfg.writeEntry( "outgoing", m_queuedMail ); 491 cfg.writeEntry( "outgoing", m_queuedMail );
490 emit queuedMails( m_queuedMail ); 492 emit queuedMails( m_queuedMail );
491 sendProgress->hide(); 493 sendProgress->hide();
492 delete sendProgress; 494 delete sendProgress;
493 sendProgress = 0; 495 sendProgress = 0;
494 wrap->deleteMails(mbox,mailsToRemove); 496 wrap->deleteMails(mbox,mailsToRemove);
495 delete wrap; 497 delete wrap;
496 if ( m_smtp ) { 498 if ( m_smtp ) {
497 mailsmtp_free(m_smtp); 499 mailsmtp_free(m_smtp);
498 m_smtp = 0; 500 m_smtp = 0;
499 } 501 }
500 return returnValue; 502 return returnValue;
501} 503}