summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/pop3wrapper.cpp
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/pop3wrapper.cpp
parentb9257cb225cd29bab5d96fcdaf557926603ee587 (diff)
downloadkdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.zip
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.gz
kdepimpi-6cefbdc9c8f3f3001373f10715361e2740c45395.tar.bz2
Mail fixes and libetpan updated
Diffstat (limited to 'kmicromail/libmailwrapper/pop3wrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp43
1 files changed, 41 insertions, 2 deletions
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,58 +1,60 @@
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) {
@@ -148,135 +150,172 @@ void POP3wrapper::login()
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();
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;
203 while (iii < count ) { 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}