author | harlekin <harlekin> | 2004-01-08 17:42:16 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-01-08 17:42:16 (UTC) |
commit | eeb69efb4e0639429e5f6fd15e65b1b6fbaa5c35 (patch) (unidiff) | |
tree | d14fa40cddeceb1b04dafa209841727811c6e71c /noncore/net/mail/libmailwrapper | |
parent | c0a0d53fb92f8a1723c57580a5fd0ade66574ec4 (diff) | |
download | opie-eeb69efb4e0639429e5f6fd15e65b1b6fbaa5c35.zip opie-eeb69efb4e0639429e5f6fd15e65b1b6fbaa5c35.tar.gz opie-eeb69efb4e0639429e5f6fd15e65b1b6fbaa5c35.tar.bz2 |
added support for pop3 tls
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 95 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/settings.cpp | 7 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/settings.h | 5 |
3 files changed, 64 insertions, 43 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index 67bde38..f5eca4a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -8,37 +8,33 @@ | |||
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 | ||
13 | POP3wrapper::POP3wrapper( POP3account *a ) | 13 | POP3wrapper::POP3wrapper( POP3account *a ) |
14 | : Genericwrapper() | 14 | : Genericwrapper() { |
15 | { | ||
16 | account = a; | 15 | account = a; |
17 | m_pop3 = NULL; | 16 | m_pop3 = NULL; |
18 | m_folder = NULL; | 17 | m_folder = NULL; |
19 | msgTempName = a->getFileName()+"_msg_cache"; | 18 | msgTempName = a->getFileName()+"_msg_cache"; |
20 | last_msg_id = 0; | 19 | last_msg_id = 0; |
21 | } | 20 | } |
22 | 21 | ||
23 | POP3wrapper::~POP3wrapper() | 22 | POP3wrapper::~POP3wrapper() { |
24 | { | ||
25 | logout(); | 23 | logout(); |
26 | QFile msg_cache(msgTempName); | 24 | QFile msg_cache(msgTempName); |
27 | if (msg_cache.exists()) { | 25 | if (msg_cache.exists()) { |
28 | msg_cache.remove(); | 26 | msg_cache.remove(); |
29 | } | 27 | } |
30 | } | 28 | } |
31 | 29 | ||
32 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) | 30 | void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { |
33 | { | ||
34 | qDebug( "POP3: %i of %i", current, maximum ); | 31 | qDebug( "POP3: %i of %i", current, maximum ); |
35 | } | 32 | } |
36 | 33 | ||
37 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) | 34 | RecBody POP3wrapper::fetchBody( const RecMail &mail ) { |
38 | { | ||
39 | int err = MAILPOP3_NO_ERROR; | 35 | int err = MAILPOP3_NO_ERROR; |
40 | char *message = 0; | 36 | char *message = 0; |
41 | size_t length = 0; | 37 | size_t length = 0; |
42 | 38 | ||
43 | login(); | 39 | login(); |
44 | if ( !m_pop3 ) { | 40 | if ( !m_pop3 ) { |
@@ -87,33 +83,36 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) | |||
87 | msg_data->msg_message = message; | 83 | msg_data->msg_message = message; |
88 | msg_data->msg_length = strlen(message); | 84 | msg_data->msg_length = strlen(message); |
89 | } | 85 | } |
90 | body = parseMail(mailmsg); | 86 | body = parseMail(mailmsg); |
91 | 87 | ||
92 | /* clean up */ | 88 | /* clean up */ |
93 | if (mailmsg) mailmessage_free(mailmsg); | 89 | if (mailmsg) |
94 | if (message) free(message); | 90 | mailmessage_free(mailmsg); |
91 | if (message) | ||
92 | free(message); | ||
95 | 93 | ||
96 | return body; | 94 | return body; |
97 | } | 95 | } |
98 | 96 | ||
99 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) | 97 | void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { |
100 | { | ||
101 | login(); | 98 | login(); |
102 | if (!m_pop3) return; | 99 | if (!m_pop3) |
100 | return; | ||
103 | uint32_t res_messages,res_recent,res_unseen; | 101 | uint32_t res_messages,res_recent,res_unseen; |
104 | mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); | 102 | mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); |
105 | parseList(target,m_folder->fld_session,"INBOX"); | 103 | parseList(target,m_folder->fld_session,"INBOX"); |
106 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); | 104 | Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); |
107 | } | 105 | } |
108 | 106 | ||
109 | void POP3wrapper::login() | 107 | void POP3wrapper::login() { |
110 | { | 108 | if (account->getOffline()) |
111 | if (account->getOffline()) return; | 109 | return; |
112 | /* we'll hold the line */ | 110 | /* we'll hold the line */ |
113 | if ( m_pop3 != NULL ) return; | 111 | if ( m_pop3 != NULL ) |
112 | return; | ||
114 | 113 | ||
115 | const char *server, *user, *pass; | 114 | const char *server, *user, *pass; |
116 | uint16_t port; | 115 | uint16_t port; |
117 | int err = MAILPOP3_NO_ERROR; | 116 | int err = MAILPOP3_NO_ERROR; |
118 | 117 | ||
119 | server = account->getServer().latin1(); | 118 | server = account->getServer().latin1(); |
@@ -133,20 +132,35 @@ void POP3wrapper::login() | |||
133 | } | 132 | } |
134 | } else { | 133 | } else { |
135 | user = account->getUser().latin1(); | 134 | user = account->getUser().latin1(); |
136 | pass = account->getPassword().latin1(); | 135 | pass = account->getPassword().latin1(); |
137 | } | 136 | } |
138 | 137 | ||
139 | bool ssl = account->getSSL(); | 138 | // bool ssl = account->getSSL(); |
140 | 139 | ||
141 | m_pop3=mailstorage_new(NULL); | 140 | m_pop3=mailstorage_new(NULL); |
142 | int conntype = (ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | 141 | |
142 | int conntypeset = account->ConnectionType(); | ||
143 | int conntype = 0; | ||
144 | if ( conntypeset == 3 ) { | ||
145 | conntype = CONNECTION_TYPE_COMMAND; | ||
146 | } else if ( conntypeset == 2 ) { | ||
147 | conntype = CONNECTION_TYPE_TLS; | ||
148 | } else if ( conntypeset == 1 ) { | ||
149 | conntype = CONNECTION_TYPE_STARTTLS; | ||
150 | } else if ( conntypeset == 0 ) { | ||
151 | conntype = CONNECTION_TYPE_TRY_STARTTLS; | ||
152 | } | ||
153 | |||
154 | //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); | ||
143 | 155 | ||
144 | pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,conntype,POP3_AUTH_TYPE_PLAIN, | 156 | pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,conntype,POP3_AUTH_TYPE_PLAIN, |
145 | (char*)user,(char*)pass,0,0,0); | 157 | (char*)user,(char*)pass,0,0,0); |
146 | 158 | ||
159 | |||
160 | |||
147 | m_folder = mailfolder_new(m_pop3, NULL, NULL); | 161 | m_folder = mailfolder_new(m_pop3, NULL, NULL); |
148 | 162 | ||
149 | if (m_folder==0) { | 163 | if (m_folder==0) { |
150 | Global::statusMessage(tr("Error initializing folder")); | 164 | Global::statusMessage(tr("Error initializing folder")); |
151 | mailstorage_free(m_pop3); | 165 | mailstorage_free(m_pop3); |
152 | m_pop3 = NULL; | 166 | m_pop3 = NULL; |
@@ -160,50 +174,47 @@ void POP3wrapper::login() | |||
160 | m_folder = 0; | 174 | m_folder = 0; |
161 | mailstorage_free(m_pop3); | 175 | mailstorage_free(m_pop3); |
162 | m_pop3 = 0; | 176 | m_pop3 = 0; |
163 | } | 177 | } |
164 | } | 178 | } |
165 | 179 | ||
166 | void POP3wrapper::logout() | 180 | void POP3wrapper::logout() { |
167 | { | ||
168 | int err = MAILPOP3_NO_ERROR; | 181 | int err = MAILPOP3_NO_ERROR; |
169 | if ( m_pop3 == NULL ) return; | 182 | if ( m_pop3 == NULL ) |
183 | return; | ||
170 | mailfolder_free(m_folder); | 184 | mailfolder_free(m_folder); |
171 | m_folder = 0; | 185 | m_folder = 0; |
172 | mailstorage_free(m_pop3); | 186 | mailstorage_free(m_pop3); |
173 | m_pop3 = 0; | 187 | m_pop3 = 0; |
174 | } | 188 | } |
175 | 189 | ||
176 | 190 | ||
177 | QList<Folder>* POP3wrapper::listFolders() | 191 | QList<Folder>* POP3wrapper::listFolders() { |
178 | { | ||
179 | QList<Folder> * folders = new QList<Folder>(); | 192 | QList<Folder> * folders = new QList<Folder>(); |
180 | folders->setAutoDelete( false ); | 193 | folders->setAutoDelete( false ); |
181 | Folder*inb=new Folder("INBOX","/"); | 194 | Folder*inb=new Folder("INBOX","/"); |
182 | folders->append(inb); | 195 | folders->append(inb); |
183 | return folders; | 196 | return folders; |
184 | } | 197 | } |
185 | 198 | ||
186 | void POP3wrapper::deleteMail(const RecMail&mail) | 199 | void POP3wrapper::deleteMail(const RecMail&mail) { |
187 | { | ||
188 | login(); | 200 | login(); |
189 | if (!m_pop3) return; | 201 | if (!m_pop3) |
202 | return; | ||
190 | int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); | 203 | int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); |
191 | if (err != MAIL_NO_ERROR) { | 204 | if (err != MAIL_NO_ERROR) { |
192 | Global::statusMessage(tr("error deleting mail")); | 205 | Global::statusMessage(tr("error deleting mail")); |
193 | } | 206 | } |
194 | } | 207 | } |
195 | 208 | ||
196 | void POP3wrapper::answeredMail(const RecMail&) | 209 | void POP3wrapper::answeredMail(const RecMail&) {} |
197 | { | ||
198 | } | ||
199 | 210 | ||
200 | int POP3wrapper::deleteAllMail(const Folder*) | 211 | int POP3wrapper::deleteAllMail(const Folder*) { |
201 | { | ||
202 | login(); | 212 | login(); |
203 | if (!m_pop3) return 0; | 213 | if (!m_pop3) |
214 | return 0; | ||
204 | int res = 1; | 215 | int res = 1; |
205 | 216 | ||
206 | uint32_t result = 0; | 217 | uint32_t result = 0; |
207 | int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); | 218 | int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); |
208 | if (err != MAIL_NO_ERROR) { | 219 | if (err != MAIL_NO_ERROR) { |
209 | Global::statusMessage(tr("Error getting folder info")); | 220 | Global::statusMessage(tr("Error getting folder info")); |
@@ -217,41 +228,39 @@ int POP3wrapper::deleteAllMail(const Folder*) | |||
217 | } | 228 | } |
218 | break; | 229 | break; |
219 | } | 230 | } |
220 | return res; | 231 | return res; |
221 | } | 232 | } |
222 | 233 | ||
223 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) | 234 | void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { |
224 | { | ||
225 | login(); | 235 | login(); |
226 | target_stat.message_count = 0; | 236 | target_stat.message_count = 0; |
227 | target_stat.message_unseen = 0; | 237 | target_stat.message_unseen = 0; |
228 | target_stat.message_recent = 0; | 238 | target_stat.message_recent = 0; |
229 | if (!m_pop3) return; | 239 | if (!m_pop3) |
240 | return; | ||
230 | int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, | 241 | int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, |
231 | &target_stat.message_recent,&target_stat.message_unseen); | 242 | &target_stat.message_recent,&target_stat.message_unseen); |
232 | } | 243 | } |
233 | 244 | ||
234 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) | 245 | encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { |
235 | { | ||
236 | char*target=0; | 246 | char*target=0; |
237 | size_t length=0; | 247 | size_t length=0; |
238 | encodedString*res = 0; | 248 | encodedString*res = 0; |
239 | mailmessage * mailmsg = 0; | 249 | mailmessage * mailmsg = 0; |
240 | int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); | 250 | int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); |
241 | err = mailmessage_fetch(mailmsg,&target,&length); | 251 | err = mailmessage_fetch(mailmsg,&target,&length); |
242 | if (mailmsg) mailmessage_free(mailmsg); | 252 | if (mailmsg) |
253 | mailmessage_free(mailmsg); | ||
243 | if (target) { | 254 | if (target) { |
244 | res = new encodedString(target,length); | 255 | res = new encodedString(target,length); |
245 | } | 256 | } |
246 | return res; | 257 | return res; |
247 | } | 258 | } |
248 | 259 | ||
249 | const QString&POP3wrapper::getType()const | 260 | const QString&POP3wrapper::getType()const { |
250 | { | ||
251 | return account->getType(); | 261 | return account->getType(); |
252 | } | 262 | } |
253 | 263 | ||
254 | const QString&POP3wrapper::getName()const | 264 | const QString&POP3wrapper::getName()const { |
255 | { | ||
256 | return account->getAccountName(); | 265 | return account->getAccountName(); |
257 | } | 266 | } |
diff --git a/noncore/net/mail/libmailwrapper/settings.cpp b/noncore/net/mail/libmailwrapper/settings.cpp index 02a80a3..83e51e3 100644 --- a/noncore/net/mail/libmailwrapper/settings.cpp +++ b/noncore/net/mail/libmailwrapper/settings.cpp | |||
@@ -105,12 +105,13 @@ void Settings::readAccounts() | |||
105 | 105 | ||
106 | Account::Account() | 106 | Account::Account() |
107 | { | 107 | { |
108 | accountName = "changeMe"; | 108 | accountName = "changeMe"; |
109 | type = "changeMe"; | 109 | type = "changeMe"; |
110 | ssl = false; | 110 | ssl = false; |
111 | connectionType = 1; | ||
111 | } | 112 | } |
112 | 113 | ||
113 | void Account::remove() | 114 | void Account::remove() |
114 | { | 115 | { |
115 | QFile file( getFileName() ); | 116 | QFile file( getFileName() ); |
116 | file.remove(); | 117 | file.remove(); |
@@ -119,22 +120,24 @@ void Account::remove() | |||
119 | IMAPaccount::IMAPaccount() | 120 | IMAPaccount::IMAPaccount() |
120 | : Account() | 121 | : Account() |
121 | { | 122 | { |
122 | file = IMAPaccount::getUniqueFileName(); | 123 | file = IMAPaccount::getUniqueFileName(); |
123 | accountName = "New IMAP Account"; | 124 | accountName = "New IMAP Account"; |
124 | ssl = false; | 125 | ssl = false; |
126 | connectionType = 1; | ||
125 | type = "IMAP"; | 127 | type = "IMAP"; |
126 | port = IMAP_PORT; | 128 | port = IMAP_PORT; |
127 | } | 129 | } |
128 | 130 | ||
129 | IMAPaccount::IMAPaccount( QString filename ) | 131 | IMAPaccount::IMAPaccount( QString filename ) |
130 | : Account() | 132 | : Account() |
131 | { | 133 | { |
132 | file = filename; | 134 | file = filename; |
133 | accountName = "New IMAP Account"; | 135 | accountName = "New IMAP Account"; |
134 | ssl = false; | 136 | ssl = false; |
137 | connectionType = 1; | ||
135 | type = "IMAP"; | 138 | type = "IMAP"; |
136 | port = IMAP_PORT; | 139 | port = IMAP_PORT; |
137 | } | 140 | } |
138 | 141 | ||
139 | QString IMAPaccount::getUniqueFileName() | 142 | QString IMAPaccount::getUniqueFileName() |
140 | { | 143 | { |
@@ -200,22 +203,24 @@ QString IMAPaccount::getFileName() | |||
200 | POP3account::POP3account() | 203 | POP3account::POP3account() |
201 | : Account() | 204 | : Account() |
202 | { | 205 | { |
203 | file = POP3account::getUniqueFileName(); | 206 | file = POP3account::getUniqueFileName(); |
204 | accountName = "New POP3 Account"; | 207 | accountName = "New POP3 Account"; |
205 | ssl = false; | 208 | ssl = false; |
209 | connectionType = 1; | ||
206 | type = "POP3"; | 210 | type = "POP3"; |
207 | port = POP3_PORT; | 211 | port = POP3_PORT; |
208 | } | 212 | } |
209 | 213 | ||
210 | POP3account::POP3account( QString filename ) | 214 | POP3account::POP3account( QString filename ) |
211 | : Account() | 215 | : Account() |
212 | { | 216 | { |
213 | file = filename; | 217 | file = filename; |
214 | accountName = "New POP3 Account"; | 218 | accountName = "New POP3 Account"; |
215 | ssl = false; | 219 | ssl = false; |
220 | connectionType = 1; | ||
216 | type = "POP3"; | 221 | type = "POP3"; |
217 | port = POP3_PORT; | 222 | port = POP3_PORT; |
218 | } | 223 | } |
219 | 224 | ||
220 | QString POP3account::getUniqueFileName() | 225 | QString POP3account::getUniqueFileName() |
221 | { | 226 | { |
@@ -237,12 +242,13 @@ void POP3account::read() | |||
237 | Config *conf = new Config( getFileName(), Config::File ); | 242 | Config *conf = new Config( getFileName(), Config::File ); |
238 | conf->setGroup( "POP3 Account" ); | 243 | conf->setGroup( "POP3 Account" ); |
239 | accountName = conf->readEntry( "Account" ); | 244 | accountName = conf->readEntry( "Account" ); |
240 | server = conf->readEntry( "Server" ); | 245 | server = conf->readEntry( "Server" ); |
241 | port = conf->readEntry( "Port" ); | 246 | port = conf->readEntry( "Port" ); |
242 | ssl = conf->readBoolEntry( "SSL" ); | 247 | ssl = conf->readBoolEntry( "SSL" ); |
248 | connectionType = conf->readNumEntry( "ConnectionType" ); | ||
243 | user = conf->readEntry( "User" ); | 249 | user = conf->readEntry( "User" ); |
244 | password = conf->readEntryCrypt( "Password" ); | 250 | password = conf->readEntryCrypt( "Password" ); |
245 | offline = conf->readBoolEntry("Offline",false); | 251 | offline = conf->readBoolEntry("Offline",false); |
246 | delete conf; | 252 | delete conf; |
247 | } | 253 | } |
248 | 254 | ||
@@ -254,12 +260,13 @@ void POP3account::save() | |||
254 | Config *conf = new Config( getFileName(), Config::File ); | 260 | Config *conf = new Config( getFileName(), Config::File ); |
255 | conf->setGroup( "POP3 Account" ); | 261 | conf->setGroup( "POP3 Account" ); |
256 | conf->writeEntry( "Account", accountName ); | 262 | conf->writeEntry( "Account", accountName ); |
257 | conf->writeEntry( "Server", server ); | 263 | conf->writeEntry( "Server", server ); |
258 | conf->writeEntry( "Port", port ); | 264 | conf->writeEntry( "Port", port ); |
259 | conf->writeEntry( "SSL", ssl ); | 265 | conf->writeEntry( "SSL", ssl ); |
266 | conf->writeEntry( "ConnectionType", connectionType ); | ||
260 | conf->writeEntry( "User", user ); | 267 | conf->writeEntry( "User", user ); |
261 | conf->writeEntryCrypt( "Password", password ); | 268 | conf->writeEntryCrypt( "Password", password ); |
262 | conf->writeEntry( "Offline",offline); | 269 | conf->writeEntry( "Offline",offline); |
263 | conf->write(); | 270 | conf->write(); |
264 | delete conf; | 271 | delete conf; |
265 | } | 272 | } |
diff --git a/noncore/net/mail/libmailwrapper/settings.h b/noncore/net/mail/libmailwrapper/settings.h index 2104997..8d7df92 100644 --- a/noncore/net/mail/libmailwrapper/settings.h +++ b/noncore/net/mail/libmailwrapper/settings.h | |||
@@ -28,22 +28,27 @@ public: | |||
28 | void setPassword(const QString&str) { password = str; } | 28 | void setPassword(const QString&str) { password = str; } |
29 | const QString&getPassword()const { return password; } | 29 | const QString&getPassword()const { return password; } |
30 | 30 | ||
31 | void setSSL( bool b ) { ssl = b; } | 31 | void setSSL( bool b ) { ssl = b; } |
32 | bool getSSL() { return ssl; } | 32 | bool getSSL() { return ssl; } |
33 | 33 | ||
34 | void setConnectionType( int x ) { connectionType = x; } | ||
35 | int ConnectionType() { return connectionType; } | ||
36 | |||
37 | |||
34 | void setOffline(bool b) {offline = b;} | 38 | void setOffline(bool b) {offline = b;} |
35 | bool getOffline()const{return offline;} | 39 | bool getOffline()const{return offline;} |
36 | 40 | ||
37 | virtual QString getFileName() { return accountName; } | 41 | virtual QString getFileName() { return accountName; } |
38 | virtual void read() { qDebug( "base reading..." ); } | 42 | virtual void read() { qDebug( "base reading..." ); } |
39 | virtual void save() { qDebug( "base saving..." ); } | 43 | virtual void save() { qDebug( "base saving..." ); } |
40 | 44 | ||
41 | protected: | 45 | protected: |
42 | QString accountName, type, server, port, user, password; | 46 | QString accountName, type, server, port, user, password; |
43 | bool ssl; | 47 | bool ssl; |
48 | int connectionType; | ||
44 | bool offline; | 49 | bool offline; |
45 | }; | 50 | }; |
46 | 51 | ||
47 | class IMAPaccount : public Account | 52 | class IMAPaccount : public Account |
48 | { | 53 | { |
49 | 54 | ||