summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp78
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
2 files changed, 76 insertions, 3 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
@@ -41,6 +41,58 @@ void IMAPwrapper::imap_progress( size_t current, size_t maximum )
41 qDebug( "IMAP: %i of %i", current, maximum ); 41 qDebug( "IMAP: %i of %i", current, maximum );
42} 42}
43 43
44bool IMAPwrapper::start_tls(bool force_tls)
45{
46 int err;
47 bool try_tls;
48 mailimap_capability_data * cap_data = 0;
49
50 err = mailimap_capability(m_imap,&cap_data);
51 if (err != MAILIMAP_NO_ERROR) {
52 Global::statusMessage("error getting capabilities!");
53 qDebug("error getting capabilities!");
54 return false;
55 }
56 clistiter * cur;
57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
58 struct mailimap_capability * cap;
59 cap = (struct mailimap_capability *)clist_content(cur);
60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
62 try_tls = true;
63 break;
64 }
65 }
66 }
67 if (cap_data) {
68 mailimap_capability_data_free(cap_data);
69 }
70 if (try_tls) {
71 err = mailimap_starttls(m_imap);
72 if (err != MAILIMAP_NO_ERROR && force_tls) {
73 Global::statusMessage(tr("Server has no TLS support!"));
74 qDebug("Server has no TLS support!");
75 try_tls = false;
76 } else {
77 mailstream_low * low;
78 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) {
81 try_tls = false;
82 } else {
83 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else {
88 try_tls = false;
89 }
90 }
91 }
92 }
93 return try_tls;
94}
95
44void IMAPwrapper::login() 96void IMAPwrapper::login()
45{ 97{
46 const char *server, *user, *pass; 98 const char *server, *user, *pass;
@@ -80,15 +132,17 @@ void IMAPwrapper::login()
80 132
81 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
82 134
83
84
85 /* connect */ 135 /* connect */
86
87 bool ssl = false; 136 bool ssl = false;
137 bool try_tls = false;
138 bool force_tls = false;
88 139
89 if ( account->ConnectionType() == 2 ) { 140 if ( account->ConnectionType() == 2 ) {
90 ssl = true; 141 ssl = true;
91 } 142 }
143 if (account->ConnectionType()==1) {
144 force_tls = true;
145 }
92 146
93 if ( ssl ) { 147 if ( ssl ) {
94 qDebug( "using ssl" ); 148 qDebug( "using ssl" );
@@ -112,10 +166,28 @@ void IMAPwrapper::login()
112 return; 166 return;
113 } 167 }
114 168
169 if (!ssl) {
170 try_tls = start_tls(force_tls);
171 }
172
173 bool ok = true;
174 if (force_tls && !try_tls) {
175 Global::statusMessage(tr("Server has no TLS support!"));
176 qDebug("Server has no TLS support!");
177 ok = false;
178 }
179
180
115 /* login */ 181 /* login */
182
183 if (ok) {
116 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
117 if ( err != MAILIMAP_NO_ERROR ) { 185 if ( err != MAILIMAP_NO_ERROR ) {
118 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
187 ok = false;
188 }
189 }
190 if (!ok) {
119 err = mailimap_close( m_imap ); 191 err = mailimap_close( m_imap );
120 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
121 m_imap = 0; 193 m_imap = 0;
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
@@ -52,6 +52,7 @@ public:
52protected: 52protected:
53 RecMail*parse_list_result(mailimap_msg_att*); 53 RecMail*parse_list_result(mailimap_msg_att*);
54 void login(); 54 void login();
55 bool start_tls(bool force=true);
55 56
56 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 57 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
57 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 58 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);