Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 3aec13d..110583f 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -128,98 +128,99 @@ void IMAPwrapper::login() | |||
128 | uint16_t port; | 128 | uint16_t port; |
129 | int err = MAILIMAP_NO_ERROR; | 129 | int err = MAILIMAP_NO_ERROR; |
130 | 130 | ||
131 | if (account->getOffline()) return; | 131 | if (account->getOffline()) return; |
132 | /* we are connected this moment */ | 132 | /* we are connected this moment */ |
133 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 133 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
134 | if (m_imap) { | 134 | if (m_imap) { |
135 | err = mailimap_noop(m_imap); | 135 | err = mailimap_noop(m_imap); |
136 | if (err!=MAILIMAP_NO_ERROR) { | 136 | if (err!=MAILIMAP_NO_ERROR) { |
137 | logout(); | 137 | logout(); |
138 | } else { | 138 | } else { |
139 | mailstream_flush(m_imap->imap_stream); | 139 | mailstream_flush(m_imap->imap_stream); |
140 | return; | 140 | return; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | server = account->getServer(); | 143 | server = account->getServer(); |
144 | port = account->getPort().toUInt(); | 144 | port = account->getPort().toUInt(); |
145 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 145 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
146 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 146 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
147 | login.show(); | 147 | login.show(); |
148 | if ( QDialog::Accepted == login.exec() ) { | 148 | if ( QDialog::Accepted == login.exec() ) { |
149 | // ok | 149 | // ok |
150 | user = login.getUser(); | 150 | user = login.getUser(); |
151 | pass = login.getPassword(); | 151 | pass = login.getPassword(); |
152 | } else { | 152 | } else { |
153 | // cancel | 153 | // cancel |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | } else { | 156 | } else { |
157 | user = account->getUser(); | 157 | user = account->getUser(); |
158 | pass = account->getPassword(); | 158 | pass = account->getPassword(); |
159 | } | 159 | } |
160 | 160 | ||
161 | m_imap = mailimap_new( 20, &imap_progress ); | 161 | m_imap = mailimap_new( 20, &imap_progress ); |
162 | 162 | ||
163 | /* connect */ | 163 | /* connect */ |
164 | bool ssl = false; | 164 | bool ssl = false; |
165 | bool try_tls = false; | 165 | bool try_tls = false; |
166 | bool force_tls = false; | 166 | bool force_tls = false; |
167 | 167 | ||
168 | if ( account->ConnectionType() == 2 ) { | 168 | if ( account->ConnectionType() == 2 ) { |
169 | ssl = true; | 169 | ssl = true; |
170 | } | 170 | } |
171 | if (account->ConnectionType()==1) { | 171 | if (account->ConnectionType()==1) { |
172 | force_tls = true; | 172 | force_tls = true; |
173 | } | 173 | } |
174 | 174 | ||
175 | if ( ssl ) { | 175 | if ( ssl ) { |
176 | //qDebug("using ssl "); | 176 | qDebug("using ssl "); |
177 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); | 177 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
178 | qDebug("back "); | ||
178 | } else { | 179 | } else { |
179 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); | 180 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
180 | } | 181 | } |
181 | 182 | ||
182 | if ( err != MAILIMAP_NO_ERROR && | 183 | if ( err != MAILIMAP_NO_ERROR && |
183 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 184 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
184 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 185 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
185 | QString failure = ""; | 186 | QString failure = ""; |
186 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 187 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
187 | failure="Connection refused"; | 188 | failure="Connection refused"; |
188 | } else { | 189 | } else { |
189 | failure="Unknown failure"; | 190 | failure="Unknown failure"; |
190 | } | 191 | } |
191 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); | 192 | Global::statusMessage(i18n("error connecting imap server: %1").arg(failure)); |
192 | mailimap_free( m_imap ); | 193 | mailimap_free( m_imap ); |
193 | m_imap = 0; | 194 | m_imap = 0; |
194 | return; | 195 | return; |
195 | } | 196 | } |
196 | 197 | ||
197 | if (!ssl) { | 198 | if (!ssl) { |
198 | try_tls = start_tls(force_tls); | 199 | try_tls = start_tls(force_tls); |
199 | } | 200 | } |
200 | 201 | ||
201 | bool ok = true; | 202 | bool ok = true; |
202 | if (force_tls && !try_tls) { | 203 | if (force_tls && !try_tls) { |
203 | Global::statusMessage(i18n("Server has no TLS support!")); | 204 | Global::statusMessage(i18n("Server has no TLS support!")); |
204 | ok = false; | 205 | ok = false; |
205 | } | 206 | } |
206 | 207 | ||
207 | 208 | ||
208 | /* login */ | 209 | /* login */ |
209 | 210 | ||
210 | if (ok) { | 211 | if (ok) { |
211 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); | 212 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
212 | if ( err != MAILIMAP_NO_ERROR ) { | 213 | if ( err != MAILIMAP_NO_ERROR ) { |
213 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); | 214 | Global::statusMessage(i18n("error logging in imap server: %1").arg(m_imap->imap_response)); |
214 | ok = false; | 215 | ok = false; |
215 | } | 216 | } |
216 | } | 217 | } |
217 | if (!ok) { | 218 | if (!ok) { |
218 | err = mailimap_close( m_imap ); | 219 | err = mailimap_close( m_imap ); |
219 | mailimap_free( m_imap ); | 220 | mailimap_free( m_imap ); |
220 | m_imap = 0; | 221 | m_imap = 0; |
221 | } | 222 | } |
222 | } | 223 | } |
223 | 224 | ||
224 | void IMAPwrapper::logout() | 225 | void IMAPwrapper::logout() |
225 | { | 226 | { |