Diffstat (limited to 'noncore/net/mail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 21 |
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,74 +1,81 @@ | |||
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 | ||
14 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
15 | POP3wrapper::POP3wrapper( POP3account *a ) | 16 | POP3wrapper::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 | ||
23 | POP3wrapper::~POP3wrapper() { | 26 | POP3wrapper::~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 | ||
31 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 34 | void 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 | ||
35 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | 38 | RecBodyP 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(); |
63 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 70 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
64 | err = mailmessage_fetch(mailmsg,&message,&length); | 71 | err = mailmessage_fetch(mailmsg,&message,&length); |
65 | msg_cache.writeBlock(message,length); | 72 | msg_cache.writeBlock(message,length); |
66 | } else { | 73 | } else { |
67 | QString msg=""; | 74 | QString msg=""; |
68 | msg_cache.open(IO_ReadOnly); | 75 | msg_cache.open(IO_ReadOnly); |
69 | message = new char[4096]; | 76 | message = new char[4096]; |
70 | memset(message,0,4096); | 77 | memset(message,0,4096); |
71 | while (msg_cache.readBlock(message,4095)>0) { | 78 | while (msg_cache.readBlock(message,4095)>0) { |
72 | msg+=message; | 79 | msg+=message; |
73 | memset(message,0,4096); | 80 | memset(message,0,4096); |
74 | } | 81 | } |
@@ -110,81 +117,81 @@ void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPoi | |||
110 | void POP3wrapper::login() | 117 | void POP3wrapper::login() |
111 | { | 118 | { |
112 | if (account->getOffline()) | 119 | if (account->getOffline()) |
113 | return; | 120 | return; |
114 | /* we'll hold the line */ | 121 | /* we'll hold the line */ |
115 | if ( m_pop3 != NULL ) | 122 | if ( m_pop3 != NULL ) |
116 | return; | 123 | return; |
117 | 124 | ||
118 | const char *server, *user, *pass; | 125 | const char *server, *user, *pass; |
119 | uint16_t port; | 126 | uint16_t port; |
120 | int err = MAILPOP3_NO_ERROR; | 127 | int err = MAILPOP3_NO_ERROR; |
121 | 128 | ||
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(); |
147 | int conntype = 0; | 154 | int conntype = 0; |
148 | if ( conntypeset == 3 ) { | 155 | if ( conntypeset == 3 ) { |
149 | conntype = CONNECTION_TYPE_COMMAND; | 156 | conntype = CONNECTION_TYPE_COMMAND; |
150 | } else if ( conntypeset == 2 ) { | 157 | } else if ( conntypeset == 2 ) { |
151 | conntype = CONNECTION_TYPE_TLS; | 158 | conntype = CONNECTION_TYPE_TLS; |
152 | } else if ( conntypeset == 1 ) { | 159 | } else if ( conntypeset == 1 ) { |
153 | conntype = CONNECTION_TYPE_STARTTLS; | 160 | conntype = CONNECTION_TYPE_STARTTLS; |
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 | ||
179 | void POP3wrapper::logout() | 186 | void POP3wrapper::logout() |
180 | { | 187 | { |
181 | if ( m_pop3 == NULL ) | 188 | if ( m_pop3 == NULL ) |
182 | return; | 189 | return; |
183 | mailstorage_free(m_pop3); | 190 | mailstorage_free(m_pop3); |
184 | m_pop3 = 0; | 191 | m_pop3 = 0; |
185 | } | 192 | } |
186 | 193 | ||
187 | 194 | ||
188 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 195 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
189 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 196 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); |
190 | FolderP inb=new Folder("INBOX","/"); | 197 | FolderP inb=new Folder("INBOX","/"); |
@@ -216,49 +223,49 @@ int POP3wrapper::deleteAllMail(const FolderP&) { | |||
216 | Global::statusMessage(tr("Error getting folder info")); | 223 | Global::statusMessage(tr("Error getting folder info")); |
217 | return 0; | 224 | return 0; |
218 | } | 225 | } |
219 | for (unsigned int i = 0; i < result; ++i) { | 226 | for (unsigned int i = 0; i < result; ++i) { |
220 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 227 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
221 | if (err != MAIL_NO_ERROR) { | 228 | if (err != MAIL_NO_ERROR) { |
222 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 229 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
223 | res=0; | 230 | res=0; |
224 | } | 231 | } |
225 | break; | 232 | break; |
226 | } | 233 | } |
227 | return res; | 234 | return res; |
228 | } | 235 | } |
229 | 236 | ||
230 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 237 | void 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 | ||
244 | encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { | 251 | encodedString* 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); |
253 | if (target) { | 260 | if (target) { |
254 | res = new encodedString(target,length); | 261 | res = new encodedString(target,length); |
255 | } | 262 | } |
256 | return res; | 263 | return res; |
257 | } | 264 | } |
258 | 265 | ||
259 | MAILLIB::ATYPE POP3wrapper::getType()const { | 266 | MAILLIB::ATYPE POP3wrapper::getType()const { |
260 | return account->getType(); | 267 | return account->getType(); |
261 | } | 268 | } |
262 | 269 | ||
263 | const QString&POP3wrapper::getName()const{ | 270 | const QString&POP3wrapper::getName()const{ |
264 | return account->getAccountName(); | 271 | return account->getAccountName(); |