summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-10-23 19:32:41 (UTC)
committer zautrix <zautrix>2004-10-23 19:32:41 (UTC)
commit94df6192e59b7d4c69e2fb43ef2c39db08bb1c39 (patch) (unidiff)
tree28956adbf73a61010d98deb27d83b324cb285471 /kmicromail/libmailwrapper
parent52b6fc17c0dcd1f13f701f698e0305440f26fc3e (diff)
downloadkdepimpi-94df6192e59b7d4c69e2fb43ef2c39db08bb1c39.zip
kdepimpi-94df6192e59b7d4c69e2fb43ef2c39db08bb1c39.tar.gz
kdepimpi-94df6192e59b7d4c69e2fb43ef2c39db08bb1c39.tar.bz2
compile fixes
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp22
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp58
-rw-r--r--kmicromail/libmailwrapper/mboxwrapper.cpp29
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp21
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp59
5 files changed, 96 insertions, 93 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 2d7533c..8ee112c 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,278 +1,278 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "abstractmail.h" 2#include "abstractmail.h"
3#include "imapwrapper.h" 3#include "imapwrapper.h"
4#include "pop3wrapper.h" 4#include "pop3wrapper.h"
5#include "nntpwrapper.h" 5#include "nntpwrapper.h"
6#include "mhwrapper.h" 6#include "mhwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include <qpe/global.h> 8#include <qpe/global.h>
9 9
10 10
11#include <qprogressbar.h> 11#include <qprogressbar.h>
12#include <qapplication.h> 12#include <qapplication.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14 14#include <klocale.h>
15#include <kdecore/kstandarddirs.h> 15#include <kdecore/kstandarddirs.h>
16#include <qfile.h> 16#include <qfile.h>
17#include <qtextstream.h> 17#include <qtextstream.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <libetpan/mailmime_content.h> 19#include <libetpan/mailmime_content.h>
20#include <libetpan/mailmime.h> 20#include <libetpan/mailmime.h>
21 21
22using namespace Opie::Core; 22using namespace Opie::Core;
23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 23AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
24{ 24{
25 return new IMAPwrapper(a); 25 return new IMAPwrapper(a);
26} 26}
27 27
28AbstractMail* AbstractMail::getWrapper(POP3account *a) 28AbstractMail* AbstractMail::getWrapper(POP3account *a)
29{ 29{
30 return new POP3wrapper(a); 30 return new POP3wrapper(a);
31} 31}
32 32
33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 33AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
34{ 34{
35 return new NNTPwrapper(a); 35 return new NNTPwrapper(a);
36} 36}
37 37
38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 38AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
39{ 39{
40 return new MHwrapper(a,name); 40 return new MHwrapper(a,name);
41} 41}
42 42
43AbstractMail* AbstractMail::getWrapper(Account*a) 43AbstractMail* AbstractMail::getWrapper(Account*a)
44{ 44{
45 if (!a) return 0; 45 if (!a) return 0;
46 switch (a->getType()) { 46 switch (a->getType()) {
47 case MAILLIB::A_IMAP: 47 case MAILLIB::A_IMAP:
48 return new IMAPwrapper((IMAPaccount*)a); 48 return new IMAPwrapper((IMAPaccount*)a);
49 break; 49 break;
50 case MAILLIB::A_POP3: 50 case MAILLIB::A_POP3:
51 return new POP3wrapper((POP3account*)a); 51 return new POP3wrapper((POP3account*)a);
52 break; 52 break;
53 case MAILLIB::A_NNTP: 53 case MAILLIB::A_NNTP:
54 return new NNTPwrapper((NNTPaccount*)a); 54 return new NNTPwrapper((NNTPaccount*)a);
55 break; 55 break;
56 default: 56 default:
57 return 0; 57 return 0;
58 } 58 }
59} 59}
60 60
61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 61encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
62{ 62{
63 // odebug << "Decode string start" << oendl; 63 // odebug << "Decode string start" << oendl;
64 char*result_text; 64 char*result_text;
65 size_t index = 0; 65 size_t index = 0;
66 /* reset for recursive use! */ 66 /* reset for recursive use! */
67 size_t target_length = 0; 67 size_t target_length = 0;
68 result_text = 0; 68 result_text = 0;
69 int mimetype = MAILMIME_MECHANISM_7BIT; 69 int mimetype = MAILMIME_MECHANISM_7BIT;
70 if (enc.lower()=="quoted-printable") { 70 if (enc.lower()=="quoted-printable") {
71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 71 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
72 } else if (enc.lower()=="base64") { 72 } else if (enc.lower()=="base64") {
73 mimetype = MAILMIME_MECHANISM_BASE64; 73 mimetype = MAILMIME_MECHANISM_BASE64;
74 } else if (enc.lower()=="8bit") { 74 } else if (enc.lower()=="8bit") {
75 mimetype = MAILMIME_MECHANISM_8BIT; 75 mimetype = MAILMIME_MECHANISM_8BIT;
76 } else if (enc.lower()=="binary") { 76 } else if (enc.lower()=="binary") {
77 mimetype = MAILMIME_MECHANISM_BINARY; 77 mimetype = MAILMIME_MECHANISM_BINARY;
78 } 78 }
79 79
80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 80 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
81 &result_text,&target_length); 81 &result_text,&target_length);
82 82
83 encodedString* result = new encodedString(); 83 encodedString* result = new encodedString();
84 if (err == MAILIMF_NO_ERROR) { 84 if (err == MAILIMF_NO_ERROR) {
85 result->setContent(result_text,target_length); 85 result->setContent(result_text,target_length);
86 } 86 }
87 //odebug << "Decode string finished" << oendl; 87 //odebug << "Decode string finished" << oendl;
88 return result; 88 return result;
89} 89}
90 90
91QString AbstractMail::convert_String(const char*text) 91QString AbstractMail::convert_String(const char*text)
92{ 92{
93 size_t index = 0; 93 size_t index = 0;
94 char*res = 0; 94 char*res = 0;
95 int err = MAILIMF_NO_ERROR; 95 int err = MAILIMF_NO_ERROR;
96 96
97 QString result(text); 97 QString result(text);
98 98
99 err = mailmime_encoded_phrase_parse("iso-8859-1", 99 err = mailmime_encoded_phrase_parse("iso-8859-1",
100 text, strlen(text),&index, "iso-8859-1",&res); 100 text, strlen(text),&index, "iso-8859-1",&res);
101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
102 result = QString(res); 102 result = QString(res);
103 } 103 }
104 //qDebug("convert_String:%s ",result.latin1() ); 104 //qDebug("convert_String:%s ",result.latin1() );
105 if (res) free(res); 105 if (res) free(res);
106 return result; 106 return result;
107} 107}
108 108
109/* cp & paste from launcher */ 109/* cp & paste from launcher */
110QString AbstractMail::gen_attachment_id() 110QString AbstractMail::gen_attachment_id()
111{ 111{
112 QFile file( "/proc/sys/kernel/random/uuid" ); 112 QFile file( "/proc/sys/kernel/random/uuid" );
113 if (!file.open(IO_ReadOnly ) ) 113 if (!file.open(IO_ReadOnly ) )
114 return QString::null; 114 return QString::null;
115 115
116 QTextStream stream(&file); 116 QTextStream stream(&file);
117 117
118 return "{" + stream.read().stripWhiteSpace() + "}"; 118 return "{" + stream.read().stripWhiteSpace() + "}";
119} 119}
120 120
121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
122{ 122{
123 return 0; 123 return 0;
124} 124}
125 125
126QString AbstractMail::defaultLocalfolder() 126QString AbstractMail::defaultLocalfolder()
127{ 127{
128 // QString f = getenv( "HOME" ); 128 // QString f = getenv( "HOME" );
129 QString f = locateLocal( "data", "kopiemail/localmail"); 129 QString f = locateLocal( "data", "kopiemail/localmail");
130 // f += "/Applications/opiemail/localmail"; 130 // f += "/Applications/opiemail/localmail";
131 return f; 131 return f;
132} 132}
133 133
134QString AbstractMail::draftFolder() 134QString AbstractMail::draftFolder()
135{ 135{
136 return QString("Drafts"); 136 return QString("Drafts");
137} 137}
138 138
139/* temporary - will be removed when implemented in all classes */ 139/* temporary - will be removed when implemented in all classes */
140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
141{ 141{
142} 142}
143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
144{ 144{
145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
146 // this is currently re-implemented in pop3wrapper and imapwrapper 146 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0; 147 int iii = 0;
148 int count = target.count(); 148 int count = target.count();
149 QProgressBar wid ( count ); 149 QProgressBar wid ( count );
150 wid.setCaption( tr("Deleting ...")); 150 wid.setCaption( i18n("Deleting ..."));
151 wid.show(); 151 wid.show();
152 while (iii < count ) { 152 while (iii < count ) {
153 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 153 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
154 wid.setProgress( iii ); 154 wid.setProgress( iii );
155 wid.raise(); 155 wid.raise();
156 qApp->processEvents(); 156 qApp->processEvents();
157 RecMailP mail = (*target.at( iii )); 157 RecMailP mail = (*target.at( iii ));
158 deleteMail(mail); 158 deleteMail(mail);
159 ++iii; 159 ++iii;
160 } 160 }
161} 161}
162 162
163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail ) 163void AbstractMail::downloadNewMails(const FolderP&fromFolder, AbstractMail*targetMail )
164{ 164{
165 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1()); 165 //qDebug("AbstractMail::downloadNewMails %s ", fromFolder->getName().latin1());
166 // get local folder 166 // get local folder
167 Account * acc = getAccount(); 167 Account * acc = getAccount();
168 if ( !acc ) return; 168 if ( !acc ) return;
169 QString lfName = acc->getLocalFolder(); 169 QString lfName = acc->getLocalFolder();
170 if ( lfName.isEmpty() ) 170 if ( lfName.isEmpty() )
171 lfName = acc->getAccountName(); 171 lfName = acc->getAccountName();
172 // create local folder 172 // create local folder
173 if ( !targetMail->createMbox(lfName)) 173 if ( !targetMail->createMbox(lfName))
174 { 174 {
175 QMessageBox::critical(0,tr("Error creating new Folder"), 175 QMessageBox::critical(0,i18n("Error creating new Folder"),
176 tr("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName)); 176 i18n("Error while creating new folder\n%1\n\nCancelling action.").arg(lfName));
177 return; 177 return;
178 } 178 }
179 QValueList<RecMailP> t; 179 QValueList<RecMailP> t;
180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() ); 180 listMessages(fromFolder->getName(),t,acc->getMaxMailSize() );
181 if ( t.count() == 0 ) { 181 if ( t.count() == 0 ) {
182 qDebug("There are no new messages %s", fromFolder->getName().latin1()); 182 qDebug("There are no new messages %s", fromFolder->getName().latin1());
183 Global::statusMessage(tr("There are no new messages")); 183 Global::statusMessage(i18n("There are no new messages"));
184 return; 184 return;
185 } 185 }
186 QValueList<RecMailP> e; 186 QValueList<RecMailP> e;
187 targetMail->listMessages(lfName,e,acc->getMaxMailSize() ); 187 targetMail->listMessages(lfName,e,acc->getMaxMailSize() );
188 //qDebug("target has mails %d ", e.count()); 188 //qDebug("target has mails %d ", e.count());
189 QValueList<RecMailP> n; 189 QValueList<RecMailP> n;
190 int iii = 0; 190 int iii = 0;
191 int count = t.count(); 191 int count = t.count();
192 while (iii < count ) { 192 while (iii < count ) {
193 RecMailP r = (*t.at( iii )); 193 RecMailP r = (*t.at( iii ));
194 bool found = false; 194 bool found = false;
195 int jjj = 0; 195 int jjj = 0;
196 int countE = e.count(); 196 int countE = e.count();
197 while (jjj < countE ) { 197 while (jjj < countE ) {
198 RecMailP re = (*e.at( jjj )); 198 RecMailP re = (*e.at( jjj ));
199 if ( re->isEqual(r) ) { 199 if ( re->isEqual(r) ) {
200 found = true; 200 found = true;
201 break; 201 break;
202 } 202 }
203 ++jjj; 203 ++jjj;
204 } 204 }
205 if ( !found ) { 205 if ( !found ) {
206 //qDebug("AAAdate *%s* ", r->isodate.latin1() ); 206 //qDebug("AAAdate *%s* ", r->isodate.latin1() );
207 n.append( r ); 207 n.append( r );
208 } 208 }
209 ++iii; 209 ++iii;
210 } 210 }
211 qDebug("Downloaded %d messages ",n.count() ); 211 qDebug("Downloaded %d messages ",n.count() );
212 if ( n.count() == 0 ) { 212 if ( n.count() == 0 ) {
213 Global::statusMessage(tr("There are no new messages")); 213 Global::statusMessage(i18n("There are no new messages"));
214 return; 214 return;
215 } 215 }
216 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer()); 216 mvcpMailList( n,lfName,targetMail,!acc->getLeaveOnServer());
217 Global::statusMessage(tr("Downloaded %1 messages").arg(n.count())); 217 Global::statusMessage(i18n("Downloaded %1 messages").arg(n.count()));
218 218
219#if 0 219#if 0
220 QValueList<RecMailP> t; 220 QValueList<RecMailP> t;
221 listMessages(fromFolder->getName(),t, maxSizeInKb); 221 listMessages(fromFolder->getName(),t, maxSizeInKb);
222 mvcpMailList( t,targetFolder,targetWrapper,moveit); 222 mvcpMailList( t,targetFolder,targetWrapper,moveit);
223#endif 223#endif
224 224
225} 225}
226void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 226void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
227 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 227 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
228{ 228{
229 QValueList<RecMailP> t; 229 QValueList<RecMailP> t;
230 listMessages(fromFolder->getName(),t, maxSizeInKb); 230 listMessages(fromFolder->getName(),t, maxSizeInKb);
231 mvcpMailList( t,targetFolder,targetWrapper,moveit); 231 mvcpMailList( t,targetFolder,targetWrapper,moveit);
232 232
233} 233}
234void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 234void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
235 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 235 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
236{ 236{
237 encodedString*st = 0; 237 encodedString*st = 0;
238 int iii = 0; 238 int iii = 0;
239 int count = t.count(); 239 int count = t.count();
240 if ( count == 0 ) 240 if ( count == 0 )
241 return; 241 return;
242 // wel, processevents is qite strange, we need a widget for getting 242 // wel, processevents is qite strange, we need a widget for getting
243 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displaye 243 // Global::statusMessage(i18n("Copy2 message %1").arg(iii)); displaye
244 244
245 QProgressBar wid ( count ); 245 QProgressBar wid ( count );
246 wid.setCaption( tr("Copying ...")); 246 wid.setCaption( i18n("Copying..."));
247 wid.show(); 247 wid.show();
248 while (iii < count ) { 248 while (iii < count ) {
249 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count)); 249 Global::statusMessage(i18n("Copy message %1 of %2").arg(iii).arg(count));
250 wid.setProgress( iii ); 250 wid.setProgress( iii );
251 wid.raise(); 251 wid.raise();
252 qApp->processEvents(); 252 qApp->processEvents();
253 RecMailP r = (*t.at( iii )); 253 RecMailP r = (*t.at( iii ));
254 st = fetchRawBody(r); 254 st = fetchRawBody(r);
255 if (st) { 255 if (st) {
256 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 256 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
257 delete st; 257 delete st;
258 } 258 }
259 ++iii; 259 ++iii;
260 } 260 }
261 if (moveit) { 261 if (moveit) {
262 deleteMailList( t ); 262 deleteMailList( t );
263 //deleteAllMail(fromFolder); 263 //deleteAllMail(fromFolder);
264 } 264 }
265} 265}
266 266
267void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 267void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
268{ 268{
269 encodedString*st = 0; 269 encodedString*st = 0;
270 st = fetchRawBody(mail); 270 st = fetchRawBody(mail);
271 if (st) { 271 if (st) {
272 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 272 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
273 delete st; 273 delete st;
274 } 274 }
275 if (moveit) { 275 if (moveit) {
276 deleteMail(mail); 276 deleteMail(mail);
277 } 277 }
278} 278}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 8150453..3aec13d 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,432 +1,432 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include <stdlib.h> 2#include <stdlib.h>
3#include <libetpan/libetpan.h> 3#include <libetpan/libetpan.h>
4#include <qpe/global.h> 4#include <qpe/global.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include "imapwrapper.h" 6#include "imapwrapper.h"
7#include "mailtypes.h" 7#include "mailtypes.h"
8#include "logindialog.h" 8#include "logindialog.h"
9#include <qprogressbar.h> 9#include <qprogressbar.h>
10#include "genericwrapper.h" 10#include "genericwrapper.h"
11#include <kglobal.h> 11#include <kglobal.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14int IMAPwrapper::mMax = 0; 14int IMAPwrapper::mMax = 0;
15int IMAPwrapper::mCurrent = 0; 15int IMAPwrapper::mCurrent = 0;
16 16
17IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 17IMAPwrapper::IMAPwrapper( IMAPaccount *a )
18 : AbstractMail() 18 : AbstractMail()
19{ 19{
20 account = a; 20 account = a;
21 m_imap = 0; 21 m_imap = 0;
22 m_Lastmbox = ""; 22 m_Lastmbox = "";
23 mCurrent = 0; 23 mCurrent = 0;
24 mMax = 0; 24 mMax = 0;
25} 25}
26 26
27IMAPwrapper::~IMAPwrapper() 27IMAPwrapper::~IMAPwrapper()
28{ 28{
29 logout(); 29 logout();
30} 30}
31 31
32/* to avoid to often select statements in loops etc. 32/* to avoid to often select statements in loops etc.
33 we trust that we are logged in and connection is established!*/ 33 we trust that we are logged in and connection is established!*/
34int IMAPwrapper::selectMbox(const QString&mbox) 34int IMAPwrapper::selectMbox(const QString&mbox)
35{ 35{
36 if (mbox == m_Lastmbox) { 36 if (mbox == m_Lastmbox) {
37 return MAILIMAP_NO_ERROR; 37 return MAILIMAP_NO_ERROR;
38 } 38 }
39 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 39 int err = mailimap_select( m_imap, (char*)mbox.latin1());
40 if ( err != MAILIMAP_NO_ERROR ) { 40 if ( err != MAILIMAP_NO_ERROR ) {
41 m_Lastmbox = ""; 41 m_Lastmbox = "";
42 return err; 42 return err;
43 } 43 }
44 m_Lastmbox = mbox; 44 m_Lastmbox = mbox;
45 return err; 45 return err;
46} 46}
47 47
48void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 48void IMAPwrapper::imap_progress( size_t current, size_t maximum )
49{ 49{
50 //qDebug("imap progress %d of %d ",current,maximum ); 50 //qDebug("imap progress %d of %d ",current,maximum );
51 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum)); 51 //Global::statusMessage(i18n("Downloading message %1 of %2").arg( current).arg(maximum));
52 //qApp->processEvents() 52 //qApp->processEvents()
53 static int last = 0; 53 static int last = 0;
54 if ( last != current ) 54 if ( last != current )
55 IMAPwrapper::progress(); 55 IMAPwrapper::progress();
56 last = current; 56 last = current;
57} 57}
58void IMAPwrapper::progress( QString m ) 58void IMAPwrapper::progress( QString m )
59{ 59{
60 60
61 static QString mProgrMess; 61 static QString mProgrMess;
62 if ( m != QString::null ) { 62 if ( m != QString::null ) {
63 mProgrMess = m; 63 mProgrMess = m;
64 mCurrent = 1; 64 mCurrent = 1;
65 return; 65 return;
66 } 66 }
67 QString mess; 67 QString mess;
68 //qDebug("progress "); 68 //qDebug("progress ");
69 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax); 69 if ( mMax ) mess = mProgrMess +i18n(" message %1 of %2").arg( mCurrent++).arg(mMax);
70 else mess = mProgrMess +tr(" message %1").arg( mCurrent++); 70 else mess = mProgrMess +i18n(" message %1").arg( mCurrent++);
71 Global::statusMessage(mess); 71 Global::statusMessage(mess);
72 //qDebug("Progress %s %s", mess.latin1(), m.latin1()); 72 //qDebug("Progress %s %s", mess.latin1(), m.latin1());
73 qApp->processEvents(); 73 qApp->processEvents();
74} 74}
75bool IMAPwrapper::start_tls(bool force_tls) 75bool IMAPwrapper::start_tls(bool force_tls)
76{ 76{
77 int err; 77 int err;
78 bool try_tls; 78 bool try_tls;
79 mailimap_capability_data * cap_data = 0; 79 mailimap_capability_data * cap_data = 0;
80 80
81 err = mailimap_capability(m_imap,&cap_data); 81 err = mailimap_capability(m_imap,&cap_data);
82 if (err != MAILIMAP_NO_ERROR) { 82 if (err != MAILIMAP_NO_ERROR) {
83 Global::statusMessage("error getting capabilities!"); 83 Global::statusMessage("error getting capabilities!");
84 return false; 84 return false;
85 } 85 }
86 clistiter * cur; 86 clistiter * cur;
87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 87 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
88 struct mailimap_capability * cap; 88 struct mailimap_capability * cap;
89 cap = (struct mailimap_capability *)clist_content(cur); 89 cap = (struct mailimap_capability *)clist_content(cur);
90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 90 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 91 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
92 try_tls = true; 92 try_tls = true;
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 if (cap_data) { 97 if (cap_data) {
98 mailimap_capability_data_free(cap_data); 98 mailimap_capability_data_free(cap_data);
99 } 99 }
100 if (try_tls) { 100 if (try_tls) {
101 err = mailimap_starttls(m_imap); 101 err = mailimap_starttls(m_imap);
102 if (err != MAILIMAP_NO_ERROR && force_tls) { 102 if (err != MAILIMAP_NO_ERROR && force_tls) {
103 Global::statusMessage(tr("Server has no TLS support!")); 103 Global::statusMessage(i18n("Server has no TLS support!"));
104 try_tls = false; 104 try_tls = false;
105 } else { 105 } else {
106 mailstream_low * low; 106 mailstream_low * low;
107 mailstream_low * new_low; 107 mailstream_low * new_low;
108 low = mailstream_get_low(m_imap->imap_stream); 108 low = mailstream_get_low(m_imap->imap_stream);
109 if (!low) { 109 if (!low) {
110 try_tls = false; 110 try_tls = false;
111 } else { 111 } else {
112 int fd = mailstream_low_get_fd(low); 112 int fd = mailstream_low_get_fd(low);
113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 113 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
114 mailstream_low_free(low); 114 mailstream_low_free(low);
115 mailstream_set_low(m_imap->imap_stream, new_low); 115 mailstream_set_low(m_imap->imap_stream, new_low);
116 } else { 116 } else {
117 try_tls = false; 117 try_tls = false;
118 } 118 }
119 } 119 }
120 } 120 }
121 } 121 }
122 return try_tls; 122 return try_tls;
123} 123}
124 124
125void IMAPwrapper::login() 125void IMAPwrapper::login()
126{ 126{
127 QString server, user, pass; 127 QString server, user, pass;
128 uint16_t port; 128 uint16_t port;
129 int err = MAILIMAP_NO_ERROR; 129 int err = MAILIMAP_NO_ERROR;
130 130
131 if (account->getOffline()) return; 131 if (account->getOffline()) return;
132 /* we are connected this moment */ 132 /* we are connected this moment */
133 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 133 /* TODO: setup a timer holding the line or if connection closed - delete the value */
134 if (m_imap) { 134 if (m_imap) {
135 err = mailimap_noop(m_imap); 135 err = mailimap_noop(m_imap);
136 if (err!=MAILIMAP_NO_ERROR) { 136 if (err!=MAILIMAP_NO_ERROR) {
137 logout(); 137 logout();
138 } else { 138 } else {
139 mailstream_flush(m_imap->imap_stream); 139 mailstream_flush(m_imap->imap_stream);
140 return; 140 return;
141 } 141 }
142 } 142 }
143 server = account->getServer(); 143 server = account->getServer();
144 port = account->getPort().toUInt(); 144 port = account->getPort().toUInt();
145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 145 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 146 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
147 login.show(); 147 login.show();
148 if ( QDialog::Accepted == login.exec() ) { 148 if ( QDialog::Accepted == login.exec() ) {
149 // ok 149 // ok
150 user = login.getUser(); 150 user = login.getUser();
151 pass = login.getPassword(); 151 pass = login.getPassword();
152 } else { 152 } else {
153 // cancel 153 // cancel
154 return; 154 return;
155 } 155 }
156 } else { 156 } else {
157 user = account->getUser(); 157 user = account->getUser();
158 pass = account->getPassword(); 158 pass = account->getPassword();
159 } 159 }
160 160
161 m_imap = mailimap_new( 20, &imap_progress ); 161 m_imap = mailimap_new( 20, &imap_progress );
162 162
163 /* connect */ 163 /* connect */
164 bool ssl = false; 164 bool ssl = false;
165 bool try_tls = false; 165 bool try_tls = false;
166 bool force_tls = false; 166 bool force_tls = false;
167 167
168 if ( account->ConnectionType() == 2 ) { 168 if ( account->ConnectionType() == 2 ) {
169 ssl = true; 169 ssl = true;
170 } 170 }
171 if (account->ConnectionType()==1) { 171 if (account->ConnectionType()==1) {
172 force_tls = true; 172 force_tls = true;
173 } 173 }
174 174
175 if ( ssl ) { 175 if ( ssl ) {
176 //qDebug("using ssl "); 176 //qDebug("using ssl ");
177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 177 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
178 } else { 178 } else {
179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 179 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
180 } 180 }
181 181
182 if ( err != MAILIMAP_NO_ERROR && 182 if ( err != MAILIMAP_NO_ERROR &&
183 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 183 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 184 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
185 QString failure = ""; 185 QString failure = "";
186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 186 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
187 failure="Connection refused"; 187 failure="Connection refused";
188 } else { 188 } else {
189 failure="Unknown failure"; 189 failure="Unknown failure";
190 } 190 }
191 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 191 Global::statusMessage(i18n("error connecting imap server: %1").arg(failure));
192 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
193 m_imap = 0; 193 m_imap = 0;
194 return; 194 return;
195 } 195 }
196 196
197 if (!ssl) { 197 if (!ssl) {
198 try_tls = start_tls(force_tls); 198 try_tls = start_tls(force_tls);
199 } 199 }
200 200
201 bool ok = true; 201 bool ok = true;
202 if (force_tls && !try_tls) { 202 if (force_tls && !try_tls) {
203 Global::statusMessage(tr("Server has no TLS support!")); 203 Global::statusMessage(i18n("Server has no TLS support!"));
204 ok = false; 204 ok = false;
205 } 205 }
206 206
207 207
208 /* login */ 208 /* login */
209 209
210 if (ok) { 210 if (ok) {
211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 211 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
212 if ( err != MAILIMAP_NO_ERROR ) { 212 if ( err != MAILIMAP_NO_ERROR ) {
213 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 213 Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response));
214 ok = false; 214 ok = false;
215 } 215 }
216 } 216 }
217 if (!ok) { 217 if (!ok) {
218 err = mailimap_close( m_imap ); 218 err = mailimap_close( m_imap );
219 mailimap_free( m_imap ); 219 mailimap_free( m_imap );
220 m_imap = 0; 220 m_imap = 0;
221 } 221 }
222} 222}
223 223
224void IMAPwrapper::logout() 224void IMAPwrapper::logout()
225{ 225{
226 int err = MAILIMAP_NO_ERROR; 226 int err = MAILIMAP_NO_ERROR;
227 if (!m_imap) return; 227 if (!m_imap) return;
228 err = mailimap_logout( m_imap ); 228 err = mailimap_logout( m_imap );
229 err = mailimap_close( m_imap ); 229 err = mailimap_close( m_imap );
230 mailimap_free( m_imap ); 230 mailimap_free( m_imap );
231 m_imap = 0; 231 m_imap = 0;
232 m_Lastmbox = ""; 232 m_Lastmbox = "";
233} 233}
234 234
235void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 235void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
236{ 236{
237 237
238 int tryAgain = 1; 238 int tryAgain = 1;
239 while ( tryAgain >= 0 ) { 239 while ( tryAgain >= 0 ) {
240 int err = MAILIMAP_NO_ERROR; 240 int err = MAILIMAP_NO_ERROR;
241 clist *result = 0; 241 clist *result = 0;
242 clistcell *current; 242 clistcell *current;
243 mailimap_fetch_type *fetchType = 0; 243 mailimap_fetch_type *fetchType = 0;
244 mailimap_set *set = 0; 244 mailimap_set *set = 0;
245 245
246 login(); 246 login();
247 if (!m_imap) { 247 if (!m_imap) {
248 return; 248 return;
249 } 249 }
250 /* select mailbox READONLY for operations */ 250 /* select mailbox READONLY for operations */
251 err = selectMbox(mailbox); 251 err = selectMbox(mailbox);
252 if ( err != MAILIMAP_NO_ERROR ) { 252 if ( err != MAILIMAP_NO_ERROR ) {
253 return; 253 return;
254 } 254 }
255 255
256 int last = m_imap->imap_selection_info->sel_exists; 256 int last = m_imap->imap_selection_info->sel_exists;
257 257
258 if (last == 0) { 258 if (last == 0) {
259 Global::statusMessage(tr("Mailbox has no mails")); 259 Global::statusMessage(i18n("Mailbox has no mails"));
260 return; 260 return;
261 } else { 261 } else {
262 } 262 }
263 progress( tr("Fetch ")); 263 progress( i18n("Fetch "));
264 mMax = last; 264 mMax = last;
265 //qDebug("last %d ", last); 265 //qDebug("last %d ", last);
266 Global::statusMessage(tr("Fetching header list")); 266 Global::statusMessage(i18n("Fetching header list"));
267 qApp->processEvents(); 267 qApp->processEvents();
268 /* the range has to start at 1!!! not with 0!!!! */ 268 /* the range has to start at 1!!! not with 0!!!! */
269 //LR the access to web.de imap server is no working with value 1 269 //LR the access to web.de imap server is no working with value 1
270 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain ); 270 //qDebug("interval %d - %d ", tryAgain, last-1+tryAgain );
271 set = mailimap_set_new_interval( tryAgain, last ); 271 set = mailimap_set_new_interval( tryAgain, last );
272 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 272 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
273 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 273 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 274 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 275 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 276 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
277 277
278 err = mailimap_fetch( m_imap, set, fetchType, &result ); 278 err = mailimap_fetch( m_imap, set, fetchType, &result );
279 mailimap_set_free( set ); 279 mailimap_set_free( set );
280 mailimap_fetch_type_free( fetchType ); 280 mailimap_fetch_type_free( fetchType );
281 281
282 QString date,subject,from; 282 QString date,subject,from;
283 283
284 if ( err == MAILIMAP_NO_ERROR ) { 284 if ( err == MAILIMAP_NO_ERROR ) {
285 tryAgain = -1; 285 tryAgain = -1;
286 mailimap_msg_att * msg_att; 286 mailimap_msg_att * msg_att;
287 int i = 0; 287 int i = 0;
288 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 288 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
289 ++i; 289 ++i;
290 //qDebug("iii %d ",i); 290 //qDebug("iii %d ",i);
291 msg_att = (mailimap_msg_att*)current->data; 291 msg_att = (mailimap_msg_att*)current->data;
292 RecMail*m = parse_list_result(msg_att); 292 RecMail*m = parse_list_result(msg_att);
293 if (m) { 293 if (m) {
294 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 294 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
295 m->setNumber(i); 295 m->setNumber(i);
296 m->setMbox(mailbox); 296 m->setMbox(mailbox);
297 m->setWrapper(this); 297 m->setWrapper(this);
298 target.append(m); 298 target.append(m);
299 } 299 }
300 } 300 }
301 } 301 }
302 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 302 Global::statusMessage(i18n("Mailbox has %1 mails").arg(target.count()));
303 } else { 303 } else {
304 --tryAgain; 304 --tryAgain;
305 --tryAgain;//disabled tryagain by adding this line 305 --tryAgain;//disabled tryagain by adding this line
306 if ( tryAgain < 0 ) 306 if ( tryAgain < 0 )
307 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 307 Global::statusMessage(i18n("Error fetching headers: %1").arg(m_imap->imap_response));
308 else 308 else
309 qDebug("try again... "); 309 qDebug("try again... ");
310 } 310 }
311 311
312 if (result) mailimap_fetch_list_free(result); 312 if (result) mailimap_fetch_list_free(result);
313 } 313 }
314} 314}
315 315
316QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 316QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
317{ 317{
318 const char *path, *mask; 318 const char *path, *mask;
319 int err = MAILIMAP_NO_ERROR; 319 int err = MAILIMAP_NO_ERROR;
320 clist *result = 0; 320 clist *result = 0;
321 clistcell *current = 0; 321 clistcell *current = 0;
322 clistcell*cur_flag = 0; 322 clistcell*cur_flag = 0;
323 mailimap_mbx_list_flags*bflags = 0; 323 mailimap_mbx_list_flags*bflags = 0;
324 324
325 QValueList<FolderP>* folders = new QValueList<FolderP>(); 325 QValueList<FolderP>* folders = new QValueList<FolderP>();
326 login(); 326 login();
327 if (!m_imap) { 327 if (!m_imap) {
328 return folders; 328 return folders;
329 } 329 }
330 330
331/* 331/*
332 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 332 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
333 * We must not forget to filter them out in next loop! 333 * We must not forget to filter them out in next loop!
334 * it seems like ugly code. and yes - it is ugly code. but the best way. 334 * it seems like ugly code. and yes - it is ugly code. but the best way.
335 */ 335 */
336 Global::statusMessage(tr("Fetching folder list")); 336 Global::statusMessage(i18n("Fetching folder list"));
337 qApp->processEvents(); 337 qApp->processEvents();
338 QString temp; 338 QString temp;
339 mask = "INBOX" ; 339 mask = "INBOX" ;
340 mailimap_mailbox_list *list; 340 mailimap_mailbox_list *list;
341 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 341 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
342 QString del; 342 QString del;
343 bool selectable = true; 343 bool selectable = true;
344 bool no_inferiors = false; 344 bool no_inferiors = false;
345 if ( err == MAILIMAP_NO_ERROR ) { 345 if ( err == MAILIMAP_NO_ERROR ) {
346 current = result->first; 346 current = result->first;
347 for ( int i = result->count; i > 0; i-- ) { 347 for ( int i = result->count; i > 0; i-- ) {
348 list = (mailimap_mailbox_list *) current->data; 348 list = (mailimap_mailbox_list *) current->data;
349 // it is better use the deep copy mechanism of qt itself 349 // it is better use the deep copy mechanism of qt itself
350 // instead of using strdup! 350 // instead of using strdup!
351 temp = list->mb_name; 351 temp = list->mb_name;
352 del = list->mb_delimiter; 352 del = list->mb_delimiter;
353 current = current->next; 353 current = current->next;
354 if ( (bflags = list->mb_flag) ) { 354 if ( (bflags = list->mb_flag) ) {
355 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 355 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
356 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 356 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
357 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 357 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
358 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 358 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
359 no_inferiors = true; 359 no_inferiors = true;
360 } 360 }
361 } 361 }
362 } 362 }
363 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 363 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
364 } 364 }
365 } else { 365 } else {
366 qDebug("error fetching folders: "); 366 qDebug("error fetching folders: ");
367 367
368 } 368 }
369 mailimap_list_result_free( result ); 369 mailimap_list_result_free( result );
370 370
371/* 371/*
372 * second stage - get the other then inbox folders 372 * second stage - get the other then inbox folders
373 */ 373 */
374 mask = "*" ; 374 mask = "*" ;
375 path = account->getPrefix().latin1(); 375 path = account->getPrefix().latin1();
376 if (!path) path = ""; 376 if (!path) path = "";
377 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 377 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
378 if ( err == MAILIMAP_NO_ERROR ) { 378 if ( err == MAILIMAP_NO_ERROR ) {
379 current = result->first; 379 current = result->first;
380 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 380 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
381 no_inferiors = false; 381 no_inferiors = false;
382 list = (mailimap_mailbox_list *) current->data; 382 list = (mailimap_mailbox_list *) current->data;
383 // it is better use the deep copy mechanism of qt itself 383 // it is better use the deep copy mechanism of qt itself
384 // instead of using strdup! 384 // instead of using strdup!
385 temp = list->mb_name; 385 temp = list->mb_name;
386 if (temp.lower()=="inbox") 386 if (temp.lower()=="inbox")
387 continue; 387 continue;
388 if (temp.lower()==account->getPrefix().lower()) 388 if (temp.lower()==account->getPrefix().lower())
389 continue; 389 continue;
390 if ( (bflags = list->mb_flag) ) { 390 if ( (bflags = list->mb_flag) ) {
391 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 391 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
392 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 392 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
393 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 393 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
394 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 394 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
395 no_inferiors = true; 395 no_inferiors = true;
396 } 396 }
397 } 397 }
398 } 398 }
399 del = list->mb_delimiter; 399 del = list->mb_delimiter;
400 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 400 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
401 } 401 }
402 } else { 402 } else {
403 qDebug("error fetching folders "); 403 qDebug("error fetching folders ");
404 404
405 } 405 }
406 if (result) mailimap_list_result_free( result ); 406 if (result) mailimap_list_result_free( result );
407 return folders; 407 return folders;
408} 408}
409 409
410RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 410RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
411{ 411{
412 RecMail * m = 0; 412 RecMail * m = 0;
413 mailimap_msg_att_item *item=0; 413 mailimap_msg_att_item *item=0;
414 clistcell *current,*c,*cf; 414 clistcell *current,*c,*cf;
415 mailimap_msg_att_dynamic*flist; 415 mailimap_msg_att_dynamic*flist;
416 mailimap_flag_fetch*cflag; 416 mailimap_flag_fetch*cflag;
417 int size; 417 int size;
418 QBitArray mFlags(7); 418 QBitArray mFlags(7);
419 QStringList addresslist; 419 QStringList addresslist;
420 420
421 if (!m_att) { 421 if (!m_att) {
422 return m; 422 return m;
423 } 423 }
424 m = new RecMail(); 424 m = new RecMail();
425 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 425 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
426 current = c; 426 current = c;
427 size = 0; 427 size = 0;
428 item = (mailimap_msg_att_item*)current->data; 428 item = (mailimap_msg_att_item*)current->data;
429 if ( !item ) 429 if ( !item )
430 continue; 430 continue;
431 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 431 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
432 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 432 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
@@ -876,461 +876,461 @@ void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_ba
876 case MAILIMAP_MEDIA_BASIC_AUDIO: 876 case MAILIMAP_MEDIA_BASIC_AUDIO:
877 type = "audio"; 877 type = "audio";
878 break; 878 break;
879 case MAILIMAP_MEDIA_BASIC_IMAGE: 879 case MAILIMAP_MEDIA_BASIC_IMAGE:
880 type = "image"; 880 type = "image";
881 break; 881 break;
882 case MAILIMAP_MEDIA_BASIC_MESSAGE: 882 case MAILIMAP_MEDIA_BASIC_MESSAGE:
883 type = "message"; 883 type = "message";
884 break; 884 break;
885 case MAILIMAP_MEDIA_BASIC_VIDEO: 885 case MAILIMAP_MEDIA_BASIC_VIDEO:
886 type = "video"; 886 type = "video";
887 break; 887 break;
888 case MAILIMAP_MEDIA_BASIC_OTHER: 888 case MAILIMAP_MEDIA_BASIC_OTHER:
889 default: 889 default:
890 if (which->bd_media_basic->med_basic_type) { 890 if (which->bd_media_basic->med_basic_type) {
891 type = which->bd_media_basic->med_basic_type; 891 type = which->bd_media_basic->med_basic_type;
892 } else { 892 } else {
893 type = ""; 893 type = "";
894 } 894 }
895 break; 895 break;
896 } 896 }
897 if (which->bd_media_basic->med_subtype) { 897 if (which->bd_media_basic->med_subtype) {
898 sub = which->bd_media_basic->med_subtype; 898 sub = which->bd_media_basic->med_subtype;
899 } else { 899 } else {
900 sub = ""; 900 sub = "";
901 } 901 }
902 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 902 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
903 target_part->setType(type.lower()); 903 target_part->setType(type.lower());
904 target_part->setSubtype(sub.lower()); 904 target_part->setSubtype(sub.lower());
905 fillBodyFields(target_part,which->bd_fields); 905 fillBodyFields(target_part,which->bd_fields);
906} 906}
907 907
908void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 908void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
909{ 909{
910 if (!which) return; 910 if (!which) return;
911 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 911 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
912 clistcell*cur; 912 clistcell*cur;
913 mailimap_single_body_fld_param*param=0; 913 mailimap_single_body_fld_param*param=0;
914 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 914 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
915 param = (mailimap_single_body_fld_param*)cur->data; 915 param = (mailimap_single_body_fld_param*)cur->data;
916 if (param) { 916 if (param) {
917 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 917 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
918 } 918 }
919 } 919 }
920 } 920 }
921 mailimap_body_fld_enc*enc = which->bd_encoding; 921 mailimap_body_fld_enc*enc = which->bd_encoding;
922 QString encoding(""); 922 QString encoding("");
923 switch (enc->enc_type) { 923 switch (enc->enc_type) {
924 case MAILIMAP_BODY_FLD_ENC_7BIT: 924 case MAILIMAP_BODY_FLD_ENC_7BIT:
925 encoding = "7bit"; 925 encoding = "7bit";
926 break; 926 break;
927 case MAILIMAP_BODY_FLD_ENC_8BIT: 927 case MAILIMAP_BODY_FLD_ENC_8BIT:
928 encoding = "8bit"; 928 encoding = "8bit";
929 break; 929 break;
930 case MAILIMAP_BODY_FLD_ENC_BINARY: 930 case MAILIMAP_BODY_FLD_ENC_BINARY:
931 encoding="binary"; 931 encoding="binary";
932 break; 932 break;
933 case MAILIMAP_BODY_FLD_ENC_BASE64: 933 case MAILIMAP_BODY_FLD_ENC_BASE64:
934 encoding="base64"; 934 encoding="base64";
935 break; 935 break;
936 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 936 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
937 encoding="quoted-printable"; 937 encoding="quoted-printable";
938 break; 938 break;
939 case MAILIMAP_BODY_FLD_ENC_OTHER: 939 case MAILIMAP_BODY_FLD_ENC_OTHER:
940 default: 940 default:
941 if (enc->enc_value) { 941 if (enc->enc_value) {
942 char*t=enc->enc_value; 942 char*t=enc->enc_value;
943 encoding=QString(enc->enc_value); 943 encoding=QString(enc->enc_value);
944 enc->enc_value=0L; 944 enc->enc_value=0L;
945 free(t); 945 free(t);
946 } 946 }
947 } 947 }
948 if (which->bd_description) { 948 if (which->bd_description) {
949 target_part->setDescription(QString(which->bd_description)); 949 target_part->setDescription(QString(which->bd_description));
950 } 950 }
951 target_part->setEncoding(encoding); 951 target_part->setEncoding(encoding);
952 target_part->setSize(which->bd_size); 952 target_part->setSize(which->bd_size);
953} 953}
954void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 954void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
955{ 955{
956 //#if 0 956 //#if 0
957 mailimap_flag_list*flist; 957 mailimap_flag_list*flist;
958 mailimap_set *set; 958 mailimap_set *set;
959 mailimap_store_att_flags * store_flags; 959 mailimap_store_att_flags * store_flags;
960 int err; 960 int err;
961 login(); 961 login();
962 //#endif 962 //#endif
963 if (!m_imap) { 963 if (!m_imap) {
964 return; 964 return;
965 } 965 }
966 int iii = 0; 966 int iii = 0;
967 int count = target.count(); 967 int count = target.count();
968 // qDebug("imap remove count %d ", count); 968 // qDebug("imap remove count %d ", count);
969 969
970 970
971 mMax = count; 971 mMax = count;
972 progress( tr("Delete")); 972 progress( i18n("Delete"));
973 973
974 QProgressBar wid ( count ); 974 QProgressBar wid ( count );
975 wid.setCaption( tr("Deleting ...")); 975 wid.setCaption( i18n("Deleting ..."));
976 wid.show(); 976 wid.show();
977 while (iii < count ) { 977 while (iii < count ) {
978 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 978 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
979 wid.setProgress( iii ); 979 wid.setProgress( iii );
980 wid.raise(); 980 wid.raise();
981 qApp->processEvents(); 981 qApp->processEvents();
982 RecMailP mail = (*target.at( iii )); 982 RecMailP mail = (*target.at( iii ));
983 //#if 0 983 //#if 0
984 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 984 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
985 err = selectMbox(mail->getMbox()); 985 err = selectMbox(mail->getMbox());
986 if ( err != MAILIMAP_NO_ERROR ) { 986 if ( err != MAILIMAP_NO_ERROR ) {
987 return; 987 return;
988 } 988 }
989 flist = mailimap_flag_list_new_empty(); 989 flist = mailimap_flag_list_new_empty();
990 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 990 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
991 store_flags = mailimap_store_att_flags_new_set_flags(flist); 991 store_flags = mailimap_store_att_flags_new_set_flags(flist);
992 set = mailimap_set_new_single(mail->getNumber()); 992 set = mailimap_set_new_single(mail->getNumber());
993 err = mailimap_store(m_imap,set,store_flags); 993 err = mailimap_store(m_imap,set,store_flags);
994 mailimap_set_free( set ); 994 mailimap_set_free( set );
995 mailimap_store_att_flags_free(store_flags); 995 mailimap_store_att_flags_free(store_flags);
996 996
997 if (err != MAILIMAP_NO_ERROR) { 997 if (err != MAILIMAP_NO_ERROR) {
998 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 998 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
999 return; 999 return;
1000 } 1000 }
1001 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1001 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1002 /* should we realy do that at this moment? */ 1002 /* should we realy do that at this moment? */
1003 1003
1004 // err = mailimap_expunge(m_imap); 1004 // err = mailimap_expunge(m_imap);
1005 //if (err != MAILIMAP_NO_ERROR) { 1005 //if (err != MAILIMAP_NO_ERROR) {
1006 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 1006 // Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1007 // } 1007 // }
1008 //#endif 1008 //#endif
1009 //deleteMail( mail); 1009 //deleteMail( mail);
1010 ++iii; 1010 ++iii;
1011 } 1011 }
1012 //qDebug("Deleting imap mails... "); 1012 //qDebug("Deleting imap mails... ");
1013 err = mailimap_expunge(m_imap); 1013 err = mailimap_expunge(m_imap);
1014 if (err != MAILIMAP_NO_ERROR) { 1014 if (err != MAILIMAP_NO_ERROR) {
1015 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 1015 Global::statusMessage(i18n("Error deleting mails: %s").arg(m_imap->imap_response));
1016 } 1016 }
1017} 1017}
1018void IMAPwrapper::deleteMail(const RecMailP&mail) 1018void IMAPwrapper::deleteMail(const RecMailP&mail)
1019{ 1019{
1020 mailimap_flag_list*flist; 1020 mailimap_flag_list*flist;
1021 mailimap_set *set; 1021 mailimap_set *set;
1022 mailimap_store_att_flags * store_flags; 1022 mailimap_store_att_flags * store_flags;
1023 int err; 1023 int err;
1024 login(); 1024 login();
1025 if (!m_imap) { 1025 if (!m_imap) {
1026 return; 1026 return;
1027 } 1027 }
1028 err = selectMbox(mail->getMbox()); 1028 err = selectMbox(mail->getMbox());
1029 if ( err != MAILIMAP_NO_ERROR ) { 1029 if ( err != MAILIMAP_NO_ERROR ) {
1030 return; 1030 return;
1031 } 1031 }
1032 flist = mailimap_flag_list_new_empty(); 1032 flist = mailimap_flag_list_new_empty();
1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1034 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1034 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1035 set = mailimap_set_new_single(mail->getNumber()); 1035 set = mailimap_set_new_single(mail->getNumber());
1036 err = mailimap_store(m_imap,set,store_flags); 1036 err = mailimap_store(m_imap,set,store_flags);
1037 mailimap_set_free( set ); 1037 mailimap_set_free( set );
1038 mailimap_store_att_flags_free(store_flags); 1038 mailimap_store_att_flags_free(store_flags);
1039 1039
1040 if (err != MAILIMAP_NO_ERROR) { 1040 if (err != MAILIMAP_NO_ERROR) {
1041 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 1041 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
1042 return; 1042 return;
1043 } 1043 }
1044 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1044 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1045 /* should we realy do that at this moment? */ 1045 /* should we realy do that at this moment? */
1046 1046
1047 err = mailimap_expunge(m_imap); 1047 err = mailimap_expunge(m_imap);
1048 if (err != MAILIMAP_NO_ERROR) { 1048 if (err != MAILIMAP_NO_ERROR) {
1049 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1049 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1050 } 1050 }
1051 //qDebug("IMAPwrapper::deleteMail 2"); 1051 //qDebug("IMAPwrapper::deleteMail 2");
1052 1052
1053} 1053}
1054 1054
1055void IMAPwrapper::answeredMail(const RecMailP&mail) 1055void IMAPwrapper::answeredMail(const RecMailP&mail)
1056{ 1056{
1057 mailimap_flag_list*flist; 1057 mailimap_flag_list*flist;
1058 mailimap_set *set; 1058 mailimap_set *set;
1059 mailimap_store_att_flags * store_flags; 1059 mailimap_store_att_flags * store_flags;
1060 int err; 1060 int err;
1061 login(); 1061 login();
1062 if (!m_imap) { 1062 if (!m_imap) {
1063 return; 1063 return;
1064 } 1064 }
1065 err = selectMbox(mail->getMbox()); 1065 err = selectMbox(mail->getMbox());
1066 if ( err != MAILIMAP_NO_ERROR ) { 1066 if ( err != MAILIMAP_NO_ERROR ) {
1067 return; 1067 return;
1068 } 1068 }
1069 flist = mailimap_flag_list_new_empty(); 1069 flist = mailimap_flag_list_new_empty();
1070 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1070 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
1071 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1071 store_flags = mailimap_store_att_flags_new_add_flags(flist);
1072 set = mailimap_set_new_single(mail->getNumber()); 1072 set = mailimap_set_new_single(mail->getNumber());
1073 err = mailimap_store(m_imap,set,store_flags); 1073 err = mailimap_store(m_imap,set,store_flags);
1074 mailimap_set_free( set ); 1074 mailimap_set_free( set );
1075 mailimap_store_att_flags_free(store_flags); 1075 mailimap_store_att_flags_free(store_flags);
1076 1076
1077 if (err != MAILIMAP_NO_ERROR) { 1077 if (err != MAILIMAP_NO_ERROR) {
1078 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1078 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1079 return; 1079 return;
1080 } 1080 }
1081} 1081}
1082 1082
1083QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1083QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
1084{ 1084{
1085 QString body(""); 1085 QString body("");
1086 encodedString*res = fetchRawPart(mail,path,internal_call); 1086 encodedString*res = fetchRawPart(mail,path,internal_call);
1087 encodedString*r = decode_String(res,enc); 1087 encodedString*r = decode_String(res,enc);
1088 delete res; 1088 delete res;
1089 if (r) { 1089 if (r) {
1090 if (r->Length()>0) { 1090 if (r->Length()>0) {
1091 body = r->Content(); 1091 body = r->Content();
1092 } 1092 }
1093 delete r; 1093 delete r;
1094 } 1094 }
1095 return body; 1095 return body;
1096} 1096}
1097 1097
1098QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1098QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1099{ 1099{
1100 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1100 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1101} 1101}
1102 1102
1103encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1103encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1104{ 1104{
1105 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1105 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1106 encodedString*r = decode_String(res,part->Encoding()); 1106 encodedString*r = decode_String(res,part->Encoding());
1107 delete res; 1107 delete res;
1108 return r; 1108 return r;
1109} 1109}
1110 1110
1111encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1111encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1112{ 1112{
1113 return fetchRawPart(mail,part->Positionlist(),false); 1113 return fetchRawPart(mail,part->Positionlist(),false);
1114} 1114}
1115 1115
1116int IMAPwrapper::deleteAllMail(const FolderP&folder) 1116int IMAPwrapper::deleteAllMail(const FolderP&folder)
1117{ 1117{
1118 login(); 1118 login();
1119 if (!m_imap) { 1119 if (!m_imap) {
1120 return 0; 1120 return 0;
1121 } 1121 }
1122 mailimap_flag_list*flist; 1122 mailimap_flag_list*flist;
1123 mailimap_set *set; 1123 mailimap_set *set;
1124 mailimap_store_att_flags * store_flags; 1124 mailimap_store_att_flags * store_flags;
1125 int err = selectMbox(folder->getName()); 1125 int err = selectMbox(folder->getName());
1126 if ( err != MAILIMAP_NO_ERROR ) { 1126 if ( err != MAILIMAP_NO_ERROR ) {
1127 return 0; 1127 return 0;
1128 } 1128 }
1129 1129
1130 int last = m_imap->imap_selection_info->sel_exists; 1130 int last = m_imap->imap_selection_info->sel_exists;
1131 if (last == 0) { 1131 if (last == 0) {
1132 Global::statusMessage(tr("Mailbox has no mails!")); 1132 Global::statusMessage(i18n("Mailbox has no mails!"));
1133 return 0; 1133 return 0;
1134 } 1134 }
1135 flist = mailimap_flag_list_new_empty(); 1135 flist = mailimap_flag_list_new_empty();
1136 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1136 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1137 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1137 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1138 set = mailimap_set_new_interval( 1, last ); 1138 set = mailimap_set_new_interval( 1, last );
1139 err = mailimap_store(m_imap,set,store_flags); 1139 err = mailimap_store(m_imap,set,store_flags);
1140 mailimap_set_free( set ); 1140 mailimap_set_free( set );
1141 mailimap_store_att_flags_free(store_flags); 1141 mailimap_store_att_flags_free(store_flags);
1142 if (err != MAILIMAP_NO_ERROR) { 1142 if (err != MAILIMAP_NO_ERROR) {
1143 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1143 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1144 return 0; 1144 return 0;
1145 } 1145 }
1146 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1146 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1147 /* should we realy do that at this moment? */ 1147 /* should we realy do that at this moment? */
1148 err = mailimap_expunge(m_imap); 1148 err = mailimap_expunge(m_imap);
1149 if (err != MAILIMAP_NO_ERROR) { 1149 if (err != MAILIMAP_NO_ERROR) {
1150 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1150 Global::statusMessage(i18n("error deleting mail: %s").arg(m_imap->imap_response));
1151 return 0; 1151 return 0;
1152 } 1152 }
1153 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1153 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1154 return 1; 1154 return 1;
1155} 1155}
1156 1156
1157int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1157int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1158{ 1158{
1159 if (folder.length()==0) return 0; 1159 if (folder.length()==0) return 0;
1160 login(); 1160 login();
1161 if (!m_imap) {return 0;} 1161 if (!m_imap) {return 0;}
1162 QString pre = account->getPrefix(); 1162 QString pre = account->getPrefix();
1163 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1163 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1164 pre+=delemiter; 1164 pre+=delemiter;
1165 } 1165 }
1166 if (parentfolder) { 1166 if (parentfolder) {
1167 pre += parentfolder->getDisplayName()+delemiter; 1167 pre += parentfolder->getDisplayName()+delemiter;
1168 } 1168 }
1169 pre+=folder; 1169 pre+=folder;
1170 if (getsubfolder) { 1170 if (getsubfolder) {
1171 if (delemiter.length()>0) { 1171 if (delemiter.length()>0) {
1172 pre+=delemiter; 1172 pre+=delemiter;
1173 } else { 1173 } else {
1174 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1174 Global::statusMessage(i18n("Cannot create folder %1 for holding subfolders").arg(pre));
1175 return 0; 1175 return 0;
1176 } 1176 }
1177 } 1177 }
1178 // odebug << "Creating " << pre.latin1() << "" << oendl; 1178 // odebug << "Creating " << pre.latin1() << "" << oendl;
1179 int res = mailimap_create(m_imap,pre.latin1()); 1179 int res = mailimap_create(m_imap,pre.latin1());
1180 if (res != MAILIMAP_NO_ERROR) { 1180 if (res != MAILIMAP_NO_ERROR) {
1181 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1181 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1182 return 0; 1182 return 0;
1183 } 1183 }
1184 return 1; 1184 return 1;
1185} 1185}
1186 1186
1187int IMAPwrapper::deleteMbox(const FolderP&folder) 1187int IMAPwrapper::deleteMbox(const FolderP&folder)
1188{ 1188{
1189 if (!folder) return 0; 1189 if (!folder) return 0;
1190 login(); 1190 login();
1191 if (!m_imap) {return 0;} 1191 if (!m_imap) {return 0;}
1192 int res = mailimap_delete(m_imap,folder->getName()); 1192 int res = mailimap_delete(m_imap,folder->getName());
1193 if (res != MAILIMAP_NO_ERROR) { 1193 if (res != MAILIMAP_NO_ERROR) {
1194 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1194 Global::statusMessage(i18n("%1").arg(m_imap->imap_response));
1195 return 0; 1195 return 0;
1196 } 1196 }
1197 return 1; 1197 return 1;
1198} 1198}
1199 1199
1200void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1200void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1201{ 1201{
1202 mailimap_status_att_list * att_list =0; 1202 mailimap_status_att_list * att_list =0;
1203 mailimap_mailbox_data_status * status=0; 1203 mailimap_mailbox_data_status * status=0;
1204 clistiter * cur = 0; 1204 clistiter * cur = 0;
1205 int r = 0; 1205 int r = 0;
1206 target_stat.message_count = 0; 1206 target_stat.message_count = 0;
1207 target_stat.message_unseen = 0; 1207 target_stat.message_unseen = 0;
1208 target_stat.message_recent = 0; 1208 target_stat.message_recent = 0;
1209 login(); 1209 login();
1210 if (!m_imap) { 1210 if (!m_imap) {
1211 return; 1211 return;
1212 } 1212 }
1213 att_list = mailimap_status_att_list_new_empty(); 1213 att_list = mailimap_status_att_list_new_empty();
1214 if (!att_list) return; 1214 if (!att_list) return;
1215 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1215 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1216 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1216 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1217 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1217 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1218 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1218 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1219 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1219 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1220 for (cur = clist_begin(status->st_info_list); 1220 for (cur = clist_begin(status->st_info_list);
1221 cur != NULL ; cur = clist_next(cur)) { 1221 cur != NULL ; cur = clist_next(cur)) {
1222 mailimap_status_info * status_info; 1222 mailimap_status_info * status_info;
1223 status_info = (mailimap_status_info *)clist_content(cur); 1223 status_info = (mailimap_status_info *)clist_content(cur);
1224 switch (status_info->st_att) { 1224 switch (status_info->st_att) {
1225 case MAILIMAP_STATUS_ATT_MESSAGES: 1225 case MAILIMAP_STATUS_ATT_MESSAGES:
1226 target_stat.message_count = status_info->st_value; 1226 target_stat.message_count = status_info->st_value;
1227 break; 1227 break;
1228 case MAILIMAP_STATUS_ATT_RECENT: 1228 case MAILIMAP_STATUS_ATT_RECENT:
1229 target_stat.message_recent = status_info->st_value; 1229 target_stat.message_recent = status_info->st_value;
1230 break; 1230 break;
1231 case MAILIMAP_STATUS_ATT_UNSEEN: 1231 case MAILIMAP_STATUS_ATT_UNSEEN:
1232 target_stat.message_unseen = status_info->st_value; 1232 target_stat.message_unseen = status_info->st_value;
1233 break; 1233 break;
1234 } 1234 }
1235 } 1235 }
1236 } else { 1236 } else {
1237 // odebug << "Error retrieving status" << oendl; 1237 // odebug << "Error retrieving status" << oendl;
1238 } 1238 }
1239 if (status) mailimap_mailbox_data_status_free(status); 1239 if (status) mailimap_mailbox_data_status_free(status);
1240 if (att_list) mailimap_status_att_list_free(att_list); 1240 if (att_list) mailimap_status_att_list_free(att_list);
1241} 1241}
1242 1242
1243void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1243void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1244{ 1244{
1245 login(); 1245 login();
1246 if (!m_imap) return; 1246 if (!m_imap) return;
1247 if (!msg) return; 1247 if (!msg) return;
1248 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1248 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1249 if (r != MAILIMAP_NO_ERROR) { 1249 if (r != MAILIMAP_NO_ERROR) {
1250 Global::statusMessage("Error storing mail!"); 1250 Global::statusMessage("Error storing mail!");
1251 } 1251 }
1252} 1252}
1253 1253
1254MAILLIB::ATYPE IMAPwrapper::getType()const 1254MAILLIB::ATYPE IMAPwrapper::getType()const
1255{ 1255{
1256 return account->getType(); 1256 return account->getType();
1257} 1257}
1258 1258
1259const QString&IMAPwrapper::getName()const 1259const QString&IMAPwrapper::getName()const
1260{ 1260{
1261 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1261 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1262 return account->getAccountName(); 1262 return account->getAccountName();
1263} 1263}
1264 1264
1265encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1265encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1266{ 1266{
1267 // dummy 1267 // dummy
1268 QValueList<int> path; 1268 QValueList<int> path;
1269 return fetchRawPart(mail,path,false); 1269 return fetchRawPart(mail,path,false);
1270} 1270}
1271 1271
1272void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1272void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1273 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1273 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1274{ 1274{
1275 if (targetWrapper != this || maxSizeInKb > 0 ) { 1275 if (targetWrapper != this || maxSizeInKb > 0 ) {
1276 mMax = 0; 1276 mMax = 0;
1277 progress( tr("Copy")); 1277 progress( i18n("Copy"));
1278 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1278 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1279 //qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1279 //qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1280 // odebug << "Using generic" << oendl; 1280 // odebug << "Using generic" << oendl;
1281 return; 1281 return;
1282 } 1282 }
1283 mailimap_set *set = 0; 1283 mailimap_set *set = 0;
1284 login(); 1284 login();
1285 if (!m_imap) { 1285 if (!m_imap) {
1286 return; 1286 return;
1287 } 1287 }
1288 int err = selectMbox(fromFolder->getName()); 1288 int err = selectMbox(fromFolder->getName());
1289 if ( err != MAILIMAP_NO_ERROR ) { 1289 if ( err != MAILIMAP_NO_ERROR ) {
1290 return; 1290 return;
1291 } 1291 }
1292 Global::statusMessage( tr("Copying mails on server...") ); 1292 Global::statusMessage( i18n("Copying mails on server...") );
1293 int last = m_imap->imap_selection_info->sel_exists; 1293 int last = m_imap->imap_selection_info->sel_exists;
1294 set = mailimap_set_new_interval( 1, last ); 1294 set = mailimap_set_new_interval( 1, last );
1295 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1295 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1296 mailimap_set_free( set ); 1296 mailimap_set_free( set );
1297 if ( err != MAILIMAP_NO_ERROR ) { 1297 if ( err != MAILIMAP_NO_ERROR ) {
1298 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); 1298 QString error_msg = i18n("Error copy mails: %1").arg(m_imap->imap_response);
1299 Global::statusMessage(error_msg); 1299 Global::statusMessage(error_msg);
1300 // odebug << error_msg << oendl; 1300 // odebug << error_msg << oendl;
1301 return; 1301 return;
1302 } 1302 }
1303 if (moveit) { 1303 if (moveit) {
1304 deleteAllMail(fromFolder); 1304 deleteAllMail(fromFolder);
1305 } 1305 }
1306} 1306}
1307 1307
1308void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1308void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1309{ 1309{
1310 if (targetWrapper != this) { 1310 if (targetWrapper != this) {
1311 // odebug << "Using generic" << oendl; 1311 // odebug << "Using generic" << oendl;
1312 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1312 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1313 return; 1313 return;
1314 } 1314 }
1315 mailimap_set *set = 0; 1315 mailimap_set *set = 0;
1316 login(); 1316 login();
1317 if (!m_imap) { 1317 if (!m_imap) {
1318 return; 1318 return;
1319 } 1319 }
1320 int err = selectMbox(mail->getMbox()); 1320 int err = selectMbox(mail->getMbox());
1321 if ( err != MAILIMAP_NO_ERROR ) { 1321 if ( err != MAILIMAP_NO_ERROR ) {
1322 return; 1322 return;
1323 } 1323 }
1324 set = mailimap_set_new_single(mail->getNumber()); 1324 set = mailimap_set_new_single(mail->getNumber());
1325 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1325 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1326 mailimap_set_free( set ); 1326 mailimap_set_free( set );
1327 if ( err != MAILIMAP_NO_ERROR ) { 1327 if ( err != MAILIMAP_NO_ERROR ) {
1328 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1328 QString error_msg = i18n("error copy mail: %1").arg(m_imap->imap_response);
1329 Global::statusMessage(error_msg); 1329 Global::statusMessage(error_msg);
1330 // odebug << error_msg << oendl; 1330 // odebug << error_msg << oendl;
1331 return; 1331 return;
1332 } 1332 }
1333 if (moveit) { 1333 if (moveit) {
1334 deleteMail(mail); 1334 deleteMail(mail);
1335 } 1335 }
1336} 1336}
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp
index 39dd156..0cdbae4 100644
--- a/kmicromail/libmailwrapper/mboxwrapper.cpp
+++ b/kmicromail/libmailwrapper/mboxwrapper.cpp
@@ -1,338 +1,339 @@
1#include "mboxwrapper.h" 1#include "mboxwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <klocale.h>
7 8
8 9
9#include <qpe/global.h> 10#include <qpe/global.h>
10 11
11using namespace Opie::Core; 12using namespace Opie::Core;
12MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) 13MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name)
13 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) 14 : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name)
14{ 15{
15 QDir dir(MBOXPath); 16 QDir dir(MBOXPath);
16 if (!dir.exists()) { 17 if (!dir.exists()) {
17 dir.mkdir(MBOXPath); 18 dir.mkdir(MBOXPath);
18 } 19 }
19} 20}
20 21
21MBOXwrapper::~MBOXwrapper() 22MBOXwrapper::~MBOXwrapper()
22{ 23{
23} 24}
24 25
25void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) 26void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target )
26{ 27{
27 mailstorage*storage = mailstorage_new(NULL); 28 mailstorage*storage = mailstorage_new(NULL);
28 QString p = MBOXPath+"/"; 29 QString p = MBOXPath+"/";
29 p+=mailbox; 30 p+=mailbox;
30 31
31 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 32 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
32 mailfolder*folder; 33 mailfolder*folder;
33 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 34 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
34 r = mailfolder_connect(folder); 35 r = mailfolder_connect(folder);
35 if (r != MAIL_NO_ERROR) { 36 if (r != MAIL_NO_ERROR) {
36 //odebug << "Error initializing mbox" << oendl; 37 //odebug << "Error initializing mbox" << oendl;
37 mailfolder_free(folder); 38 mailfolder_free(folder);
38 mailstorage_free(storage); 39 mailstorage_free(storage);
39 return; 40 return;
40 } 41 }
41 42
42 parseList(target,folder->fld_session,mailbox); 43 parseList(target,folder->fld_session,mailbox);
43 44
44 mailfolder_disconnect(folder); 45 mailfolder_disconnect(folder);
45 mailfolder_free(folder); 46 mailfolder_free(folder);
46 mailstorage_free(storage); 47 mailstorage_free(storage);
47 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 48 Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count()));
48} 49}
49 50
50QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() 51QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders()
51{ 52{
52 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 53 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
53 QDir dir(MBOXPath); 54 QDir dir(MBOXPath);
54 if (!dir.exists()) return folders; 55 if (!dir.exists()) return folders;
55 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); 56 dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
56 QStringList entries = dir.entryList(); 57 QStringList entries = dir.entryList();
57 QStringList::ConstIterator it = entries.begin(); 58 QStringList::ConstIterator it = entries.begin();
58 for (;it!=entries.end();++it) { 59 for (;it!=entries.end();++it) {
59 FolderP inb=new Folder(*it,"/"); 60 FolderP inb=new Folder(*it,"/");
60 folders->append(inb); 61 folders->append(inb);
61 } 62 }
62 return folders; 63 return folders;
63} 64}
64 65
65void MBOXwrapper::deleteMail(const RecMailP & mail) 66void MBOXwrapper::deleteMail(const RecMailP & mail)
66{ 67{
67 mailstorage*storage = mailstorage_new(NULL); 68 mailstorage*storage = mailstorage_new(NULL);
68 QString p = MBOXPath+"/"; 69 QString p = MBOXPath+"/";
69 p+=mail->getMbox(); 70 p+=mail->getMbox();
70 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 71 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
71 mailfolder*folder; 72 mailfolder*folder;
72 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 73 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
73 r = mailfolder_connect(folder); 74 r = mailfolder_connect(folder);
74 if (r != MAIL_NO_ERROR) { 75 if (r != MAIL_NO_ERROR) {
75 ; // << "Error initializing mbox" << oendl; 76 ; // << "Error initializing mbox" << oendl;
76 mailfolder_free(folder); 77 mailfolder_free(folder);
77 mailstorage_free(storage); 78 mailstorage_free(storage);
78 return; 79 return;
79 } 80 }
80 r = mailsession_remove_message(folder->fld_session,mail->getNumber()); 81 r = mailsession_remove_message(folder->fld_session,mail->getNumber());
81 if (r != MAIL_NO_ERROR) { 82 if (r != MAIL_NO_ERROR) {
82 ; // << "error deleting mail" << oendl; 83 ; // << "error deleting mail" << oendl;
83 } 84 }
84 mailfolder_free(folder); 85 mailfolder_free(folder);
85 mailstorage_free(storage); 86 mailstorage_free(storage);
86} 87}
87 88
88void MBOXwrapper::answeredMail(const RecMailP&) 89void MBOXwrapper::answeredMail(const RecMailP&)
89{ 90{
90} 91}
91 92
92RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail ) 93RecBodyP MBOXwrapper::fetchBody( const RecMailP &mail )
93{ 94{
94 RecBodyP body = new RecBody(); 95 RecBodyP body = new RecBody();
95 mailstorage*storage = mailstorage_new(NULL); 96 mailstorage*storage = mailstorage_new(NULL);
96 QString p = MBOXPath+"/"; 97 QString p = MBOXPath+"/";
97 p+=mail->getMbox(); 98 p+=mail->getMbox();
98 mailmessage * msg; 99 mailmessage * msg;
99 char*data=0; 100 char*data=0;
100 size_t size; 101 size_t size;
101 102
102 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 103 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
103 mailfolder*folder; 104 mailfolder*folder;
104 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 105 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
105 r = mailfolder_connect(folder); 106 r = mailfolder_connect(folder);
106 if (r != MAIL_NO_ERROR) { 107 if (r != MAIL_NO_ERROR) {
107 ; // << "Error initializing mbox" << oendl; 108 ; // << "Error initializing mbox" << oendl;
108 mailfolder_free(folder); 109 mailfolder_free(folder);
109 mailstorage_free(storage); 110 mailstorage_free(storage);
110 return body; 111 return body;
111 } 112 }
112 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 113 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
113 if (r != MAIL_NO_ERROR) { 114 if (r != MAIL_NO_ERROR) {
114 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 115 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
115 mailfolder_free(folder); 116 mailfolder_free(folder);
116 mailstorage_free(storage); 117 mailstorage_free(storage);
117 return body; 118 return body;
118 } 119 }
119 r = mailmessage_fetch(msg,&data,&size); 120 r = mailmessage_fetch(msg,&data,&size);
120 if (r != MAIL_NO_ERROR) { 121 if (r != MAIL_NO_ERROR) {
121 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl; 122 ; // << "Error fetching mail " << mail->getNumber() << "" << oendl;
122 mailfolder_free(folder); 123 mailfolder_free(folder);
123 mailstorage_free(storage); 124 mailstorage_free(storage);
124 mailmessage_free(msg); 125 mailmessage_free(msg);
125 return body; 126 return body;
126 } 127 }
127 body = parseMail(msg); 128 body = parseMail(msg);
128 mailmessage_fetch_result_free(msg,data); 129 mailmessage_fetch_result_free(msg,data);
129 mailfolder_free(folder); 130 mailfolder_free(folder);
130 mailstorage_free(storage); 131 mailstorage_free(storage);
131 132
132 return body; 133 return body;
133} 134}
134 135
135void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) 136void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
136{ 137{
137 ; // << "MBOX " << current << " von " << maximum << "" << oendl; 138 ; // << "MBOX " << current << " von " << maximum << "" << oendl;
138} 139}
139 140
140int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool ) 141int MBOXwrapper::createMbox(const QString&folder,const FolderP&,const QString&,bool )
141{ 142{
142 QString p = MBOXPath+"/"; 143 QString p = MBOXPath+"/";
143 p+=folder; 144 p+=folder;
144 QFileInfo fi(p); 145 QFileInfo fi(p);
145 if (fi.exists()) { 146 if (fi.exists()) {
146 Global::statusMessage(tr("Mailbox exists.")); 147 Global::statusMessage(i18n("Mailbox exists."));
147 return 0; 148 return 0;
148 } 149 }
149 mailmbox_folder*f = 0; 150 mailmbox_folder*f = 0;
150 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { 151 if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
151 Global::statusMessage(tr("Error init folder")); 152 Global::statusMessage(i18n("Error init folder"));
152 return 0; 153 return 0;
153 } 154 }
154 if (f) mailmbox_done(f); 155 if (f) mailmbox_done(f);
155 return 1; 156 return 1;
156} 157}
157 158
158void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 159void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
159{ 160{
160 QString p = MBOXPath+"/"; 161 QString p = MBOXPath+"/";
161 p+=folder; 162 p+=folder;
162 mailmbox_folder*f = 0; 163 mailmbox_folder*f = 0;
163 int r = mailmbox_init(p.latin1(),0,1,0,&f); 164 int r = mailmbox_init(p.latin1(),0,1,0,&f);
164 if (r != MAIL_NO_ERROR) { 165 if (r != MAIL_NO_ERROR) {
165 Global::statusMessage(tr("Error init folder")); 166 Global::statusMessage(i18n("Error init folder"));
166 return; 167 return;
167 } 168 }
168 r = mailmbox_append_message(f,msg,length); 169 r = mailmbox_append_message(f,msg,length);
169 if (r != MAIL_NO_ERROR) { 170 if (r != MAIL_NO_ERROR) {
170 Global::statusMessage(tr("Error writing to message folder")); 171 Global::statusMessage(i18n("Error writing to message folder"));
171 } 172 }
172 mailmbox_done(f); 173 mailmbox_done(f);
173} 174}
174 175
175encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) 176encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail)
176{ 177{
177 RecBody body; 178 RecBody body;
178 mailstorage*storage = mailstorage_new(NULL); 179 mailstorage*storage = mailstorage_new(NULL);
179 QString p = MBOXPath+"/"; 180 QString p = MBOXPath+"/";
180 p+=mail->getMbox(); 181 p+=mail->getMbox();
181 mailmessage * msg; 182 mailmessage * msg;
182 char*data=0; 183 char*data=0;
183 size_t size; 184 size_t size;
184 185
185 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 186 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
186 mailfolder*folder; 187 mailfolder*folder;
187 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 188 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
188 r = mailfolder_connect(folder); 189 r = mailfolder_connect(folder);
189 if (r != MAIL_NO_ERROR) { 190 if (r != MAIL_NO_ERROR) {
190 Global::statusMessage(tr("Error initializing mbox")); 191 Global::statusMessage(i18n("Error initializing mbox"));
191 mailfolder_free(folder); 192 mailfolder_free(folder);
192 mailstorage_free(storage); 193 mailstorage_free(storage);
193 return 0; 194 return 0;
194 } 195 }
195 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); 196 r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg);
196 if (r != MAIL_NO_ERROR) { 197 if (r != MAIL_NO_ERROR) {
197 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 198 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
198 mailfolder_free(folder); 199 mailfolder_free(folder);
199 mailstorage_free(storage); 200 mailstorage_free(storage);
200 return 0; 201 return 0;
201 } 202 }
202 r = mailmessage_fetch(msg,&data,&size); 203 r = mailmessage_fetch(msg,&data,&size);
203 if (r != MAIL_NO_ERROR) { 204 if (r != MAIL_NO_ERROR) {
204 Global::statusMessage(tr("Error fetching mail %i").arg(mail->getNumber())); 205 Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber()));
205 mailfolder_free(folder); 206 mailfolder_free(folder);
206 mailstorage_free(storage); 207 mailstorage_free(storage);
207 mailmessage_free(msg); 208 mailmessage_free(msg);
208 return 0; 209 return 0;
209 } 210 }
210 encodedString*result = new encodedString(data,size); 211 encodedString*result = new encodedString(data,size);
211 212
212 mailfolder_free(folder); 213 mailfolder_free(folder);
213 mailstorage_free(storage); 214 mailstorage_free(storage);
214 mailmessage_free(msg); 215 mailmessage_free(msg);
215 return result; 216 return result;
216} 217}
217 218
218void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) 219void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target)
219{ 220{
220 QString p = MBOXPath+"/"; 221 QString p = MBOXPath+"/";
221 p+=mailbox; 222 p+=mailbox;
222 mailmbox_folder*f = 0; 223 mailmbox_folder*f = 0;
223 int r = mailmbox_init(p.latin1(),0,1,0,&f); 224 int r = mailmbox_init(p.latin1(),0,1,0,&f);
224 if (r != MAIL_NO_ERROR) { 225 if (r != MAIL_NO_ERROR) {
225 ; // << "Error init folder" << oendl; 226 ; // << "Error init folder" << oendl;
226 return; 227 return;
227 } 228 }
228 deleteMails(f,target); 229 deleteMails(f,target);
229 mailmbox_done(f); 230 mailmbox_done(f);
230} 231}
231 232
232void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) 233void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target)
233{ 234{
234 if (!f) return; 235 if (!f) return;
235 int r; 236 int r;
236 QValueList<RecMailP>::ConstIterator it; 237 QValueList<RecMailP>::ConstIterator it;
237 for (it=target.begin(); it != target.end();++it) { 238 for (it=target.begin(); it != target.end();++it) {
238 r = mailmbox_delete_msg(f,(*it)->getNumber()); 239 r = mailmbox_delete_msg(f,(*it)->getNumber());
239 if (r!=MAILMBOX_NO_ERROR) { 240 if (r!=MAILMBOX_NO_ERROR) {
240 ; // << "error delete mail" << oendl; 241 ; // << "error delete mail" << oendl;
241 } 242 }
242 } 243 }
243 r = mailmbox_expunge(f); 244 r = mailmbox_expunge(f);
244 if (r != MAILMBOX_NO_ERROR) { 245 if (r != MAILMBOX_NO_ERROR) {
245 ; // << "error expunge mailbox" << oendl; 246 ; // << "error expunge mailbox" << oendl;
246 } 247 }
247} 248}
248 249
249int MBOXwrapper::deleteAllMail(const FolderP&tfolder) 250int MBOXwrapper::deleteAllMail(const FolderP&tfolder)
250{ 251{
251 if (!tfolder) return 0; 252 if (!tfolder) return 0;
252 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 253 QString p = MBOXPath+"/"+tfolder->getDisplayName();
253 int res = 1; 254 int res = 1;
254 255
255 mailfolder*folder = 0; 256 mailfolder*folder = 0;
256 mailmessage_list*l=0; 257 mailmessage_list*l=0;
257 mailstorage*storage = mailstorage_new(NULL); 258 mailstorage*storage = mailstorage_new(NULL);
258 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 259 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
259 if (r != MAIL_NO_ERROR) { 260 if (r != MAIL_NO_ERROR) {
260 Global::statusMessage(tr("Error initializing mbox")); 261 Global::statusMessage(i18n("Error initializing mbox"));
261 res = 0; 262 res = 0;
262 } 263 }
263 if (res) { 264 if (res) {
264 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 265 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
265 r = mailfolder_connect(folder); 266 r = mailfolder_connect(folder);
266 if (r != MAIL_NO_ERROR) { 267 if (r != MAIL_NO_ERROR) {
267 Global::statusMessage(tr("Error initializing mbox")); 268 Global::statusMessage(i18n("Error initializing mbox"));
268 res = 0; 269 res = 0;
269 } 270 }
270 } 271 }
271 if (res) { 272 if (res) {
272 r = mailsession_get_messages_list(folder->fld_session,&l); 273 r = mailsession_get_messages_list(folder->fld_session,&l);
273 if (r != MAIL_NO_ERROR) { 274 if (r != MAIL_NO_ERROR) {
274 ; // << "Error message list" << oendl; 275 ; // << "Error message list" << oendl;
275 res=0; 276 res=0;
276 } 277 }
277 } 278 }
278 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 279 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
279 r = mailsession_remove_message(folder->fld_session,i+1); 280 r = mailsession_remove_message(folder->fld_session,i+1);
280 if (r != MAIL_NO_ERROR) { 281 if (r != MAIL_NO_ERROR) {
281 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 282 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
282 res = 0; 283 res = 0;
283 break; 284 break;
284 } 285 }
285 } 286 }
286 if (l) mailmessage_list_free(l); 287 if (l) mailmessage_list_free(l);
287 if (folder) mailfolder_free(folder); 288 if (folder) mailfolder_free(folder);
288 if (storage) mailstorage_free(storage); 289 if (storage) mailstorage_free(storage);
289 return res; 290 return res;
290} 291}
291 292
292int MBOXwrapper::deleteMbox(const FolderP&tfolder) 293int MBOXwrapper::deleteMbox(const FolderP&tfolder)
293{ 294{
294 if (!tfolder) return 0; 295 if (!tfolder) return 0;
295 QString p = MBOXPath+"/"+tfolder->getDisplayName(); 296 QString p = MBOXPath+"/"+tfolder->getDisplayName();
296 QFile fi(p); 297 QFile fi(p);
297 if (!fi.exists()) { 298 if (!fi.exists()) {
298 Global::statusMessage(tr("Mailbox doesn't exist.")); 299 Global::statusMessage(i18n("Mailbox doesn't exist."));
299 return 0; 300 return 0;
300 } 301 }
301 if (!fi.remove()) { 302 if (!fi.remove()) {
302 Global::statusMessage(tr("Error deleting Mailbox.")); 303 Global::statusMessage(i18n("Error deleting Mailbox."));
303 return 0; 304 return 0;
304 } 305 }
305 return 1; 306 return 1;
306} 307}
307 308
308void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 309void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
309{ 310{
310 mailfolder*folder = 0; 311 mailfolder*folder = 0;
311 mailstorage*storage = mailstorage_new(NULL); 312 mailstorage*storage = mailstorage_new(NULL);
312 target_stat.message_count = 0; 313 target_stat.message_count = 0;
313 target_stat.message_unseen = 0; 314 target_stat.message_unseen = 0;
314 target_stat.message_recent = 0; 315 target_stat.message_recent = 0;
315 QString p = MBOXPath+"/"+mailbox; 316 QString p = MBOXPath+"/"+mailbox;
316 QFile fi(p); 317 QFile fi(p);
317 if (!fi.exists()) { 318 if (!fi.exists()) {
318 Global::statusMessage(tr("Mailbox doesn't exist.")); 319 Global::statusMessage(i18n("Mailbox doesn't exist."));
319 return; 320 return;
320 } 321 }
321 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); 322 int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
322 folder = mailfolder_new( storage,(char*)p.latin1(),NULL); 323 folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
323 r = mailfolder_connect(folder); 324 r = mailfolder_connect(folder);
324 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, 325 r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count,
325 &target_stat.message_recent,&target_stat.message_unseen); 326 &target_stat.message_recent,&target_stat.message_unseen);
326 if (folder) mailfolder_free(folder); 327 if (folder) mailfolder_free(folder);
327 if (storage) mailstorage_free(storage); 328 if (storage) mailstorage_free(storage);
328} 329}
329 330
330MAILLIB::ATYPE MBOXwrapper::getType()const 331MAILLIB::ATYPE MBOXwrapper::getType()const
331{ 332{
332 return MAILLIB::A_MBOX; 333 return MAILLIB::A_MBOX;
333} 334}
334 335
335const QString&MBOXwrapper::getName()const 336const QString&MBOXwrapper::getName()const
336{ 337{
337 return MBOXName; 338 return MBOXName;
338} 339}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 9d52f52..2888f7c 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,302 +1,303 @@
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 9
9#include <qpe/global.h> 10#include <qpe/global.h>
10#include <qfile.h> 11#include <qfile.h>
11#include <qprogressbar.h> 12#include <qprogressbar.h>
12#include <qapplication.h> 13#include <qapplication.h>
13 14
14/* we don't fetch messages larger than 5 MB */ 15/* we don't fetch messages larger than 5 MB */
15#define HARD_MSG_SIZE_LIMIT 5242880 16#define HARD_MSG_SIZE_LIMIT 5242880
16 17
17using namespace Opie::Core; 18using namespace Opie::Core;
18POP3wrapper::POP3wrapper( POP3account *a ) 19POP3wrapper::POP3wrapper( POP3account *a )
19: Genericwrapper() { 20: Genericwrapper() {
20 account = a; 21 account = a;
21 m_pop3 = NULL; 22 m_pop3 = NULL;
22 msgTempName = a->getFileName()+"_msg_cache"; 23 msgTempName = a->getFileName()+"_msg_cache";
23 last_msg_id = 0; 24 last_msg_id = 0;
24} 25}
25 26
26POP3wrapper::~POP3wrapper() { 27POP3wrapper::~POP3wrapper() {
27 logout(); 28 logout();
28 QFile msg_cache(msgTempName); 29 QFile msg_cache(msgTempName);
29 if (msg_cache.exists()) { 30 if (msg_cache.exists()) {
30 msg_cache.remove(); 31 msg_cache.remove();
31 } 32 }
32} 33}
33 34
34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 35void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 36 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
36} 37}
37 38
38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 39RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
39 int err = MAILPOP3_NO_ERROR; 40 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 41 char *message = 0;
41 size_t length = 0; 42 size_t length = 0;
42 43
43 RecBodyP body = new RecBody(); 44 RecBodyP body = new RecBody();
44 45
45 login(); 46 login();
46 if ( !m_pop3 ) { 47 if ( !m_pop3 ) {
47 return body; 48 return body;
48 } 49 }
49 50
50 mailmessage * mailmsg; 51 mailmessage * mailmsg;
51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 52 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 53 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
53 return body; 54 return body;
54 } 55 }
55 56
56 QFile msg_cache(msgTempName); 57 QFile msg_cache(msgTempName);
57 58
58 cleanMimeCache(); 59 cleanMimeCache();
59 60
60 if (mail->getNumber()!=last_msg_id) { 61 if (mail->getNumber()!=last_msg_id) {
61 if (msg_cache.exists()) { 62 if (msg_cache.exists()) {
62 msg_cache.remove(); 63 msg_cache.remove();
63 } 64 }
64 msg_cache.open(IO_ReadWrite|IO_Truncate); 65 msg_cache.open(IO_ReadWrite|IO_Truncate);
65 last_msg_id = mail->getNumber(); 66 last_msg_id = mail->getNumber();
66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 67 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
67 err = mailmessage_fetch(mailmsg,&message,&length); 68 err = mailmessage_fetch(mailmsg,&message,&length);
68 msg_cache.writeBlock(message,length); 69 msg_cache.writeBlock(message,length);
69 } else { 70 } else {
70 QString msg=""; 71 QString msg="";
71 msg_cache.open(IO_ReadOnly); 72 msg_cache.open(IO_ReadOnly);
72 message = new char[4096]; 73 message = new char[4096];
73 memset(message,0,4096); 74 memset(message,0,4096);
74 while (msg_cache.readBlock(message,4095)>0) { 75 while (msg_cache.readBlock(message,4095)>0) {
75 msg+=message; 76 msg+=message;
76 memset(message,0,4096); 77 memset(message,0,4096);
77 } 78 }
78 delete message; 79 delete message;
79 message = (char*)malloc(msg.length()+1*sizeof(char)); 80 message = (char*)malloc(msg.length()+1*sizeof(char));
80 memset(message,0,msg.length()+1); 81 memset(message,0,msg.length()+1);
81 memcpy(message,msg.latin1(),msg.length()); 82 memcpy(message,msg.latin1(),msg.length());
82 /* transform to libetpan stuff */ 83 /* transform to libetpan stuff */
83 mailmsg = mailmessage_new(); 84 mailmsg = mailmessage_new();
84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 85 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
85 generic_message_t * msg_data; 86 generic_message_t * msg_data;
86 msg_data = (generic_message_t *)mailmsg->msg_data; 87 msg_data = (generic_message_t *)mailmsg->msg_data;
87 msg_data->msg_fetched = 1; 88 msg_data->msg_fetched = 1;
88 msg_data->msg_message = message; 89 msg_data->msg_message = message;
89 msg_data->msg_length = strlen(message); 90 msg_data->msg_length = strlen(message);
90 } 91 }
91 body = parseMail(mailmsg); 92 body = parseMail(mailmsg);
92 93
93 /* clean up */ 94 /* clean up */
94 if (mailmsg) 95 if (mailmsg)
95 mailmessage_free(mailmsg); 96 mailmessage_free(mailmsg);
96 if (message) 97 if (message)
97 free(message); 98 free(message);
98 99
99 return body; 100 return body;
100} 101}
101 102
102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 103void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
103{ 104{
104 login(); 105 login();
105 if (!m_pop3) 106 if (!m_pop3)
106 return; 107 return;
107 uint32_t res_messages,res_recent,res_unseen; 108 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 109 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 110 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 111 Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages));
111} 112}
112 113
113void POP3wrapper::login() 114void POP3wrapper::login()
114{ 115{
115 if (account->getOffline()) 116 if (account->getOffline())
116 return; 117 return;
117 /* we'll hold the line */ 118 /* we'll hold the line */
118 if ( m_pop3 != NULL ) 119 if ( m_pop3 != NULL )
119 return; 120 return;
120 121
121 QString server,user, pass; 122 QString server,user, pass;
122 uint16_t port; 123 uint16_t port;
123 int err = MAILPOP3_NO_ERROR; 124 int err = MAILPOP3_NO_ERROR;
124 125
125 server = account->getServer(); 126 server = account->getServer();
126 port = account->getPort().toUInt(); 127 port = account->getPort().toUInt();
127 128
128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 129 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
129 qApp->processEvents(); 130 qApp->processEvents();
130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 131 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
131 login.show(); 132 login.show();
132 if ( QDialog::Accepted == login.exec() ) { 133 if ( QDialog::Accepted == login.exec() ) {
133 // ok 134 // ok
134 user = login.getUser(); 135 user = login.getUser();
135 pass = login.getPassword(); 136 pass = login.getPassword();
136 } else { 137 } else {
137 // cancel 138 // cancel
138 ; // odebug << "POP3: Login canceled" << oendl; 139 ; // odebug << "POP3: Login canceled" << oendl;
139 return; 140 return;
140 } 141 }
141 } else { 142 } else {
142 user = account->getUser(); 143 user = account->getUser();
143 pass = account->getPassword(); 144 pass = account->getPassword();
144 } 145 }
145 // bool ssl = account->getSSL(); 146 // bool ssl = account->getSSL();
146 147
147 m_pop3=mailstorage_new(NULL); 148 m_pop3=mailstorage_new(NULL);
148 int conntypeset = account->ConnectionType(); 149 int conntypeset = account->ConnectionType();
149 int conntype = 0; 150 int conntype = 0;
150 if ( conntypeset == 3 ) { 151 if ( conntypeset == 3 ) {
151 conntype = CONNECTION_TYPE_COMMAND; 152 conntype = CONNECTION_TYPE_COMMAND;
152 } else if ( conntypeset == 2 ) { 153 } else if ( conntypeset == 2 ) {
153 conntype = CONNECTION_TYPE_TLS; 154 conntype = CONNECTION_TYPE_TLS;
154 } else if ( conntypeset == 1 ) { 155 } else if ( conntypeset == 1 ) {
155 conntype = CONNECTION_TYPE_STARTTLS; 156 conntype = CONNECTION_TYPE_STARTTLS;
156 } else if ( conntypeset == 0 ) { 157 } else if ( conntypeset == 0 ) {
157 conntype = CONNECTION_TYPE_TRY_STARTTLS; 158 conntype = CONNECTION_TYPE_TRY_STARTTLS;
158 } 159 }
159 160
160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
161 162
162 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 163 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
163 (char*)user.latin1(),(char*)pass.latin1(),0,0,0); 164 (char*)user.latin1(),(char*)pass.latin1(),0,0,0);
164 165
165 err = mailstorage_connect(m_pop3); 166 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 167 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 168 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error %1 initializing folder").arg( err )); 169 Global::statusMessage(i18n("Error %1 initializing folder").arg( err ));
169 mailstorage_free(m_pop3); 170 mailstorage_free(m_pop3);
170 m_pop3 = 0; 171 m_pop3 = 0;
171 } else { 172 } else {
172 mailsession * session = m_pop3->sto_session; 173 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 174 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 175 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 176 mail->pop3_progr_fun = &pop3_progress;
176 } 177 }
177 } 178 }
178} 179}
179 180
180void POP3wrapper::logout() 181void POP3wrapper::logout()
181{ 182{
182 if ( m_pop3 == NULL ) 183 if ( m_pop3 == NULL )
183 return; 184 return;
184 mailstorage_free(m_pop3); 185 mailstorage_free(m_pop3);
185 m_pop3 = 0; 186 m_pop3 = 0;
186} 187}
187 188
188 189
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 190QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 191 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 192 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 193 folders->append(inb);
193 return folders; 194 return folders;
194} 195}
195 196
196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) 197void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 198{
198 login(); 199 login();
199 if (!m_pop3) 200 if (!m_pop3)
200 return; 201 return;
201 int iii = 0; 202 int iii = 0;
202 int count = target.count(); 203 int count = target.count();
203 204
204 QProgressBar wid ( count ); 205 QProgressBar wid ( count );
205 wid.setCaption( tr("Deleting ...")); 206 wid.setCaption( i18n("Deleting ..."));
206 wid.show(); 207 wid.show();
207 while (iii < count ) { 208 while (iii < count ) {
208 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 209 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
209 wid.setProgress( iii ); 210 wid.setProgress( iii );
210 wid.raise(); 211 wid.raise();
211 qApp->processEvents(); 212 qApp->processEvents();
212 //qDebug("delete "); 213 //qDebug("delete ");
213 RecMailP mail = (*target.at( iii )); 214 RecMailP mail = (*target.at( iii ));
214 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 215 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
215 if (err != MAIL_NO_ERROR) { 216 if (err != MAIL_NO_ERROR) {
216 Global::statusMessage(tr("Error deleting mail")); 217 Global::statusMessage(i18n("Error deleting mail"));
217 } 218 }
218 ++iii; 219 ++iii;
219 } 220 }
220} 221}
221void POP3wrapper::deleteMail(const RecMailP&mail) { 222void POP3wrapper::deleteMail(const RecMailP&mail) {
222 login(); 223 login();
223 if (!m_pop3) 224 if (!m_pop3)
224 return; 225 return;
225 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
226 if (err != MAIL_NO_ERROR) { 227 if (err != MAIL_NO_ERROR) {
227 Global::statusMessage(tr("error deleting mail")); 228 Global::statusMessage(i18n("error deleting mail"));
228 } 229 }
229} 230}
230 231
231void POP3wrapper::answeredMail(const RecMailP&) {} 232void POP3wrapper::answeredMail(const RecMailP&) {}
232 233
233int POP3wrapper::deleteAllMail(const FolderP&) { 234int POP3wrapper::deleteAllMail(const FolderP&) {
234 login(); 235 login();
235 if (!m_pop3) 236 if (!m_pop3)
236 return 0; 237 return 0;
237 int res = 1; 238 int res = 1;
238 239
239 uint32_t result = 0; 240 uint32_t result = 0;
240 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 241 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
241 if (err != MAIL_NO_ERROR) { 242 if (err != MAIL_NO_ERROR) {
242 Global::statusMessage(tr("Error getting folder info")); 243 Global::statusMessage(i18n("Error getting folder info"));
243 return 0; 244 return 0;
244 } 245 }
245 246
246 247
247 248
248 QProgressBar wid ( result ); 249 QProgressBar wid ( result );
249 wid.setCaption( tr("Deleting ...")); 250 wid.setCaption( i18n("Deleting ..."));
250 wid.show(); 251 wid.show();
251 for (unsigned int i = 0; i < result; ++i) { 252 for (unsigned int i = 0; i < result; ++i) {
252 Global::statusMessage(tr("Delete message %1 of %2").arg(i).arg(result)); 253 Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result));
253 wid.setProgress( i ); 254 wid.setProgress( i );
254 wid.raise(); 255 wid.raise();
255 qApp->processEvents(); 256 qApp->processEvents();
256 257
257 err = mailsession_remove_message(m_pop3->sto_session,i+1); 258 err = mailsession_remove_message(m_pop3->sto_session,i+1);
258 if (err != MAIL_NO_ERROR) { 259 if (err != MAIL_NO_ERROR) {
259 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 260 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
260 res=0; 261 res=0;
261 } 262 }
262 break; 263 break;
263 } 264 }
264 return res; 265 return res;
265} 266}
266 267
267void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 268void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
268 login(); 269 login();
269 target_stat.message_count = 0; 270 target_stat.message_count = 0;
270 target_stat.message_unseen = 0; 271 target_stat.message_unseen = 0;
271 target_stat.message_recent = 0; 272 target_stat.message_recent = 0;
272 if (!m_pop3) 273 if (!m_pop3)
273 return; 274 return;
274 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 275 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
275 &target_stat.message_recent,&target_stat.message_unseen); 276 &target_stat.message_recent,&target_stat.message_unseen);
276 if (r != MAIL_NO_ERROR) { 277 if (r != MAIL_NO_ERROR) {
277 ; // odebug << "error getting folter status." << oendl; 278 ; // odebug << "error getting folter status." << oendl;
278 } 279 }
279} 280}
280 281
281encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 282encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
282 char*target=0; 283 char*target=0;
283 size_t length=0; 284 size_t length=0;
284 encodedString*res = 0; 285 encodedString*res = 0;
285 mailmessage * mailmsg = 0; 286 mailmessage * mailmsg = 0;
286 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 287 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
287 err = mailmessage_fetch(mailmsg,&target,&length); 288 err = mailmessage_fetch(mailmsg,&target,&length);
288 if (mailmsg) 289 if (mailmsg)
289 mailmessage_free(mailmsg); 290 mailmessage_free(mailmsg);
290 if (target) { 291 if (target) {
291 res = new encodedString(target,length); 292 res = new encodedString(target,length);
292 } 293 }
293 return res; 294 return res;
294} 295}
295 296
296MAILLIB::ATYPE POP3wrapper::getType()const { 297MAILLIB::ATYPE POP3wrapper::getType()const {
297 return account->getType(); 298 return account->getType();
298} 299}
299 300
300const QString&POP3wrapper::getName()const{ 301const QString&POP3wrapper::getName()const{
301 return account->getAccountName(); 302 return account->getAccountName();
302} 303}
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp
index d5a528c..dee1477 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.cpp
+++ b/kmicromail/libmailwrapper/smtpwrapper.cpp
@@ -1,460 +1,461 @@
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#include <stdlib.h> 12#include <stdlib.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/qcopenvelope_qws.h> 14#include <qpe/qcopenvelope_qws.h>
15 15
16#include <libetpan/libetpan.h> 16#include <libetpan/libetpan.h>
17#include <klocale.h>
17 18
18 19
19using namespace Opie::Core; 20using namespace Opie::Core;
20progressMailSend*SMTPwrapper::sendProgress = 0; 21progressMailSend*SMTPwrapper::sendProgress = 0;
21 22
22SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 23SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp )
23 : Generatemail() 24 : Generatemail()
24{ 25{
25 m_SmtpAccount = aSmtp; 26 m_SmtpAccount = aSmtp;
26 Config cfg( "mail" ); 27 Config cfg( "mail" );
27 cfg.setGroup( "Status" ); 28 cfg.setGroup( "Status" );
28 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 29 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
29 emit queuedMails( m_queuedMail ); 30 emit queuedMails( m_queuedMail );
30 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); 31 connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) );
31 m_smtp = 0; 32 m_smtp = 0;
32} 33}
33 34
34SMTPwrapper::~SMTPwrapper() 35SMTPwrapper::~SMTPwrapper()
35{ 36{
36 disc_server(); 37 disc_server();
37} 38}
38 39
39void SMTPwrapper::emitQCop( int queued ) { 40void SMTPwrapper::emitQCop( int queued ) {
40 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 41 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
41 env << queued; 42 env << queued;
42} 43}
43 44
44QString SMTPwrapper::mailsmtpError( int errnum ) { 45QString SMTPwrapper::mailsmtpError( int errnum ) {
45 switch ( errnum ) { 46 switch ( errnum ) {
46 case MAILSMTP_NO_ERROR: 47 case MAILSMTP_NO_ERROR:
47 return tr( "No error" ); 48 return i18n( "No error" );
48 case MAILSMTP_ERROR_UNEXPECTED_CODE: 49 case MAILSMTP_ERROR_UNEXPECTED_CODE:
49 return tr( "Unexpected error code" ); 50 return i18n( "Unexpected error code" );
50 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 51 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
51 return tr( "Service not available" ); 52 return i18n( "Service not available" );
52 case MAILSMTP_ERROR_STREAM: 53 case MAILSMTP_ERROR_STREAM:
53 return tr( "Stream error" ); 54 return i18n( "Stream error" );
54 case MAILSMTP_ERROR_HOSTNAME: 55 case MAILSMTP_ERROR_HOSTNAME:
55 return tr( "gethostname() failed" ); 56 return i18n( "gethostname() failed" );
56 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 57 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
57 return tr( "Not implemented" ); 58 return i18n( "Not implemented" );
58 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 59 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
59 return tr( "Error, action not taken" ); 60 return i18n( "Error, action not taken" );
60 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 61 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
61 return tr( "Data exceeds storage allocation" ); 62 return i18n( "Data exceeds storage allocation" );
62 case MAILSMTP_ERROR_IN_PROCESSING: 63 case MAILSMTP_ERROR_IN_PROCESSING:
63 return tr( "Error in processing" ); 64 return i18n( "Error in processing" );
64 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: 65 case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED:
65 return tr( "Starttls not supported" ); 66 return i18n( "Starttls not supported" );
66 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 67 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
67 // return tr( "Insufficient system storage" ); 68 // return i18n( "Insufficient system storage" );
68 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 69 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
69 return tr( "Mailbox unavailable" ); 70 return i18n( "Mailbox unavailable" );
70 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 71 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
71 return tr( "Mailbox name not allowed" ); 72 return i18n( "Mailbox name not allowed" );
72 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 73 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
73 return tr( "Bad command sequence" ); 74 return i18n( "Bad command sequence" );
74 case MAILSMTP_ERROR_USER_NOT_LOCAL: 75 case MAILSMTP_ERROR_USER_NOT_LOCAL:
75 return tr( "User not local" ); 76 return i18n( "User not local" );
76 case MAILSMTP_ERROR_TRANSACTION_FAILED: 77 case MAILSMTP_ERROR_TRANSACTION_FAILED:
77 return tr( "Transaction failed" ); 78 return i18n( "Transaction failed" );
78 case MAILSMTP_ERROR_MEMORY: 79 case MAILSMTP_ERROR_MEMORY:
79 return tr( "Memory error" ); 80 return i18n( "Memory error" );
80 case MAILSMTP_ERROR_CONNECTION_REFUSED: 81 case MAILSMTP_ERROR_CONNECTION_REFUSED:
81 return tr( "Connection refused" ); 82 return i18n( "Connection refused" );
82 default: 83 default:
83 return tr( "Unknown error code" ); 84 return i18n( "Unknown error code" );
84 } 85 }
85} 86}
86 87
87 88
88void SMTPwrapper::progress( size_t current, size_t maximum ) { 89void SMTPwrapper::progress( size_t current, size_t maximum ) {
89 if (SMTPwrapper::sendProgress) { 90 if (SMTPwrapper::sendProgress) {
90 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 91 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
91 qApp->processEvents(); 92 qApp->processEvents();
92 } 93 }
93} 94}
94 95
95void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 96void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
96 if (!mail) 97 if (!mail)
97 return; 98 return;
98 QString localfolders = AbstractMail::defaultLocalfolder(); 99 QString localfolders = AbstractMail::defaultLocalfolder();
99 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 100 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
100 wrap->createMbox(box); 101 wrap->createMbox(box);
101 wrap->storeMessage(mail,length,box); 102 wrap->storeMessage(mail,length,box);
102 delete wrap; 103 delete wrap;
103} 104}
104 105
105bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { 106bool SMTPwrapper::smtpSend( mailmime *mail,bool later) {
106 clist *rcpts = 0; 107 clist *rcpts = 0;
107 char *from, *data; 108 char *from, *data;
108 size_t size; 109 size_t size;
109 110
110 from = data = 0; 111 from = data = 0;
111 112
112 mailmessage * msg = 0; 113 mailmessage * msg = 0;
113 msg = mime_message_init(mail); 114 msg = mime_message_init(mail);
114 mime_message_set_tmpdir(msg,getenv( "HOME" )); 115 mime_message_set_tmpdir(msg,getenv( "HOME" ));
115 int r = mailmessage_fetch(msg,&data,&size); 116 int r = mailmessage_fetch(msg,&data,&size);
116 mime_message_detach_mime(msg); 117 mime_message_detach_mime(msg);
117 mailmessage_free(msg); 118 mailmessage_free(msg);
118 if (r != MAIL_NO_ERROR || !data) { 119 if (r != MAIL_NO_ERROR || !data) {
119 if (data) 120 if (data)
120 free(data); 121 free(data);
121 qDebug("Error fetching mime... "); 122 qDebug("Error fetching mime... ");
122 return false; 123 return false;
123 } 124 }
124 msg = 0; 125 msg = 0;
125 if (later) { 126 if (later) {
126 storeMail(data,size,"Outgoing"); 127 storeMail(data,size,"Outgoing");
127 if (data) 128 if (data)
128 free( data ); 129 free( data );
129 Config cfg( "mail" ); 130 Config cfg( "mail" );
130 cfg.setGroup( "Status" ); 131 cfg.setGroup( "Status" );
131 cfg.writeEntry( "outgoing", ++m_queuedMail ); 132 cfg.writeEntry( "outgoing", ++m_queuedMail );
132 emit queuedMails( m_queuedMail ); 133 emit queuedMails( m_queuedMail );
133 return true; 134 return true;
134 } 135 }
135 from = getFrom( mail ); 136 from = getFrom( mail );
136 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 137 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
137 bool result = smtpSend(from,rcpts,data,size); 138 bool result = smtpSend(from,rcpts,data,size);
138 if (data) { 139 if (data) {
139 free(data); 140 free(data);
140 } 141 }
141 if (from) { 142 if (from) {
142 free(from); 143 free(from);
143 } 144 }
144 if (rcpts) 145 if (rcpts)
145 smtp_address_list_free( rcpts ); 146 smtp_address_list_free( rcpts );
146 return result; 147 return result;
147} 148}
148 149
149void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 150void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
150{ 151{
151 if (data) { 152 if (data) {
152 storeMail(data,size,"Sendfailed"); 153 storeMail(data,size,"Sendfailed");
153 } 154 }
154 if (failuremessage) { 155 if (failuremessage) {
155 QMessageBox::critical(0,tr("Error sending mail"), 156 QMessageBox::critical(0,i18n("Error sending mail"),
156 tr("<center>%1</center>").arg(failuremessage)); 157 i18n("<center>%1</center>").arg(failuremessage));
157 } 158 }
158} 159}
159 160
160int SMTPwrapper::start_smtp_tls() 161int SMTPwrapper::start_smtp_tls()
161{ 162{
162 if (!m_smtp) { 163 if (!m_smtp) {
163 return MAILSMTP_ERROR_IN_PROCESSING; 164 return MAILSMTP_ERROR_IN_PROCESSING;
164 } 165 }
165 int err = mailesmtp_starttls(m_smtp); 166 int err = mailesmtp_starttls(m_smtp);
166 if (err != MAILSMTP_NO_ERROR) return err; 167 if (err != MAILSMTP_NO_ERROR) return err;
167 mailstream_low * low; 168 mailstream_low * low;
168 mailstream_low * new_low; 169 mailstream_low * new_low;
169 low = mailstream_get_low(m_smtp->stream); 170 low = mailstream_get_low(m_smtp->stream);
170 if (!low) { 171 if (!low) {
171 return MAILSMTP_ERROR_IN_PROCESSING; 172 return MAILSMTP_ERROR_IN_PROCESSING;
172 } 173 }
173 int fd = mailstream_low_get_fd(low); 174 int fd = mailstream_low_get_fd(low);
174 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 175 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
175 mailstream_low_free(low); 176 mailstream_low_free(low);
176 mailstream_set_low(m_smtp->stream, new_low); 177 mailstream_set_low(m_smtp->stream, new_low);
177 } else { 178 } else {
178 return MAILSMTP_ERROR_IN_PROCESSING; 179 return MAILSMTP_ERROR_IN_PROCESSING;
179 } 180 }
180 return err; 181 return err;
181} 182}
182 183
183void SMTPwrapper::connect_server() 184void SMTPwrapper::connect_server()
184{ 185{
185 QString server, user, pass; 186 QString server, user, pass;
186 bool ssl; 187 bool ssl;
187 uint16_t port; 188 uint16_t port;
188 ssl = false; 189 ssl = false;
189 bool try_tls = true; 190 bool try_tls = true;
190 bool force_tls=false; 191 bool force_tls=false;
191 QString failuretext = ""; 192 QString failuretext = "";
192 193
193 if (m_smtp || !m_SmtpAccount) { 194 if (m_smtp || !m_SmtpAccount) {
194 return; 195 return;
195 } 196 }
196 server = m_SmtpAccount->getServer(); 197 server = m_SmtpAccount->getServer();
197 if ( m_SmtpAccount->ConnectionType() == 2 ) { 198 if ( m_SmtpAccount->ConnectionType() == 2 ) {
198 ssl = true; 199 ssl = true;
199 try_tls = false; 200 try_tls = false;
200 } else if (m_SmtpAccount->ConnectionType() == 1) { 201 } else if (m_SmtpAccount->ConnectionType() == 1) {
201 force_tls = true; 202 force_tls = true;
202 } 203 }
203 int result = 1; 204 int result = 1;
204 port = m_SmtpAccount->getPort().toUInt(); 205 port = m_SmtpAccount->getPort().toUInt();
205 206
206 m_smtp = mailsmtp_new( 20, &progress ); 207 m_smtp = mailsmtp_new( 20, &progress );
207 if ( m_smtp == NULL ) { 208 if ( m_smtp == NULL ) {
208 /* no failure message cause this happens when problems with memory - than we 209 /* no failure message cause this happens when problems with memory - than we
209 we can not display any messagebox */ 210 we can not display any messagebox */
210 return; 211 return;
211 } 212 }
212 213
213 int err = MAILSMTP_NO_ERROR; 214 int err = MAILSMTP_NO_ERROR;
214 ; // odebug << "Servername " << server << " at port " << port << "" << oendl; 215 ; // odebug << "Servername " << server << " at port " << port << "" << oendl;
215 if ( ssl ) { 216 if ( ssl ) {
216 ; // odebug << "SSL session" << oendl; 217 ; // odebug << "SSL session" << oendl;
217 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); 218 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port );
218 } else { 219 } else {
219 ; // odebug << "No SSL session" << oendl; 220 ; // odebug << "No SSL session" << oendl;
220 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); 221 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port );
221 } 222 }
222 if ( err != MAILSMTP_NO_ERROR ) { 223 if ( err != MAILSMTP_NO_ERROR ) {
223 ; // odebug << "Error init connection" << oendl; 224 ; // odebug << "Error init connection" << oendl;
224 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 225 failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err));
225 result = 0; 226 result = 0;
226 } 227 }
227 228
228 /* switch to tls after init 'cause there it will send the ehlo */ 229 /* switch to tls after init 'cause there it will send the ehlo */
229 if (result) { 230 if (result) {
230 err = mailsmtp_init( m_smtp ); 231 err = mailsmtp_init( m_smtp );
231 if (err != MAILSMTP_NO_ERROR) { 232 if (err != MAILSMTP_NO_ERROR) {
232 result = 0; 233 result = 0;
233 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 234 failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err));
234 } 235 }
235 } 236 }
236 237
237 if (try_tls) { 238 if (try_tls) {
238 err = start_smtp_tls(); 239 err = start_smtp_tls();
239 if (err != MAILSMTP_NO_ERROR) { 240 if (err != MAILSMTP_NO_ERROR) {
240 try_tls = false; 241 try_tls = false;
241 } else { 242 } else {
242 err = mailesmtp_ehlo(m_smtp); 243 err = mailesmtp_ehlo(m_smtp);
243 } 244 }
244 } 245 }
245 246
246 if (!try_tls && force_tls) { 247 if (!try_tls && force_tls) {
247 result = 0; 248 result = 0;
248 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); 249 failuretext = i18n("Error init SMTP tls: %1").arg(mailsmtpError(err));
249 } 250 }
250 251
251 if (result==1 && m_SmtpAccount->getLogin() ) { 252 if (result==1 && m_SmtpAccount->getLogin() ) {
252 ; // odebug << "smtp with auth" << oendl; 253 ; // odebug << "smtp with auth" << oendl;
253 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 254 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
254 // get'em 255 // get'em
255 LoginDialog login( m_SmtpAccount->getUser(), 256 LoginDialog login( m_SmtpAccount->getUser(),
256 m_SmtpAccount->getPassword(), NULL, 0, true ); 257 m_SmtpAccount->getPassword(), NULL, 0, true );
257 login.show(); 258 login.show();
258 if ( QDialog::Accepted == login.exec() ) { 259 if ( QDialog::Accepted == login.exec() ) {
259 // ok 260 // ok
260 user = login.getUser(); 261 user = login.getUser();
261 pass = login.getPassword(); 262 pass = login.getPassword();
262 } else { 263 } else {
263 result = 0; 264 result = 0;
264 failuretext=tr("Login aborted - storing mail to localfolder"); 265 failuretext=i18n("Login aborted - storing mail to localfolder");
265 } 266 }
266 } else { 267 } else {
267 user = m_SmtpAccount->getUser(); 268 user = m_SmtpAccount->getUser();
268 pass = m_SmtpAccount->getPassword(); 269 pass = m_SmtpAccount->getPassword();
269 } 270 }
270 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; 271 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl;
271 if (result) { 272 if (result) {
272 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); 273 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() );
273 if ( err == MAILSMTP_NO_ERROR ) { 274 if ( err == MAILSMTP_NO_ERROR ) {
274 ; // odebug << "auth ok" << oendl; 275 ; // odebug << "auth ok" << oendl;
275 } else { 276 } else {
276 failuretext = tr("Authentification failed"); 277 failuretext = i18n("Authentification failed");
277 result = 0; 278 result = 0;
278 } 279 }
279 } 280 }
280 } 281 }
281} 282}
282 283
283void SMTPwrapper::disc_server() 284void SMTPwrapper::disc_server()
284{ 285{
285 if (m_smtp) { 286 if (m_smtp) {
286 mailsmtp_quit( m_smtp ); 287 mailsmtp_quit( m_smtp );
287 mailsmtp_free( m_smtp ); 288 mailsmtp_free( m_smtp );
288 m_smtp = 0; 289 m_smtp = 0;
289 } 290 }
290} 291}
291 292
292int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 293int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
293{ 294{
294 int err,result; 295 int err,result;
295 QString failuretext = ""; 296 QString failuretext = "";
296 297
297 connect_server(); 298 connect_server();
298 299
299 result = 1; 300 result = 1;
300 if (m_smtp) { 301 if (m_smtp) {
301 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 302 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
302 if ( err != MAILSMTP_NO_ERROR ) { 303 if ( err != MAILSMTP_NO_ERROR ) {
303 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); 304 failuretext=i18n("Error sending mail: %1").arg(mailsmtpError(err));
304 result = 0; 305 result = 0;
305 } 306 }
306 } else { 307 } else {
307 result = 0; 308 result = 0;
308 } 309 }
309 310
310 if (!result) { 311 if (!result) {
311 storeFailedMail(data,size,failuretext); 312 storeFailedMail(data,size,failuretext);
312 } else { 313 } else {
313 ; // odebug << "Mail sent." << oendl; 314 ; // odebug << "Mail sent." << oendl;
314 storeMail(data,size,"Sent"); 315 storeMail(data,size,"Sent");
315 } 316 }
316 return result; 317 return result;
317} 318}
318 319
319bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) 320bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later )
320{ 321{
321 mailmime * mimeMail; 322 mailmime * mimeMail;
322 bool result = true; 323 bool result = true;
323 mimeMail = createMimeMail(mail ); 324 mimeMail = createMimeMail(mail );
324 if ( mimeMail == 0 ) { 325 if ( mimeMail == 0 ) {
325 qDebug("SMTP wrapper:Error creating mail! "); 326 qDebug("SMTP wrapper:Error creating mail! ");
326 return false; 327 return false;
327 } else { 328 } else {
328 sendProgress = new progressMailSend(); 329 sendProgress = new progressMailSend();
329 sendProgress->show(); 330 sendProgress->show();
330 sendProgress->setMaxMails(1); 331 sendProgress->setMaxMails(1);
331 result = smtpSend( mimeMail,later); 332 result = smtpSend( mimeMail,later);
332 ; // odebug << "Clean up done" << oendl; 333 ; // odebug << "Clean up done" << oendl;
333 sendProgress->hide(); 334 sendProgress->hide();
334 delete sendProgress; 335 delete sendProgress;
335 sendProgress = 0; 336 sendProgress = 0;
336 mailmime_free( mimeMail ); 337 mailmime_free( mimeMail );
337 } 338 }
338 return result; 339 return result;
339} 340}
340 341
341int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { 342int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
342 size_t curTok = 0; 343 size_t curTok = 0;
343 mailimf_fields *fields = 0; 344 mailimf_fields *fields = 0;
344 mailimf_field*ffrom = 0; 345 mailimf_field*ffrom = 0;
345 clist *rcpts = 0; 346 clist *rcpts = 0;
346 char*from = 0; 347 char*from = 0;
347 int res = 0; 348 int res = 0;
348 349
349 encodedString * data = wrap->fetchRawBody(which); 350 encodedString * data = wrap->fetchRawBody(which);
350 if (!data) 351 if (!data)
351 return 0; 352 return 0;
352 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 353 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
353 if (err != MAILIMF_NO_ERROR) { 354 if (err != MAILIMF_NO_ERROR) {
354 delete data; 355 delete data;
355 delete wrap; 356 delete wrap;
356 return 0; 357 return 0;
357 } 358 }
358 359
359 rcpts = createRcptList( fields ); 360 rcpts = createRcptList( fields );
360 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 361 ffrom = getField(fields, MAILIMF_FIELD_FROM );
361 from = getFrom(ffrom); 362 from = getFrom(ffrom);
362 363
363 if (rcpts && from) { 364 if (rcpts && from) {
364 res = smtpSend(from,rcpts,data->Content(),data->Length()); 365 res = smtpSend(from,rcpts,data->Content(),data->Length());
365 } 366 }
366 if (fields) { 367 if (fields) {
367 mailimf_fields_free(fields); 368 mailimf_fields_free(fields);
368 fields = 0; 369 fields = 0;
369 } 370 }
370 if (data) { 371 if (data) {
371 delete data; 372 delete data;
372 } 373 }
373 if (from) { 374 if (from) {
374 free(from); 375 free(from);
375 } 376 }
376 if (rcpts) { 377 if (rcpts) {
377 smtp_address_list_free( rcpts ); 378 smtp_address_list_free( rcpts );
378 } 379 }
379 return res; 380 return res;
380} 381}
381 382
382/* this is a special fun */ 383/* this is a special fun */
383bool SMTPwrapper::flushOutbox() { 384bool SMTPwrapper::flushOutbox() {
384 bool returnValue = true; 385 bool returnValue = true;
385 386
386 ; // odebug << "Sending the queue" << oendl; 387 ; // odebug << "Sending the queue" << oendl;
387 if (!m_SmtpAccount) { 388 if (!m_SmtpAccount) {
388 ; // odebug << "No smtp account given" << oendl; 389 ; // odebug << "No smtp account given" << oendl;
389 return false; 390 return false;
390 } 391 }
391 392
392 bool reset_user_value = false; 393 bool reset_user_value = false;
393 QString localfolders = AbstractMail::defaultLocalfolder(); 394 QString localfolders = AbstractMail::defaultLocalfolder();
394 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 395 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
395 if (!wrap) { 396 if (!wrap) {
396 ; // odebug << "memory error" << oendl; 397 ; // odebug << "memory error" << oendl;
397 return false; 398 return false;
398 } 399 }
399 QString oldPw, oldUser; 400 QString oldPw, oldUser;
400 QValueList<RecMailP> mailsToSend; 401 QValueList<RecMailP> mailsToSend;
401 QValueList<RecMailP> mailsToRemove; 402 QValueList<RecMailP> mailsToRemove;
402 QString mbox("Outgoing"); 403 QString mbox("Outgoing");
403 wrap->listMessages(mbox,mailsToSend); 404 wrap->listMessages(mbox,mailsToSend);
404 if (mailsToSend.count()==0) { 405 if (mailsToSend.count()==0) {
405 delete wrap; 406 delete wrap;
406 ; // odebug << "No mails to send" << oendl; 407 ; // odebug << "No mails to send" << oendl;
407 return false; 408 return false;
408 } 409 }
409 410
410 oldPw = m_SmtpAccount->getPassword(); 411 oldPw = m_SmtpAccount->getPassword();
411 oldUser = m_SmtpAccount->getUser(); 412 oldUser = m_SmtpAccount->getUser();
412 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 413 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
413 // get'em 414 // get'em
414 QString user,pass; 415 QString user,pass;
415 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 416 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
416 login.show(); 417 login.show();
417 if ( QDialog::Accepted == login.exec() ) { 418 if ( QDialog::Accepted == login.exec() ) {
418 // ok 419 // ok
419 user = login.getUser().latin1(); 420 user = login.getUser().latin1();
420 pass = login.getPassword().latin1(); 421 pass = login.getPassword().latin1();
421 reset_user_value = true; 422 reset_user_value = true;
422 m_SmtpAccount->setUser(user); 423 m_SmtpAccount->setUser(user);
423 m_SmtpAccount->setPassword(pass); 424 m_SmtpAccount->setPassword(pass);
424 } else { 425 } else {
425 return true; 426 return true;
426 } 427 }
427 } 428 }
428 429
429 430
430 sendProgress = new progressMailSend(); 431 sendProgress = new progressMailSend();
431 sendProgress->show(); 432 sendProgress->show();
432 sendProgress->setMaxMails(mailsToSend.count()); 433 sendProgress->setMaxMails(mailsToSend.count());
433 434
434 while (mailsToSend.count()>0) { 435 while (mailsToSend.count()>0) {
435 if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { 436 if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) {
436 QMessageBox::critical(0,tr("Error sending mail"), 437 QMessageBox::critical(0,i18n("Error sending mail"),
437 tr("Error sending queued mail - breaking")); 438 i18n("Error sending queued mail - breaking"));
438 returnValue = false; 439 returnValue = false;
439 break; 440 break;
440 } 441 }
441 mailsToRemove.append((*mailsToSend.begin())); 442 mailsToRemove.append((*mailsToSend.begin()));
442 mailsToSend.remove(mailsToSend.begin()); 443 mailsToSend.remove(mailsToSend.begin());
443 sendProgress->setCurrentMails(mailsToRemove.count()); 444 sendProgress->setCurrentMails(mailsToRemove.count());
444 } 445 }
445 if (reset_user_value) { 446 if (reset_user_value) {
446 m_SmtpAccount->setUser(oldUser); 447 m_SmtpAccount->setUser(oldUser);
447 m_SmtpAccount->setPassword(oldPw); 448 m_SmtpAccount->setPassword(oldPw);
448 } 449 }
449 Config cfg( "mail" ); 450 Config cfg( "mail" );
450 cfg.setGroup( "Status" ); 451 cfg.setGroup( "Status" );
451 m_queuedMail = 0; 452 m_queuedMail = 0;
452 cfg.writeEntry( "outgoing", m_queuedMail ); 453 cfg.writeEntry( "outgoing", m_queuedMail );
453 emit queuedMails( m_queuedMail ); 454 emit queuedMails( m_queuedMail );
454 sendProgress->hide(); 455 sendProgress->hide();
455 delete sendProgress; 456 delete sendProgress;
456 sendProgress = 0; 457 sendProgress = 0;
457 wrap->deleteMails(mbox,mailsToRemove); 458 wrap->deleteMails(mbox,mailsToRemove);
458 delete wrap; 459 delete wrap;
459 return returnValue; 460 return returnValue;
460} 461}