author | alwin <alwin> | 2004-10-27 00:20:35 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-10-27 00:20:35 (UTC) |
commit | e44d35ca3fd26ef7a3184b07516f6535d8844a83 (patch) (unidiff) | |
tree | 4c4ac98450106bb9b05ca76bf5f29e2b6d4fc58b | |
parent | ae5855babec6e46802be89ee408d26a2cbbb1981 (diff) | |
download | opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.zip opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.tar.gz opie-e44d35ca3fd26ef7a3184b07516f6535d8844a83.tar.bz2 |
fixed a bug within tls support
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 8e5212b..576804d 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -44,67 +44,69 @@ void IMAPwrapper::imap_progress( size_t current, size_t maximum ) | |||
44 | qApp->processEvents(); | 44 | qApp->processEvents(); |
45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; | 45 | odebug << "IMAP: " << current << " of " << maximum << "" << oendl; |
46 | } | 46 | } |
47 | 47 | ||
48 | bool IMAPwrapper::start_tls(bool force_tls) | 48 | bool IMAPwrapper::start_tls(bool force_tls) |
49 | { | 49 | { |
50 | int err; | 50 | int err; |
51 | bool try_tls; | 51 | bool try_tls; |
52 | mailimap_capability_data * cap_data = 0; | 52 | mailimap_capability_data * cap_data = 0; |
53 | 53 | ||
54 | err = mailimap_capability(m_imap,&cap_data); | 54 | err = mailimap_capability(m_imap,&cap_data); |
55 | if (err != MAILIMAP_NO_ERROR) { | 55 | if (err != MAILIMAP_NO_ERROR) { |
56 | Global::statusMessage("error getting capabilities!"); | 56 | Global::statusMessage("error getting capabilities!"); |
57 | odebug << "error getting capabilities!" << oendl; | 57 | odebug << "error getting capabilities!" << oendl; |
58 | return false; | 58 | return false; |
59 | } | 59 | } |
60 | clistiter * cur; | 60 | clistiter * cur; |
61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { | 61 | for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) { |
62 | struct mailimap_capability * cap; | 62 | struct mailimap_capability * cap; |
63 | cap = (struct mailimap_capability *)clist_content(cur); | 63 | cap = (struct mailimap_capability *)clist_content(cur); |
64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { | 64 | if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) { |
65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { | 65 | if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) { |
66 | try_tls = true; | 66 | try_tls = true; |
67 | break; | 67 | break; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | } | 70 | } |
71 | if (cap_data) { | 71 | if (cap_data) { |
72 | mailimap_capability_data_free(cap_data); | 72 | mailimap_capability_data_free(cap_data); |
73 | } | 73 | } |
74 | if (try_tls) { | 74 | if (try_tls) { |
75 | err = mailimap_starttls(m_imap); | 75 | err = mailimap_starttls(m_imap); |
76 | if (err != MAILIMAP_NO_ERROR && force_tls) { | 76 | if (err != MAILIMAP_NO_ERROR) { |
77 | Global::statusMessage(tr("Server has no TLS support!")); | 77 | if (force_tls) { |
78 | odebug << "Server has no TLS support!" << oendl; | 78 | Global::statusMessage(tr("Server has no TLS support!")); |
79 | odebug << "Server has no TLS support!" << oendl; | ||
80 | } | ||
79 | try_tls = false; | 81 | try_tls = false; |
80 | } else { | 82 | } else { |
81 | mailstream_low * low; | 83 | mailstream_low * low; |
82 | mailstream_low * new_low; | 84 | mailstream_low * new_low; |
83 | low = mailstream_get_low(m_imap->imap_stream); | 85 | low = mailstream_get_low(m_imap->imap_stream); |
84 | if (!low) { | 86 | if (!low) { |
85 | try_tls = false; | 87 | try_tls = false; |
86 | } else { | 88 | } else { |
87 | int fd = mailstream_low_get_fd(low); | 89 | int fd = mailstream_low_get_fd(low); |
88 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 90 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
89 | mailstream_low_free(low); | 91 | mailstream_low_free(low); |
90 | mailstream_set_low(m_imap->imap_stream, new_low); | 92 | mailstream_set_low(m_imap->imap_stream, new_low); |
91 | } else { | 93 | } else { |
92 | try_tls = false; | 94 | try_tls = false; |
93 | } | 95 | } |
94 | } | 96 | } |
95 | } | 97 | } |
96 | } | 98 | } |
97 | return try_tls; | 99 | return try_tls; |
98 | } | 100 | } |
99 | 101 | ||
100 | void IMAPwrapper::login() | 102 | void IMAPwrapper::login() |
101 | { | 103 | { |
102 | const char *server, *user, *pass; | 104 | const char *server, *user, *pass; |
103 | uint16_t port; | 105 | uint16_t port; |
104 | int err = MAILIMAP_NO_ERROR; | 106 | int err = MAILIMAP_NO_ERROR; |
105 | 107 | ||
106 | if (account->getOffline()) return; | 108 | if (account->getOffline()) return; |
107 | /* we are connected this moment */ | 109 | /* we are connected this moment */ |
108 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 110 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
109 | if (m_imap) { | 111 | if (m_imap) { |
110 | err = mailimap_noop(m_imap); | 112 | err = mailimap_noop(m_imap); |
@@ -156,65 +158,65 @@ void IMAPwrapper::login() | |||
156 | } | 158 | } |
157 | 159 | ||
158 | if ( err != MAILIMAP_NO_ERROR && | 160 | if ( err != MAILIMAP_NO_ERROR && |
159 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 161 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
160 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 162 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
161 | QString failure = ""; | 163 | QString failure = ""; |
162 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 164 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
163 | failure="Connection refused"; | 165 | failure="Connection refused"; |
164 | } else { | 166 | } else { |
165 | failure="Unknown failure"; | 167 | failure="Unknown failure"; |
166 | } | 168 | } |
167 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 169 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
168 | mailimap_free( m_imap ); | 170 | mailimap_free( m_imap ); |
169 | m_imap = 0; | 171 | m_imap = 0; |
170 | return; | 172 | return; |
171 | } | 173 | } |
172 | 174 | ||
173 | if (!ssl) { | 175 | if (!ssl) { |
174 | try_tls = start_tls(force_tls); | 176 | try_tls = start_tls(force_tls); |
175 | } | 177 | } |
176 | 178 | ||
177 | bool ok = true; | 179 | bool ok = true; |
178 | if (force_tls && !try_tls) { | 180 | if (force_tls && !try_tls) { |
179 | Global::statusMessage(tr("Server has no TLS support!")); | 181 | Global::statusMessage(tr("Server has no TLS support!")); |
180 | odebug << "Server has no TLS support!" << oendl; | 182 | odebug << "Server has no TLS support!" << oendl; |
181 | ok = false; | 183 | ok = false; |
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
185 | /* login */ | 187 | /* login */ |
186 | 188 | ||
187 | if (ok) { | 189 | if (ok) { |
188 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 190 | err = mailimap_login( m_imap, (char*)user, (char*)pass ); |
189 | if ( err != MAILIMAP_NO_ERROR ) { | 191 | if ( err != MAILIMAP_NO_ERROR ) { |
190 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 192 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
191 | ok = false; | 193 | ok = false; |
192 | } | 194 | } |
193 | } | 195 | } |
194 | if (!ok) { | 196 | if (!ok) { |
195 | err = mailimap_close( m_imap ); | 197 | err = mailimap_close( m_imap ); |
196 | mailimap_free( m_imap ); | 198 | mailimap_free( m_imap ); |
197 | m_imap = 0; | 199 | m_imap = 0; |
198 | } | 200 | } |
199 | } | 201 | } |
200 | 202 | ||
201 | void IMAPwrapper::logout() | 203 | void IMAPwrapper::logout() |
202 | { | 204 | { |
203 | int err = MAILIMAP_NO_ERROR; | 205 | int err = MAILIMAP_NO_ERROR; |
204 | if (!m_imap) return; | 206 | if (!m_imap) return; |
205 | err = mailimap_logout( m_imap ); | 207 | err = mailimap_logout( m_imap ); |
206 | err = mailimap_close( m_imap ); | 208 | err = mailimap_close( m_imap ); |
207 | mailimap_free( m_imap ); | 209 | mailimap_free( m_imap ); |
208 | m_imap = 0; | 210 | m_imap = 0; |
209 | m_Lastmbox = ""; | 211 | m_Lastmbox = ""; |
210 | } | 212 | } |
211 | 213 | ||
212 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) | 214 | void IMAPwrapper::listMessages(const QString&mailbox,QValueList<Opie::Core::OSmartPointer<RecMail> > &target ) |
213 | { | 215 | { |
214 | int err = MAILIMAP_NO_ERROR; | 216 | int err = MAILIMAP_NO_ERROR; |
215 | clist *result = 0; | 217 | clist *result = 0; |
216 | clistcell *current; | 218 | clistcell *current; |
217 | mailimap_fetch_type *fetchType = 0; | 219 | mailimap_fetch_type *fetchType = 0; |
218 | mailimap_set *set = 0; | 220 | mailimap_set *set = 0; |
219 | 221 | ||
220 | login(); | 222 | login(); |