summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 3cfd1ee..2d66fc9 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,62 +1,69 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6 6
7#include <opie2/odebug.h> 7#include <opie2/odebug.h>
8#include <qpe/global.h> 8#include <qpe/global.h>
9#include <qfile.h> 9#include <qfile.h>
10#include <qmessagebox.h>
10 11
11/* we don't fetch messages larger than 5 MB */ 12/* we don't fetch messages larger than 5 MB */
12#define HARD_MSG_SIZE_LIMIT 5242880 13#define HARD_MSG_SIZE_LIMIT 5242880
13 14
14using namespace Opie::Core; 15using namespace Opie::Core;
15POP3wrapper::POP3wrapper( POP3account *a ) 16POP3wrapper::POP3wrapper( POP3account *a )
16: Genericwrapper() { 17: Genericwrapper() {
17 account = a; 18 account = a;
18 m_pop3 = NULL; 19 m_pop3 = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 20 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 21 last_msg_id = 0;
22 m_maxsize = account->getMaxSize();
23 m_checksize = account->getCheckMaxSize();
21} 24}
22 25
23POP3wrapper::~POP3wrapper() { 26POP3wrapper::~POP3wrapper() {
24 logout(); 27 logout();
25 QFile msg_cache(msgTempName); 28 QFile msg_cache(msgTempName);
26 if (msg_cache.exists()) { 29 if (msg_cache.exists()) {
27 msg_cache.remove(); 30 msg_cache.remove();
28 } 31 }
29} 32}
30 33
31void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 34void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
32 odebug << "POP3: " << current << " of " << maximum << "" << oendl; 35 odebug << "POP3: " << current << " of " << maximum << "" << oendl;
33} 36}
34 37
35RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { 38RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
36 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
37 char *message = 0; 40 char *message = 0;
38 size_t length = 0; 41 size_t length = 0;
39 42
40 RecBodyP body = new RecBody(); 43 RecBodyP body = new RecBody();
41 44
42 login(); 45 login();
43 if ( !m_pop3 ) { 46 if ( !m_pop3 ) {
44 return body; 47 return body;
45 } 48 }
46 49
47 mailmessage * mailmsg; 50 mailmessage * mailmsg;
48 if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { 51 if (mail->Msgsize()/1024>m_maxsize && m_checksize && mail->getNumber()!=last_msg_id) {
49 odebug << "Message to large: " << mail->Msgsize() << "" << oendl; 52 QString quest = QString(tr("Download mail?\nIt is %1 kByte but your limit is %2 kByte")).arg(mail->Msgsize()/1024).arg(m_maxsize);
50 return body; 53 int yesno = QMessageBox::warning(0,tr("Download message"),
54 quest,tr("Yes"),tr("No"),QString::null,0,1);
55 odebug << "Message to large: " << mail->Msgsize() << "" << oendl;
56 if (yesno==1)
57 return body;
51 } 58 }
52 59
53 QFile msg_cache(msgTempName); 60 QFile msg_cache(msgTempName);
54 61
55 cleanMimeCache(); 62 cleanMimeCache();
56 63
57 if (mail->getNumber()!=last_msg_id) { 64 if (mail->getNumber()!=last_msg_id) {
58 if (msg_cache.exists()) { 65 if (msg_cache.exists()) {
59 msg_cache.remove(); 66 msg_cache.remove();
60 } 67 }
61 msg_cache.open(IO_ReadWrite|IO_Truncate); 68 msg_cache.open(IO_ReadWrite|IO_Truncate);
62 last_msg_id = mail->getNumber(); 69 last_msg_id = mail->getNumber();
@@ -122,25 +129,25 @@ void POP3wrapper::login()
122 server = account->getServer().latin1(); 129 server = account->getServer().latin1();
123 port = account->getPort().toUInt(); 130 port = account->getPort().toUInt();
124 131
125 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 132 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
126 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 133 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
127 login.show(); 134 login.show();
128 if ( QDialog::Accepted == login.exec() ) { 135 if ( QDialog::Accepted == login.exec() ) {
129 // ok 136 // ok
130 user = login.getUser().latin1(); 137 user = login.getUser().latin1();
131 pass = login.getPassword().latin1(); 138 pass = login.getPassword().latin1();
132 } else { 139 } else {
133 // cancel 140 // cancel
134 odebug << "POP3: Login canceled" << oendl; 141 odebug << "POP3: Login canceled" << oendl;
135 return; 142 return;
136 } 143 }
137 } else { 144 } else {
138 user = account->getUser().latin1(); 145 user = account->getUser().latin1();
139 pass = account->getPassword().latin1(); 146 pass = account->getPassword().latin1();
140 } 147 }
141 148
142 // bool ssl = account->getSSL(); 149 // bool ssl = account->getSSL();
143 150
144 m_pop3=mailstorage_new(NULL); 151 m_pop3=mailstorage_new(NULL);
145 152
146 int conntypeset = account->ConnectionType(); 153 int conntypeset = account->ConnectionType();
@@ -154,25 +161,25 @@ void POP3wrapper::login()
154 } else if ( conntypeset == 0 ) { 161 } else if ( conntypeset == 0 ) {
155 conntype = CONNECTION_TYPE_TRY_STARTTLS; 162 conntype = CONNECTION_TYPE_TRY_STARTTLS;
156 } 163 }
157 164
158 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 165 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
159 166
160 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 167 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
161 (char*)user,(char*)pass,0,0,0); 168 (char*)user,(char*)pass,0,0,0);
162 169
163 170
164 err = mailstorage_connect(m_pop3); 171 err = mailstorage_connect(m_pop3);
165 if (err != MAIL_NO_ERROR) { 172 if (err != MAIL_NO_ERROR) {
166 odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 173 odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
167 Global::statusMessage(tr("Error initializing folder")); 174 Global::statusMessage(tr("Error initializing folder"));
168 mailstorage_free(m_pop3); 175 mailstorage_free(m_pop3);
169 m_pop3 = 0; 176 m_pop3 = 0;
170 } else { 177 } else {
171 mailsession * session = m_pop3->sto_session; 178 mailsession * session = m_pop3->sto_session;
172 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 179 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
173 if (mail) { 180 if (mail) {
174 mail->pop3_progr_fun = &pop3_progress; 181 mail->pop3_progr_fun = &pop3_progress;
175 } 182 }
176 } 183 }
177} 184}
178 185
@@ -228,25 +235,25 @@ int POP3wrapper::deleteAllMail(const FolderP&) {
228} 235}
229 236
230void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 237void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
231 login(); 238 login();
232 target_stat.message_count = 0; 239 target_stat.message_count = 0;
233 target_stat.message_unseen = 0; 240 target_stat.message_unseen = 0;
234 target_stat.message_recent = 0; 241 target_stat.message_recent = 0;
235 if (!m_pop3) 242 if (!m_pop3)
236 return; 243 return;
237 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 244 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
238 &target_stat.message_recent,&target_stat.message_unseen); 245 &target_stat.message_recent,&target_stat.message_unseen);
239 if (r != MAIL_NO_ERROR) { 246 if (r != MAIL_NO_ERROR) {
240 odebug << "error getting folter status." << oendl; 247 odebug << "error getting folter status." << oendl;
241 } 248 }
242} 249}
243 250
244encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 251encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
245 char*target=0; 252 char*target=0;
246 size_t length=0; 253 size_t length=0;
247 encodedString*res = 0; 254 encodedString*res = 0;
248 mailmessage * mailmsg = 0; 255 mailmessage * mailmsg = 0;
249 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); 256 int err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg);
250 err = mailmessage_fetch(mailmsg,&target,&length); 257 err = mailmessage_fetch(mailmsg,&target,&length);
251 if (mailmsg) 258 if (mailmsg)
252 mailmessage_free(mailmsg); 259 mailmessage_free(mailmsg);