summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper
authorzautrix <zautrix>2004-09-01 10:23:29 (UTC)
committer zautrix <zautrix>2004-09-01 10:23:29 (UTC)
commit6cefbdc9c8f3f3001373f10715361e2740c45395 (patch) (unidiff)
treecb2c36f57620e698913c27ca4ebe59e4a7c9d46e /kmicromail/libmailwrapper
parentb9257cb225cd29bab5d96fcdaf557926603ee587 (diff)
downloadkdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.zip
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.gz
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.bz2
Mail fixes and libetpan updated
Diffstat (limited to 'kmicromail/libmailwrapper') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/abstractmail.cpp58
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp46
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp47
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.h2
4 files changed, 136 insertions, 17 deletions
diff --git a/kmicromail/libmailwrapper/abstractmail.cpp b/kmicromail/libmailwrapper/abstractmail.cpp
index 3998abd..3b0ca1f 100644
--- a/kmicromail/libmailwrapper/abstractmail.cpp
+++ b/kmicromail/libmailwrapper/abstractmail.cpp
@@ -1,187 +1,237 @@
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 8
9 9
10#include <qprogressbar.h>
11#include <qapplication.h>
10 12
11#include <kdecore/kstandarddirs.h> 13#include <kdecore/kstandarddirs.h>
12#include <qfile.h> 14#include <qfile.h>
13#include <qtextstream.h> 15#include <qtextstream.h>
14#include <stdlib.h> 16#include <stdlib.h>
15#include <libetpan/mailmime_content.h> 17#include <libetpan/mailmime_content.h>
16#include <libetpan/mailmime.h> 18#include <libetpan/mailmime.h>
17 19
18using namespace Opie::Core; 20using namespace Opie::Core;
19AbstractMail* AbstractMail::getWrapper(IMAPaccount *a) 21AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
20{ 22{
21 return new IMAPwrapper(a); 23 return new IMAPwrapper(a);
22} 24}
23 25
24AbstractMail* AbstractMail::getWrapper(POP3account *a) 26AbstractMail* AbstractMail::getWrapper(POP3account *a)
25{ 27{
26 return new POP3wrapper(a); 28 return new POP3wrapper(a);
27} 29}
28 30
29AbstractMail* AbstractMail::getWrapper(NNTPaccount *a) 31AbstractMail* AbstractMail::getWrapper(NNTPaccount *a)
30{ 32{
31 return new NNTPwrapper(a); 33 return new NNTPwrapper(a);
32} 34}
33 35
34AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 36AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
35{ 37{
36 return new MHwrapper(a,name); 38 return new MHwrapper(a,name);
37} 39}
38 40
39AbstractMail* AbstractMail::getWrapper(Account*a) 41AbstractMail* AbstractMail::getWrapper(Account*a)
40{ 42{
41 if (!a) return 0; 43 if (!a) return 0;
42 switch (a->getType()) { 44 switch (a->getType()) {
43 case MAILLIB::A_IMAP: 45 case MAILLIB::A_IMAP:
44 return new IMAPwrapper((IMAPaccount*)a); 46 return new IMAPwrapper((IMAPaccount*)a);
45 break; 47 break;
46 case MAILLIB::A_POP3: 48 case MAILLIB::A_POP3:
47 return new POP3wrapper((POP3account*)a); 49 return new POP3wrapper((POP3account*)a);
48 break; 50 break;
49 case MAILLIB::A_NNTP: 51 case MAILLIB::A_NNTP:
50 return new NNTPwrapper((NNTPaccount*)a); 52 return new NNTPwrapper((NNTPaccount*)a);
51 break; 53 break;
52 default: 54 default:
53 return 0; 55 return 0;
54 } 56 }
55} 57}
56 58
57encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) 59encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
58{ 60{
59 // odebug << "Decode string start" << oendl; 61 // odebug << "Decode string start" << oendl;
60 char*result_text; 62 char*result_text;
61 size_t index = 0; 63 size_t index = 0;
62 /* reset for recursive use! */ 64 /* reset for recursive use! */
63 size_t target_length = 0; 65 size_t target_length = 0;
64 result_text = 0; 66 result_text = 0;
65 int mimetype = MAILMIME_MECHANISM_7BIT; 67 int mimetype = MAILMIME_MECHANISM_7BIT;
66 if (enc.lower()=="quoted-printable") { 68 if (enc.lower()=="quoted-printable") {
67 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 69 mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
68 } else if (enc.lower()=="base64") { 70 } else if (enc.lower()=="base64") {
69 mimetype = MAILMIME_MECHANISM_BASE64; 71 mimetype = MAILMIME_MECHANISM_BASE64;
70 } else if (enc.lower()=="8bit") { 72 } else if (enc.lower()=="8bit") {
71 mimetype = MAILMIME_MECHANISM_8BIT; 73 mimetype = MAILMIME_MECHANISM_8BIT;
72 } else if (enc.lower()=="binary") { 74 } else if (enc.lower()=="binary") {
73 mimetype = MAILMIME_MECHANISM_BINARY; 75 mimetype = MAILMIME_MECHANISM_BINARY;
74 } 76 }
75 77
76 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, 78 int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
77 &result_text,&target_length); 79 &result_text,&target_length);
78 80
79 encodedString* result = new encodedString(); 81 encodedString* result = new encodedString();
80 if (err == MAILIMF_NO_ERROR) { 82 if (err == MAILIMF_NO_ERROR) {
81 result->setContent(result_text,target_length); 83 result->setContent(result_text,target_length);
82 } 84 }
83 //odebug << "Decode string finished" << oendl; 85 //odebug << "Decode string finished" << oendl;
84 return result; 86 return result;
85} 87}
86 88
87QString AbstractMail::convert_String(const char*text) 89QString AbstractMail::convert_String(const char*text)
88{ 90{
89 //size_t index = 0; 91 //size_t index = 0;
90 char*res = 0; 92 char*res = 0;
91 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
92 94
93 QString result(text); 95 QString result(text);
94 96
95 /* due a bug in libetpan it isn't usable this moment */ 97 /* due a bug in libetpan it isn't usable this moment */
96/* int err = mailmime_encoded_phrase_parse("iso-8859-1", 98/* int err = mailmime_encoded_phrase_parse("iso-8859-1",
97 text, strlen(text),&index, "iso-8859-1",&res);*/ 99 text, strlen(text),&index, "iso-8859-1",&res);*/
98 //odebug << "Input: " << text << "" << oendl; 100 //odebug << "Input: " << text << "" << oendl;
99 if (err == MAILIMF_NO_ERROR && res && strlen(res)) { 101 if (err == MAILIMF_NO_ERROR && res && strlen(res)) {
100// result = QString(res); 102// result = QString(res);
101// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl; 103// odebug << "Res: " << res << ", length: " << strlen(res) << "" << oendl;
102 } 104 }
103 if (res) free(res); 105 if (res) free(res);
104 return result; 106 return result;
105} 107}
106 108
107/* cp & paste from launcher */ 109/* cp & paste from launcher */
108QString AbstractMail::gen_attachment_id() 110QString AbstractMail::gen_attachment_id()
109{ 111{
110 QFile file( "/proc/sys/kernel/random/uuid" ); 112 QFile file( "/proc/sys/kernel/random/uuid" );
111 if (!file.open(IO_ReadOnly ) ) 113 if (!file.open(IO_ReadOnly ) )
112 return QString::null; 114 return QString::null;
113 115
114 QTextStream stream(&file); 116 QTextStream stream(&file);
115 117
116 return "{" + stream.read().stripWhiteSpace() + "}"; 118 return "{" + stream.read().stripWhiteSpace() + "}";
117} 119}
118 120
119int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool) 121int AbstractMail::createMbox(const QString&,const FolderP&,const QString& ,bool)
120{ 122{
121 return 0; 123 return 0;
122} 124}
123 125
124QString AbstractMail::defaultLocalfolder() 126QString AbstractMail::defaultLocalfolder()
125{ 127{
126 // QString f = getenv( "HOME" ); 128 // QString f = getenv( "HOME" );
127 QString f = locateLocal( "data", "kmicromail/localmail"); 129 QString f = locateLocal( "data", "kmicromail/localmail");
128 // f += "/Applications/opiemail/localmail"; 130 // f += "/Applications/opiemail/localmail";
129 return f; 131 return f;
130} 132}
131 133
132QString AbstractMail::draftFolder() 134QString AbstractMail::draftFolder()
133{ 135{
134 return QString("Drafts"); 136 return QString("Drafts");
135} 137}
136 138
137/* temporary - will be removed when implemented in all classes */ 139/* temporary - will be removed when implemented in all classes */
138void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &) 140void AbstractMail::deleteMails(const QString &,const QValueList<Opie::Core::OSmartPointer<RecMail> > &)
139{ 141{
140} 142}
141void AbstractMail::deleteMailList(const QValueList<RecMailP>&target) 143void AbstractMail::deleteMailList(const QValueList<RecMailP>&target)
142{ 144{
143 qDebug("AbstractMail::deleteMailList:: Please reimplement! "); 145 //qDebug("AbstractMail::deleteMailList:: Please reimplement! ");
144 146 // this is currently re-implemented in pop3wrapper and imapwrapper
147 int iii = 0;
148 int count = target.count();
149 QProgressBar bar( count,0 );
150 bar.setCaption (("Removing mails - close to abort!") );
151 int w = 300;
152 if ( QApplication::desktop()->width() < 320 )
153 w = 220;
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();
168 RecMailP mail = (*target.at( iii ));
169 deleteMail(mail);
170 ++iii;
171 }
145} 172}
146void AbstractMail::mvcpAllMails(const FolderP&fromFolder, 173void AbstractMail::mvcpAllMails(const FolderP&fromFolder,
147 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 174 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
148{ 175{
149 QValueList<RecMailP> t; 176 QValueList<RecMailP> t;
150 listMessages(fromFolder->getName(),t, maxSizeInKb); 177 listMessages(fromFolder->getName(),t, maxSizeInKb);
151 mvcpMailList( t,targetFolder,targetWrapper,moveit); 178 mvcpMailList( t,targetFolder,targetWrapper,moveit);
152 179
153} 180}
154void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t, 181void AbstractMail::mvcpMailList(const QValueList<RecMailP>& t,
155 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 182 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
156{ 183{
157
158 encodedString*st = 0; 184 encodedString*st = 0;
159 int iii = 0; 185 int iii = 0;
160 int count = t.count(); 186 int count = t.count();
187 if ( count == 0 )
188 return;
189
190 QProgressBar bar( count,0 );
191 bar.setCaption (("Copying mails - close to abort!") );
192 int w = 300;
193 if ( QApplication::desktop()->width() < 320 )
194 w = 220;
195 int h = bar.sizeHint().height() ;
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;
161 while (iii < count ) { 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();
210 //qDebug("copy ");
162 RecMailP r = (*t.at( iii )); 211 RecMailP r = (*t.at( iii ));
163 st = fetchRawBody(r); 212 st = fetchRawBody(r);
164 if (st) { 213 if (st) {
165 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 214 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
166 delete st; 215 delete st;
167 } 216 }
168 ++iii; 217 ++iii;
169 } 218 }
219 bar.hide();
170 if (moveit) { 220 if (moveit) {
171 deleteMailList( t ); 221 deleteMailList( t );
172 //deleteAllMail(fromFolder); 222 //deleteAllMail(fromFolder);
173 } 223 }
174} 224}
175 225
176void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 226void AbstractMail::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
177{ 227{
178 encodedString*st = 0; 228 encodedString*st = 0;
179 st = fetchRawBody(mail); 229 st = fetchRawBody(mail);
180 if (st) { 230 if (st) {
181 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder); 231 targetWrapper->storeMessage(st->Content(),st->Length(),targetFolder);
182 delete st; 232 delete st;
183 } 233 }
184 if (moveit) { 234 if (moveit) {
185 deleteMail(mail); 235 deleteMail(mail);
186 } 236 }
187} 237}
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index bb8bbfc..11d3343 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -1,136 +1,137 @@
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 10
10using namespace Opie::Core; 11using namespace Opie::Core;
11IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 12IMAPwrapper::IMAPwrapper( IMAPaccount *a )
12 : AbstractMail() 13 : AbstractMail()
13{ 14{
14 account = a; 15 account = a;
15 m_imap = 0; 16 m_imap = 0;
16 m_Lastmbox = ""; 17 m_Lastmbox = "";
17} 18}
18 19
19IMAPwrapper::~IMAPwrapper() 20IMAPwrapper::~IMAPwrapper()
20{ 21{
21 logout(); 22 logout();
22} 23}
23 24
24/* to avoid to often select statements in loops etc. 25/* to avoid to often select statements in loops etc.
25 we trust that we are logged in and connection is established!*/ 26 we trust that we are logged in and connection is established!*/
26int IMAPwrapper::selectMbox(const QString&mbox) 27int IMAPwrapper::selectMbox(const QString&mbox)
27{ 28{
28 if (mbox == m_Lastmbox) { 29 if (mbox == m_Lastmbox) {
29 return MAILIMAP_NO_ERROR; 30 return MAILIMAP_NO_ERROR;
30 } 31 }
31 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 32 int err = mailimap_select( m_imap, (char*)mbox.latin1());
32 if ( err != MAILIMAP_NO_ERROR ) { 33 if ( err != MAILIMAP_NO_ERROR ) {
33 m_Lastmbox = ""; 34 m_Lastmbox = "";
34 return err; 35 return err;
35 } 36 }
36 m_Lastmbox = mbox; 37 m_Lastmbox = mbox;
37 return err; 38 return err;
38} 39}
39 40
40void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 41void IMAPwrapper::imap_progress( size_t current, size_t maximum )
41{ 42{
42 qApp->processEvents(); 43 qApp->processEvents();
43 qDebug("imap progress %d of %d ",current,maximum ); 44 qDebug("imap progress %d of %d ",current,maximum );
44} 45}
45 46
46bool IMAPwrapper::start_tls(bool force_tls) 47bool IMAPwrapper::start_tls(bool force_tls)
47{ 48{
48 int err; 49 int err;
49 bool try_tls; 50 bool try_tls;
50 mailimap_capability_data * cap_data = 0; 51 mailimap_capability_data * cap_data = 0;
51 52
52 err = mailimap_capability(m_imap,&cap_data); 53 err = mailimap_capability(m_imap,&cap_data);
53 if (err != MAILIMAP_NO_ERROR) { 54 if (err != MAILIMAP_NO_ERROR) {
54 Global::statusMessage("error getting capabilities!"); 55 Global::statusMessage("error getting capabilities!");
55 return false; 56 return false;
56 } 57 }
57 clistiter * cur; 58 clistiter * cur;
58 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { 59 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
59 struct mailimap_capability * cap; 60 struct mailimap_capability * cap;
60 cap = (struct mailimap_capability *)clist_content(cur); 61 cap = (struct mailimap_capability *)clist_content(cur);
61 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { 62 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
62 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { 63 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
63 try_tls = true; 64 try_tls = true;
64 break; 65 break;
65 } 66 }
66 } 67 }
67 } 68 }
68 if (cap_data) { 69 if (cap_data) {
69 mailimap_capability_data_free(cap_data); 70 mailimap_capability_data_free(cap_data);
70 } 71 }
71 if (try_tls) { 72 if (try_tls) {
72 err = mailimap_starttls(m_imap); 73 err = mailimap_starttls(m_imap);
73 if (err != MAILIMAP_NO_ERROR && force_tls) { 74 if (err != MAILIMAP_NO_ERROR && force_tls) {
74 Global::statusMessage(tr("Server has no TLS support!")); 75 Global::statusMessage(tr("Server has no TLS support!"));
75 try_tls = false; 76 try_tls = false;
76 } else { 77 } else {
77 mailstream_low * low; 78 mailstream_low * low;
78 mailstream_low * new_low; 79 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream); 80 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) { 81 if (!low) {
81 try_tls = false; 82 try_tls = false;
82 } else { 83 } else {
83 int fd = mailstream_low_get_fd(low); 84 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 85 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low); 86 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low); 87 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else { 88 } else {
88 try_tls = false; 89 try_tls = false;
89 } 90 }
90 } 91 }
91 } 92 }
92 } 93 }
93 return try_tls; 94 return try_tls;
94} 95}
95 96
96void IMAPwrapper::login() 97void IMAPwrapper::login()
97{ 98{
98 const char *server, *user, *pass; 99 const char *server, *user, *pass;
99 uint16_t port; 100 uint16_t port;
100 int err = MAILIMAP_NO_ERROR; 101 int err = MAILIMAP_NO_ERROR;
101 102
102 if (account->getOffline()) return; 103 if (account->getOffline()) return;
103 /* we are connected this moment */ 104 /* we are connected this moment */
104 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 105 /* TODO: setup a timer holding the line or if connection closed - delete the value */
105 if (m_imap) { 106 if (m_imap) {
106 err = mailimap_noop(m_imap); 107 err = mailimap_noop(m_imap);
107 if (err!=MAILIMAP_NO_ERROR) { 108 if (err!=MAILIMAP_NO_ERROR) {
108 logout(); 109 logout();
109 } else { 110 } else {
110 mailstream_flush(m_imap->imap_stream); 111 mailstream_flush(m_imap->imap_stream);
111 return; 112 return;
112 } 113 }
113 } 114 }
114 server = account->getServer().latin1(); 115 server = account->getServer().latin1();
115 port = account->getPort().toUInt(); 116 port = account->getPort().toUInt();
116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 117 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 118 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
118 login.show(); 119 login.show();
119 if ( QDialog::Accepted == login.exec() ) { 120 if ( QDialog::Accepted == login.exec() ) {
120 // ok 121 // ok
121 user = login.getUser().latin1(); 122 user = login.getUser().latin1();
122 pass = login.getPassword().latin1(); 123 pass = login.getPassword().latin1();
123 } else { 124 } else {
124 // cancel 125 // cancel
125 return; 126 return;
126 } 127 }
127 } else { 128 } else {
128 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
129 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
130 } 131 }
131 132
132 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
133 134
134 /* connect */ 135 /* connect */
135 bool ssl = false; 136 bool ssl = false;
136 bool try_tls = false; 137 bool try_tls = false;
@@ -746,485 +747,514 @@ void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_tex
746 } 747 }
747 QString sub; 748 QString sub;
748 sub = which->bd_media_text; 749 sub = which->bd_media_text;
749 //odebug << "Type= text/" << which->bd_media_text << "" << oendl; 750 //odebug << "Type= text/" << which->bd_media_text << "" << oendl;
750 target_part->setSubtype(sub.lower()); 751 target_part->setSubtype(sub.lower());
751 target_part->setLines(which->bd_lines); 752 target_part->setLines(which->bd_lines);
752 fillBodyFields(target_part,which->bd_fields); 753 fillBodyFields(target_part,which->bd_fields);
753} 754}
754 755
755void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which) 756void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
756{ 757{
757 if (!which) { 758 if (!which) {
758 return; 759 return;
759 } 760 }
760 target_part->setSubtype("rfc822"); 761 target_part->setSubtype("rfc822");
761 //odebug << "Message part" << oendl; 762 //odebug << "Message part" << oendl;
762 /* we set this type to text/plain */ 763 /* we set this type to text/plain */
763 target_part->setLines(which->bd_lines); 764 target_part->setLines(which->bd_lines);
764 fillBodyFields(target_part,which->bd_fields); 765 fillBodyFields(target_part,which->bd_fields);
765} 766}
766 767
767void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which) 768void IMAPwrapper::fillMultiPart(RecPartP&target_part,mailimap_body_type_mpart*which)
768{ 769{
769 if (!which) return; 770 if (!which) return;
770 QString sub = which->bd_media_subtype; 771 QString sub = which->bd_media_subtype;
771 target_part->setSubtype(sub.lower()); 772 target_part->setSubtype(sub.lower());
772 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 773 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
773 clistcell*cur = 0; 774 clistcell*cur = 0;
774 mailimap_single_body_fld_param*param=0; 775 mailimap_single_body_fld_param*param=0;
775 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 776 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
776 param = (mailimap_single_body_fld_param*)cur->data; 777 param = (mailimap_single_body_fld_param*)cur->data;
777 if (param) { 778 if (param) {
778 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 779 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
779 } 780 }
780 } 781 }
781 } 782 }
782} 783}
783 784
784void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which) 785void IMAPwrapper::fillSingleBasicPart(RecPartP&target_part,mailimap_body_type_basic*which)
785{ 786{
786 if (!which) { 787 if (!which) {
787 return; 788 return;
788 } 789 }
789 QString type,sub; 790 QString type,sub;
790 switch (which->bd_media_basic->med_type) { 791 switch (which->bd_media_basic->med_type) {
791 case MAILIMAP_MEDIA_BASIC_APPLICATION: 792 case MAILIMAP_MEDIA_BASIC_APPLICATION:
792 type = "application"; 793 type = "application";
793 break; 794 break;
794 case MAILIMAP_MEDIA_BASIC_AUDIO: 795 case MAILIMAP_MEDIA_BASIC_AUDIO:
795 type = "audio"; 796 type = "audio";
796 break; 797 break;
797 case MAILIMAP_MEDIA_BASIC_IMAGE: 798 case MAILIMAP_MEDIA_BASIC_IMAGE:
798 type = "image"; 799 type = "image";
799 break; 800 break;
800 case MAILIMAP_MEDIA_BASIC_MESSAGE: 801 case MAILIMAP_MEDIA_BASIC_MESSAGE:
801 type = "message"; 802 type = "message";
802 break; 803 break;
803 case MAILIMAP_MEDIA_BASIC_VIDEO: 804 case MAILIMAP_MEDIA_BASIC_VIDEO:
804 type = "video"; 805 type = "video";
805 break; 806 break;
806 case MAILIMAP_MEDIA_BASIC_OTHER: 807 case MAILIMAP_MEDIA_BASIC_OTHER:
807 default: 808 default:
808 if (which->bd_media_basic->med_basic_type) { 809 if (which->bd_media_basic->med_basic_type) {
809 type = which->bd_media_basic->med_basic_type; 810 type = which->bd_media_basic->med_basic_type;
810 } else { 811 } else {
811 type = ""; 812 type = "";
812 } 813 }
813 break; 814 break;
814 } 815 }
815 if (which->bd_media_basic->med_subtype) { 816 if (which->bd_media_basic->med_subtype) {
816 sub = which->bd_media_basic->med_subtype; 817 sub = which->bd_media_basic->med_subtype;
817 } else { 818 } else {
818 sub = ""; 819 sub = "";
819 } 820 }
820 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl; 821 // odebug << "Type = " << type.latin1() << "/" << sub.latin1() << "" << oendl;
821 target_part->setType(type.lower()); 822 target_part->setType(type.lower());
822 target_part->setSubtype(sub.lower()); 823 target_part->setSubtype(sub.lower());
823 fillBodyFields(target_part,which->bd_fields); 824 fillBodyFields(target_part,which->bd_fields);
824} 825}
825 826
826void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which) 827void IMAPwrapper::fillBodyFields(RecPartP&target_part,mailimap_body_fields*which)
827{ 828{
828 if (!which) return; 829 if (!which) return;
829 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 830 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
830 clistcell*cur; 831 clistcell*cur;
831 mailimap_single_body_fld_param*param=0; 832 mailimap_single_body_fld_param*param=0;
832 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 833 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
833 param = (mailimap_single_body_fld_param*)cur->data; 834 param = (mailimap_single_body_fld_param*)cur->data;
834 if (param) { 835 if (param) {
835 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 836 target_part->addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
836 } 837 }
837 } 838 }
838 } 839 }
839 mailimap_body_fld_enc*enc = which->bd_encoding; 840 mailimap_body_fld_enc*enc = which->bd_encoding;
840 QString encoding(""); 841 QString encoding("");
841 switch (enc->enc_type) { 842 switch (enc->enc_type) {
842 case MAILIMAP_BODY_FLD_ENC_7BIT: 843 case MAILIMAP_BODY_FLD_ENC_7BIT:
843 encoding = "7bit"; 844 encoding = "7bit";
844 break; 845 break;
845 case MAILIMAP_BODY_FLD_ENC_8BIT: 846 case MAILIMAP_BODY_FLD_ENC_8BIT:
846 encoding = "8bit"; 847 encoding = "8bit";
847 break; 848 break;
848 case MAILIMAP_BODY_FLD_ENC_BINARY: 849 case MAILIMAP_BODY_FLD_ENC_BINARY:
849 encoding="binary"; 850 encoding="binary";
850 break; 851 break;
851 case MAILIMAP_BODY_FLD_ENC_BASE64: 852 case MAILIMAP_BODY_FLD_ENC_BASE64:
852 encoding="base64"; 853 encoding="base64";
853 break; 854 break;
854 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 855 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
855 encoding="quoted-printable"; 856 encoding="quoted-printable";
856 break; 857 break;
857 case MAILIMAP_BODY_FLD_ENC_OTHER: 858 case MAILIMAP_BODY_FLD_ENC_OTHER:
858 default: 859 default:
859 if (enc->enc_value) { 860 if (enc->enc_value) {
860 char*t=enc->enc_value; 861 char*t=enc->enc_value;
861 encoding=QString(enc->enc_value); 862 encoding=QString(enc->enc_value);
862 enc->enc_value=0L; 863 enc->enc_value=0L;
863 free(t); 864 free(t);
864 } 865 }
865 } 866 }
866 if (which->bd_description) { 867 if (which->bd_description) {
867 target_part->setDescription(QString(which->bd_description)); 868 target_part->setDescription(QString(which->bd_description));
868 } 869 }
869 target_part->setEncoding(encoding); 870 target_part->setEncoding(encoding);
870 target_part->setSize(which->bd_size); 871 target_part->setSize(which->bd_size);
871} 872}
872void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target) 873void IMAPwrapper::deleteMailList(const QValueList<RecMailP>&target)
873{ 874{
875 //#if 0
874 mailimap_flag_list*flist; 876 mailimap_flag_list*flist;
875 mailimap_set *set; 877 mailimap_set *set;
876 mailimap_store_att_flags * store_flags; 878 mailimap_store_att_flags * store_flags;
877 int err; 879 int err;
878 login(); 880 login();
881 //#endif
879 if (!m_imap) { 882 if (!m_imap) {
880 return; 883 return;
881 } 884 }
882 int iii = 0; 885 int iii = 0;
883 int count = target.count(); 886 int count = target.count();
884 qDebug("imap remove count %d ", count); 887 // qDebug("imap remove count %d ", count);
888
889 QProgressBar bar( count,0 );
890 bar.setCaption (("Removing mails - close to abort!") );
891 int w = 300;
892 if ( QApplication::desktop()->width() < 320 )
893 w = 220;
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
885 while (iii < count ) { 902 while (iii < count ) {
886 qDebug("IMAP remove %d ", iii); 903 if ( ! bar.isVisible() )
904 return ;
905 if ( incCounter % modulo == 0 )
906 bar.setProgress( incCounter );
907 ++incCounter;
908 qApp->processEvents();
887 RecMailP mail = (*target.at( iii )); 909 RecMailP mail = (*target.at( iii ));
888 910 //#if 0
911 //qDebug("IMAP remove %d %d ", iii, mail->getNumber() );
889 err = selectMbox(mail->getMbox()); 912 err = selectMbox(mail->getMbox());
890 if ( err != MAILIMAP_NO_ERROR ) { 913 if ( err != MAILIMAP_NO_ERROR ) {
891 return; 914 return;
892 } 915 }
893 flist = mailimap_flag_list_new_empty(); 916 flist = mailimap_flag_list_new_empty();
894 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 917 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
895 store_flags = mailimap_store_att_flags_new_set_flags(flist); 918 store_flags = mailimap_store_att_flags_new_set_flags(flist);
896 set = mailimap_set_new_single(mail->getNumber()); 919 set = mailimap_set_new_single(mail->getNumber());
897 err = mailimap_store(m_imap,set,store_flags); 920 err = mailimap_store(m_imap,set,store_flags);
898 mailimap_set_free( set ); 921 mailimap_set_free( set );
899 mailimap_store_att_flags_free(store_flags); 922 mailimap_store_att_flags_free(store_flags);
900 923
901 if (err != MAILIMAP_NO_ERROR) { 924 if (err != MAILIMAP_NO_ERROR) {
902 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 925 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
903 return; 926 return;
904 } 927 }
905 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 928 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
906 /* should we realy do that at this moment? */ 929 /* should we realy do that at this moment? */
907 930
931 // err = mailimap_expunge(m_imap);
932 //if (err != MAILIMAP_NO_ERROR) {
933 // Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
934 // }
935 //#endif
936 //deleteMail( mail);
937 ++iii;
938 }
939 //qDebug("Deleting imap mails... ");
908 err = mailimap_expunge(m_imap); 940 err = mailimap_expunge(m_imap);
909 if (err != MAILIMAP_NO_ERROR) { 941 if (err != MAILIMAP_NO_ERROR) {
910 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 942 Global::statusMessage(tr("Error deleting mails: %s").arg(m_imap->imap_response));
911 } 943 }
912 ++iii;
913 }
914} 944}
915void IMAPwrapper::deleteMail(const RecMailP&mail) 945void IMAPwrapper::deleteMail(const RecMailP&mail)
916{ 946{
917 mailimap_flag_list*flist; 947 mailimap_flag_list*flist;
918 mailimap_set *set; 948 mailimap_set *set;
919 mailimap_store_att_flags * store_flags; 949 mailimap_store_att_flags * store_flags;
920 int err; 950 int err;
921 login(); 951 login();
922 if (!m_imap) { 952 if (!m_imap) {
923 return; 953 return;
924 } 954 }
925 err = selectMbox(mail->getMbox()); 955 err = selectMbox(mail->getMbox());
926 if ( err != MAILIMAP_NO_ERROR ) { 956 if ( err != MAILIMAP_NO_ERROR ) {
927 return; 957 return;
928 } 958 }
929 flist = mailimap_flag_list_new_empty(); 959 flist = mailimap_flag_list_new_empty();
930 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 960 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
931 store_flags = mailimap_store_att_flags_new_set_flags(flist); 961 store_flags = mailimap_store_att_flags_new_set_flags(flist);
932 set = mailimap_set_new_single(mail->getNumber()); 962 set = mailimap_set_new_single(mail->getNumber());
933 err = mailimap_store(m_imap,set,store_flags); 963 err = mailimap_store(m_imap,set,store_flags);
934 mailimap_set_free( set ); 964 mailimap_set_free( set );
935 mailimap_store_att_flags_free(store_flags); 965 mailimap_store_att_flags_free(store_flags);
936 966
937 if (err != MAILIMAP_NO_ERROR) { 967 if (err != MAILIMAP_NO_ERROR) {
938 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl; 968 // odebug << "error deleting mail: " << m_imap->imap_response << "" << oendl;
939 return; 969 return;
940 } 970 }
941 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 971 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
942 /* should we realy do that at this moment? */ 972 /* should we realy do that at this moment? */
943 973
944 err = mailimap_expunge(m_imap); 974 err = mailimap_expunge(m_imap);
945 if (err != MAILIMAP_NO_ERROR) { 975 if (err != MAILIMAP_NO_ERROR) {
946 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 976 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
947 } 977 }
948 qDebug("IMAPwrapper::deleteMail "); 978 //qDebug("IMAPwrapper::deleteMail 2");
949 979
950} 980}
951 981
952void IMAPwrapper::answeredMail(const RecMailP&mail) 982void IMAPwrapper::answeredMail(const RecMailP&mail)
953{ 983{
954 mailimap_flag_list*flist; 984 mailimap_flag_list*flist;
955 mailimap_set *set; 985 mailimap_set *set;
956 mailimap_store_att_flags * store_flags; 986 mailimap_store_att_flags * store_flags;
957 int err; 987 int err;
958 login(); 988 login();
959 if (!m_imap) { 989 if (!m_imap) {
960 return; 990 return;
961 } 991 }
962 err = selectMbox(mail->getMbox()); 992 err = selectMbox(mail->getMbox());
963 if ( err != MAILIMAP_NO_ERROR ) { 993 if ( err != MAILIMAP_NO_ERROR ) {
964 return; 994 return;
965 } 995 }
966 flist = mailimap_flag_list_new_empty(); 996 flist = mailimap_flag_list_new_empty();
967 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 997 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
968 store_flags = mailimap_store_att_flags_new_add_flags(flist); 998 store_flags = mailimap_store_att_flags_new_add_flags(flist);
969 set = mailimap_set_new_single(mail->getNumber()); 999 set = mailimap_set_new_single(mail->getNumber());
970 err = mailimap_store(m_imap,set,store_flags); 1000 err = mailimap_store(m_imap,set,store_flags);
971 mailimap_set_free( set ); 1001 mailimap_set_free( set );
972 mailimap_store_att_flags_free(store_flags); 1002 mailimap_store_att_flags_free(store_flags);
973 1003
974 if (err != MAILIMAP_NO_ERROR) { 1004 if (err != MAILIMAP_NO_ERROR) {
975 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl; 1005 // odebug << "error marking mail: " << m_imap->imap_response << "" << oendl;
976 return; 1006 return;
977 } 1007 }
978} 1008}
979 1009
980QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 1010QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
981{ 1011{
982 QString body(""); 1012 QString body("");
983 encodedString*res = fetchRawPart(mail,path,internal_call); 1013 encodedString*res = fetchRawPart(mail,path,internal_call);
984 encodedString*r = decode_String(res,enc); 1014 encodedString*r = decode_String(res,enc);
985 delete res; 1015 delete res;
986 if (r) { 1016 if (r) {
987 if (r->Length()>0) { 1017 if (r->Length()>0) {
988 body = r->Content(); 1018 body = r->Content();
989 } 1019 }
990 delete r; 1020 delete r;
991 } 1021 }
992 return body; 1022 return body;
993} 1023}
994 1024
995QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) 1025QString IMAPwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part)
996{ 1026{
997 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding()); 1027 return fetchTextPart(mail,part->Positionlist(),false,part->Encoding());
998} 1028}
999 1029
1000encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part) 1030encodedString* IMAPwrapper::fetchDecodedPart(const RecMailP&mail,const RecPartP&part)
1001{ 1031{
1002 encodedString*res = fetchRawPart(mail,part->Positionlist(),false); 1032 encodedString*res = fetchRawPart(mail,part->Positionlist(),false);
1003 encodedString*r = decode_String(res,part->Encoding()); 1033 encodedString*r = decode_String(res,part->Encoding());
1004 delete res; 1034 delete res;
1005 return r; 1035 return r;
1006} 1036}
1007 1037
1008encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part) 1038encodedString* IMAPwrapper::fetchRawPart(const RecMailP&mail,const RecPartP&part)
1009{ 1039{
1010 return fetchRawPart(mail,part->Positionlist(),false); 1040 return fetchRawPart(mail,part->Positionlist(),false);
1011} 1041}
1012 1042
1013int IMAPwrapper::deleteAllMail(const FolderP&folder) 1043int IMAPwrapper::deleteAllMail(const FolderP&folder)
1014{ 1044{
1015 login(); 1045 login();
1016 if (!m_imap) { 1046 if (!m_imap) {
1017 return 0; 1047 return 0;
1018 } 1048 }
1019 mailimap_flag_list*flist; 1049 mailimap_flag_list*flist;
1020 mailimap_set *set; 1050 mailimap_set *set;
1021 mailimap_store_att_flags * store_flags; 1051 mailimap_store_att_flags * store_flags;
1022 int err = selectMbox(folder->getName()); 1052 int err = selectMbox(folder->getName());
1023 if ( err != MAILIMAP_NO_ERROR ) { 1053 if ( err != MAILIMAP_NO_ERROR ) {
1024 return 0; 1054 return 0;
1025 } 1055 }
1026 1056
1027 int last = m_imap->imap_selection_info->sel_exists; 1057 int last = m_imap->imap_selection_info->sel_exists;
1028 if (last == 0) { 1058 if (last == 0) {
1029 Global::statusMessage(tr("Mailbox has no mails!")); 1059 Global::statusMessage(tr("Mailbox has no mails!"));
1030 return 0; 1060 return 0;
1031 } 1061 }
1032 flist = mailimap_flag_list_new_empty(); 1062 flist = mailimap_flag_list_new_empty();
1033 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 1063 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
1034 store_flags = mailimap_store_att_flags_new_set_flags(flist); 1064 store_flags = mailimap_store_att_flags_new_set_flags(flist);
1035 set = mailimap_set_new_interval( 1, last ); 1065 set = mailimap_set_new_interval( 1, last );
1036 err = mailimap_store(m_imap,set,store_flags); 1066 err = mailimap_store(m_imap,set,store_flags);
1037 mailimap_set_free( set ); 1067 mailimap_set_free( set );
1038 mailimap_store_att_flags_free(store_flags); 1068 mailimap_store_att_flags_free(store_flags);
1039 if (err != MAILIMAP_NO_ERROR) { 1069 if (err != MAILIMAP_NO_ERROR) {
1040 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1070 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1041 return 0; 1071 return 0;
1042 } 1072 }
1043 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl; 1073 // odebug << "deleting mail: " << m_imap->imap_response << "" << oendl;
1044 /* should we realy do that at this moment? */ 1074 /* should we realy do that at this moment? */
1045 err = mailimap_expunge(m_imap); 1075 err = mailimap_expunge(m_imap);
1046 if (err != MAILIMAP_NO_ERROR) { 1076 if (err != MAILIMAP_NO_ERROR) {
1047 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 1077 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
1048 return 0; 1078 return 0;
1049 } 1079 }
1050 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl; 1080 // odebug << "Delete successfull " << m_imap->imap_response << "" << oendl;
1051 return 1; 1081 return 1;
1052} 1082}
1053 1083
1054int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder) 1084int IMAPwrapper::createMbox(const QString&folder,const FolderP&parentfolder,const QString& delemiter,bool getsubfolder)
1055{ 1085{
1056 if (folder.length()==0) return 0; 1086 if (folder.length()==0) return 0;
1057 login(); 1087 login();
1058 if (!m_imap) {return 0;} 1088 if (!m_imap) {return 0;}
1059 QString pre = account->getPrefix(); 1089 QString pre = account->getPrefix();
1060 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1090 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
1061 pre+=delemiter; 1091 pre+=delemiter;
1062 } 1092 }
1063 if (parentfolder) { 1093 if (parentfolder) {
1064 pre += parentfolder->getDisplayName()+delemiter; 1094 pre += parentfolder->getDisplayName()+delemiter;
1065 } 1095 }
1066 pre+=folder; 1096 pre+=folder;
1067 if (getsubfolder) { 1097 if (getsubfolder) {
1068 if (delemiter.length()>0) { 1098 if (delemiter.length()>0) {
1069 pre+=delemiter; 1099 pre+=delemiter;
1070 } else { 1100 } else {
1071 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1101 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
1072 return 0; 1102 return 0;
1073 } 1103 }
1074 } 1104 }
1075 // odebug << "Creating " << pre.latin1() << "" << oendl; 1105 // odebug << "Creating " << pre.latin1() << "" << oendl;
1076 int res = mailimap_create(m_imap,pre.latin1()); 1106 int res = mailimap_create(m_imap,pre.latin1());
1077 if (res != MAILIMAP_NO_ERROR) { 1107 if (res != MAILIMAP_NO_ERROR) {
1078 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1108 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1079 return 0; 1109 return 0;
1080 } 1110 }
1081 return 1; 1111 return 1;
1082} 1112}
1083 1113
1084int IMAPwrapper::deleteMbox(const FolderP&folder) 1114int IMAPwrapper::deleteMbox(const FolderP&folder)
1085{ 1115{
1086 if (!folder) return 0; 1116 if (!folder) return 0;
1087 login(); 1117 login();
1088 if (!m_imap) {return 0;} 1118 if (!m_imap) {return 0;}
1089 int res = mailimap_delete(m_imap,folder->getName()); 1119 int res = mailimap_delete(m_imap,folder->getName());
1090 if (res != MAILIMAP_NO_ERROR) { 1120 if (res != MAILIMAP_NO_ERROR) {
1091 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1121 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
1092 return 0; 1122 return 0;
1093 } 1123 }
1094 return 1; 1124 return 1;
1095} 1125}
1096 1126
1097void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1127void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
1098{ 1128{
1099 mailimap_status_att_list * att_list =0; 1129 mailimap_status_att_list * att_list =0;
1100 mailimap_mailbox_data_status * status=0; 1130 mailimap_mailbox_data_status * status=0;
1101 clistiter * cur = 0; 1131 clistiter * cur = 0;
1102 int r = 0; 1132 int r = 0;
1103 target_stat.message_count = 0; 1133 target_stat.message_count = 0;
1104 target_stat.message_unseen = 0; 1134 target_stat.message_unseen = 0;
1105 target_stat.message_recent = 0; 1135 target_stat.message_recent = 0;
1106 login(); 1136 login();
1107 if (!m_imap) { 1137 if (!m_imap) {
1108 return; 1138 return;
1109 } 1139 }
1110 att_list = mailimap_status_att_list_new_empty(); 1140 att_list = mailimap_status_att_list_new_empty();
1111 if (!att_list) return; 1141 if (!att_list) return;
1112 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1142 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
1113 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1143 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
1114 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1144 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
1115 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1145 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
1116 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1146 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
1117 for (cur = clist_begin(status->st_info_list); 1147 for (cur = clist_begin(status->st_info_list);
1118 cur != NULL ; cur = clist_next(cur)) { 1148 cur != NULL ; cur = clist_next(cur)) {
1119 mailimap_status_info * status_info; 1149 mailimap_status_info * status_info;
1120 status_info = (mailimap_status_info *)clist_content(cur); 1150 status_info = (mailimap_status_info *)clist_content(cur);
1121 switch (status_info->st_att) { 1151 switch (status_info->st_att) {
1122 case MAILIMAP_STATUS_ATT_MESSAGES: 1152 case MAILIMAP_STATUS_ATT_MESSAGES:
1123 target_stat.message_count = status_info->st_value; 1153 target_stat.message_count = status_info->st_value;
1124 break; 1154 break;
1125 case MAILIMAP_STATUS_ATT_RECENT: 1155 case MAILIMAP_STATUS_ATT_RECENT:
1126 target_stat.message_recent = status_info->st_value; 1156 target_stat.message_recent = status_info->st_value;
1127 break; 1157 break;
1128 case MAILIMAP_STATUS_ATT_UNSEEN: 1158 case MAILIMAP_STATUS_ATT_UNSEEN:
1129 target_stat.message_unseen = status_info->st_value; 1159 target_stat.message_unseen = status_info->st_value;
1130 break; 1160 break;
1131 } 1161 }
1132 } 1162 }
1133 } else { 1163 } else {
1134 // odebug << "Error retrieving status" << oendl; 1164 // odebug << "Error retrieving status" << oendl;
1135 } 1165 }
1136 if (status) mailimap_mailbox_data_status_free(status); 1166 if (status) mailimap_mailbox_data_status_free(status);
1137 if (att_list) mailimap_status_att_list_free(att_list); 1167 if (att_list) mailimap_status_att_list_free(att_list);
1138} 1168}
1139 1169
1140void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1170void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1141{ 1171{
1142 login(); 1172 login();
1143 if (!m_imap) return; 1173 if (!m_imap) return;
1144 if (!msg) return; 1174 if (!msg) return;
1145 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1175 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1146 if (r != MAILIMAP_NO_ERROR) { 1176 if (r != MAILIMAP_NO_ERROR) {
1147 Global::statusMessage("Error storing mail!"); 1177 Global::statusMessage("Error storing mail!");
1148 } 1178 }
1149} 1179}
1150 1180
1151MAILLIB::ATYPE IMAPwrapper::getType()const 1181MAILLIB::ATYPE IMAPwrapper::getType()const
1152{ 1182{
1153 return account->getType(); 1183 return account->getType();
1154} 1184}
1155 1185
1156const QString&IMAPwrapper::getName()const 1186const QString&IMAPwrapper::getName()const
1157{ 1187{
1158 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl; 1188 // odebug << "Get name: " << account->getAccountName().latin1() << "" << oendl;
1159 return account->getAccountName(); 1189 return account->getAccountName();
1160} 1190}
1161 1191
1162encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail) 1192encodedString* IMAPwrapper::fetchRawBody(const RecMailP&mail)
1163{ 1193{
1164 // dummy 1194 // dummy
1165 QValueList<int> path; 1195 QValueList<int> path;
1166 return fetchRawPart(mail,path,false); 1196 return fetchRawPart(mail,path,false);
1167} 1197}
1168 1198
1169void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder, 1199void IMAPwrapper::mvcpAllMails(const FolderP&fromFolder,
1170 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb) 1200 const QString&targetFolder,AbstractMail*targetWrapper,bool moveit, int maxSizeInKb)
1171{ 1201{
1172 if (targetWrapper != this || maxSizeInKb > 0 ) { 1202 if (targetWrapper != this || maxSizeInKb > 0 ) {
1173 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb); 1203 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit, maxSizeInKb);
1174 qDebug("IMAPwrapper::mvcpAllMails::Using generic"); 1204 qDebug("IMAPwrapper::mvcpAllMails::Using generic");
1175 // odebug << "Using generic" << oendl; 1205 // odebug << "Using generic" << oendl;
1176 return; 1206 return;
1177 } 1207 }
1178 mailimap_set *set = 0; 1208 mailimap_set *set = 0;
1179 login(); 1209 login();
1180 if (!m_imap) { 1210 if (!m_imap) {
1181 return; 1211 return;
1182 } 1212 }
1183 int err = selectMbox(fromFolder->getName()); 1213 int err = selectMbox(fromFolder->getName());
1184 if ( err != MAILIMAP_NO_ERROR ) { 1214 if ( err != MAILIMAP_NO_ERROR ) {
1185 return; 1215 return;
1186 } 1216 }
1187 int last = m_imap->imap_selection_info->sel_exists; 1217 int last = m_imap->imap_selection_info->sel_exists;
1188 set = mailimap_set_new_interval( 1, last ); 1218 set = mailimap_set_new_interval( 1, last );
1189 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1219 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1190 mailimap_set_free( set ); 1220 mailimap_set_free( set );
1191 if ( err != MAILIMAP_NO_ERROR ) { 1221 if ( err != MAILIMAP_NO_ERROR ) {
1192 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1222 QString error_msg = tr("Error copy mails: %1").arg(m_imap->imap_response);
1193 Global::statusMessage(error_msg); 1223 Global::statusMessage(error_msg);
1194 // odebug << error_msg << oendl; 1224 // odebug << error_msg << oendl;
1195 return; 1225 return;
1196 } 1226 }
1197 if (moveit) { 1227 if (moveit) {
1198 deleteAllMail(fromFolder); 1228 deleteAllMail(fromFolder);
1199 } 1229 }
1200} 1230}
1201 1231
1202void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1232void IMAPwrapper::mvcpMail(const RecMailP&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1203{ 1233{
1204 if (targetWrapper != this) { 1234 if (targetWrapper != this) {
1205 // odebug << "Using generic" << oendl; 1235 // odebug << "Using generic" << oendl;
1206 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1236 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1207 return; 1237 return;
1208 } 1238 }
1209 mailimap_set *set = 0; 1239 mailimap_set *set = 0;
1210 login(); 1240 login();
1211 if (!m_imap) { 1241 if (!m_imap) {
1212 return; 1242 return;
1213 } 1243 }
1214 int err = selectMbox(mail->getMbox()); 1244 int err = selectMbox(mail->getMbox());
1215 if ( err != MAILIMAP_NO_ERROR ) { 1245 if ( err != MAILIMAP_NO_ERROR ) {
1216 return; 1246 return;
1217 } 1247 }
1218 set = mailimap_set_new_single(mail->getNumber()); 1248 set = mailimap_set_new_single(mail->getNumber());
1219 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1249 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1220 mailimap_set_free( set ); 1250 mailimap_set_free( set );
1221 if ( err != MAILIMAP_NO_ERROR ) { 1251 if ( err != MAILIMAP_NO_ERROR ) {
1222 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1252 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1223 Global::statusMessage(error_msg); 1253 Global::statusMessage(error_msg);
1224 // odebug << error_msg << oendl; 1254 // odebug << error_msg << oendl;
1225 return; 1255 return;
1226 } 1256 }
1227 if (moveit) { 1257 if (moveit) {
1228 deleteMail(mail); 1258 deleteMail(mail);
1229 } 1259 }
1230} 1260}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 7a84b30..0e6612c 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,282 +1,321 @@
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>
12#include <qapplication.h>
11 13
12/* we don't fetch messages larger than 5 MB */ 14/* we don't fetch messages larger than 5 MB */
13#define HARD_MSG_SIZE_LIMIT 5242880 15#define HARD_MSG_SIZE_LIMIT 5242880
14 16
15using namespace Opie::Core; 17using namespace Opie::Core;
16POP3wrapper::POP3wrapper( POP3account *a ) 18POP3wrapper::POP3wrapper( POP3account *a )
17: Genericwrapper() { 19: Genericwrapper() {
18 account = a; 20 account = a;
19 m_pop3 = NULL; 21 m_pop3 = NULL;
20 msgTempName = a->getFileName()+"_msg_cache"; 22 msgTempName = a->getFileName()+"_msg_cache";
21 last_msg_id = 0; 23 last_msg_id = 0;
22} 24}
23 25
24POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
25 logout(); 27 logout();
26 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
28 msg_cache.remove(); 30 msg_cache.remove();
29 } 31 }
30} 32}
31 33
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
33 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl;
34} 36}
35 37
36RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
37 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
38 char *message = 0; 40 char *message = 0;
39 size_t length = 0; 41 size_t length = 0;
40 42
41 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
42 44
43 login(); 45 login();
44 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
45 return body; 47 return body;
46 } 48 }
47 49
48 mailmessage * mailmsg; 50 mailmessage * mailmsg;
49 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) {
50 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
51 return body; 53 return body;
52 } 54 }
53 55
54 QFile msg_cache(msgTempName); 56 QFile msg_cache(msgTempName);
55 57
56 cleanMimeCache(); 58 cleanMimeCache();
57 59
58 if (mail->getNumber()!=last_msg_id) { 60 if (mail->getNumber()!=last_msg_id) {
59 if (msg_cache.exists()) { 61 if (msg_cache.exists()) {
60 msg_cache.remove(); 62 msg_cache.remove();
61 } 63 }
62 msg_cache.open(IO_ReadWrite|IO_Truncate); 64 msg_cache.open(IO_ReadWrite|IO_Truncate);
63 last_msg_id = mail->getNumber(); 65 last_msg_id = mail->getNumber();
64 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 66 err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
65 err = mailmessage_fetch(mailmsg,&message,&length); 67 err = mailmessage_fetch(mailmsg,&message,&length);
66 msg_cache.writeBlock(message,length); 68 msg_cache.writeBlock(message,length);
67 } else { 69 } else {
68 QString msg=""; 70 QString msg="";
69 msg_cache.open(IO_ReadOnly); 71 msg_cache.open(IO_ReadOnly);
70 message = new char[4096]; 72 message = new char[4096];
71 memset(message,0,4096); 73 memset(message,0,4096);
72 while (msg_cache.readBlock(message,4095)>0) { 74 while (msg_cache.readBlock(message,4095)>0) {
73 msg+=message; 75 msg+=message;
74 memset(message,0,4096); 76 memset(message,0,4096);
75 } 77 }
76 delete message; 78 delete message;
77 message = (char*)malloc(msg.length()+1*sizeof(char)); 79 message = (char*)malloc(msg.length()+1*sizeof(char));
78 memset(message,0,msg.length()+1); 80 memset(message,0,msg.length()+1);
79 memcpy(message,msg.latin1(),msg.length()); 81 memcpy(message,msg.latin1(),msg.length());
80 /* transform to libetpan stuff */ 82 /* transform to libetpan stuff */
81 mailmsg = mailmessage_new(); 83 mailmsg = mailmessage_new();
82 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 84 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
83 generic_message_t * msg_data; 85 generic_message_t * msg_data;
84 msg_data = (generic_message_t *)mailmsg->msg_data; 86 msg_data = (generic_message_t *)mailmsg->msg_data;
85 msg_data->msg_fetched = 1; 87 msg_data->msg_fetched = 1;
86 msg_data->msg_message = message; 88 msg_data->msg_message = message;
87 msg_data->msg_length = strlen(message); 89 msg_data->msg_length = strlen(message);
88 } 90 }
89 body = parseMail(mailmsg); 91 body = parseMail(mailmsg);
90 92
91 /* clean up */ 93 /* clean up */
92 if (mailmsg) 94 if (mailmsg)
93 mailmessage_free(mailmsg); 95 mailmessage_free(mailmsg);
94 if (message) 96 if (message)
95 free(message); 97 free(message);
96 98
97 return body; 99 return body;
98} 100}
99 101
100void 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 )
101{ 103{
102 login(); 104 login();
103 if (!m_pop3) 105 if (!m_pop3)
104 return; 106 return;
105 uint32_t res_messages,res_recent,res_unseen; 107 uint32_t res_messages,res_recent,res_unseen;
106 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);
107 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
108 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
109} 111}
110 112
111void POP3wrapper::login() 113void POP3wrapper::login()
112{ 114{
113 if (account->getOffline()) 115 if (account->getOffline())
114 return; 116 return;
115 /* we'll hold the line */ 117 /* we'll hold the line */
116 if ( m_pop3 != NULL ) 118 if ( m_pop3 != NULL )
117 return; 119 return;
118 120
119 const char *server, *user, *pass; 121 const char *server, *user, *pass;
120 uint16_t port; 122 uint16_t port;
121 int err = MAILPOP3_NO_ERROR; 123 int err = MAILPOP3_NO_ERROR;
122 124
123 server = account->getServer().latin1(); 125 server = account->getServer().latin1();
124 port = account->getPort().toUInt(); 126 port = account->getPort().toUInt();
125 127
126 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
127 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 129 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
128 login.show(); 130 login.show();
129 if ( QDialog::Accepted == login.exec() ) { 131 if ( QDialog::Accepted == login.exec() ) {
130 // ok 132 // ok
131 user = login.getUser().latin1(); 133 user = login.getUser().latin1();
132 pass = login.getPassword().latin1(); 134 pass = login.getPassword().latin1();
133 } else { 135 } else {
134 // cancel 136 // cancel
135 ; // odebug << "POP3: Login canceled" << oendl; 137 ; // odebug << "POP3: Login canceled" << oendl;
136 return; 138 return;
137 } 139 }
138 } else { 140 } else {
139 user = account->getUser().latin1(); 141 user = account->getUser().latin1();
140 pass = account->getPassword().latin1(); 142 pass = account->getPassword().latin1();
141 } 143 }
142 144
143 // bool ssl = account->getSSL(); 145 // bool ssl = account->getSSL();
144 146
145 m_pop3=mailstorage_new(NULL); 147 m_pop3=mailstorage_new(NULL);
146 148
147 int conntypeset = account->ConnectionType(); 149 int conntypeset = account->ConnectionType();
148 int conntype = 0; 150 int conntype = 0;
149 if ( conntypeset == 3 ) { 151 if ( conntypeset == 3 ) {
150 conntype = CONNECTION_TYPE_COMMAND; 152 conntype = CONNECTION_TYPE_COMMAND;
151 } else if ( conntypeset == 2 ) { 153 } else if ( conntypeset == 2 ) {
152 conntype = CONNECTION_TYPE_TLS; 154 conntype = CONNECTION_TYPE_TLS;
153 } else if ( conntypeset == 1 ) { 155 } else if ( conntypeset == 1 ) {
154 conntype = CONNECTION_TYPE_STARTTLS; 156 conntype = CONNECTION_TYPE_STARTTLS;
155 } else if ( conntypeset == 0 ) { 157 } else if ( conntypeset == 0 ) {
156 conntype = CONNECTION_TYPE_TRY_STARTTLS; 158 conntype = CONNECTION_TYPE_TRY_STARTTLS;
157 } 159 }
158 160
159 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
160 162
161 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 163 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
162 (char*)user,(char*)pass,0,0,0); 164 (char*)user,(char*)pass,0,0,0);
163 165
164 166
165 err = mailstorage_connect(m_pop3); 167 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 168 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 169 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error initializing folder")); 170 Global::statusMessage(tr("Error initializing folder"));
169 mailstorage_free(m_pop3); 171 mailstorage_free(m_pop3);
170 m_pop3 = 0; 172 m_pop3 = 0;
171 } else { 173 } else {
172 mailsession * session = m_pop3->sto_session; 174 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 175 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 176 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 177 mail->pop3_progr_fun = &pop3_progress;
176 } 178 }
177 } 179 }
178} 180}
179 181
180void POP3wrapper::logout() 182void POP3wrapper::logout()
181{ 183{
182 if ( m_pop3 == NULL ) 184 if ( m_pop3 == NULL )
183 return; 185 return;
184 mailstorage_free(m_pop3); 186 mailstorage_free(m_pop3);
185 m_pop3 = 0; 187 m_pop3 = 0;
186} 188}
187 189
188 190
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 191QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 192 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 193 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 194 folders->append(inb);
193 return folders; 195 return folders;
194} 196}
195 197
196void POP3wrapper::deleteMailList(QValueList<RecMailP>&target) 198void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 199{
198 login(); 200 login();
199 if (!m_pop3) 201 if (!m_pop3)
200 return; 202 return;
201 int iii = 0; 203 int iii = 0;
202 int count = target.count(); 204 int count = target.count();
203 while (iii < count ) { 205 QProgressBar bar( count,0 );
206 bar.setCaption (("Removing mails - close to abort!") );
207 int w = 300;
208 if ( QApplication::desktop()->width() < 320 )
209 w = 220;
210 int h = bar.sizeHint().height() ;
211 int dw = QApplication::desktop()->width();
212 int dh = QApplication::desktop()->height();
213 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
214 bar.show();
215 int modulo = (count/10)+1;
216 int incCounter = 0;
217 while (iii < count ) {
218 if ( ! bar.isVisible() )
219 return ;
220 if ( incCounter % modulo == 0 )
221 bar.setProgress( incCounter );
222 ++incCounter;
223 qApp->processEvents();
224 //qDebug("delete ");
204 RecMailP mail = (*target.at( iii )); 225 RecMailP mail = (*target.at( iii ));
205 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
206 if (err != MAIL_NO_ERROR) { 227 if (err != MAIL_NO_ERROR) {
207 Global::statusMessage(tr("error deleting mail")); 228 Global::statusMessage(tr("Error deleting mail"));
208 } 229 }
209 ++iii; 230 ++iii;
210 } 231 }
211} 232}
212void POP3wrapper::deleteMail(const RecMailP&mail) { 233void POP3wrapper::deleteMail(const RecMailP&mail) {
213 login(); 234 login();
214 if (!m_pop3) 235 if (!m_pop3)
215 return; 236 return;
216 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 237 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
217 if (err != MAIL_NO_ERROR) { 238 if (err != MAIL_NO_ERROR) {
218 Global::statusMessage(tr("error deleting mail")); 239 Global::statusMessage(tr("error deleting mail"));
219 } 240 }
220} 241}
221 242
222void POP3wrapper::answeredMail(const RecMailP&) {} 243void POP3wrapper::answeredMail(const RecMailP&) {}
223 244
224int POP3wrapper::deleteAllMail(const FolderP&) { 245int POP3wrapper::deleteAllMail(const FolderP&) {
225 login(); 246 login();
226 if (!m_pop3) 247 if (!m_pop3)
227 return 0; 248 return 0;
228 int res = 1; 249 int res = 1;
229 250
230 uint32_t result = 0; 251 uint32_t result = 0;
231 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 252 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
232 if (err != MAIL_NO_ERROR) { 253 if (err != MAIL_NO_ERROR) {
233 Global::statusMessage(tr("Error getting folder info")); 254 Global::statusMessage(tr("Error getting folder info"));
234 return 0; 255 return 0;
235 } 256 }
257 QProgressBar bar( result,0 );
258 bar.setCaption (("Deleting mails - close to abort!") );
259 int w = 300;
260 if ( QApplication::desktop()->width() < 320 )
261 w = 220;
262 int h = bar.sizeHint().height() ;
263 int dw = QApplication::desktop()->width();
264 int dh = QApplication::desktop()->height();
265 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
266 bar.show();
267 int modulo = (result/10)+1;
268 int incCounter = 0;
236 for (unsigned int i = 0; i < result; ++i) { 269 for (unsigned int i = 0; i < result; ++i) {
270 if ( ! bar.isVisible() )
271 return 0;
272 if ( incCounter % modulo == 0 )
273 bar.setProgress( incCounter );
274 ++incCounter;
275 qApp->processEvents();
237 err = mailsession_remove_message(m_pop3->sto_session,i+1); 276 err = mailsession_remove_message(m_pop3->sto_session,i+1);
238 if (err != MAIL_NO_ERROR) { 277 if (err != MAIL_NO_ERROR) {
239 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 278 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
240 res=0; 279 res=0;
241 } 280 }
242 break; 281 break;
243 } 282 }
244 return res; 283 return res;
245} 284}
246 285
247void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 286void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
248 login(); 287 login();
249 target_stat.message_count = 0; 288 target_stat.message_count = 0;
250 target_stat.message_unseen = 0; 289 target_stat.message_unseen = 0;
251 target_stat.message_recent = 0; 290 target_stat.message_recent = 0;
252 if (!m_pop3) 291 if (!m_pop3)
253 return; 292 return;
254 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 293 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
255 &target_stat.message_recent,&target_stat.message_unseen); 294 &target_stat.message_recent,&target_stat.message_unseen);
256 if (r != MAIL_NO_ERROR) { 295 if (r != MAIL_NO_ERROR) {
257 ; // odebug << "error getting folter status." << oendl; 296 ; // odebug << "error getting folter status." << oendl;
258 } 297 }
259} 298}
260 299
261encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 300encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
262 char*target=0; 301 char*target=0;
263 size_t length=0; 302 size_t length=0;
264 encodedString*res = 0; 303 encodedString*res = 0;
265 mailmessage * mailmsg = 0; 304 mailmessage * mailmsg = 0;
266 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 305 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
267 err = mailmessage_fetch(mailmsg,&target,&length); 306 err = mailmessage_fetch(mailmsg,&target,&length);
268 if (mailmsg) 307 if (mailmsg)
269 mailmessage_free(mailmsg); 308 mailmessage_free(mailmsg);
270 if (target) { 309 if (target) {
271 res = new encodedString(target,length); 310 res = new encodedString(target,length);
272 } 311 }
273 return res; 312 return res;
274} 313}
275 314
276MAILLIB::ATYPE POP3wrapper::getType()const { 315MAILLIB::ATYPE POP3wrapper::getType()const {
277 return account->getType(); 316 return account->getType();
278} 317}
279 318
280const QString&POP3wrapper::getName()const{ 319const QString&POP3wrapper::getName()const{
281 return account->getAccountName(); 320 return account->getAccountName();
282} 321}
diff --git a/kmicromail/libmailwrapper/pop3wrapper.h b/kmicromail/libmailwrapper/pop3wrapper.h
index ee754a4..7c70942 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.h
+++ b/kmicromail/libmailwrapper/pop3wrapper.h
@@ -1,44 +1,44 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#ifndef __POP3WRAPPER 2#ifndef __POP3WRAPPER
3#define __POP3WRAPPER 3#define __POP3WRAPPER
4 4
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "genericwrapper.h" 6#include "genericwrapper.h"
7#include <qstring.h> 7#include <qstring.h>
8 8
9class encodedString; 9class encodedString;
10struct mailstorage; 10struct mailstorage;
11struct mailfolder; 11struct mailfolder;
12 12
13class POP3wrapper : public Genericwrapper 13class POP3wrapper : public Genericwrapper
14{ 14{
15 Q_OBJECT 15 Q_OBJECT
16 16
17public: 17public:
18 POP3wrapper( POP3account *a ); 18 POP3wrapper( POP3account *a );
19 virtual ~POP3wrapper(); 19 virtual ~POP3wrapper();
20 /* mailbox will be ignored */ 20 /* mailbox will be ignored */
21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 ); 21 virtual void listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb = 0 );
22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders(); 22 virtual QValueList<Opie::Core::OSmartPointer<Folder> >* listFolders();
23 /* mailbox will be ignored */ 23 /* mailbox will be ignored */
24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 24 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
25 25
26 virtual void deleteMail(const RecMailP&mail); 26 virtual void deleteMail(const RecMailP&mail);
27 virtual void deleteMailList(const QValueList<RecMailP>&target);
27 virtual void answeredMail(const RecMailP&mail); 28 virtual void answeredMail(const RecMailP&mail);
28 virtual void deleteMailList(QValueList<RecMailP>&target);
29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&); 29 virtual int deleteAllMail(const Opie::Core::OSmartPointer<Folder>&);
30 30
31 virtual RecBodyP fetchBody( const RecMailP &mail ); 31 virtual RecBodyP fetchBody( const RecMailP &mail );
32 virtual encodedString* fetchRawBody(const RecMailP&mail); 32 virtual encodedString* fetchRawBody(const RecMailP&mail);
33 virtual void logout(); 33 virtual void logout();
34 virtual MAILLIB::ATYPE getType()const; 34 virtual MAILLIB::ATYPE getType()const;
35 virtual const QString&getName()const; 35 virtual const QString&getName()const;
36 static void pop3_progress( size_t current, size_t maximum ); 36 static void pop3_progress( size_t current, size_t maximum );
37 37
38protected: 38protected:
39 void login(); 39 void login();
40 POP3account *account; 40 POP3account *account;
41 mailstorage*m_pop3; 41 mailstorage*m_pop3;
42}; 42};
43 43
44#endif 44#endif