summaryrefslogtreecommitdiff
Unidiff
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
@@ -38,12 +38,64 @@ int IMAPwrapper::selectMbox(const QString&mbox)
38 38
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void IMAPwrapper::imap_progress( size_t current, size_t maximum )
40{ 40{
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;
47 uint16_t port; 99 uint16_t port;
48 int err = MAILIMAP_NO_ERROR; 100 int err = MAILIMAP_NO_ERROR;
49 101
@@ -77,21 +129,23 @@ void IMAPwrapper::login()
77 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
78 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
79 } 131 }
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" );
95 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 149 err = mailimap_ssl_connect( m_imap, (char*)server, port );
96 } else { 150 } else {
97 err = mailimap_socket_connect( m_imap, (char*)server, port ); 151 err = mailimap_socket_connect( m_imap, (char*)server, port );
@@ -109,16 +163,34 @@ void IMAPwrapper::login()
109 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
110 mailimap_free( m_imap ); 164 mailimap_free( m_imap );
111 m_imap = 0; 165 m_imap = 0;
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 */
116 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 182
117 if ( err != MAILIMAP_NO_ERROR ) { 183 if (ok) {
118 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
185 if ( err != MAILIMAP_NO_ERROR ) {
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;
122 } 194 }
123} 195}
124 196
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
@@ -49,12 +49,13 @@ public:
49 virtual const QString&getType()const; 49 virtual const QString&getType()const;
50 virtual const QString&getName()const; 50 virtual const QString&getName()const;
51 51
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);
58 int selectMbox(const QString&mbox); 59 int selectMbox(const QString&mbox);
59 60
60 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 61 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);