Diffstat (limited to 'kmicromail/libmailwrapper/pop3wrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/pop3wrapper.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/kmicromail/libmailwrapper/pop3wrapper.cpp b/kmicromail/libmailwrapper/pop3wrapper.cpp index 2888f7c..ebeed71 100644 --- a/kmicromail/libmailwrapper/pop3wrapper.cpp +++ b/kmicromail/libmailwrapper/pop3wrapper.cpp | |||
@@ -1,135 +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 "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 | #include <klocale.h> |
9 | 9 | ||
10 | #include <qpe/global.h> | 10 | #include <qpe/global.h> |
11 | #include <qfile.h> | 11 | #include <qfile.h> |
12 | #include <qprogressbar.h> | 12 | #include <q3progressbar.h> |
13 | #include <qapplication.h> | 13 | #include <qapplication.h> |
14 | //Added by qt3to4: | ||
15 | #include <Q3ValueList> | ||
14 | 16 | ||
15 | /* we don't fetch messages larger than 5 MB */ | 17 | /* we don't fetch messages larger than 5 MB */ |
16 | #define HARD_MSG_SIZE_LIMIT 5242880 | 18 | #define HARD_MSG_SIZE_LIMIT 5242880 |
17 | 19 | ||
18 | using namespace Opie::Core; | 20 | using namespace Opie::Core; |
19 | POP3wrapper::POP3wrapper( POP3account *a ) | 21 | POP3wrapper::POP3wrapper( POP3account *a ) |
20 | : Genericwrapper() { | 22 | : Genericwrapper() { |
21 | account = a; | 23 | account = a; |
22 | m_pop3 = NULL; | 24 | m_pop3 = NULL; |
23 | msgTempName = a->getFileName()+"_msg_cache"; | 25 | msgTempName = a->getFileName()+"_msg_cache"; |
24 | last_msg_id = 0; | 26 | last_msg_id = 0; |
25 | } | 27 | } |
26 | 28 | ||
27 | POP3wrapper::~POP3wrapper() { | 29 | POP3wrapper::~POP3wrapper() { |
28 | logout(); | 30 | logout(); |
29 | QFile msg_cache(msgTempName); | 31 | QFile msg_cache(msgTempName); |
30 | if (msg_cache.exists()) { | 32 | if (msg_cache.exists()) { |
31 | msg_cache.remove(); | 33 | msg_cache.remove(); |
32 | } | 34 | } |
33 | } | 35 | } |
34 | 36 | ||
35 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { | 37 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
36 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; | 38 | ; // odebug << "POP3: " << current << " of " << maximum << "" << oendl; |
37 | } | 39 | } |
38 | 40 | ||
39 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | 41 | RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { |
40 | int err = MAILPOP3_NO_ERROR; | 42 | int err = MAILPOP3_NO_ERROR; |
41 | char *message = 0; | 43 | char *message = 0; |
42 | size_t length = 0; | 44 | size_t length = 0; |
43 | 45 | ||
44 | RecBodyP body = new RecBody(); | 46 | RecBodyP body = new RecBody(); |
45 | 47 | ||
46 | login(); | 48 | login(); |
47 | if ( !m_pop3 ) { | 49 | if ( !m_pop3 ) { |
48 | return body; | 50 | return body; |
49 | } | 51 | } |
50 | 52 | ||
51 | mailmessage * mailmsg; | 53 | mailmessage * mailmsg; |
52 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { | 54 | if (mail->Msgsize()>HARD_MSG_SIZE_LIMIT) { |
53 | ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; | 55 | ; // odebug << "Message to large: " << mail->Msgsize() << "" << oendl; |
54 | return body; | 56 | return body; |
55 | } | 57 | } |
56 | 58 | ||
57 | QFile msg_cache(msgTempName); | 59 | QFile msg_cache(msgTempName); |
58 | 60 | ||
59 | cleanMimeCache(); | 61 | cleanMimeCache(); |
60 | 62 | ||
61 | if (mail->getNumber()!=last_msg_id) { | 63 | if (mail->getNumber()!=last_msg_id) { |
62 | if (msg_cache.exists()) { | 64 | if (msg_cache.exists()) { |
63 | msg_cache.remove(); | 65 | msg_cache.remove(); |
64 | } | 66 | } |
65 | msg_cache.open(IO_ReadWrite|IO_Truncate); | 67 | msg_cache.open(QIODevice::ReadWrite|QIODevice::Truncate); |
66 | last_msg_id = mail->getNumber(); | 68 | last_msg_id = mail->getNumber(); |
67 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); | 69 | err = mailsession_get_message(m_pop3->sto_session, mail->getNumber(), &mailmsg); |
68 | err = mailmessage_fetch(mailmsg,&message,&length); | 70 | err = mailmessage_fetch(mailmsg,&message,&length); |
69 | msg_cache.writeBlock(message,length); | 71 | msg_cache.writeBlock(message,length); |
70 | } else { | 72 | } else { |
71 | QString msg=""; | 73 | QString msg=""; |
72 | msg_cache.open(IO_ReadOnly); | 74 | msg_cache.open(QIODevice::ReadOnly); |
73 | message = new char[4096]; | 75 | message = new char[4096]; |
74 | memset(message,0,4096); | 76 | memset(message,0,4096); |
75 | while (msg_cache.readBlock(message,4095)>0) { | 77 | while (msg_cache.readBlock(message,4095)>0) { |
76 | msg+=message; | 78 | msg+=message; |
77 | memset(message,0,4096); | 79 | memset(message,0,4096); |
78 | } | 80 | } |
79 | delete message; | 81 | delete message; |
80 | message = (char*)malloc(msg.length()+1*sizeof(char)); | 82 | message = (char*)malloc(msg.length()+1*sizeof(char)); |
81 | memset(message,0,msg.length()+1); | 83 | memset(message,0,msg.length()+1); |
82 | memcpy(message,msg.latin1(),msg.length()); | 84 | memcpy(message,msg.latin1(),msg.length()); |
83 | /* transform to libetpan stuff */ | 85 | /* transform to libetpan stuff */ |
84 | mailmsg = mailmessage_new(); | 86 | mailmsg = mailmessage_new(); |
85 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); | 87 | mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); |
86 | generic_message_t * msg_data; | 88 | generic_message_t * msg_data; |
87 | msg_data = (generic_message_t *)mailmsg->msg_data; | 89 | msg_data = (generic_message_t *)mailmsg->msg_data; |
88 | msg_data->msg_fetched = 1; | 90 | msg_data->msg_fetched = 1; |
89 | msg_data->msg_message = message; | 91 | msg_data->msg_message = message; |
90 | msg_data->msg_length = strlen(message); | 92 | msg_data->msg_length = strlen(message); |
91 | } | 93 | } |
92 | body = parseMail(mailmsg); | 94 | body = parseMail(mailmsg); |
93 | 95 | ||
94 | /* clean up */ | 96 | /* clean up */ |
95 | if (mailmsg) | 97 | if (mailmsg) |
96 | mailmessage_free(mailmsg); | 98 | mailmessage_free(mailmsg); |
97 | if (message) | 99 | if (message) |
98 | free(message); | 100 | free(message); |
99 | 101 | ||
100 | return body; | 102 | return body; |
101 | } | 103 | } |
102 | 104 | ||
103 | void POP3wrapper::listMessages(const QString &, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 105 | void POP3wrapper::listMessages(const QString &, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
104 | { | 106 | { |
105 | login(); | 107 | login(); |
106 | if (!m_pop3) | 108 | if (!m_pop3) |
107 | return; | 109 | return; |
108 | uint32_t res_messages,res_recent,res_unseen; | 110 | uint32_t res_messages,res_recent,res_unseen; |
109 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 111 | mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
110 | parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); | 112 | parseList(target,m_pop3->sto_session,"INBOX", false, maxSizeInKb); |
111 | Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages)); | 113 | Global::statusMessage( i18n("Mailbox contains %1 mail(s)").arg(res_messages)); |
112 | } | 114 | } |
113 | 115 | ||
114 | void POP3wrapper::login() | 116 | void POP3wrapper::login() |
115 | { | 117 | { |
116 | if (account->getOffline()) | 118 | if (account->getOffline()) |
117 | return; | 119 | return; |
118 | /* we'll hold the line */ | 120 | /* we'll hold the line */ |
119 | if ( m_pop3 != NULL ) | 121 | if ( m_pop3 != NULL ) |
120 | return; | 122 | return; |
121 | 123 | ||
122 | QString server,user, pass; | 124 | QString server,user, pass; |
123 | uint16_t port; | 125 | uint16_t port; |
124 | int err = MAILPOP3_NO_ERROR; | 126 | int err = MAILPOP3_NO_ERROR; |
125 | 127 | ||
126 | server = account->getServer(); | 128 | server = account->getServer(); |
127 | port = account->getPort().toUInt(); | 129 | port = account->getPort().toUInt(); |
128 | 130 | ||
129 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 131 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
130 | qApp->processEvents(); | 132 | qApp->processEvents(); |
131 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 133 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
132 | login.show(); | 134 | login.show(); |
133 | if ( QDialog::Accepted == login.exec() ) { | 135 | if ( QDialog::Accepted == login.exec() ) { |
134 | // ok | 136 | // ok |
135 | user = login.getUser(); | 137 | user = login.getUser(); |
@@ -158,124 +160,124 @@ void POP3wrapper::login() | |||
158 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | 160 | conntype = CONNECTION_TYPE_TRY_STARTTLS; |
159 | } | 161 | } |
160 | 162 | ||
161 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 163 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); |
162 | 164 | ||
163 | pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, | 165 | pop3_mailstorage_init(m_pop3,(char*)server.latin1(), port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, |
164 | (char*)user.latin1(),(char*)pass.latin1(),0,0,0); | 166 | (char*)user.latin1(),(char*)pass.latin1(),0,0,0); |
165 | 167 | ||
166 | err = mailstorage_connect(m_pop3); | 168 | err = mailstorage_connect(m_pop3); |
167 | if (err != MAIL_NO_ERROR) { | 169 | if (err != MAIL_NO_ERROR) { |
168 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; | 170 | ; // odebug << QString( "FEHLERNUMMER %1" ).arg( err ) << oendl; |
169 | Global::statusMessage(i18n("Error %1 initializing folder").arg( err )); | 171 | Global::statusMessage(i18n("Error %1 initializing folder").arg( err )); |
170 | mailstorage_free(m_pop3); | 172 | mailstorage_free(m_pop3); |
171 | m_pop3 = 0; | 173 | m_pop3 = 0; |
172 | } else { | 174 | } else { |
173 | mailsession * session = m_pop3->sto_session; | 175 | mailsession * session = m_pop3->sto_session; |
174 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; | 176 | mailpop3 * mail = ( ( pop3_session_state_data * )session->sess_data )->pop3_session; |
175 | if (mail) { | 177 | if (mail) { |
176 | mail->pop3_progr_fun = &pop3_progress; | 178 | mail->pop3_progr_fun = &pop3_progress; |
177 | } | 179 | } |
178 | } | 180 | } |
179 | } | 181 | } |
180 | 182 | ||
181 | void POP3wrapper::logout() | 183 | void POP3wrapper::logout() |
182 | { | 184 | { |
183 | if ( m_pop3 == NULL ) | 185 | if ( m_pop3 == NULL ) |
184 | return; | 186 | return; |
185 | mailstorage_free(m_pop3); | 187 | mailstorage_free(m_pop3); |
186 | m_pop3 = 0; | 188 | m_pop3 = 0; |
187 | } | 189 | } |
188 | 190 | ||
189 | 191 | ||
190 | QValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { | 192 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* POP3wrapper::listFolders() { |
191 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<FolderP>(); | 193 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<FolderP>(); |
192 | FolderP inb=new Folder("INBOX","/"); | 194 | FolderP inb=new Folder("INBOX","/"); |
193 | folders->append(inb); | 195 | folders->append(inb); |
194 | return folders; | 196 | return folders; |
195 | } | 197 | } |
196 | 198 | ||
197 | void POP3wrapper::deleteMailList(const QValueList<RecMailP>&target) | 199 | void POP3wrapper::deleteMailList(const Q3ValueList<RecMailP>&target) |
198 | { | 200 | { |
199 | login(); | 201 | login(); |
200 | if (!m_pop3) | 202 | if (!m_pop3) |
201 | return; | 203 | return; |
202 | int iii = 0; | 204 | int iii = 0; |
203 | int count = target.count(); | 205 | int count = target.count(); |
204 | 206 | ||
205 | QProgressBar wid ( count ); | 207 | Q3ProgressBar wid ( count ); |
206 | wid.setCaption( i18n("Deleting ...")); | 208 | wid.setCaption( i18n("Deleting ...")); |
207 | wid.show(); | 209 | wid.show(); |
208 | while (iii < count ) { | 210 | while (iii < count ) { |
209 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); | 211 | Global::statusMessage(i18n("Delete message %1 of %2").arg(iii).arg(count)); |
210 | wid.setProgress( iii ); | 212 | wid.setProgress( iii ); |
211 | wid.raise(); | 213 | wid.raise(); |
212 | qApp->processEvents(); | 214 | qApp->processEvents(); |
213 | //qDebug("delete "); | 215 | //qDebug("delete "); |
214 | RecMailP mail = (*target.at( iii )); | 216 | RecMailP mail = (*target.at( iii )); |
215 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 217 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
216 | if (err != MAIL_NO_ERROR) { | 218 | if (err != MAIL_NO_ERROR) { |
217 | Global::statusMessage(i18n("Error deleting mail")); | 219 | Global::statusMessage(i18n("Error deleting mail")); |
218 | } | 220 | } |
219 | ++iii; | 221 | ++iii; |
220 | } | 222 | } |
221 | } | 223 | } |
222 | void POP3wrapper::deleteMail(const RecMailP&mail) { | 224 | void POP3wrapper::deleteMail(const RecMailP&mail) { |
223 | login(); | 225 | login(); |
224 | if (!m_pop3) | 226 | if (!m_pop3) |
225 | return; | 227 | return; |
226 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); | 228 | int err = mailsession_remove_message(m_pop3->sto_session,mail->getNumber()); |
227 | if (err != MAIL_NO_ERROR) { | 229 | if (err != MAIL_NO_ERROR) { |
228 | Global::statusMessage(i18n("error deleting mail")); | 230 | Global::statusMessage(i18n("error deleting mail")); |
229 | } | 231 | } |
230 | } | 232 | } |
231 | 233 | ||
232 | void POP3wrapper::answeredMail(const RecMailP&) {} | 234 | void POP3wrapper::answeredMail(const RecMailP&) {} |
233 | 235 | ||
234 | int POP3wrapper::deleteAllMail(const FolderP&) { | 236 | int POP3wrapper::deleteAllMail(const FolderP&) { |
235 | login(); | 237 | login(); |
236 | if (!m_pop3) | 238 | if (!m_pop3) |
237 | return 0; | 239 | return 0; |
238 | int res = 1; | 240 | int res = 1; |
239 | 241 | ||
240 | uint32_t result = 0; | 242 | uint32_t result = 0; |
241 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); | 243 | int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); |
242 | if (err != MAIL_NO_ERROR) { | 244 | if (err != MAIL_NO_ERROR) { |
243 | Global::statusMessage(i18n("Error getting folder info")); | 245 | Global::statusMessage(i18n("Error getting folder info")); |
244 | return 0; | 246 | return 0; |
245 | } | 247 | } |
246 | 248 | ||
247 | 249 | ||
248 | 250 | ||
249 | QProgressBar wid ( result ); | 251 | Q3ProgressBar wid ( result ); |
250 | wid.setCaption( i18n("Deleting ...")); | 252 | wid.setCaption( i18n("Deleting ...")); |
251 | wid.show(); | 253 | wid.show(); |
252 | for (unsigned int i = 0; i < result; ++i) { | 254 | for (unsigned int i = 0; i < result; ++i) { |
253 | Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result)); | 255 | Global::statusMessage(i18n("Delete message %1 of %2").arg(i).arg(result)); |
254 | wid.setProgress( i ); | 256 | wid.setProgress( i ); |
255 | wid.raise(); | 257 | wid.raise(); |
256 | qApp->processEvents(); | 258 | qApp->processEvents(); |
257 | 259 | ||
258 | err = mailsession_remove_message(m_pop3->sto_session,i+1); | 260 | err = mailsession_remove_message(m_pop3->sto_session,i+1); |
259 | if (err != MAIL_NO_ERROR) { | 261 | if (err != MAIL_NO_ERROR) { |
260 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); | 262 | Global::statusMessage(i18n("Error deleting mail %1").arg(i+1)); |
261 | res=0; | 263 | res=0; |
262 | } | 264 | } |
263 | break; | 265 | break; |
264 | } | 266 | } |
265 | return res; | 267 | return res; |
266 | } | 268 | } |
267 | 269 | ||
268 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { | 270 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
269 | login(); | 271 | login(); |
270 | target_stat.message_count = 0; | 272 | target_stat.message_count = 0; |
271 | target_stat.message_unseen = 0; | 273 | target_stat.message_unseen = 0; |
272 | target_stat.message_recent = 0; | 274 | target_stat.message_recent = 0; |
273 | if (!m_pop3) | 275 | if (!m_pop3) |
274 | return; | 276 | return; |
275 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, | 277 | int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, |
276 | &target_stat.message_recent,&target_stat.message_unseen); | 278 | &target_stat.message_recent,&target_stat.message_unseen); |
277 | if (r != MAIL_NO_ERROR) { | 279 | if (r != MAIL_NO_ERROR) { |
278 | ; // odebug << "error getting folter status." << oendl; | 280 | ; // odebug << "error getting folter status." << oendl; |
279 | } | 281 | } |
280 | } | 282 | } |
281 | 283 | ||