summaryrefslogtreecommitdiffabout
path: root/kmicromail
authorzautrix <zautrix>2004-09-10 19:57:55 (UTC)
committer zautrix <zautrix>2004-09-10 19:57:55 (UTC)
commitcebdd6de7481514ad5ea0517f7a2e8f4db422be5 (patch) (unidiff)
tree0b29859b5bbfdcb702724c3b0c721f22b0d0e666 /kmicromail
parent157120031b77a3d9f10d780a66b6441dac1399fa (diff)
downloadkdepimpi-cebdd6de7481514ad5ea0517f7a2e8f4db422be5.zip
kdepimpi-cebdd6de7481514ad5ea0517f7a2e8f4db422be5.tar.gz
kdepimpi-cebdd6de7481514ad5ea0517f7a2e8f4db422be5.tar.bz2
Added status info when deleting mails
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp53
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp62
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.h4
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp49
4 files changed, 67 insertions, 101 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index cef4e97..f876235 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,237 +1,210 @@
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 9
9 10
10#include <qprogressbar.h> 11#include <qprogressbar.h>
11#include <qapplication.h> 12#include <qapplication.h>
12 13
13#include <kdecore/kstandarddirs.h> 14#include <kdecore/kstandarddirs.h>
14#include <qfile.h> 15#include <qfile.h>
15#include <qtextstream.h> 16#include <qtextstream.h>
16#include <stdlib.h> 17#include <stdlib.h>
17#include <libetpan/mailmime_content.h> 18#include <libetpan/mailmime_content.h>
18#include <libetpan/mailmime.h> 19#include <libetpan/mailmime.h>
19 20
20using namespace Opie::Core; 21using namespace Opie::Core;
21AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 22AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
22{ 23{
23 return new IMAPwrapper(a); 24 return new IMAPwrapper(a);
24} 25}
25 26
26AbstractMail* AbstractMail::getWrapper(POP3account *a) 27AbstractMail* AbstractMail::getWrapper(POP3account *a)
27{ 28{
28 return new POP3wrapper(a); 29 return new POP3wrapper(a);
29} 30}
30 31
31AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 32AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
32{ 33{
33 return new NNTPwrapper(a); 34 return new NNTPwrapper(a);
34} 35}
35 36
36AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 37AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
37{ 38{
38 return new MHwrapper(a,name); 39 return new MHwrapper(a,name);
39} 40}
40 41
41AbstractMail* AbstractMail::getWrapper(Account*a) 42AbstractMail* AbstractMail::getWrapper(Account*a)
42{ 43{
43 if (!a) return 0; 44 if (!a) return 0;
44 switch (a->getType()) { 45 switch (a->getType()) {
45 case MAILLIB::A_IMAP: 46 case MAILLIB::A_IMAP:
46 return new IMAPwrapper((IMAPaccount*)a); 47 return new IMAPwrapper((IMAPaccount*)a);
47 break; 48 break;
48 case MAILLIB::A_POP3: 49 case MAILLIB::A_POP3:
49 return new POP3wrapper((POP3account*)a); 50 return new POP3wrapper((POP3account*)a);
50 break; 51 break;
51 case MAILLIB::A_NNTP: 52 case MAILLIB::A_NNTP:
52 return new NNTPwrapper((NNTPaccount*)a); 53 return new NNTPwrapper((NNTPaccount*)a);
53 break; 54 break;
54 default: 55 default:
55 return 0; 56 return 0;
56 } 57 }
57} 58}
58 59
59encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 60encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
60{ 61{
61 // odebug << "Decode string start" << oendl; 62 // odebug << "Decode string start" << oendl;
62 char*result_text; 63 char*result_text;
63 size_t index = 0; 64 size_t index = 0;
64 /* reset for recursive use! */ 65 /* reset for recursive use! */
65 size_t target_length = 0; 66 size_t target_length = 0;
66 result_text = 0; 67 result_text = 0;
67 int mimetype = MAILMIME_MECHANISM_7BIT; 68 int mimetype = MAILMIME_MECHANISM_7BIT;
68 if (enc.lower()=="quoted-printable") { 69 if (enc.lower()=="quoted-printable") {
69 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 70 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
70 } else if (enc.lower()=="base64") { 71 } else if (enc.lower()=="base64") {
71 mimetype = MAILMIME_MECHANISM_BASE64; 72 mimetype = MAILMIME_MECHANISM_BASE64;
72 } else if (enc.lower()=="8bit") { 73 } else if (enc.lower()=="8bit") {
73 mimetype = MAILMIME_MECHANISM_8BIT; 74 mimetype = MAILMIME_MECHANISM_8BIT;
74 } else if (enc.lower()=="binary") { 75 } else if (enc.lower()=="binary") {
75 mimetype = MAILMIME_MECHANISM_BINARY; 76 mimetype = MAILMIME_MECHANISM_BINARY;
76 } 77 }
77 78
78 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 79 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
79 &result_text,&target_length); 80 &result_text,&target_length);
80 81
81 encodedString* result = new encodedString(); 82 encodedString* result = new encodedString();
82 if (err == MAILIMF_NO_ERROR) { 83 if (err == MAILIMF_NO_ERROR) {
83 result->setContent(result_text,target_length); 84 result->setContent(result_text,target_length);
84 } 85 }
85 //odebug << "Decode string finished" << oendl; 86 //odebug << "Decode string finished" << oendl;
86 return result; 87 return result;
87} 88}
88 89
89QString AbstractMail::convert_String(const char*text) 90QString AbstractMail::convert_String(const char*text)
90{ 91{
91 //size_t index = 0; 92 //size_t index = 0;
92 char*res = 0; 93 char*res = 0;
93 int err = MAILIMF_NO_ERROR; 94 int err = MAILIMF_NO_ERROR;
94 95
95 QString result(text); 96 QString result(text);
96 97
97 /* due a bug in libetpan it isn't usable this moment */ 98 /* due a bug in libetpan it isn't usable this moment */
98/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 99/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
99 text, strlen(text),&index, "iso-8859-1",&res);*/ 100 text, strlen(text),&index, "iso-8859-1",&res);*/
100 //odebug << "Input: " << text << "" << oendl; 101 //odebug << "Input: " << text << "" << oendl;
101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 102 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
102// result = QString(res); 103// result = QString(res);
103// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 104// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
104 } 105 }
105 if (res) free(res); 106 if (res) free(res);
106 return result; 107 return result;
107} 108}
108 109
109/* cp & paste from launcher */ 110/* cp & paste from launcher */
110QString AbstractMail::gen_attachment_id() 111QString AbstractMail::gen_attachment_id()
111{ 112{
112 QFile file( "/proc/sys/kernel/random/uuid" ); 113 QFile file( "/proc/sys/kernel/random/uuid" );
113 if (!file.open(IO_ReadOnly ) ) 114 if (!file.open(IO_ReadOnly ) )
114 return QString::null; 115 return QString::null;
115 116
116 QTextStream stream(&file); 117 QTextStream stream(&file);
117 118
118 return "{" + stream.read().stripWhiteSpace() + "}"; 119 return "{" + stream.read().stripWhiteSpace() + "}";
119} 120}
120 121
121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 122int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
122{ 123{
123 return 0; 124 return 0;
124} 125}
125 126
126QString AbstractMail::defaultLocalfolder() 127QString AbstractMail::defaultLocalfolder()
127{ 128{
128 // QString f = getenv( "HOME" ); 129 // QString f = getenv( "HOME" );
129 QString f = locateLocal( "data", "kopiemail/localmail"); 130 QString f = locateLocal( "data", "kopiemail/localmail");
130 // f += "/Applications/opiemail/localmail"; 131 // f += "/Applications/opiemail/localmail";
131 return f; 132 return f;
132} 133}
133 134
134QString AbstractMail::draftFolder() 135QString AbstractMail::draftFolder()
135{ 136{
136 return QString("Drafts"); 137 return QString("Drafts");
137} 138}
138 139
139/* temporary - will be removed when implemented in all classes */ 140/* temporary - will be removed when implemented in all classes */
140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 141void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
141{ 142{
142} 143}
143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 144void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
144{ 145{
145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 146 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
146 // this is currently re-implemented in pop3wrapper and imapwrapper 147 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0; 148 int iii = 0;
148 int count = target.count(); 149 int count = target.count();
149 QProgressBar bar( count,0 ); 150 QWidget wid;
150 bar.setCaption (("Removing mails - close to abort!") ); 151 wid.show();
151 int w = 300; 152 while (iii < count ) {
152 if ( QApplication::desktop()->width() < 320 ) 153 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
153 w = 220; 154 wid.raise();
154 int h = bar.sizeHint().height() ;
155 int dw = QApplication::desktop()->width();
156 int dh = QApplication::desktop()->height();
157 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
158 bar.show();
159 int modulo = (count/10)+1;
160 int incCounter = 0;
161 while (iii < count ) {
162 if ( ! bar.isVisible() )
163 return ;
164 if ( incCounter % modulo == 0 )
165 bar.setProgress( incCounter );
166 ++incCounter;
167 qApp->processEvents(); 155 qApp->processEvents();
168 RecMailP mail = (*target.at( iii )); 156 RecMailP mail = (*target.at( iii ));
169 deleteMail(mail); 157 deleteMail(mail);
170 ++iii; 158 ++iii;
171 } 159 }
172} 160}
173void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 161void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
174 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 162 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
175{ 163{
176 QValueList<RecMailP> t; 164 QValueList<RecMailP> t;
177 listMessages(fromFolder->getName(),t, maxSizeInKb); 165 listMessages(fromFolder->getName(),t, maxSizeInKb);
178 mvcpMailList( t,targetFolder,targetWrapper,moveit); 166 mvcpMailList( t,targetFolder,targetWrapper,moveit);
179 167
180} 168}
181void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 169void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
182 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
183{ 171{
184 encodedString*st = 0; 172 encodedString*st = 0;
185 int iii = 0; 173 int iii = 0;
186 int count = t.count(); 174 int count = t.count();
187 if ( count == 0 ) 175 if ( count == 0 )
188 return; 176 return;
189 177 // wel, processevents is qite strange, we need a widget for getting
190 QProgressBar bar( count,0 ); 178 // Global::statusMessage(tr("Copy2 message %1").arg(iii)); displayed
191 bar.setCaption (("Copying mails - close to abort!") ); 179 QWidget wid;
192 int w = 300; 180 wid.show();
193 if ( QApplication::desktop()->width() < 320 ) 181 while (iii < count ) {
194 w = 220; 182 Global::statusMessage(tr("Copy message %1 of %2").arg(iii).arg(count));
195 int h = bar.sizeHint().height() ; 183 wid.raise();
196 int dw = QApplication::desktop()->width();
197 int dh = QApplication::desktop()->height();
198 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
199 bar.show();
200 int modulo = (count/10)+1;
201 int incCounter = 0;
202 while (iii < count ) {
203 if ( ! bar.isVisible() )
204 return ;
205 if ( incCounter % modulo == 0 )
206 bar.setProgress( incCounter );
207 ++incCounter;
208 bar.raise();
209 qApp->processEvents(); 184 qApp->processEvents();
210 //qDebug("copy ");
211 RecMailP r = (*t.at( iii )); 185 RecMailP r = (*t.at( iii ));
212 st = fetchRawBody(r); 186 st = fetchRawBody(r);
213 if (st) { 187 if (st) {
214 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 188 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
215 delete st; 189 delete st;
216 } 190 }
217 ++iii; 191 ++iii;
218 } 192 }
219 bar.hide();
220 if (moveit) { 193 if (moveit) {
221 deleteMailList( t ); 194 deleteMailList( t );
222 //deleteAllMail(fromFolder); 195 //deleteAllMail(fromFolder);
223 } 196 }
224} 197}
225 198
226void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 199void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
227{ 200{
228 encodedString*st = 0; 201 encodedString*st = 0;
229 st = fetchRawBody(mail); 202 st = fetchRawBody(mail);
230 if (st) { 203 if (st) {
231 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 204 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
232 delete st; 205 delete st;
233 } 206 }
234 if (moveit) { 207 if (moveit) {
235 deleteMail(mail); 208 deleteMail(mail);
236 } 209 }
237} 210}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 021633b..be825ef 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,1260 +1,1276 @@
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 10
11using namespace Opie::Core; 11using namespace Opie::Core;
12int IMAPwrapper::mMax = 0;
13int IMAPwrapper::mCurrent = 0;
14
12IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 15IMAPwrapper::IMAPwrapper( IMAPaccount *a )
13 : AbstractMail() 16 : AbstractMail()
14{ 17{
15 account = a; 18 account = a;
16 m_imap = 0; 19 m_imap = 0;
17 m_Lastmbox = ""; 20 m_Lastmbox = "";
21 mCurrent = 0;
22 mMax = 0;
18} 23}
19 24
20IMAPwrapper::~IMAPwrapper() 25IMAPwrapper::~IMAPwrapper()
21{ 26{
22 logout(); 27 logout();
23} 28}
24 29
25/* to avoid to often select statements in loops etc. 30/* to avoid to often select statements in loops etc.
26 we trust that we are logged in and connection is established!*/ 31 we trust that we are logged in and connection is established!*/
27int IMAPwrapper::selectMbox(const QString&mbox) 32int IMAPwrapper::selectMbox(const QString&mbox)
28{ 33{
29 if (mbox == m_Lastmbox) { 34 if (mbox == m_Lastmbox) {
30 return MAILIMAP_NO_ERROR; 35 return MAILIMAP_NO_ERROR;
31 } 36 }
32 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 37 int err = mailimap_select( m_imap, (char*)mbox.latin1());
33 if ( err != MAILIMAP_NO_ERROR ) { 38 if ( err != MAILIMAP_NO_ERROR ) {
34 m_Lastmbox = ""; 39 m_Lastmbox = "";
35 return err; 40 return err;
36 } 41 }
37 m_Lastmbox = mbox; 42 m_Lastmbox = mbox;
38 return err; 43 return err;
39} 44}
40 45
41void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 46void IMAPwrapper::imap_progress( size_t current, size_t maximum )
42{ 47{
48 //qDebug("imap progress %d of %d ",current,maximum );
49 //Global::statusMessage(tr("Downloading message %1 of %2").arg( current).arg(maximum));
50 //qApp->processEvents()
51 static int last = 0;
52 if ( last != current )
53 IMAPwrapper::progress();
54 last = current;
55}
56void IMAPwrapper::progress( QString m )
57{
58
59 static QString mProgrMess;
60 if ( m != QString::null ) {
61 mProgrMess = m;
62 mCurrent = 0;
63 return;
64 }
65 QString mess;
66 //qDebug("progress ");
67 if ( mMax ) mess = mProgrMess +tr(" message %1 of %2").arg( mCurrent++).arg(mMax);
68 else mess = mProgrMess +tr(" message %1").arg( mCurrent++);
69 Global::statusMessage(mess);
43 qApp->processEvents(); 70 qApp->processEvents();
44 qDebug("imap progress %d of %d ",current,maximum );
45} 71}
46
47bool IMAPwrapper::start_tls(bool force_tls) 72bool IMAPwrapper::start_tls(bool force_tls)
48{ 73{
49 int err; 74 int err;
50 bool try_tls; 75 bool try_tls;
51 mailimap_capability_data * cap_data = 0; 76 mailimap_capability_data * cap_data = 0;
52 77
53 err = mailimap_capability(m_imap,&cap_data); 78 err = mailimap_capability(m_imap,&cap_data);
54 if (err != MAILIMAP_NO_ERROR) { 79 if (err != MAILIMAP_NO_ERROR) {
55 Global::statusMessage("error getting capabilities!"); 80 Global::statusMessage("error getting capabilities!");
56 return false; 81 return false;
57 } 82 }
58 clistiter * cur; 83 clistiter * cur;
59 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 84 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
60 struct mailimap_capability * cap; 85 struct mailimap_capability * cap;
61 cap = (struct mailimap_capability *)clist_content(cur); 86 cap = (struct mailimap_capability *)clist_content(cur);
62 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 87 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
63 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 88 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
64 try_tls = true; 89 try_tls = true;
65 break; 90 break;
66 } 91 }
67 } 92 }
68 } 93 }
69 if (cap_data) { 94 if (cap_data) {
70 mailimap_capability_data_free(cap_data); 95 mailimap_capability_data_free(cap_data);
71 } 96 }
72 if (try_tls) { 97 if (try_tls) {
73 err = mailimap_starttls(m_imap); 98 err = mailimap_starttls(m_imap);
74 if (err != MAILIMAP_NO_ERROR && force_tls) { 99 if (err != MAILIMAP_NO_ERROR && force_tls) {
75 Global::statusMessage(tr("Server has no TLS support!")); 100 Global::statusMessage(tr("Server has no TLS support!"));
76 try_tls = false; 101 try_tls = false;
77 } else { 102 } else {
78 mailstream_low * low; 103 mailstream_low * low;
79 mailstream_low * new_low; 104 mailstream_low * new_low;
80 low = mailstream_get_low(m_imap->imap_stream); 105 low = mailstream_get_low(m_imap->imap_stream);
81 if (!low) { 106 if (!low) {
82 try_tls = false; 107 try_tls = false;
83 } else { 108 } else {
84 int fd = mailstream_low_get_fd(low); 109 int fd = mailstream_low_get_fd(low);
85 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 110 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
86 mailstream_low_free(low); 111 mailstream_low_free(low);
87 mailstream_set_low(m_imap->imap_stream, new_low); 112 mailstream_set_low(m_imap->imap_stream, new_low);
88 } else { 113 } else {
89 try_tls = false; 114 try_tls = false;
90 } 115 }
91 } 116 }
92 } 117 }
93 } 118 }
94 return try_tls; 119 return try_tls;
95} 120}
96 121
97void IMAPwrapper::login() 122void IMAPwrapper::login()
98{ 123{
99 QString server, user, pass; 124 QString server, user, pass;
100 uint16_t port; 125 uint16_t port;
101 int err = MAILIMAP_NO_ERROR; 126 int err = MAILIMAP_NO_ERROR;
102 127
103 if (account->getOffline()) return; 128 if (account->getOffline()) return;
104 /* we are connected this moment */ 129 /* we are connected this moment */
105 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 130 /* TODO: setup a timer holding the line or if connection closed - delete the value */
106 if (m_imap) { 131 if (m_imap) {
107 err = mailimap_noop(m_imap); 132 err = mailimap_noop(m_imap);
108 if (err!=MAILIMAP_NO_ERROR) { 133 if (err!=MAILIMAP_NO_ERROR) {
109 logout(); 134 logout();
110 } else { 135 } else {
111 mailstream_flush(m_imap->imap_stream); 136 mailstream_flush(m_imap->imap_stream);
112 return; 137 return;
113 } 138 }
114 } 139 }
115 server = account->getServer(); 140 server = account->getServer();
116 port = account->getPort().toUInt(); 141 port = account->getPort().toUInt();
117 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 142 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
118 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 143 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
119 login.show(); 144 login.show();
120 if ( QDialog::Accepted == login.exec() ) { 145 if ( QDialog::Accepted == login.exec() ) {
121 // ok 146 // ok
122 user = login.getUser(); 147 user = login.getUser();
123 pass = login.getPassword(); 148 pass = login.getPassword();
124 } else { 149 } else {
125 // cancel 150 // cancel
126 return; 151 return;
127 } 152 }
128 } else { 153 } else {
129 user = account->getUser(); 154 user = account->getUser();
130 pass = account->getPassword(); 155 pass = account->getPassword();
131 } 156 }
132 157
133 m_imap = mailimap_new( 20, &imap_progress ); 158 m_imap = mailimap_new( 20, &imap_progress );
134 159
135 /* connect */ 160 /* connect */
136 bool ssl = false; 161 bool ssl = false;
137 bool try_tls = false; 162 bool try_tls = false;
138 bool force_tls = false; 163 bool force_tls = false;
139 164
140 if ( account->ConnectionType() == 2 ) { 165 if ( account->ConnectionType() == 2 ) {
141 ssl = true; 166 ssl = true;
142 } 167 }
143 if (account->ConnectionType()==1) { 168 if (account->ConnectionType()==1) {
144 force_tls = true; 169 force_tls = true;
145 } 170 }
146 171
147 if ( ssl ) { 172 if ( ssl ) {
148 qDebug("using ssl "); 173 qDebug("using ssl ");
149 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); 174 err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port );
150 } else { 175 } else {
151 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); 176 err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port );
152 } 177 }
153 178
154 if ( err != MAILIMAP_NO_ERROR && 179 if ( err != MAILIMAP_NO_ERROR &&
155 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 180 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 181 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
157 QString failure = ""; 182 QString failure = "";
158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 183 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
159 failure="Connection refused"; 184 failure="Connection refused";
160 } else { 185 } else {
161 failure="Unknown failure"; 186 failure="Unknown failure";
162 } 187 }
163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 188 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
164 mailimap_free( m_imap ); 189 mailimap_free( m_imap );
165 m_imap = 0; 190 m_imap = 0;
166 return; 191 return;
167 } 192 }
168 193
169 if (!ssl) { 194 if (!ssl) {
170 try_tls = start_tls(force_tls); 195 try_tls = start_tls(force_tls);
171 } 196 }
172 197
173 bool ok = true; 198 bool ok = true;
174 if (force_tls && !try_tls) { 199 if (force_tls && !try_tls) {
175 Global::statusMessage(tr("Server has no TLS support!")); 200 Global::statusMessage(tr("Server has no TLS support!"));
176 ok = false; 201 ok = false;
177 } 202 }
178 203
179 204
180 /* login */ 205 /* login */
181 206
182 if (ok) { 207 if (ok) {
183 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); 208 err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() );
184 if ( err != MAILIMAP_NO_ERROR ) { 209 if ( err != MAILIMAP_NO_ERROR ) {
185 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 210 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
186 ok = false; 211 ok = false;
187 } 212 }
188 } 213 }
189 if (!ok) { 214 if (!ok) {
190 err = mailimap_close( m_imap ); 215 err = mailimap_close( m_imap );
191 mailimap_free( m_imap ); 216 mailimap_free( m_imap );
192 m_imap = 0; 217 m_imap = 0;
193 } 218 }
194} 219}
195 220
196void IMAPwrapper::logout() 221void IMAPwrapper::logout()
197{ 222{
198 int err = MAILIMAP_NO_ERROR; 223 int err = MAILIMAP_NO_ERROR;
199 if (!m_imap) return; 224 if (!m_imap) return;
200 err = mailimap_logout( m_imap ); 225 err = mailimap_logout( m_imap );
201 err = mailimap_close( m_imap ); 226 err = mailimap_close( m_imap );
202 mailimap_free( m_imap ); 227 mailimap_free( m_imap );
203 m_imap = 0; 228 m_imap = 0;
204 m_Lastmbox = ""; 229 m_Lastmbox = "";
205} 230}
206 231
207void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb) 232void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target , int maxSizeInKb)
208{ 233{
209 int err = MAILIMAP_NO_ERROR; 234 int err = MAILIMAP_NO_ERROR;
210 clist *result = 0; 235 clist *result = 0;
211 clistcell *current; 236 clistcell *current;
212 mailimap_fetch_type *fetchType = 0; 237 mailimap_fetch_type *fetchType = 0;
213 mailimap_set *set = 0; 238 mailimap_set *set = 0;
214 239
215 login(); 240 login();
216 if (!m_imap) { 241 if (!m_imap) {
217 return; 242 return;
218 } 243 }
219 /* select mailbox READONLY for operations */ 244 /* select mailbox READONLY for operations */
220 err = selectMbox(mailbox); 245 err = selectMbox(mailbox);
221 if ( err != MAILIMAP_NO_ERROR ) { 246 if ( err != MAILIMAP_NO_ERROR ) {
222 return; 247 return;
223 } 248 }
224 249
225 int last = m_imap->imap_selection_info->sel_exists; 250 int last = m_imap->imap_selection_info->sel_exists;
226 251
227 if (last == 0) { 252 if (last == 0) {
228 Global::statusMessage(tr("Mailbox has no mails")); 253 Global::statusMessage(tr("Mailbox has no mails"));
229 return; 254 return;
230 } else { 255 } else {
231 } 256 }
232 257
233 /* the range has to start at 1!!! not with 0!!!! */ 258 /* the range has to start at 1!!! not with 0!!!! */
234 set = mailimap_set_new_interval( 1, last ); 259 set = mailimap_set_new_interval( 1, last );
235 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 260 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
236 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 261 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 262 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 263 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 264 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
240 265
241 err = mailimap_fetch( m_imap, set, fetchType, &result ); 266 err = mailimap_fetch( m_imap, set, fetchType, &result );
242 mailimap_set_free( set ); 267 mailimap_set_free( set );
243 mailimap_fetch_type_free( fetchType ); 268 mailimap_fetch_type_free( fetchType );
244 269
245 QString date,subject,from; 270 QString date,subject,from;
246 271
247 if ( err == MAILIMAP_NO_ERROR ) { 272 if ( err == MAILIMAP_NO_ERROR ) {
248 mailimap_msg_att * msg_att; 273 mailimap_msg_att * msg_att;
249 int i = 0; 274 int i = 0;
250 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 275 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
251 ++i; 276 ++i;
252 msg_att = (mailimap_msg_att*)current->data; 277 msg_att = (mailimap_msg_att*)current->data;
253 RecMail*m = parse_list_result(msg_att); 278 RecMail*m = parse_list_result(msg_att);
254 if (m) { 279 if (m) {
255 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) { 280 if ( maxSizeInKb == 0 || m->Msgsize()<=maxSizeInKb*1024 ) {
256 m->setNumber(i); 281 m->setNumber(i);
257 m->setMbox(mailbox); 282 m->setMbox(mailbox);
258 m->setWrapper(this); 283 m->setWrapper(this);
259 target.append(m); 284 target.append(m);
260 } 285 }
261 } 286 }
262 } 287 }
263 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 288 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
264 } else { 289 } else {
265 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 290 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
266 } 291 }
267 if (result) mailimap_fetch_list_free(result); 292 if (result) mailimap_fetch_list_free(result);
268} 293}
269 294
270QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders() 295QValueList<Opie::Core::OSmartPointer<Folder> >* IMAPwrapper::listFolders()
271{ 296{
272 const char *path, *mask; 297 const char *path, *mask;
273 int err = MAILIMAP_NO_ERROR; 298 int err = MAILIMAP_NO_ERROR;
274 clist *result = 0; 299 clist *result = 0;
275 clistcell *current = 0; 300 clistcell *current = 0;
276 clistcell*cur_flag = 0; 301 clistcell*cur_flag = 0;
277 mailimap_mbx_list_flags*bflags = 0; 302 mailimap_mbx_list_flags*bflags = 0;
278 303
279 QValueList<FolderP>* folders = new QValueList<FolderP>(); 304 QValueList<FolderP>* folders = new QValueList<FolderP>();
280 login(); 305 login();
281 if (!m_imap) { 306 if (!m_imap) {
282 return folders; 307 return folders;
283 } 308 }
284 309
285/* 310/*
286 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 311 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
287 * We must not forget to filter them out in next loop! 312 * We must not forget to filter them out in next loop!
288 * it seems like ugly code. and yes - it is ugly code. but the best way. 313 * it seems like ugly code. and yes - it is ugly code. but the best way.
289 */ 314 */
290 QString temp; 315 QString temp;
291 mask = "INBOX" ; 316 mask = "INBOX" ;
292 mailimap_mailbox_list *list; 317 mailimap_mailbox_list *list;
293 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 318 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
294 QString del; 319 QString del;
295 bool selectable = true; 320 bool selectable = true;
296 bool no_inferiors = false; 321 bool no_inferiors = false;
297 if ( err == MAILIMAP_NO_ERROR ) { 322 if ( err == MAILIMAP_NO_ERROR ) {
298 current = result->first; 323 current = result->first;
299 for ( int i = result->count; i > 0; i-- ) { 324 for ( int i = result->count; i > 0; i-- ) {
300 list = (mailimap_mailbox_list *) current->data; 325 list = (mailimap_mailbox_list *) current->data;
301 // it is better use the deep copy mechanism of qt itself 326 // it is better use the deep copy mechanism of qt itself
302 // instead of using strdup! 327 // instead of using strdup!
303 temp = list->mb_name; 328 temp = list->mb_name;
304 del = list->mb_delimiter; 329 del = list->mb_delimiter;
305 current = current->next; 330 current = current->next;
306 if ( (bflags = list->mb_flag) ) { 331 if ( (bflags = list->mb_flag) ) {
307 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 332 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
308 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 333 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
309 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 334 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
310 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 335 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
311 no_inferiors = true; 336 no_inferiors = true;
312 } 337 }
313 } 338 }
314 } 339 }
315 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 340 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
316 } 341 }
317 } else { 342 } else {
318 qDebug("error fetching folders: "); 343 qDebug("error fetching folders: ");
319 344
320 } 345 }
321 mailimap_list_result_free( result ); 346 mailimap_list_result_free( result );
322 347
323/* 348/*
324 * second stage - get the other then inbox folders 349 * second stage - get the other then inbox folders
325 */ 350 */
326 mask = "*" ; 351 mask = "*" ;
327 path = account->getPrefix().latin1(); 352 path = account->getPrefix().latin1();
328 if (!path) path = ""; 353 if (!path) path = "";
329 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 354 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
330 if ( err == MAILIMAP_NO_ERROR ) { 355 if ( err == MAILIMAP_NO_ERROR ) {
331 current = result->first; 356 current = result->first;
332 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 357 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
333 no_inferiors = false; 358 no_inferiors = false;
334 list = (mailimap_mailbox_list *) current->data; 359 list = (mailimap_mailbox_list *) current->data;
335 // it is better use the deep copy mechanism of qt itself 360 // it is better use the deep copy mechanism of qt itself
336 // instead of using strdup! 361 // instead of using strdup!
337 temp = list->mb_name; 362 temp = list->mb_name;
338 if (temp.lower()=="inbox") 363 if (temp.lower()=="inbox")
339 continue; 364 continue;
340 if (temp.lower()==account->getPrefix().lower()) 365 if (temp.lower()==account->getPrefix().lower())
341 continue; 366 continue;
342 if ( (bflags = list->mb_flag) ) { 367 if ( (bflags = list->mb_flag) ) {
343 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 368 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
344 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 369 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
345 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 370 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
346 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 371 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
347 no_inferiors = true; 372 no_inferiors = true;
348 } 373 }
349 } 374 }
350 } 375 }
351 del = list->mb_delimiter; 376 del = list->mb_delimiter;
352 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 377 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
353 } 378 }
354 } else { 379 } else {
355 qDebug("error fetching folders "); 380 qDebug("error fetching folders ");
356 381
357 } 382 }
358 if (result) mailimap_list_result_free( result ); 383 if (result) mailimap_list_result_free( result );
359 return folders; 384 return folders;
360} 385}
361 386
362RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 387RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
363{ 388{
364 RecMail * m = 0; 389 RecMail * m = 0;
365 mailimap_msg_att_item *item=0; 390 mailimap_msg_att_item *item=0;
366 clistcell *current,*c,*cf; 391 clistcell *current,*c,*cf;
367 mailimap_msg_att_dynamic*flist; 392 mailimap_msg_att_dynamic*flist;
368 mailimap_flag_fetch*cflag; 393 mailimap_flag_fetch*cflag;
369 int size; 394 int size;
370 QBitArray mFlags(7); 395 QBitArray mFlags(7);
371 QStringList addresslist; 396 QStringList addresslist;
372 397
373 if (!m_att) { 398 if (!m_att) {
374 return m; 399 return m;
375 } 400 }
376 m = new RecMail(); 401 m = new RecMail();
377 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 402 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
378 current = c; 403 current = c;
379 size = 0; 404 size = 0;
380 item = (mailimap_msg_att_item*)current->data; 405 item = (mailimap_msg_att_item*)current->data;
381 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 406 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
382 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 407 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
383 if (!flist->att_list) { 408 if (!flist->att_list) {
384 continue; 409 continue;
385 } 410 }
386 cf = flist->att_list->first; 411 cf = flist->att_list->first;
387 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 412 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
388 cflag = (mailimap_flag_fetch*)cf->data; 413 cflag = (mailimap_flag_fetch*)cf->data;
389 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 414 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
390 switch (cflag->fl_flag->fl_type) { 415 switch (cflag->fl_flag->fl_type) {
391 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 416 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
392 mFlags.setBit(FLAG_ANSWERED); 417 mFlags.setBit(FLAG_ANSWERED);
393 break; 418 break;
394 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 419 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
395 mFlags.setBit(FLAG_FLAGGED); 420 mFlags.setBit(FLAG_FLAGGED);
396 break; 421 break;
397 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 422 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
398 mFlags.setBit(FLAG_DELETED); 423 mFlags.setBit(FLAG_DELETED);
399 break; 424 break;
400 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 425 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
401 mFlags.setBit(FLAG_SEEN); 426 mFlags.setBit(FLAG_SEEN);
402 break; 427 break;
403 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 428 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
404 mFlags.setBit(FLAG_DRAFT); 429 mFlags.setBit(FLAG_DRAFT);
405 break; 430 break;
406 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 431 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
407 break; 432 break;
408 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 433 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
409 break; 434 break;
410 default: 435 default:
411 break; 436 break;
412 } 437 }
413 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 438 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
414 mFlags.setBit(FLAG_RECENT); 439 mFlags.setBit(FLAG_RECENT);
415 } 440 }
416 } 441 }
417 continue; 442 continue;
418 } 443 }
419 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 444 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
420 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 445 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
421 m->setDate(head->env_date); 446 m->setDate(head->env_date);
422 m->setSubject(convert_String((const char*)head->env_subject)); 447 m->setSubject(convert_String((const char*)head->env_subject));
423 //m->setSubject(head->env_subject); 448 //m->setSubject(head->env_subject);
424 if (head->env_from!=NULL) { 449 if (head->env_from!=NULL) {
425 addresslist = address_list_to_stringlist(head->env_from->frm_list); 450 addresslist = address_list_to_stringlist(head->env_from->frm_list);
426 if (addresslist.count()) { 451 if (addresslist.count()) {
427 m->setFrom(addresslist.first()); 452 m->setFrom(addresslist.first());
428 } 453 }
429 } 454 }
430 if (head->env_to!=NULL) { 455 if (head->env_to!=NULL) {
431 addresslist = address_list_to_stringlist(head->env_to->to_list); 456 addresslist = address_list_to_stringlist(head->env_to->to_list);
432 m->setTo(addresslist); 457 m->setTo(addresslist);
433 } 458 }
434 if (head->env_cc!=NULL) { 459 if (head->env_cc!=NULL) {
435 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 460 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
436 m->setCC(addresslist); 461 m->setCC(addresslist);
437 } 462 }
438 if (head->env_bcc!=NULL) { 463 if (head->env_bcc!=NULL) {
439 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 464 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
440 m->setBcc(addresslist); 465 m->setBcc(addresslist);
441 } 466 }
442 /* reply to address, eg. email. */ 467 /* reply to address, eg. email. */
443 if (head->env_reply_to!=NULL) { 468 if (head->env_reply_to!=NULL) {
444 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 469 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
445 if (addresslist.count()) { 470 if (addresslist.count()) {
446 m->setReplyto(addresslist.first()); 471 m->setReplyto(addresslist.first());
447 } 472 }
448 } 473 }
449 if (head->env_in_reply_to!=NULL) { 474 if (head->env_in_reply_to!=NULL) {
450 QString h(head->env_in_reply_to); 475 QString h(head->env_in_reply_to);
451 while (h.length()>0 && h[0]=='<') { 476 while (h.length()>0 && h[0]=='<') {
452 h.remove(0,1); 477 h.remove(0,1);
453 } 478 }
454 while (h.length()>0 && h[h.length()-1]=='>') { 479 while (h.length()>0 && h[h.length()-1]=='>') {
455 h.remove(h.length()-1,1); 480 h.remove(h.length()-1,1);
456 } 481 }
457 if (h.length()>0) { 482 if (h.length()>0) {
458 m->setInreply(QStringList(h)); 483 m->setInreply(QStringList(h));
459 } 484 }
460 } 485 }
461 if (head->env_message_id) { 486 if (head->env_message_id) {
462 m->setMsgid(QString(head->env_message_id)); 487 m->setMsgid(QString(head->env_message_id));
463 } 488 }
464 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 489 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
465#if 0 490#if 0
466 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 491 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
467 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 492 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
468 //odebug << "" << d->dt_year << " " << d->dt_month << " " << d->dt_day << " - " << d->dt_hour << " " << d->dt_min << " " << d->dt_sec << "" << oendl; 493 qDebug("time %s ",da.toString().latin1() );
469 //odebug << da.toString() << oendl;
470#endif 494#endif
471 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 495 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
472 size = item->att_data.att_static->att_data.att_rfc822_size; 496 size = item->att_data.att_static->att_data.att_rfc822_size;
473 } 497 }
474 } 498 }
475 /* msg is already deleted */ 499 /* msg is already deleted */
476 if (mFlags.testBit(FLAG_DELETED) && m) { 500 if (mFlags.testBit(FLAG_DELETED) && m) {
477 delete m; 501 delete m;
478 m = 0; 502 m = 0;
479 } 503 }
480 if (m) { 504 if (m) {
481 m->setFlags(mFlags); 505 m->setFlags(mFlags);
482 m->setMsgsize(size); 506 m->setMsgsize(size);
483 } 507 }
484 return m; 508 return m;
485} 509}
486 510
487RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail) 511RecBodyP IMAPwrapper::fetchBody(const RecMailP&mail)
488{ 512{
489 RecBodyP body = new RecBody(); 513 RecBodyP body = new RecBody();
490 const char *mb; 514 const char *mb;
491 int err = MAILIMAP_NO_ERROR; 515 int err = MAILIMAP_NO_ERROR;
492 clist *result = 0; 516 clist *result = 0;
493 clistcell *current; 517 clistcell *current;
494 mailimap_fetch_att *fetchAtt = 0; 518 mailimap_fetch_att *fetchAtt = 0;
495 mailimap_fetch_type *fetchType = 0; 519 mailimap_fetch_type *fetchType = 0;
496 mailimap_set *set = 0; 520 mailimap_set *set = 0;
497 mailimap_body*body_desc = 0; 521 mailimap_body*body_desc = 0;
498 522
499 mb = mail->getMbox().latin1(); 523 mb = mail->getMbox().latin1();
500 524
501 login(); 525 login();
502 if (!m_imap) { 526 if (!m_imap) {
503 return body; 527 return body;
504 } 528 }
505 err = selectMbox(mail->getMbox()); 529 err = selectMbox(mail->getMbox());
506 if ( err != MAILIMAP_NO_ERROR ) { 530 if ( err != MAILIMAP_NO_ERROR ) {
507 return body; 531 return body;
508 } 532 }
509 533
510 /* the range has to start at 1!!! not with 0!!!! */ 534 /* the range has to start at 1!!! not with 0!!!! */
511 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() ); 535 set = mailimap_set_new_interval( mail->getNumber(),mail->getNumber() );
512 fetchAtt = mailimap_fetch_att_new_bodystructure(); 536 fetchAtt = mailimap_fetch_att_new_bodystructure();
513 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 537 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
514 err = mailimap_fetch( m_imap, set, fetchType, &result ); 538 err = mailimap_fetch( m_imap, set, fetchType, &result );
515 mailimap_set_free( set ); 539 mailimap_set_free( set );
516 mailimap_fetch_type_free( fetchType ); 540 mailimap_fetch_type_free( fetchType );
517 541
518 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 542 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
519 mailimap_msg_att * msg_att; 543 mailimap_msg_att * msg_att;
520 msg_att = (mailimap_msg_att*)current->data; 544 msg_att = (mailimap_msg_att*)current->data;
521 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 545 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
522 QValueList<int> path; 546 QValueList<int> path;
523 body_desc = item->att_data.att_static->att_data.att_body; 547 body_desc = item->att_data.att_static->att_data.att_body;
524 traverseBody(mail,body_desc,body,0,path); 548 traverseBody(mail,body_desc,body,0,path);
525 } else { 549 } else {
526 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl; 550 //odebug << "error fetching body: " << m_imap->imap_response << "" << oendl;
527 } 551 }
528 if (result) mailimap_fetch_list_free(result); 552 if (result) mailimap_fetch_list_free(result);
529 return body; 553 return body;
530} 554}
531 555
532QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 556QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
533{ 557{
534 QStringList l; 558 QStringList l;
535 QString from; 559 QString from;
536 bool named_from; 560 bool named_from;
537 clistcell *current = NULL; 561 clistcell *current = NULL;
538 mailimap_address * current_address=NULL; 562 mailimap_address * current_address=NULL;
539 if (!list) { 563 if (!list) {
540 return l; 564 return l;
541 } 565 }
542 unsigned int count = 0; 566 unsigned int count = 0;
543 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 567 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
544 from = ""; 568 from = "";
545 named_from = false; 569 named_from = false;
546 current_address=(mailimap_address*)current->data; 570 current_address=(mailimap_address*)current->data;
547 if (current_address->ad_personal_name){ 571 if (current_address->ad_personal_name){
548 from+=convert_String((const char*)current_address->ad_personal_name); 572 from+=convert_String((const char*)current_address->ad_personal_name);
549 from+=" "; 573 from+=" ";
550 named_from = true; 574 named_from = true;
551 } 575 }
552 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 576 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
553 from+="<"; 577 from+="<";
554 } 578 }
555 if (current_address->ad_mailbox_name) { 579 if (current_address->ad_mailbox_name) {
556 from+=QString(current_address->ad_mailbox_name); 580 from+=QString(current_address->ad_mailbox_name);
557 from+="@"; 581 from+="@";
558 } 582 }
559 if (current_address->ad_host_name) { 583 if (current_address->ad_host_name) {
560 from+=QString(current_address->ad_host_name); 584 from+=QString(current_address->ad_host_name);
561 } 585 }
562 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 586 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
563 from+=">"; 587 from+=">";
564 } 588 }
565 l.append(QString(from)); 589 l.append(QString(from));
566 if (++count > 99) { 590 if (++count > 99) {
567 break; 591 break;
568 } 592 }
569 } 593 }
570 return l; 594 return l;
571} 595}
572 596
573encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call) 597encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call)
574{ 598{
575 encodedString*res=new encodedString; 599 encodedString*res=new encodedString;
576 int err; 600 int err;
577 mailimap_fetch_type *fetchType; 601 mailimap_fetch_type *fetchType;
578 mailimap_set *set; 602 mailimap_set *set;
579 clistcell*current,*cur; 603 clistcell*current,*cur;
580 mailimap_section_part * section_part = 0; 604 mailimap_section_part * section_part = 0;
581 mailimap_section_spec * section_spec = 0; 605 mailimap_section_spec * section_spec = 0;
582 mailimap_section * section = 0; 606 mailimap_section * section = 0;
583 mailimap_fetch_att * fetch_att = 0; 607 mailimap_fetch_att * fetch_att = 0;
584 608
585 login(); 609 login();
586 if (!m_imap) { 610 if (!m_imap) {
587 return res; 611 return res;
588 } 612 }
589 if (!internal_call) { 613 if (!internal_call) {
590 err = selectMbox(mail->getMbox()); 614 err = selectMbox(mail->getMbox());
591 if ( err != MAILIMAP_NO_ERROR ) { 615 if ( err != MAILIMAP_NO_ERROR ) {
592 return res; 616 return res;
593 } 617 }
594 } 618 }
595 set = mailimap_set_new_single(mail->getNumber()); 619 set = mailimap_set_new_single(mail->getNumber());
596 620
597 clist*id_list = 0; 621 clist*id_list = 0;
598 622
599 /* if path == empty then its a request for the whole rfc822 mail and generates 623 /* if path == empty then its a request for the whole rfc822 mail and generates
600 a "fetch <id> (body[])" statement on imap server */ 624 a "fetch <id> (body[])" statement on imap server */
601 if (path.count()>0 ) { 625 if (path.count()>0 ) {
602 id_list = clist_new(); 626 id_list = clist_new();
603 for (unsigned j=0; j < path.count();++j) { 627 for (unsigned j=0; j < path.count();++j) {
604 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 628 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
605 *p_id = path[j]; 629 *p_id = path[j];
606 clist_append(id_list,p_id); 630 clist_append(id_list,p_id);
607 } 631 }
608 section_part = mailimap_section_part_new(id_list); 632 section_part = mailimap_section_part_new(id_list);
609 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 633 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
610 } 634 }
611 635
612 section = mailimap_section_new(section_spec); 636 section = mailimap_section_new(section_spec);
613 fetch_att = mailimap_fetch_att_new_body_section(section); 637 fetch_att = mailimap_fetch_att_new_body_section(section);
614 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 638 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
615 639
616 clist*result = 0; 640 clist*result = 0;
617 641
618 err = mailimap_fetch( m_imap, set, fetchType, &result ); 642 err = mailimap_fetch( m_imap, set, fetchType, &result );
619 mailimap_set_free( set ); 643 mailimap_set_free( set );
620 mailimap_fetch_type_free( fetchType ); 644 mailimap_fetch_type_free( fetchType );
621 645
622 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 646 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
623 mailimap_msg_att * msg_att; 647 mailimap_msg_att * msg_att;
624 msg_att = (mailimap_msg_att*)current->data; 648 msg_att = (mailimap_msg_att*)current->data;
625 mailimap_msg_att_item*msg_att_item; 649 mailimap_msg_att_item*msg_att_item;
626 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 650 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
627 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 651 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
628 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 652 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
629 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 653 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
630 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 654 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
631 /* detach - we take over the content */ 655 /* detach - we take over the content */
632 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 656 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
633 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 657 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
634 } 658 }
635 } 659 }
636 } 660 }
637 } else { 661 } else {
638 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl; 662 ;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
639 } 663 }
640 if (result) mailimap_fetch_list_free(result); 664 if (result) mailimap_fetch_list_free(result);
641 return res; 665 return res;
642} 666}
643 667
644/* current_recursion is for recursive calls. 668/* current_recursion is for recursive calls.
645 current_count means the position inside the internal loop! */ 669 current_count means the position inside the internal loop! */
646void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body, 670void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
647 int current_recursion,QValueList<int>recList,int current_count) 671 int current_recursion,QValueList<int>recList,int current_count)
648{ 672{
649 if (!body || current_recursion>=10) { 673 if (!body || current_recursion>=10) {
650 return; 674 return;
651 } 675 }
652 switch (body->bd_type) { 676 switch (body->bd_type) {
653 case MAILIMAP_BODY_1PART: 677 case MAILIMAP_BODY_1PART:
654 { 678 {
655 QValueList<int>countlist = recList; 679 QValueList<int>countlist = recList;
656 countlist.append(current_count); 680 countlist.append(current_count);
657 RecPartP currentPart = new RecPart(); 681 RecPartP currentPart = new RecPart();
658 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 682 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
659 QString id(""); 683 QString id("");
660 currentPart->setPositionlist(countlist); 684 currentPart->setPositionlist(countlist);
661 for (unsigned int j = 0; j < countlist.count();++j) { 685 for (unsigned int j = 0; j < countlist.count();++j) {
662 id+=(j>0?" ":""); 686 id+=(j>0?" ":"");
663 id+=QString("%1").arg(countlist[j]); 687 id+=QString("%1").arg(countlist[j]);
664 } 688 }
665 //odebug << "ID = " << id.latin1() << "" << oendl; 689 //odebug << "ID = " << id.latin1() << "" << oendl;
666 currentPart->setIdentifier(id); 690 currentPart->setIdentifier(id);
667 fillSinglePart(currentPart,part1); 691 fillSinglePart(currentPart,part1);
668 /* important: Check for is NULL 'cause a body can be empty! 692 /* important: Check for is NULL 'cause a body can be empty!
669 And we put it only into the mail if it is the FIRST part */ 693 And we put it only into the mail if it is the FIRST part */
670 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) { 694 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
671 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding()); 695 QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
672 target_body->setDescription(currentPart); 696 target_body->setDescription(currentPart);
673 target_body->setBodytext(body_text); 697 target_body->setBodytext(body_text);
674 if (countlist.count()>1) { 698 if (countlist.count()>1) {
675 target_body->addPart(currentPart); 699 target_body->addPart(currentPart);
676 } 700 }
677 } else { 701 } else {
678 target_body->addPart(currentPart); 702 target_body->addPart(currentPart);
679 } 703 }
680 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 704 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
681 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 705 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
682 } 706 }
683 } 707 }
684 break; 708 break;
685 case MAILIMAP_BODY_MPART: 709 case MAILIMAP_BODY_MPART:
686 { 710 {
687 QValueList<int>countlist = recList; 711 QValueList<int>countlist = recList;
688 clistcell*current=0; 712 clistcell*current=0;
689 mailimap_body*current_body=0; 713 mailimap_body*current_body=0;
690 unsigned int ccount = 1; 714 unsigned int ccount = 1;
691 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 715 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
692 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 716 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
693 current_body = (mailimap_body*)current->data; 717 current_body = (mailimap_body*)current->data;
694 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 718 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
695 RecPartP targetPart = new RecPart(); 719 RecPartP targetPart = new RecPart();
696 targetPart->setType("multipart"); 720 targetPart->setType("multipart");
697 fillMultiPart(targetPart,mailDescription); 721 fillMultiPart(targetPart,mailDescription);
698 countlist.append(current_count); 722 countlist.append(current_count);
699 targetPart->setPositionlist(countlist); 723 targetPart->setPositionlist(countlist);
700 target_body->addPart(targetPart); 724 target_body->addPart(targetPart);
701 QString id(""); 725 QString id("");
702 for (unsigned int j = 0; j < countlist.count();++j) { 726 for (unsigned int j = 0; j < countlist.count();++j) {
703 id+=(j>0?" ":""); 727 id+=(j>0?" ":"");
704 id+=QString("%1").arg(countlist[j]); 728 id+=QString("%1").arg(countlist[j]);
705 } 729 }
706 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl; 730 // odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
707 } 731 }
708 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 732 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
709 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 733 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
710 countlist = recList; 734 countlist = recList;
711 } 735 }
712 ++ccount; 736 ++ccount;
713 } 737 }
714 } 738 }
715 break; 739 break;
716 default: 740 default:
717 break; 741 break;
718 } 742 }
719} 743}
720 744
721void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description) 745void IMAPwrapper::fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description)
722{ 746{
723 if (!Description) { 747 if (!Description) {
724 return; 748 return;
725 } 749 }
726 switch (Description->bd_type) { 750 switch (Description->bd_type) {
727 case MAILIMAP_BODY_TYPE_1PART_TEXT: 751 case MAILIMAP_BODY_TYPE_1PART_TEXT:
728 target_part->setType("text"); 752 target_part->setType("text");
729 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 753 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
730 break; 754 break;
731 case MAILIMAP_BODY_TYPE_1PART_BASIC: 755 case MAILIMAP_BODY_TYPE_1PART_BASIC:
732 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 756 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
733 break; 757 break;
734 case MAILIMAP_BODY_TYPE_1PART_MSG: 758 case MAILIMAP_BODY_TYPE_1PART_MSG:
735 target_part->setType("message"); 759 target_part->setType("message");
736 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 760 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
737 break; 761 break;
738 default: 762 default:
739 break; 763 break;
740 } 764 }
741} 765}
742 766
743void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which) 767void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
744{ 768{
745 if (!which) { 769 if (!which) {
746 return; 770 return;
747 } 771 }
748 QString sub; 772 QString sub;
749 sub = which->bd_media_text; 773 sub = which->bd_media_text;
750 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 774 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
751 target_part->setSubtype(sub.lower()); 775 target_part->setSubtype(sub.lower());
752 target_part->setLines(which->bd_lines); 776 target_part->setLines(which->bd_lines);
753 fillBodyFields(target_part,which->bd_fields); 777 fillBodyFields(target_part,which->bd_fields);
754} 778}
755 779
756void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 780void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
757{ 781{
758 if (!which) { 782 if (!which) {
759 return; 783 return;
760 } 784 }
761 target_part->setSubtype("rfc822"); 785 target_part->setSubtype("rfc822");
762 //odebug << "Message part" << oendl; 786 //odebug << "Message part" << oendl;
763 /* we set this type to text/plain */ 787 /* we set this type to text/plain */
764 target_part->setLines(which->bd_lines); 788 target_part->setLines(which->bd_lines);
765 fillBodyFields(target_part,which->bd_fields); 789 fillBodyFields(target_part,which->bd_fields);
766} 790}
767 791
768void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 792void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
769{ 793{
770 if (!which) return; 794 if (!which) return;
771 QString sub = which->bd_media_subtype; 795 QString sub = which->bd_media_subtype;
772 target_part->setSubtype(sub.lower()); 796 target_part->setSubtype(sub.lower());
773 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 797 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
774 clistcell*cur = 0; 798 clistcell*cur = 0;
775 mailimap_single_body_fld_param*param=0; 799 mailimap_single_body_fld_param*param=0;
776 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 800 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
777 param = (mailimap_single_body_fld_param*)cur->data; 801 param = (mailimap_single_body_fld_param*)cur->data;
778 if (param) { 802 if (param) {
779 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 803 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
780 } 804 }
781 } 805 }
782 } 806 }
783} 807}
784 808
785void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 809void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
786{ 810{
787 if (!which) { 811 if (!which) {
788 return; 812 return;
789 } 813 }
790 QString type,sub; 814 QString type,sub;
791 switch (which->bd_media_basic->med_type) { 815 switch (which->bd_media_basic->med_type) {
792 case MAILIMAP_MEDIA_BASIC_APPLICATION: 816 case MAILIMAP_MEDIA_BASIC_APPLICATION:
793 type = "application"; 817 type = "application";
794 break; 818 break;
795 case MAILIMAP_MEDIA_BASIC_AUDIO: 819 case MAILIMAP_MEDIA_BASIC_AUDIO:
796 type = "audio"; 820 type = "audio";
797 break; 821 break;
798 case MAILIMAP_MEDIA_BASIC_IMAGE: 822 case MAILIMAP_MEDIA_BASIC_IMAGE:
799 type = "image"; 823 type = "image";
800 break; 824 break;
801 case MAILIMAP_MEDIA_BASIC_MESSAGE: 825 case MAILIMAP_MEDIA_BASIC_MESSAGE:
802 type = "message"; 826 type = "message";
803 break; 827 break;
804 case MAILIMAP_MEDIA_BASIC_VIDEO: 828 case MAILIMAP_MEDIA_BASIC_VIDEO:
805 type = "video"; 829 type = "video";
806 break; 830 break;
807 case MAILIMAP_MEDIA_BASIC_OTHER: 831 case MAILIMAP_MEDIA_BASIC_OTHER:
808 default: 832 default:
809 if (which->bd_media_basic->med_basic_type) { 833 if (which->bd_media_basic->med_basic_type) {
810 type = which->bd_media_basic->med_basic_type; 834 type = which->bd_media_basic->med_basic_type;
811 } else { 835 } else {
812 type = ""; 836 type = "";
813 } 837 }
814 break; 838 break;
815 } 839 }
816 if (which->bd_media_basic->med_subtype) { 840 if (which->bd_media_basic->med_subtype) {
817 sub = which->bd_media_basic->med_subtype; 841 sub = which->bd_media_basic->med_subtype;
818 } else { 842 } else {
819 sub = ""; 843 sub = "";
820 } 844 }
821 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 845 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
822 target_part->setType(type.lower()); 846 target_part->setType(type.lower());
823 target_part->setSubtype(sub.lower()); 847 target_part->setSubtype(sub.lower());
824 fillBodyFields(target_part,which->bd_fields); 848 fillBodyFields(target_part,which->bd_fields);
825} 849}
826 850
827void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 851void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
828{ 852{
829 if (!which) return; 853 if (!which) return;
830 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 854 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
831 clistcell*cur; 855 clistcell*cur;
832 mailimap_single_body_fld_param*param=0; 856 mailimap_single_body_fld_param*param=0;
833 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 857 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
834 param = (mailimap_single_body_fld_param*)cur->data; 858 param = (mailimap_single_body_fld_param*)cur->data;
835 if (param) { 859 if (param) {
836 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 860 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
837 } 861 }
838 } 862 }
839 } 863 }
840 mailimap_body_fld_enc*enc = which->bd_encoding; 864 mailimap_body_fld_enc*enc = which->bd_encoding;
841 QString encoding(""); 865 QString encoding("");
842 switch (enc->enc_type) { 866 switch (enc->enc_type) {
843 case MAILIMAP_BODY_FLD_ENC_7BIT: 867 case MAILIMAP_BODY_FLD_ENC_7BIT:
844 encoding = "7bit"; 868 encoding = "7bit";
845 break; 869 break;
846 case MAILIMAP_BODY_FLD_ENC_8BIT: 870 case MAILIMAP_BODY_FLD_ENC_8BIT:
847 encoding = "8bit"; 871 encoding = "8bit";
848 break; 872 break;
849 case MAILIMAP_BODY_FLD_ENC_BINARY: 873 case MAILIMAP_BODY_FLD_ENC_BINARY:
850 encoding="binary"; 874 encoding="binary";
851 break; 875 break;
852 case MAILIMAP_BODY_FLD_ENC_BASE64: 876 case MAILIMAP_BODY_FLD_ENC_BASE64:
853 encoding="base64"; 877 encoding="base64";
854 break; 878 break;
855 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 879 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
856 encoding="quoted-printable"; 880 encoding="quoted-printable";
857 break; 881 break;
858 case MAILIMAP_BODY_FLD_ENC_OTHER: 882 case MAILIMAP_BODY_FLD_ENC_OTHER:
859 default: 883 default:
860 if (enc->enc_value) { 884 if (enc->enc_value) {
861 char*t=enc->enc_value; 885 char*t=enc->enc_value;
862 encoding=QString(enc->enc_value); 886 encoding=QString(enc->enc_value);
863 enc->enc_value=0L; 887 enc->enc_value=0L;
864 free(t); 888 free(t);
865 } 889 }
866 } 890 }
867 if (which->bd_description) { 891 if (which->bd_description) {
868 target_part->setDescription(QString(which->bd_description)); 892 target_part->setDescription(QString(which->bd_description));
869 } 893 }
870 target_part->setEncoding(encoding); 894 target_part->setEncoding(encoding);
871 target_part->setSize(which->bd_size); 895 target_part->setSize(which->bd_size);
872} 896}
873void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 897void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
874{ 898{
875 //#if 0 899 //#if 0
876 mailimap_flag_list*flist; 900 mailimap_flag_list*flist;
877 mailimap_set *set; 901 mailimap_set *set;
878 mailimap_store_att_flags * store_flags; 902 mailimap_store_att_flags * store_flags;
879 int err; 903 int err;
880 login(); 904 login();
881 //#endif 905 //#endif
882 if (!m_imap) { 906 if (!m_imap) {
883 return; 907 return;
884 } 908 }
885 int iii = 0; 909 int iii = 0;
886 int count = target.count(); 910 int count = target.count();
887 // qDebug("imap remove count %d ", count); 911 // qDebug("imap remove count %d ", count);
888 912
889 QProgressBar bar( count,0 ); 913
890 bar.setCaption (("Removing mails - close to abort!") ); 914 mMax = count;
891 int w = 300; 915 //progress( tr("Delete"));
892 if ( QApplication::desktop()->width() < 320 ) 916 QWidget wid;
893 w = 220; 917 wid.show();
894 int h = bar.sizeHint().height() ;
895 int dw = QApplication::desktop()->width();
896 int dh = QApplication::desktop()->height();
897 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
898 bar.show();
899 int modulo = (count/10)+1;
900 int incCounter = 0;
901
902 while (iii < count ) { 918 while (iii < count ) {
903 if ( ! bar.isVisible() ) 919 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
904 return ; 920 wid.raise();
905 if ( incCounter % modulo == 0 )
906 bar.setProgress( incCounter );
907 ++incCounter;
908 qApp->processEvents(); 921 qApp->processEvents();
909 RecMailP mail = (*target.at( iii )); 922 RecMailP mail = (*target.at( iii ));
910 //#if 0 923 //#if 0
911 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() ); 924 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
912 err = selectMbox(mail->getMbox()); 925 err = selectMbox(mail->getMbox());
913 if ( err != MAILIMAP_NO_ERROR ) { 926 if ( err != MAILIMAP_NO_ERROR ) {
914 return; 927 return;
915 } 928 }
916 flist = mailimap_flag_list_new_empty(); 929 flist = mailimap_flag_list_new_empty();
917 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 930 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
918 store_flags = mailimap_store_att_flags_new_set_flags(flist); 931 store_flags = mailimap_store_att_flags_new_set_flags(flist);
919 set = mailimap_set_new_single(mail->getNumber()); 932 set = mailimap_set_new_single(mail->getNumber());
920 err = mailimap_store(m_imap,set,store_flags); 933 err = mailimap_store(m_imap,set,store_flags);
921 mailimap_set_free( set ); 934 mailimap_set_free( set );
922 mailimap_store_att_flags_free(store_flags); 935 mailimap_store_att_flags_free(store_flags);
923 936
924 if (err != MAILIMAP_NO_ERROR) { 937 if (err != MAILIMAP_NO_ERROR) {
925 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 938 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
926 return; 939 return;
927 } 940 }
928 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 941 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
929 /* should we realy do that at this moment? */ 942 /* should we realy do that at this moment? */
930 943
931 // err = mailimap_expunge(m_imap); 944 // err = mailimap_expunge(m_imap);
932 //if (err != MAILIMAP_NO_ERROR) { 945 //if (err != MAILIMAP_NO_ERROR) {
933 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 946 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
934 // } 947 // }
935 //#endif 948 //#endif
936 //deleteMail( mail); 949 //deleteMail( mail);
937 ++iii; 950 ++iii;
938 } 951 }
939 //qDebug("Deleting imap mails... "); 952 //qDebug("Deleting imap mails... ");
940 err = mailimap_expunge(m_imap); 953 err = mailimap_expunge(m_imap);
941 if (err != MAILIMAP_NO_ERROR) { 954 if (err != MAILIMAP_NO_ERROR) {
942 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response)); 955 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
943 } 956 }
944} 957}
945void IMAPwrapper::deleteMail(const RecMailP&mail) 958void IMAPwrapper::deleteMail(const RecMailP&mail)
946{ 959{
947 mailimap_flag_list*flist; 960 mailimap_flag_list*flist;
948 mailimap_set *set; 961 mailimap_set *set;
949 mailimap_store_att_flags * store_flags; 962 mailimap_store_att_flags * store_flags;
950 int err; 963 int err;
951 login(); 964 login();
952 if (!m_imap) { 965 if (!m_imap) {
953 return; 966 return;
954 } 967 }
955 err = selectMbox(mail->getMbox()); 968 err = selectMbox(mail->getMbox());
956 if ( err != MAILIMAP_NO_ERROR ) { 969 if ( err != MAILIMAP_NO_ERROR ) {
957 return; 970 return;
958 } 971 }
959 flist = mailimap_flag_list_new_empty(); 972 flist = mailimap_flag_list_new_empty();
960 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 973 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
961 store_flags = mailimap_store_att_flags_new_set_flags(flist); 974 store_flags = mailimap_store_att_flags_new_set_flags(flist);
962 set = mailimap_set_new_single(mail->getNumber()); 975 set = mailimap_set_new_single(mail->getNumber());
963 err = mailimap_store(m_imap,set,store_flags); 976 err = mailimap_store(m_imap,set,store_flags);
964 mailimap_set_free( set ); 977 mailimap_set_free( set );
965 mailimap_store_att_flags_free(store_flags); 978 mailimap_store_att_flags_free(store_flags);
966 979
967 if (err != MAILIMAP_NO_ERROR) { 980 if (err != MAILIMAP_NO_ERROR) {
968 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 981 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
969 return; 982 return;
970 } 983 }
971 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 984 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
972 /* should we realy do that at this moment? */ 985 /* should we realy do that at this moment? */
973 986
974 err = mailimap_expunge(m_imap); 987 err = mailimap_expunge(m_imap);
975 if (err != MAILIMAP_NO_ERROR) { 988 if (err != MAILIMAP_NO_ERROR) {
976 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 989 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
977 } 990 }
978 //qDebug("IMAPwrapper::deleteMail 2"); 991 //qDebug("IMAPwrapper::deleteMail 2");
979 992
980} 993}
981 994
982void IMAPwrapper::answeredMail(const RecMailP&mail) 995void IMAPwrapper::answeredMail(const RecMailP&mail)
983{ 996{
984 mailimap_flag_list*flist; 997 mailimap_flag_list*flist;
985 mailimap_set *set; 998 mailimap_set *set;
986 mailimap_store_att_flags * store_flags; 999 mailimap_store_att_flags * store_flags;
987 int err; 1000 int err;
988 login(); 1001 login();
989 if (!m_imap) { 1002 if (!m_imap) {
990 return; 1003 return;
991 } 1004 }
992 err = selectMbox(mail->getMbox()); 1005 err = selectMbox(mail->getMbox());
993 if ( err != MAILIMAP_NO_ERROR ) { 1006 if ( err != MAILIMAP_NO_ERROR ) {
994 return; 1007 return;
995 } 1008 }
996 flist = mailimap_flag_list_new_empty(); 1009 flist = mailimap_flag_list_new_empty();
997 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 1010 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
998 store_flags = mailimap_store_att_flags_new_add_flags(flist); 1011 store_flags = mailimap_store_att_flags_new_add_flags(flist);
999 set = mailimap_set_new_single(mail->getNumber()); 1012 set = mailimap_set_new_single(mail->getNumber());
1000 err = mailimap_store(m_imap,set,store_flags); 1013 err = mailimap_store(m_imap,set,store_flags);
1001 mailimap_set_free( set ); 1014 mailimap_set_free( set );
1002 mailimap_store_att_flags_free(store_flags); 1015 mailimap_store_att_flags_free(store_flags);
1003 1016
1004 if (err != MAILIMAP_NO_ERROR) { 1017 if (err != MAILIMAP_NO_ERROR) {
1005 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1018 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
1006 return; 1019 return;
1007 } 1020 }
1008} 1021}
1009 1022
1010QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1023QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
1011{ 1024{
1012 QString body(""); 1025 QString body("");
1013 encodedString*res = fetchRawPart(mail,path,internal_call); 1026 encodedString*res = fetchRawPart(mail,path,internal_call);
1014 encodedString*r = decode_String(res,enc); 1027 encodedString*r = decode_String(res,enc);
1015 delete res; 1028 delete res;
1016 if (r) { 1029 if (r) {
1017 if (r->Length()>0) { 1030 if (r->Length()>0) {
1018 body = r->Content(); 1031 body = r->Content();
1019 } 1032 }
1020 delete r; 1033 delete r;
1021 } 1034 }
1022 return body; 1035 return body;
1023} 1036}
1024 1037
1025QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1038QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
1026{ 1039{
1027 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1040 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
1028} 1041}
1029 1042
1030encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1043encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1031{ 1044{
1032 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1045 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1033 encodedString*r = decode_String(res,part->Encoding()); 1046 encodedString*r = decode_String(res,part->Encoding());
1034 delete res; 1047 delete res;
1035 return r; 1048 return r;
1036} 1049}
1037 1050
1038encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1051encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1039{ 1052{
1040 return fetchRawPart(mail,part->Positionlist(),false); 1053 return fetchRawPart(mail,part->Positionlist(),false);
1041} 1054}
1042 1055
1043int IMAPwrapper::deleteAllMail(const FolderP&folder) 1056int IMAPwrapper::deleteAllMail(const FolderP&folder)
1044{ 1057{
1045 login(); 1058 login();
1046 if (!m_imap) { 1059 if (!m_imap) {
1047 return 0; 1060 return 0;
1048 } 1061 }
1049 mailimap_flag_list*flist; 1062 mailimap_flag_list*flist;
1050 mailimap_set *set; 1063 mailimap_set *set;
1051 mailimap_store_att_flags * store_flags; 1064 mailimap_store_att_flags * store_flags;
1052 int err = selectMbox(folder->getName()); 1065 int err = selectMbox(folder->getName());
1053 if ( err != MAILIMAP_NO_ERROR ) { 1066 if ( err != MAILIMAP_NO_ERROR ) {
1054 return 0; 1067 return 0;
1055 } 1068 }
1056 1069
1057 int last = m_imap->imap_selection_info->sel_exists; 1070 int last = m_imap->imap_selection_info->sel_exists;
1058 if (last == 0) { 1071 if (last == 0) {
1059 Global::statusMessage(tr("Mailbox has no mails!")); 1072 Global::statusMessage(tr("Mailbox has no mails!"));
1060 return 0; 1073 return 0;
1061 } 1074 }
1062 flist = mailimap_flag_list_new_empty(); 1075 flist = mailimap_flag_list_new_empty();
1063 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1076 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1064 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1077 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1065 set = mailimap_set_new_interval( 1, last ); 1078 set = mailimap_set_new_interval( 1, last );
1066 err = mailimap_store(m_imap,set,store_flags); 1079 err = mailimap_store(m_imap,set,store_flags);
1067 mailimap_set_free( set ); 1080 mailimap_set_free( set );
1068 mailimap_store_att_flags_free(store_flags); 1081 mailimap_store_att_flags_free(store_flags);
1069 if (err != MAILIMAP_NO_ERROR) { 1082 if (err != MAILIMAP_NO_ERROR) {
1070 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1083 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1071 return 0; 1084 return 0;
1072 } 1085 }
1073 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1086 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1074 /* should we realy do that at this moment? */ 1087 /* should we realy do that at this moment? */
1075 err = mailimap_expunge(m_imap); 1088 err = mailimap_expunge(m_imap);
1076 if (err != MAILIMAP_NO_ERROR) { 1089 if (err != MAILIMAP_NO_ERROR) {
1077 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1090 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1078 return 0; 1091 return 0;
1079 } 1092 }
1080 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1093 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1081 return 1; 1094 return 1;
1082} 1095}
1083 1096
1084int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1097int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1085{ 1098{
1086 if (folder.length()==0) return 0; 1099 if (folder.length()==0) return 0;
1087 login(); 1100 login();
1088 if (!m_imap) {return 0;} 1101 if (!m_imap) {return 0;}
1089 QString pre = account->getPrefix(); 1102 QString pre = account->getPrefix();
1090 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1103 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1091 pre+=delemiter; 1104 pre+=delemiter;
1092 } 1105 }
1093 if (parentfolder) { 1106 if (parentfolder) {
1094 pre += parentfolder->getDisplayName()+delemiter; 1107 pre += parentfolder->getDisplayName()+delemiter;
1095 } 1108 }
1096 pre+=folder; 1109 pre+=folder;
1097 if (getsubfolder) { 1110 if (getsubfolder) {
1098 if (delemiter.length()>0) { 1111 if (delemiter.length()>0) {
1099 pre+=delemiter; 1112 pre+=delemiter;
1100 } else { 1113 } else {
1101 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1114 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1102 return 0; 1115 return 0;
1103 } 1116 }
1104 } 1117 }
1105 // odebug << "Creating " << pre.latin1() << "" << oendl; 1118 // odebug << "Creating " << pre.latin1() << "" << oendl;
1106 int res = mailimap_create(m_imap,pre.latin1()); 1119 int res = mailimap_create(m_imap,pre.latin1());
1107 if (res != MAILIMAP_NO_ERROR) { 1120 if (res != MAILIMAP_NO_ERROR) {
1108 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1121 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1109 return 0; 1122 return 0;
1110 } 1123 }
1111 return 1; 1124 return 1;
1112} 1125}
1113 1126
1114int IMAPwrapper::deleteMbox(const FolderP&folder) 1127int IMAPwrapper::deleteMbox(const FolderP&folder)
1115{ 1128{
1116 if (!folder) return 0; 1129 if (!folder) return 0;
1117 login(); 1130 login();
1118 if (!m_imap) {return 0;} 1131 if (!m_imap) {return 0;}
1119 int res = mailimap_delete(m_imap,folder->getName()); 1132 int res = mailimap_delete(m_imap,folder->getName());
1120 if (res != MAILIMAP_NO_ERROR) { 1133 if (res != MAILIMAP_NO_ERROR) {
1121 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1134 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1122 return 0; 1135 return 0;
1123 } 1136 }
1124 return 1; 1137 return 1;
1125} 1138}
1126 1139
1127void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1140void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1128{ 1141{
1129 mailimap_status_att_list * att_list =0; 1142 mailimap_status_att_list * att_list =0;
1130 mailimap_mailbox_data_status * status=0; 1143 mailimap_mailbox_data_status * status=0;
1131 clistiter * cur = 0; 1144 clistiter * cur = 0;
1132 int r = 0; 1145 int r = 0;
1133 target_stat.message_count = 0; 1146 target_stat.message_count = 0;
1134 target_stat.message_unseen = 0; 1147 target_stat.message_unseen = 0;
1135 target_stat.message_recent = 0; 1148 target_stat.message_recent = 0;
1136 login(); 1149 login();
1137 if (!m_imap) { 1150 if (!m_imap) {
1138 return; 1151 return;
1139 } 1152 }
1140 att_list = mailimap_status_att_list_new_empty(); 1153 att_list = mailimap_status_att_list_new_empty();
1141 if (!att_list) return; 1154 if (!att_list) return;
1142 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1155 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1143 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1156 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1144 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1157 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1145 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1158 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1146 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1159 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1147 for (cur = clist_begin(status->st_info_list); 1160 for (cur = clist_begin(status->st_info_list);
1148 cur != NULL ; cur = clist_next(cur)) { 1161 cur != NULL ; cur = clist_next(cur)) {
1149 mailimap_status_info * status_info; 1162 mailimap_status_info * status_info;
1150 status_info = (mailimap_status_info *)clist_content(cur); 1163 status_info = (mailimap_status_info *)clist_content(cur);
1151 switch (status_info->st_att) { 1164 switch (status_info->st_att) {
1152 case MAILIMAP_STATUS_ATT_MESSAGES: 1165 case MAILIMAP_STATUS_ATT_MESSAGES:
1153 target_stat.message_count = status_info->st_value; 1166 target_stat.message_count = status_info->st_value;
1154 break; 1167 break;
1155 case MAILIMAP_STATUS_ATT_RECENT: 1168 case MAILIMAP_STATUS_ATT_RECENT:
1156 target_stat.message_recent = status_info->st_value; 1169 target_stat.message_recent = status_info->st_value;
1157 break; 1170 break;
1158 case MAILIMAP_STATUS_ATT_UNSEEN: 1171 case MAILIMAP_STATUS_ATT_UNSEEN:
1159 target_stat.message_unseen = status_info->st_value; 1172 target_stat.message_unseen = status_info->st_value;
1160 break; 1173 break;
1161 } 1174 }
1162 } 1175 }
1163 } else { 1176 } else {
1164 // odebug << "Error retrieving status" << oendl; 1177 // odebug << "Error retrieving status" << oendl;
1165 } 1178 }
1166 if (status) mailimap_mailbox_data_status_free(status); 1179 if (status) mailimap_mailbox_data_status_free(status);
1167 if (att_list) mailimap_status_att_list_free(att_list); 1180 if (att_list) mailimap_status_att_list_free(att_list);
1168} 1181}
1169 1182
1170void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1183void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1171{ 1184{
1172 login(); 1185 login();
1173 if (!m_imap) return; 1186 if (!m_imap) return;
1174 if (!msg) return; 1187 if (!msg) return;
1175 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1188 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1176 if (r != MAILIMAP_NO_ERROR) { 1189 if (r != MAILIMAP_NO_ERROR) {
1177 Global::statusMessage("Error storing mail!"); 1190 Global::statusMessage("Error storing mail!");
1178 } 1191 }
1179} 1192}
1180 1193
1181MAILLIB::ATYPE IMAPwrapper::getType()const 1194MAILLIB::ATYPE IMAPwrapper::getType()const
1182{ 1195{
1183 return account->getType(); 1196 return account->getType();
1184} 1197}
1185 1198
1186const QString&IMAPwrapper::getName()const 1199const QString&IMAPwrapper::getName()const
1187{ 1200{
1188 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1201 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1189 return account->getAccountName(); 1202 return account->getAccountName();
1190} 1203}
1191 1204
1192encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1205encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1193{ 1206{
1194 // dummy 1207 // dummy
1195 QValueList<int> path; 1208 QValueList<int> path;
1196 return fetchRawPart(mail,path,false); 1209 return fetchRawPart(mail,path,false);
1197} 1210}
1198 1211
1199void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1212void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1200 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1213 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1201{ 1214{
1202 if (targetWrapper != this || maxSizeInKb > 0 ) { 1215 if (targetWrapper != this || maxSizeInKb > 0 ) {
1216 mMax = 0;
1217 progress( tr("Copy"));
1203 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1218 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1204 qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1219 qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1205 // odebug << "Using generic" << oendl; 1220 // odebug << "Using generic" << oendl;
1206 return; 1221 return;
1207 } 1222 }
1208 mailimap_set *set = 0; 1223 mailimap_set *set = 0;
1209 login(); 1224 login();
1210 if (!m_imap) { 1225 if (!m_imap) {
1211 return; 1226 return;
1212 } 1227 }
1213 int err = selectMbox(fromFolder->getName()); 1228 int err = selectMbox(fromFolder->getName());
1214 if ( err != MAILIMAP_NO_ERROR ) { 1229 if ( err != MAILIMAP_NO_ERROR ) {
1215 return; 1230 return;
1216 } 1231 }
1232 Global::statusMessage( tr("Copying mails on server...") );
1217 int last = m_imap->imap_selection_info->sel_exists; 1233 int last = m_imap->imap_selection_info->sel_exists;
1218 set = mailimap_set_new_interval( 1, last ); 1234 set = mailimap_set_new_interval( 1, last );
1219 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1235 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1220 mailimap_set_free( set ); 1236 mailimap_set_free( set );
1221 if ( err != MAILIMAP_NO_ERROR ) { 1237 if ( err != MAILIMAP_NO_ERROR ) {
1222 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response); 1238 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response);
1223 Global::statusMessage(error_msg); 1239 Global::statusMessage(error_msg);
1224 // odebug << error_msg << oendl; 1240 // odebug << error_msg << oendl;
1225 return; 1241 return;
1226 } 1242 }
1227 if (moveit) { 1243 if (moveit) {
1228 deleteAllMail(fromFolder); 1244 deleteAllMail(fromFolder);
1229 } 1245 }
1230} 1246}
1231 1247
1232void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1248void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1233{ 1249{
1234 if (targetWrapper != this) { 1250 if (targetWrapper != this) {
1235 // odebug << "Using generic" << oendl; 1251 // odebug << "Using generic" << oendl;
1236 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1252 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1237 return; 1253 return;
1238 } 1254 }
1239 mailimap_set *set = 0; 1255 mailimap_set *set = 0;
1240 login(); 1256 login();
1241 if (!m_imap) { 1257 if (!m_imap) {
1242 return; 1258 return;
1243 } 1259 }
1244 int err = selectMbox(mail->getMbox()); 1260 int err = selectMbox(mail->getMbox());
1245 if ( err != MAILIMAP_NO_ERROR ) { 1261 if ( err != MAILIMAP_NO_ERROR ) {
1246 return; 1262 return;
1247 } 1263 }
1248 set = mailimap_set_new_single(mail->getNumber()); 1264 set = mailimap_set_new_single(mail->getNumber());
1249 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1265 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1250 mailimap_set_free( set ); 1266 mailimap_set_free( set );
1251 if ( err != MAILIMAP_NO_ERROR ) { 1267 if ( err != MAILIMAP_NO_ERROR ) {
1252 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1268 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1253 Global::statusMessage(error_msg); 1269 Global::statusMessage(error_msg);
1254 // odebug << error_msg << oendl; 1270 // odebug << error_msg << oendl;
1255 return; 1271 return;
1256 } 1272 }
1257 if (moveit) { 1273 if (moveit) {
1258 deleteMail(mail); 1274 deleteMail(mail);
1259 } 1275 }
1260} 1276}
diff --git a/kmicromail/libmailwrapper/imapwrapper.h b/kmicromail/libmailwrapper/imapwrapper.h
index 222fe95..db8ab5b 100644
--- a/kmicromail/libmailwrapper/imapwrapper.h
+++ b/kmicromail/libmailwrapper/imapwrapper.h
@@ -1,82 +1,84 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __IMAPWRAPPER 2#ifndef __IMAPWRAPPER
3#define __IMAPWRAPPER 3#define __IMAPWRAPPER
4 4
5#include <qlist.h> 5#include <qlist.h>
6#include "mailwrapper.h" 6#include "mailwrapper.h"
7#include "abstractmail.h" 7#include "abstractmail.h"
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10struct mailimap; 10struct mailimap;
11struct mailimap_body; 11struct mailimap_body;
12struct mailimap_body_type_1part; 12struct mailimap_body_type_1part;
13struct mailimap_body_type_text; 13struct mailimap_body_type_text;
14struct mailimap_body_type_basic; 14struct mailimap_body_type_basic;
15struct mailimap_body_type_msg; 15struct mailimap_body_type_msg;
16struct mailimap_body_type_mpart; 16struct mailimap_body_type_mpart;
17struct mailimap_body_fields; 17struct mailimap_body_fields;
18struct mailimap_msg_att; 18struct mailimap_msg_att;
19class encodedString; 19class encodedString;
20 20
21class IMAPwrapper : public AbstractMail 21class IMAPwrapper : public AbstractMail
22{ 22{
23 Q_OBJECT 23 Q_OBJECT
24public: 24public:
25 IMAPwrapper( IMAPaccount *a ); 25 IMAPwrapper( IMAPaccount *a );
26 virtual ~IMAPwrapper(); 26 virtual ~IMAPwrapper();
27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 27 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0); 28 virtual void listMessages(const QString & mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> >&target , int sizeInKb = 0);
29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 29 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
30 30
31 virtual void deleteMail(const RecMailP&mail); 31 virtual void deleteMail(const RecMailP&mail);
32 void deleteMailList(const QValueList<RecMailP>&target); 32 void deleteMailList(const QValueList<RecMailP>&target);
33 virtual void answeredMail(const RecMailP&mail); 33 virtual void answeredMail(const RecMailP&mail);
34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder); 34 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&folder);
35 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 35 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder, 36 virtual void mvcpAllMails(const Opie::Core::OSmartPointer<Folder>&fromFolder,
37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0); 37 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit,int sizeInKb = 0);
38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 38 virtual void mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
39 39
40 virtual RecBodyP fetchBody(const RecMailP&mail); 40 virtual RecBodyP fetchBody(const RecMailP&mail);
41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part); 41 virtual QString fetchTextPart(const RecMailP&mail,const RecPartP&part);
42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part); 42 virtual encodedString* fetchDecodedPart(const RecMailP&mail,const RecPartP&part);
43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part); 43 virtual encodedString* fetchRawPart(const RecMailP&mail,const RecPartP&part);
44 virtual encodedString* fetchRawBody(const RecMailP&mail); 44 virtual encodedString* fetchRawBody(const RecMailP&mail);
45 45
46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0, 46 virtual int createMbox(const QString&,const Opie::Core::OSmartPointer<Folder>&parentfolder=0,
47 const QString& delemiter="/",bool getsubfolder=false); 47 const QString& delemiter="/",bool getsubfolder=false);
48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder); 48 virtual int deleteMbox(const Opie::Core::OSmartPointer<Folder>&folder);
49 49
50 static void imap_progress( size_t current, size_t maximum ); 50 static void imap_progress( size_t current, size_t maximum );
51 51
52 virtual void logout(); 52 virtual void logout();
53 virtual MAILLIB::ATYPE getType()const; 53 virtual MAILLIB::ATYPE getType()const;
54 virtual const QString&getName()const; 54 virtual const QString&getName()const;
55 55
56protected: 56protected:
57 RecMail*parse_list_result(mailimap_msg_att*); 57 RecMail*parse_list_result(mailimap_msg_att*);
58 void login(); 58 void login();
59 bool start_tls(bool force=true); 59 bool start_tls(bool force=true);
60 60
61 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 61 virtual QString fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
62 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call); 62 virtual encodedString*fetchRawPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call);
63 int selectMbox(const QString&mbox); 63 int selectMbox(const QString&mbox);
64 64
65 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description); 65 void fillSinglePart(RecPartP&target_part,mailimap_body_type_1part*Description);
66 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which); 66 void fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which);
67 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which); 67 void fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which);
68 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which); 68 void fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which);
69 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which); 69 void fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which);
70 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 70 void traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
71 71
72 /* just helpers */ 72 /* just helpers */
73 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which); 73 static void fillBodyFields(RecPartP&target_part,mailimap_body_fields*which);
74 static QStringList address_list_to_stringlist(clist*list); 74 static QStringList address_list_to_stringlist(clist*list);
75 75
76 76 static void progress(QString mess = QString::null);
77 static int mCurrent;
78 static int mMax;
77 IMAPaccount *account; 79 IMAPaccount *account;
78 mailimap *m_imap; 80 mailimap *m_imap;
79 QString m_Lastmbox; 81 QString m_Lastmbox;
80}; 82};
81 83
82#endif 84#endif
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index f430121..8d2f778 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,319 +1,294 @@
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 8
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <qfile.h> 10#include <qfile.h>
11#include <qprogressbar.h> 11#include <qprogressbar.h>
12#include <qapplication.h> 12#include <qapplication.h>
13 13
14/* we don't fetch messages larger than 5 MB */ 14/* we don't fetch messages larger than 5 MB */
15#define HARD_MSG_SIZE_LIMIT 5242880 15#define HARD_MSG_SIZE_LIMIT 5242880
16 16
17using namespace Opie::Core; 17using namespace Opie::Core;
18POP3wrapper::POP3wrapper( POP3account *a ) 18POP3wrapper::POP3wrapper( POP3account *a )
19: Genericwrapper() { 19: Genericwrapper() {
20 account = a; 20 account = a;
21 m_pop3 = NULL; 21 m_pop3 = NULL;
22 msgTempName = a->getFileName()+"_msg_cache"; 22 msgTempName = a->getFileName()+"_msg_cache";
23 last_msg_id = 0; 23 last_msg_id = 0;
24} 24}
25 25
26POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
27 logout(); 27 logout();
28 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
29 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
30 msg_cache.remove(); 30 msg_cache.remove();
31 } 31 }
32} 32}
33 33
34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
36} 36}
37 37
38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
44 44
45 login(); 45 login();
46 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
47 return body; 47 return body;
48 } 48 }
49 49
50 mailmessage * mailmsg; 50 mailmessage * mailmsg;
51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
53 return body; 53 return body;
54 } 54 }
55 55
56 QFile msg_cache(msgTempName); 56 QFile msg_cache(msgTempName);
57 57
58 cleanMimeCache(); 58 cleanMimeCache();
59 59
60 if (mail->getNumber()!=last_msg_id) { 60 if (mail->getNumber()!=last_msg_id) {
61 if (msg_cache.exists()) { 61 if (msg_cache.exists()) {
62 msg_cache.remove(); 62 msg_cache.remove();
63 } 63 }
64 msg_cache.open(IO_ReadWrite|IO_Truncate); 64 msg_cache.open(IO_ReadWrite|IO_Truncate);
65 last_msg_id = mail->getNumber(); 65 last_msg_id = mail->getNumber();
66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
67 err = mailmessage_fetch(mailmsg,&message,&length); 67 err = mailmessage_fetch(mailmsg,&message,&length);
68 msg_cache.writeBlock(message,length); 68 msg_cache.writeBlock(message,length);
69 } else { 69 } else {
70 QString msg=""; 70 QString msg="";
71 msg_cache.open(IO_ReadOnly); 71 msg_cache.open(IO_ReadOnly);
72 message = new char[4096]; 72 message = new char[4096];
73 memset(message,0,4096); 73 memset(message,0,4096);
74 while (msg_cache.readBlock(message,4095)>0) { 74 while (msg_cache.readBlock(message,4095)>0) {
75 msg+=message; 75 msg+=message;
76 memset(message,0,4096); 76 memset(message,0,4096);
77 } 77 }
78 delete message; 78 delete message;
79 message = (char*)malloc(msg.length()+1*sizeof(char)); 79 message = (char*)malloc(msg.length()+1*sizeof(char));
80 memset(message,0,msg.length()+1); 80 memset(message,0,msg.length()+1);
81 memcpy(message,msg.latin1(),msg.length()); 81 memcpy(message,msg.latin1(),msg.length());
82 /* transform to libetpan stuff */ 82 /* transform to libetpan stuff */
83 mailmsg = mailmessage_new(); 83 mailmsg = mailmessage_new();
84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
85 generic_message_t * msg_data; 85 generic_message_t * msg_data;
86 msg_data = (generic_message_t *)mailmsg->msg_data; 86 msg_data = (generic_message_t *)mailmsg->msg_data;
87 msg_data->msg_fetched = 1; 87 msg_data->msg_fetched = 1;
88 msg_data->msg_message = message; 88 msg_data->msg_message = message;
89 msg_data->msg_length = strlen(message); 89 msg_data->msg_length = strlen(message);
90 } 90 }
91 body = parseMail(mailmsg); 91 body = parseMail(mailmsg);
92 92
93 /* clean up */ 93 /* clean up */
94 if (mailmsg) 94 if (mailmsg)
95 mailmessage_free(mailmsg); 95 mailmessage_free(mailmsg);
96 if (message) 96 if (message)
97 free(message); 97 free(message);
98 98
99 return body; 99 return body;
100} 100}
101 101
102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
103{ 103{
104 login(); 104 login();
105 if (!m_pop3) 105 if (!m_pop3)
106 return; 106 return;
107 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
111} 111}
112 112
113void POP3wrapper::login() 113void POP3wrapper::login()
114{ 114{
115 if (account->getOffline()) 115 if (account->getOffline())
116 return; 116 return;
117 /* we'll hold the line */ 117 /* we'll hold the line */
118 if ( m_pop3 != NULL ) 118 if ( m_pop3 != NULL )
119 return; 119 return;
120 120
121 QString server,user, pass; 121 QString server,user, pass;
122 uint16_t port; 122 uint16_t port;
123 int err = MAILPOP3_NO_ERROR; 123 int err = MAILPOP3_NO_ERROR;
124 124
125 server = account->getServer().latin1(); 125 server = account->getServer().latin1();
126 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
127 127
128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
129 qApp->processEvents();
129 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
130 login.show(); 131 login.show();
131 if ( QDialog::Accepted == login.exec() ) { 132 if ( QDialog::Accepted == login.exec() ) {
132 // ok 133 // ok
133 qDebug("ok ");
134 user = login.getUser(); 134 user = login.getUser();
135 pass = login.getPassword(); 135 pass = login.getPassword();
136 } else { 136 } else {
137 // cancel 137 // cancel
138 ; // odebug << "POP3: Login canceled" << oendl; 138 ; // odebug << "POP3: Login canceled" << oendl;
139 return; 139 return;
140 } 140 }
141 } else { 141 } else {
142 user = account->getUser(); 142 user = account->getUser();
143 pass = account->getPassword(); 143 pass = account->getPassword();
144 } 144 }
145 // bool ssl = account->getSSL(); 145 // bool ssl = account->getSSL();
146 146
147 m_pop3=mailstorage_new(NULL); 147 m_pop3=mailstorage_new(NULL);
148 int conntypeset = account->ConnectionType(); 148 int conntypeset = account->ConnectionType();
149 int conntype = 0; 149 int conntype = 0;
150 if ( conntypeset == 3 ) { 150 if ( conntypeset == 3 ) {
151 conntype = CONNECTION_TYPE_COMMAND; 151 conntype = CONNECTION_TYPE_COMMAND;
152 } else if ( conntypeset == 2 ) { 152 } else if ( conntypeset == 2 ) {
153 conntype = CONNECTION_TYPE_TLS; 153 conntype = CONNECTION_TYPE_TLS;
154 } else if ( conntypeset == 1 ) { 154 } else if ( conntypeset == 1 ) {
155 conntype = CONNECTION_TYPE_STARTTLS; 155 conntype = CONNECTION_TYPE_STARTTLS;
156 } else if ( conntypeset == 0 ) { 156 } else if ( conntypeset == 0 ) {
157 conntype = CONNECTION_TYPE_TRY_STARTTLS; 157 conntype = CONNECTION_TYPE_TRY_STARTTLS;
158 } 158 }
159 159
160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
161 161
162 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 162 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); 163 (char*)user.latin1(),(char*)pass.latin1(),0,0,0);
164 164
165 err = mailstorage_connect(m_pop3); 165 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 166 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error initializing folder")); 168 Global::statusMessage(tr("Error %1 initializing folder").arg( err ));
169 mailstorage_free(m_pop3); 169 mailstorage_free(m_pop3);
170 m_pop3 = 0; 170 m_pop3 = 0;
171 } else { 171 } else {
172 mailsession * session = m_pop3->sto_session; 172 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 174 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 175 mail->pop3_progr_fun = &pop3_progress;
176 } 176 }
177 } 177 }
178} 178}
179 179
180void POP3wrapper::logout() 180void POP3wrapper::logout()
181{ 181{
182 if ( m_pop3 == NULL ) 182 if ( m_pop3 == NULL )
183 return; 183 return;
184 mailstorage_free(m_pop3); 184 mailstorage_free(m_pop3);
185 m_pop3 = 0; 185 m_pop3 = 0;
186} 186}
187 187
188 188
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 191 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 192 folders->append(inb);
193 return folders; 193 return folders;
194} 194}
195 195
196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) 196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 197{
198 login(); 198 login();
199 if (!m_pop3) 199 if (!m_pop3)
200 return; 200 return;
201 int iii = 0; 201 int iii = 0;
202 int count = target.count(); 202 int count = target.count();
203 QProgressBar bar( count,0 ); 203 QWidget wid;
204 bar.setCaption (("Removing mails - close to abort!") ); 204 wid.show();
205 int w = 300;
206 if ( QApplication::desktop()->width() < 320 )
207 w = 220;
208 int h = bar.sizeHint().height() ;
209 int dw = QApplication::desktop()->width();
210 int dh = QApplication::desktop()->height();
211 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
212 bar.show();
213 int modulo = (count/10)+1;
214 int incCounter = 0;
215 while (iii < count ) { 205 while (iii < count ) {
216 if ( ! bar.isVisible() ) 206 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count));
217 return ; 207 wid.raise();
218 if ( incCounter % modulo == 0 )
219 bar.setProgress( incCounter );
220 ++incCounter;
221 qApp->processEvents(); 208 qApp->processEvents();
222 //qDebug("delete "); 209 //qDebug("delete ");
223 RecMailP mail = (*target.at( iii )); 210 RecMailP mail = (*target.at( iii ));
224 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 211 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
225 if (err != MAIL_NO_ERROR) { 212 if (err != MAIL_NO_ERROR) {
226 Global::statusMessage(tr("Error deleting mail")); 213 Global::statusMessage(tr("Error deleting mail"));
227 } 214 }
228 ++iii; 215 ++iii;
229 } 216 }
230} 217}
231void POP3wrapper::deleteMail(const RecMailP&mail) { 218void POP3wrapper::deleteMail(const RecMailP&mail) {
232 login(); 219 login();
233 if (!m_pop3) 220 if (!m_pop3)
234 return; 221 return;
235 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 222 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
236 if (err != MAIL_NO_ERROR) { 223 if (err != MAIL_NO_ERROR) {
237 Global::statusMessage(tr("error deleting mail")); 224 Global::statusMessage(tr("error deleting mail"));
238 } 225 }
239} 226}
240 227
241void POP3wrapper::answeredMail(const RecMailP&) {} 228void POP3wrapper::answeredMail(const RecMailP&) {}
242 229
243int POP3wrapper::deleteAllMail(const FolderP&) { 230int POP3wrapper::deleteAllMail(const FolderP&) {
244 login(); 231 login();
245 if (!m_pop3) 232 if (!m_pop3)
246 return 0; 233 return 0;
247 int res = 1; 234 int res = 1;
248 235
249 uint32_t result = 0; 236 uint32_t result = 0;
250 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 237 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
251 if (err != MAIL_NO_ERROR) { 238 if (err != MAIL_NO_ERROR) {
252 Global::statusMessage(tr("Error getting folder info")); 239 Global::statusMessage(tr("Error getting folder info"));
253 return 0; 240 return 0;
254 } 241 }
255 QProgressBar bar( result,0 ); 242 QWidget wid;
256 bar.setCaption (("Deleting mails - close to abort!") ); 243 wid.show();
257 int w = 300; 244 for (unsigned int i = 0; i < result; ++i) {
258 if ( QApplication::desktop()->width() < 320 ) 245 Global::statusMessage(tr("Delete message %1 of %2").arg(i).arg(result));
259 w = 220; 246 wid.raise();
260 int h = bar.sizeHint().height() ;
261 int dw = QApplication::desktop()->width();
262 int dh = QApplication::desktop()->height();
263 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
264 bar.show();
265 int modulo = (result/10)+1;
266 int incCounter = 0;
267 for (unsigned int i = 0; i < result; ++i) {
268 if ( ! bar.isVisible() )
269 return 0;
270 if ( incCounter % modulo == 0 )
271 bar.setProgress( incCounter );
272 ++incCounter;
273 qApp->processEvents(); 247 qApp->processEvents();
248
274 err = mailsession_remove_message(m_pop3->sto_session,i+1); 249 err = mailsession_remove_message(m_pop3->sto_session,i+1);
275 if (err != MAIL_NO_ERROR) { 250 if (err != MAIL_NO_ERROR) {
276 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 251 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
277 res=0; 252 res=0;
278 } 253 }
279 break; 254 break;
280 } 255 }
281 return res; 256 return res;
282} 257}
283 258
284void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 259void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
285 login(); 260 login();
286 target_stat.message_count = 0; 261 target_stat.message_count = 0;
287 target_stat.message_unseen = 0; 262 target_stat.message_unseen = 0;
288 target_stat.message_recent = 0; 263 target_stat.message_recent = 0;
289 if (!m_pop3) 264 if (!m_pop3)
290 return; 265 return;
291 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 266 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
292 &target_stat.message_recent,&target_stat.message_unseen); 267 &target_stat.message_recent,&target_stat.message_unseen);
293 if (r != MAIL_NO_ERROR) { 268 if (r != MAIL_NO_ERROR) {
294 ; // odebug << "error getting folter status." << oendl; 269 ; // odebug << "error getting folter status." << oendl;
295 } 270 }
296} 271}
297 272
298encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 273encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
299 char*target=0; 274 char*target=0;
300 size_t length=0; 275 size_t length=0;
301 encodedString*res = 0; 276 encodedString*res = 0;
302 mailmessage * mailmsg = 0; 277 mailmessage * mailmsg = 0;
303 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 278 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
304 err = mailmessage_fetch(mailmsg,&target,&length); 279 err = mailmessage_fetch(mailmsg,&target,&length);
305 if (mailmsg) 280 if (mailmsg)
306 mailmessage_free(mailmsg); 281 mailmessage_free(mailmsg);
307 if (target) { 282 if (target) {
308 res = new encodedString(target,length); 283 res = new encodedString(target,length);
309 } 284 }
310 return res; 285 return res;
311} 286}
312 287
313MAILLIB::ATYPE POP3wrapper::getType()const { 288MAILLIB::ATYPE POP3wrapper::getType()const {
314 return account->getType(); 289 return account->getType();
315} 290}
316 291
317const QString&POP3wrapper::getName()const{ 292const QString&POP3wrapper::getName()const{
318 return account->getAccountName(); 293 return account->getAccountName();
319} 294}