author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kmicromail/libmailwrapper/pop3wrapper.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
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,29 +1,31 @@ | |||
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); |
@@ -49,71 +51,71 @@ RecBodyP POP3wrapper::fetchBody( const RecMailP &mail ) { | |||
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 ) |
@@ -174,48 +176,48 @@ void POP3wrapper::login() | |||
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 | } |
@@ -233,33 +235,33 @@ 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; |