summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/pop3wrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/pop3wrapper.cpp21
1 files changed, 11 insertions, 10 deletions
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp
index 9d52f52..2888f7c 100644
--- a/kmicromail/libmailwrapper/pop3wrapper.cpp
+++ b/kmicromail/libmailwrapper/pop3wrapper.cpp
@@ -1,31 +1,32 @@
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#include <klocale.h>
8 9
9#include <qpe/global.h> 10#include <qpe/global.h>
10#include <qfile.h> 11#include <qfile.h>
11#include <qprogressbar.h> 12#include <qprogressbar.h>
12#include <qapplication.h> 13#include <qapplication.h>
13 14
14/* we don't fetch messages larger than 5 MB */ 15/* we don't fetch messages larger than 5 MB */
15#define HARD_MSG_SIZE_LIMIT 5242880 16#define HARD_MSG_SIZE_LIMIT 5242880
16 17
17using namespace Opie::Core; 18using namespace Opie::Core;
18POP3wrapper::POP3wrapper( POP3account *a ) 19POP3wrapper::POP3wrapper( POP3account *a )
19: Genericwrapper() { 20: Genericwrapper() {
20 account = a; 21 account = a;
21 m_pop3 = NULL; 22 m_pop3 = NULL;
22 msgTempName = a->getFileName()+"_msg_cache"; 23 msgTempName = a->getFileName()+"_msg_cache";
23 last_msg_id = 0; 24 last_msg_id = 0;
24} 25}
25 26
26POP3wrapper::~POP3wrapper() { 27POP3wrapper::~POP3wrapper() {
27 logout(); 28 logout();
28 QFile msg_cache(msgTempName); 29 QFile msg_cache(msgTempName);
29 if (msg_cache.exists()) { 30 if (msg_cache.exists()) {
30 msg_cache.remove(); 31 msg_cache.remove();
31 } 32 }
@@ -86,49 +87,49 @@ RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) {
86 msg_data = (generic_message_t *)mailmsg->msg_data; 87 msg_data = (generic_message_t *)mailmsg->msg_data;
87 msg_data->msg_fetched = 1; 88 msg_data->msg_fetched = 1;
88 msg_data->msg_message = message; 89 msg_data->msg_message = message;
89 msg_data->msg_length = strlen(message); 90 msg_data->msg_length = strlen(message);
90 } 91 }
91 body = parseMail(mailmsg); 92 body = parseMail(mailmsg);
92 93
93 /* clean up */ 94 /* clean up */
94 if (mailmsg) 95 if (mailmsg)
95 mailmessage_free(mailmsg); 96 mailmessage_free(mailmsg);
96 if (message) 97 if (message)
97 free(message); 98 free(message);
98 99
99 return body; 100 return body;
100} 101}
101 102
102void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 103void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
103{ 104{
104 login(); 105 login();
105 if (!m_pop3) 106 if (!m_pop3)
106 return; 107 return;
107 uint32_t res_messages,res_recent,res_unseen; 108 uint32_t res_messages,res_recent,res_unseen;
108 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); 109 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
109 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); 110 parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb);
110 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 111 Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages));
111} 112}
112 113
113void POP3wrapper::login() 114void POP3wrapper::login()
114{ 115{
115 if (account->getOffline()) 116 if (account->getOffline())
116 return; 117 return;
117 /* we'll hold the line */ 118 /* we'll hold the line */
118 if ( m_pop3 != NULL ) 119 if ( m_pop3 != NULL )
119 return; 120 return;
120 121
121 QString server,user, pass; 122 QString server,user, pass;
122 uint16_t port; 123 uint16_t port;
123 int err = MAILPOP3_NO_ERROR; 124 int err = MAILPOP3_NO_ERROR;
124 125
125 server = account->getServer(); 126 server = account->getServer();
126 port = account->getPort().toUInt(); 127 port = account->getPort().toUInt();
127 128
128 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 129 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
129 qApp->processEvents(); 130 qApp->processEvents();
130 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 131 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
131 login.show(); 132 login.show();
132 if ( QDialog::Accepted == login.exec() ) { 133 if ( QDialog::Accepted == login.exec() ) {
133 // ok 134 // ok
134 user = login.getUser(); 135 user = login.getUser();
@@ -144,140 +145,140 @@ void POP3wrapper::login()
144 } 145 }
145 // bool ssl = account->getSSL(); 146 // bool ssl = account->getSSL();
146 147
147 m_pop3=mailstorage_new(NULL); 148 m_pop3=mailstorage_new(NULL);
148 int conntypeset = account->ConnectionType(); 149 int conntypeset = account->ConnectionType();
149 int conntype = 0; 150 int conntype = 0;
150 if ( conntypeset == 3 ) { 151 if ( conntypeset == 3 ) {
151 conntype = CONNECTION_TYPE_COMMAND; 152 conntype = CONNECTION_TYPE_COMMAND;
152 } else if ( conntypeset == 2 ) { 153 } else if ( conntypeset == 2 ) {
153 conntype = CONNECTION_TYPE_TLS; 154 conntype = CONNECTION_TYPE_TLS;
154 } else if ( conntypeset == 1 ) { 155 } else if ( conntypeset == 1 ) {
155 conntype = CONNECTION_TYPE_STARTTLS; 156 conntype = CONNECTION_TYPE_STARTTLS;
156 } else if ( conntypeset == 0 ) { 157 } else if ( conntypeset == 0 ) {
157 conntype = CONNECTION_TYPE_TRY_STARTTLS; 158 conntype = CONNECTION_TYPE_TRY_STARTTLS;
158 } 159 }
159 160
160 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 161 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
161 162
162 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 163 pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
163 (char*)user.latin1(),(char*)pass.latin1(),0,0,0); 164 (char*)user.latin1(),(char*)pass.latin1(),0,0,0);
164 165
165 err = mailstorage_connect(m_pop3); 166 err = mailstorage_connect(m_pop3);
166 if (err != MAIL_NO_ERROR) { 167 if (err != MAIL_NO_ERROR) {
167 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; 168 ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl;
168 Global::statusMessage(tr("Error %1 initializing folder").arg( err )); 169 Global::statusMessage(i18n("Error %1 initializing folder").arg( err ));
169 mailstorage_free(m_pop3); 170 mailstorage_free(m_pop3);
170 m_pop3 = 0; 171 m_pop3 = 0;
171 } else { 172 } else {
172 mailsession * session = m_pop3->sto_session; 173 mailsession * session = m_pop3->sto_session;
173 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; 174 mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session;
174 if (mail) { 175 if (mail) {
175 mail->pop3_progr_fun = &pop3_progress; 176 mail->pop3_progr_fun = &pop3_progress;
176 } 177 }
177 } 178 }
178} 179}
179 180
180void POP3wrapper::logout() 181void POP3wrapper::logout()
181{ 182{
182 if ( m_pop3 == NULL ) 183 if ( m_pop3 == NULL )
183 return; 184 return;
184 mailstorage_free(m_pop3); 185 mailstorage_free(m_pop3);
185 m_pop3 = 0; 186 m_pop3 = 0;
186} 187}
187 188
188 189
189QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { 190QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() {
190 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); 191 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>();
191 FolderP inb=new Folder("INBOX","/"); 192 FolderP inb=new Folder("INBOX","/");
192 folders->append(inb); 193 folders->append(inb);
193 return folders; 194 return folders;
194} 195}
195 196
196void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) 197void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target)
197{ 198{
198 login(); 199 login();
199 if (!m_pop3) 200 if (!m_pop3)
200 return; 201 return;
201 int iii = 0; 202 int iii = 0;
202 int count = target.count(); 203 int count = target.count();
203 204
204 QProgressBar wid ( count ); 205 QProgressBar wid ( count );
205 wid.setCaption( tr("Deleting ...")); 206 wid.setCaption( i18n("Deleting ..."));
206 wid.show(); 207 wid.show();
207 while (iii < count ) { 208 while (iii < count ) {
208 Global::statusMessage(tr("Delete message %1 of %2").arg(iii).arg(count)); 209 Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count));
209 wid.setProgress( iii ); 210 wid.setProgress( iii );
210 wid.raise(); 211 wid.raise();
211 qApp->processEvents(); 212 qApp->processEvents();
212 //qDebug("delete "); 213 //qDebug("delete ");
213 RecMailP mail = (*target.at( iii )); 214 RecMailP mail = (*target.at( iii ));
214 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 215 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
215 if (err != MAIL_NO_ERROR) { 216 if (err != MAIL_NO_ERROR) {
216 Global::statusMessage(tr("Error deleting mail")); 217 Global::statusMessage(i18n("Error deleting mail"));
217 } 218 }
218 ++iii; 219 ++iii;
219 } 220 }
220} 221}
221void POP3wrapper::deleteMail(const RecMailP&mail) { 222void POP3wrapper::deleteMail(const RecMailP&mail) {
222 login(); 223 login();
223 if (!m_pop3) 224 if (!m_pop3)
224 return; 225 return;
225 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); 226 int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber());
226 if (err != MAIL_NO_ERROR) { 227 if (err != MAIL_NO_ERROR) {
227 Global::statusMessage(tr("error deleting mail")); 228 Global::statusMessage(i18n("error deleting mail"));
228 } 229 }
229} 230}
230 231
231void POP3wrapper::answeredMail(const RecMailP&) {} 232void POP3wrapper::answeredMail(const RecMailP&) {}
232 233
233int POP3wrapper::deleteAllMail(const FolderP&) { 234int POP3wrapper::deleteAllMail(const FolderP&) {
234 login(); 235 login();
235 if (!m_pop3) 236 if (!m_pop3)
236 return 0; 237 return 0;
237 int res = 1; 238 int res = 1;
238 239
239 uint32_t result = 0; 240 uint32_t result = 0;
240 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); 241 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
241 if (err != MAIL_NO_ERROR) { 242 if (err != MAIL_NO_ERROR) {
242 Global::statusMessage(tr("Error getting folder info")); 243 Global::statusMessage(i18n("Error getting folder info"));
243 return 0; 244 return 0;
244 } 245 }
245 246
246 247
247 248
248 QProgressBar wid ( result ); 249 QProgressBar wid ( result );
249 wid.setCaption( tr("Deleting ...")); 250 wid.setCaption( i18n("Deleting ..."));
250 wid.show(); 251 wid.show();
251 for (unsigned int i = 0; i < result; ++i) { 252 for (unsigned int i = 0; i < result; ++i) {
252 Global::statusMessage(tr("Delete message %1 of %2").arg(i).arg(result)); 253 Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result));
253 wid.setProgress( i ); 254 wid.setProgress( i );
254 wid.raise(); 255 wid.raise();
255 qApp->processEvents(); 256 qApp->processEvents();
256 257
257 err = mailsession_remove_message(m_pop3->sto_session,i+1); 258 err = mailsession_remove_message(m_pop3->sto_session,i+1);
258 if (err != MAIL_NO_ERROR) { 259 if (err != MAIL_NO_ERROR) {
259 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 260 Global::statusMessage(i18n("Error deleting mail %1").arg(i+1));
260 res=0; 261 res=0;
261 } 262 }
262 break; 263 break;
263 } 264 }
264 return res; 265 return res;
265} 266}
266 267
267void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 268void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
268 login(); 269 login();
269 target_stat.message_count = 0; 270 target_stat.message_count = 0;
270 target_stat.message_unseen = 0; 271 target_stat.message_unseen = 0;
271 target_stat.message_recent = 0; 272 target_stat.message_recent = 0;
272 if (!m_pop3) 273 if (!m_pop3)
273 return; 274 return;
274 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, 275 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
275 &target_stat.message_recent,&target_stat.message_unseen); 276 &target_stat.message_recent,&target_stat.message_unseen);
276 if (r != MAIL_NO_ERROR) { 277 if (r != MAIL_NO_ERROR) {
277 ; // odebug << "error getting folter status." << oendl; 278 ; // odebug << "error getting folter status." << oendl;
278 } 279 }
279} 280}
280 281
281encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) { 282encodedString* POP3wrapper::fetchRawBody(const RecMailP&mail) {
282 char*target=0; 283 char*target=0;
283 size_t length=0; 284 size_t length=0;