summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-29 15:06:30 (UTC)
committer alwin <alwin>2004-01-29 15:06:30 (UTC)
commit9ccf499bd8d213ec9a5e8aede7c55a4b4e77ae0d (patch) (side-by-side diff)
tree9d5844721558146c84dc3e5efb19424be78b4fec
parent6e34e6e90f3ea6a18101395afc7cf5fe86c427e8 (diff)
downloadopie-9ccf499bd8d213ec9a5e8aede7c55a4b4e77ae0d.zip
opie-9ccf499bd8d213ec9a5e8aede7c55a4b4e77ae0d.tar.gz
opie-9ccf499bd8d213ec9a5e8aede7c55a4b4e77ae0d.tar.bz2
tls support for IMAP implemented
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp84
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
2 files changed, 79 insertions, 6 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 098dbdc..1dfcc4c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -43,2 +43,54 @@ void IMAPwrapper::imap_progress( size_t current, size_t maximum )
+bool IMAPwrapper::start_tls(bool force_tls)
+{
+ int err;
+ bool try_tls;
+ mailimap_capability_data * cap_data = 0;
+
+ err = mailimap_capability(m_imap,&cap_data);
+ if (err != MAILIMAP_NO_ERROR) {
+ Global::statusMessage("error getting capabilities!");
+ qDebug("error getting capabilities!");
+ return false;
+ }
+ clistiter * cur;
+ for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
+ struct mailimap_capability * cap;
+ cap = (struct mailimap_capability *)clist_content(cur);
+ if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
+ if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
+ try_tls = true;
+ break;
+ }
+ }
+ }
+ if (cap_data) {
+ mailimap_capability_data_free(cap_data);
+ }
+ if (try_tls) {
+ err = mailimap_starttls(m_imap);
+ if (err != MAILIMAP_NO_ERROR && force_tls) {
+ Global::statusMessage(tr("Server has no TLS support!"));
+ qDebug("Server has no TLS support!");
+ try_tls = false;
+ } else {
+ mailstream_low * low;
+ mailstream_low * new_low;
+ low = mailstream_get_low(m_imap->imap_stream);
+ if (!low) {
+ try_tls = false;
+ } else {
+ int fd = mailstream_low_get_fd(low);
+ if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
+ mailstream_low_free(low);
+ mailstream_set_low(m_imap->imap_stream, new_low);
+ } else {
+ try_tls = false;
+ }
+ }
+ }
+ }
+ return try_tls;
+}
+
void IMAPwrapper::login()
@@ -82,7 +134,6 @@ void IMAPwrapper::login()
-
-
/* connect */
-
bool ssl = false;
+ bool try_tls = false;
+ bool force_tls = false;
@@ -91,2 +142,5 @@ void IMAPwrapper::login()
}
+ if (account->ConnectionType()==1) {
+ force_tls = true;
+ }
@@ -114,6 +168,24 @@ void IMAPwrapper::login()
+ if (!ssl) {
+ try_tls = start_tls(force_tls);
+ }
+
+ bool ok = true;
+ if (force_tls && !try_tls) {
+ Global::statusMessage(tr("Server has no TLS support!"));
+ qDebug("Server has no TLS support!");
+ ok = false;
+ }
+
+
/* login */
- err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
- if ( err != MAILIMAP_NO_ERROR ) {
- Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
+
+ if (ok) {
+ err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
+ if ( err != MAILIMAP_NO_ERROR ) {
+ Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
+ ok = false;
+ }
+ }
+ if (!ok) {
err = mailimap_close( m_imap );
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index c10f86a..0a1fe2c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -54,2 +54,3 @@ protected:
void login();
+ bool start_tls(bool force=true);