summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-06 10:50:04 (UTC)
committer alwin <alwin>2004-01-06 10:50:04 (UTC)
commit37ac44d5582a5c4793482ed544a38a014c5fe8a2 (patch) (unidiff)
tree9dea89a03d7d3ebf68190ff55848b6756a4b47d6
parentd462abe3a8f908111eeb9bdf1b2675a0bc322edc (diff)
downloadopie-37ac44d5582a5c4793482ed544a38a014c5fe8a2.zip
opie-37ac44d5582a5c4793482ed544a38a014c5fe8a2.tar.gz
opie-37ac44d5582a5c4793482ed544a38a014c5fe8a2.tar.bz2
hopefully fixed problems when logging into pop3 servers
it seems, that APOP login isn't working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 72c145b..ec4dcd2 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,249 +1,250 @@
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#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h> 8#include <qstring.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14 : Genericwrapper() 14 : Genericwrapper()
15{ 15{
16 account = a; 16 account = a;
17 m_pop3 = NULL; 17 m_pop3 = NULL;
18 m_folder = NULL; 18 m_folder = NULL;
19 msgTempName = a->getFileName()+"_msg_cache"; 19 msgTempName = a->getFileName()+"_msg_cache";
20 last_msg_id = 0; 20 last_msg_id = 0;
21} 21}
22 22
23POP3wrapper::~POP3wrapper() 23POP3wrapper::~POP3wrapper()
24{ 24{
25 logout(); 25 logout();
26 QFile msg_cache(msgTempName); 26 QFile msg_cache(msgTempName);
27 if (msg_cache.exists()) { 27 if (msg_cache.exists()) {
28 msg_cache.remove(); 28 msg_cache.remove();
29 } 29 }
30} 30}
31 31
32void POP3wrapper::pop3_progress( size_t current, size_t maximum ) 32void POP3wrapper::pop3_progress( size_t current, size_t maximum )
33{ 33{
34 qDebug( "POP3: %i of %i", current, maximum ); 34 qDebug( "POP3: %i of %i", current, maximum );
35} 35}
36 36
37RecBody POP3wrapper::fetchBody( const RecMail &mail ) 37RecBody POP3wrapper::fetchBody( const RecMail &mail )
38{ 38{
39 int err = MAILPOP3_NO_ERROR; 39 int err = MAILPOP3_NO_ERROR;
40 char *message = 0; 40 char *message = 0;
41 size_t length = 0; 41 size_t length = 0;
42 42
43 login(); 43 login();
44 if ( !m_pop3 ) { 44 if ( !m_pop3 ) {
45 return RecBody(); 45 return RecBody();
46 } 46 }
47 47
48 RecBody body; 48 RecBody body;
49 mailmessage * mailmsg; 49 mailmessage * mailmsg;
50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 50 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
51 qDebug("Message to large: %i",mail.Msgsize()); 51 qDebug("Message to large: %i",mail.Msgsize());
52 return body; 52 return body;
53 } 53 }
54 54
55 QFile msg_cache(msgTempName); 55 QFile msg_cache(msgTempName);
56 56
57 cleanMimeCache(); 57 cleanMimeCache();
58 58
59 if (mail.getNumber()!=last_msg_id) { 59 if (mail.getNumber()!=last_msg_id) {
60 if (msg_cache.exists()) { 60 if (msg_cache.exists()) {
61 msg_cache.remove(); 61 msg_cache.remove();
62 } 62 }
63 msg_cache.open(IO_ReadWrite|IO_Truncate); 63 msg_cache.open(IO_ReadWrite|IO_Truncate);
64 last_msg_id = mail.getNumber(); 64 last_msg_id = mail.getNumber();
65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 65 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
66 err = mailmessage_fetch(mailmsg,&message,&length); 66 err = mailmessage_fetch(mailmsg,&message,&length);
67 msg_cache.writeBlock(message,length); 67 msg_cache.writeBlock(message,length);
68 } else { 68 } else {
69 QString msg=""; 69 QString msg="";
70 msg_cache.open(IO_ReadOnly); 70 msg_cache.open(IO_ReadOnly);
71 message = new char[4096]; 71 message = new char[4096];
72 memset(message,0,4096); 72 memset(message,0,4096);
73 while (msg_cache.readBlock(message,4095)>0) { 73 while (msg_cache.readBlock(message,4095)>0) {
74 msg+=message; 74 msg+=message;
75 memset(message,0,4096); 75 memset(message,0,4096);
76 } 76 }
77 delete message; 77 delete message;
78 message = (char*)malloc(msg.length()+1*sizeof(char)); 78 message = (char*)malloc(msg.length()+1*sizeof(char));
79 memset(message,0,msg.length()+1); 79 memset(message,0,msg.length()+1);
80 memcpy(message,msg.latin1(),msg.length()); 80 memcpy(message,msg.latin1(),msg.length());
81 /* transform to libetpan stuff */ 81 /* transform to libetpan stuff */
82 mailmsg = mailmessage_new(); 82 mailmsg = mailmessage_new();
83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message)); 83 mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
84 generic_message_t * msg_data; 84 generic_message_t * msg_data;
85 msg_data = (generic_message_t *)mailmsg->msg_data; 85 msg_data = (generic_message_t *)mailmsg->msg_data;
86 msg_data->msg_fetched = 1; 86 msg_data->msg_fetched = 1;
87 msg_data->msg_message = message; 87 msg_data->msg_message = message;
88 msg_data->msg_length = strlen(message); 88 msg_data->msg_length = strlen(message);
89 } 89 }
90 body = parseMail(mailmsg); 90 body = parseMail(mailmsg);
91 91
92 /* clean up */ 92 /* clean up */
93 if (mailmsg) mailmessage_free(mailmsg); 93 if (mailmsg) mailmessage_free(mailmsg);
94 if (message) free(message); 94 if (message) free(message);
95 95
96 return body; 96 return body;
97} 97}
98 98
99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 99void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
100{ 100{
101 login(); 101 login();
102 if (!m_pop3) return; 102 if (!m_pop3) return;
103 uint32_t res_messages,res_recent,res_unseen; 103 uint32_t res_messages,res_recent,res_unseen;
104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); 104 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
105 parseList(target,m_folder->fld_session,"INBOX"); 105 parseList(target,m_folder->fld_session,"INBOX");
106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 106 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
107} 107}
108 108
109void POP3wrapper::login() 109void POP3wrapper::login()
110{ 110{
111 /* we'll hold the line */ 111 /* we'll hold the line */
112 if ( m_pop3 != NULL ) return; 112 if ( m_pop3 != NULL ) return;
113 113
114 const char *server, *user, *pass; 114 const char *server, *user, *pass;
115 uint16_t port; 115 uint16_t port;
116 int err = MAILPOP3_NO_ERROR; 116 int err = MAILPOP3_NO_ERROR;
117 117
118 server = account->getServer().latin1(); 118 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 119 port = account->getPort().toUInt();
120 120
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show(); 123 login.show();
124 if ( QDialog::Accepted == login.exec() ) { 124 if ( QDialog::Accepted == login.exec() ) {
125 // ok 125 // ok
126 user = login.getUser().latin1(); 126 user = login.getUser().latin1();
127 pass = login.getPassword().latin1(); 127 pass = login.getPassword().latin1();
128 } else { 128 } else {
129 // cancel 129 // cancel
130 qDebug( "POP3: Login canceled" ); 130 qDebug( "POP3: Login canceled" );
131 return; 131 return;
132 } 132 }
133 } else { 133 } else {
134 user = account->getUser().latin1(); 134 user = account->getUser().latin1();
135 pass = account->getPassword().latin1(); 135 pass = account->getPassword().latin1();
136 } 136 }
137 137
138 bool ssl = account->getSSL(); 138 bool ssl = account->getSSL();
139 139
140 m_pop3=mailstorage_new(NULL); 140 m_pop3=mailstorage_new(NULL);
141 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP, 141 int conntype = (ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
142
143 pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,conntype,POP3_AUTH_TYPE_PLAIN,
142 (char*)user,(char*)pass,0,0,0); 144 (char*)user,(char*)pass,0,0,0);
143 145
144 m_folder = mailfolder_new(m_pop3, NULL, NULL); 146 m_folder = mailfolder_new(m_pop3, NULL, NULL);
145 147
146 if (m_folder==0) { 148 if (m_folder==0) {
147 Global::statusMessage(tr("Error initializing folder")); 149 Global::statusMessage(tr("Error initializing folder"));
148 mailstorage_free(m_pop3); 150 mailstorage_free(m_pop3);
149 m_pop3 = NULL; 151 m_pop3 = NULL;
150 return; 152 return;
151 } 153 }
152 err = mailfolder_connect(m_folder); 154 err = mailfolder_connect(m_folder);
153 if (err != MAIL_NO_ERROR) { 155 if (err != MAIL_NO_ERROR) {
154 Global::statusMessage(tr("Error initializing folder")); 156 Global::statusMessage(tr("Error initializing folder"));
155 mailfolder_free(m_folder); 157 mailfolder_free(m_folder);
156 m_folder = 0; 158 m_folder = 0;
157 mailstorage_free(m_pop3); 159 mailstorage_free(m_pop3);
158 m_pop3 = 0; 160 m_pop3 = 0;
159 } 161 }
160 qDebug( "POP3: logged in!" );
161} 162}
162 163
163void POP3wrapper::logout() 164void POP3wrapper::logout()
164{ 165{
165 int err = MAILPOP3_NO_ERROR; 166 int err = MAILPOP3_NO_ERROR;
166 if ( m_pop3 == NULL ) return; 167 if ( m_pop3 == NULL ) return;
167 mailfolder_free(m_folder); 168 mailfolder_free(m_folder);
168 m_folder = 0; 169 m_folder = 0;
169 mailstorage_free(m_pop3); 170 mailstorage_free(m_pop3);
170 m_pop3 = 0; 171 m_pop3 = 0;
171} 172}
172 173
173 174
174QList<Folder>* POP3wrapper::listFolders() 175QList<Folder>* POP3wrapper::listFolders()
175{ 176{
176 QList<Folder> * folders = new QList<Folder>(); 177 QList<Folder> * folders = new QList<Folder>();
177 folders->setAutoDelete( false ); 178 folders->setAutoDelete( false );
178 Folder*inb=new Folder("INBOX","/"); 179 Folder*inb=new Folder("INBOX","/");
179 folders->append(inb); 180 folders->append(inb);
180 return folders; 181 return folders;
181} 182}
182 183
183void POP3wrapper::deleteMail(const RecMail&mail) 184void POP3wrapper::deleteMail(const RecMail&mail)
184{ 185{
185 login(); 186 login();
186 if (!m_pop3) return; 187 if (!m_pop3) return;
187 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); 188 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
188 if (err != MAIL_NO_ERROR) { 189 if (err != MAIL_NO_ERROR) {
189 Global::statusMessage(tr("error deleting mail")); 190 Global::statusMessage(tr("error deleting mail"));
190 } 191 }
191} 192}
192 193
193void POP3wrapper::answeredMail(const RecMail&) 194void POP3wrapper::answeredMail(const RecMail&)
194{ 195{
195} 196}
196 197
197int POP3wrapper::deleteAllMail(const Folder*) 198int POP3wrapper::deleteAllMail(const Folder*)
198{ 199{
199 login(); 200 login();
200 if (!m_pop3) return 0; 201 if (!m_pop3) return 0;
201 int res = 1; 202 int res = 1;
202 203
203 uint32_t result = 0; 204 uint32_t result = 0;
204 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); 205 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
205 if (err != MAIL_NO_ERROR) { 206 if (err != MAIL_NO_ERROR) {
206 Global::statusMessage(tr("Error getting folder info")); 207 Global::statusMessage(tr("Error getting folder info"));
207 return 0; 208 return 0;
208 } 209 }
209 for (unsigned int i = 0; i < result; ++i) { 210 for (unsigned int i = 0; i < result; ++i) {
210 err = mailsession_remove_message(m_folder->fld_session,i+1); 211 err = mailsession_remove_message(m_folder->fld_session,i+1);
211 if (err != MAIL_NO_ERROR) { 212 if (err != MAIL_NO_ERROR) {
212 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 213 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
213 res=0; 214 res=0;
214 } 215 }
215 break; 216 break;
216 } 217 }
217 return res; 218 return res;
218} 219}
219 220
220void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) 221void POP3wrapper::statusFolder(folderStat&target_stat,const QString&)
221{ 222{
222 login(); 223 login();
223 target_stat.message_count = 0; 224 target_stat.message_count = 0;
224 target_stat.message_unseen = 0; 225 target_stat.message_unseen = 0;
225 target_stat.message_recent = 0; 226 target_stat.message_recent = 0;
226 if (!m_pop3) return; 227 if (!m_pop3) return;
227 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, 228 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count,
228 &target_stat.message_recent,&target_stat.message_unseen); 229 &target_stat.message_recent,&target_stat.message_unseen);
229} 230}
230 231
231encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) 232encodedString* POP3wrapper::fetchRawBody(const RecMail&mail)
232{ 233{
233 char*target=0; 234 char*target=0;
234 size_t length=0; 235 size_t length=0;
235 encodedString*res = 0; 236 encodedString*res = 0;
236 mailmessage * mailmsg = 0; 237 mailmessage * mailmsg = 0;
237 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 238 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
238 err = mailmessage_fetch(mailmsg,&target,&length); 239 err = mailmessage_fetch(mailmsg,&target,&length);
239 if (mailmsg) mailmessage_free(mailmsg); 240 if (mailmsg) mailmessage_free(mailmsg);
240 if (target) { 241 if (target) {
241 res = new encodedString(target,length); 242 res = new encodedString(target,length);
242 } 243 }
243 return res; 244 return res;
244} 245}
245 246
246const QString&POP3wrapper::getType()const 247const QString&POP3wrapper::getType()const
247{ 248{
248 return account->getType(); 249 return account->getType();
249} 250}