Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/imapwrapper.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp index 11d3343..021633b 100644 --- a/kmicromail/libmailwrapper/imapwrapper.cpp +++ b/kmicromail/libmailwrapper/imapwrapper.cpp | |||
@@ -83,117 +83,117 @@ bool IMAPwrapper::start_tls(bool force_tls) | |||
83 | } else { | 83 | } else { |
84 | int fd = mailstream_low_get_fd(low); | 84 | int fd = mailstream_low_get_fd(low); |
85 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 85 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
86 | mailstream_low_free(low); | 86 | mailstream_low_free(low); |
87 | mailstream_set_low(m_imap->imap_stream, new_low); | 87 | mailstream_set_low(m_imap->imap_stream, new_low); |
88 | } else { | 88 | } else { |
89 | try_tls = false; | 89 | try_tls = false; |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | } |
93 | } | 93 | } |
94 | return try_tls; | 94 | return try_tls; |
95 | } | 95 | } |
96 | 96 | ||
97 | void IMAPwrapper::login() | 97 | void IMAPwrapper::login() |
98 | { | 98 | { |
99 | const char *server, *user, *pass; | 99 | QString server, user, pass; |
100 | uint16_t port; | 100 | uint16_t port; |
101 | int err = MAILIMAP_NO_ERROR; | 101 | int err = MAILIMAP_NO_ERROR; |
102 | 102 | ||
103 | if (account->getOffline()) return; | 103 | if (account->getOffline()) return; |
104 | /* we are connected this moment */ | 104 | /* we are connected this moment */ |
105 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ | 105 | /* TODO: setup a timer holding the line or if connection closed - delete the value */ |
106 | if (m_imap) { | 106 | if (m_imap) { |
107 | err = mailimap_noop(m_imap); | 107 | err = mailimap_noop(m_imap); |
108 | if (err!=MAILIMAP_NO_ERROR) { | 108 | if (err!=MAILIMAP_NO_ERROR) { |
109 | logout(); | 109 | logout(); |
110 | } else { | 110 | } else { |
111 | mailstream_flush(m_imap->imap_stream); | 111 | mailstream_flush(m_imap->imap_stream); |
112 | return; | 112 | return; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | server = account->getServer().latin1(); | 115 | server = account->getServer(); |
116 | port = account->getPort().toUInt(); | 116 | port = account->getPort().toUInt(); |
117 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { | 117 | if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { |
118 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); | 118 | LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); |
119 | login.show(); | 119 | login.show(); |
120 | if ( QDialog::Accepted == login.exec() ) { | 120 | if ( QDialog::Accepted == login.exec() ) { |
121 | // ok | 121 | // ok |
122 | user = login.getUser().latin1(); | 122 | user = login.getUser(); |
123 | pass = login.getPassword().latin1(); | 123 | pass = login.getPassword(); |
124 | } else { | 124 | } else { |
125 | // cancel | 125 | // cancel |
126 | return; | 126 | return; |
127 | } | 127 | } |
128 | } else { | 128 | } else { |
129 | user = account->getUser().latin1(); | 129 | user = account->getUser(); |
130 | pass = account->getPassword().latin1(); | 130 | pass = account->getPassword(); |
131 | } | 131 | } |
132 | 132 | ||
133 | m_imap = mailimap_new( 20, &imap_progress ); | 133 | m_imap = mailimap_new( 20, &imap_progress ); |
134 | 134 | ||
135 | /* connect */ | 135 | /* connect */ |
136 | bool ssl = false; | 136 | bool ssl = false; |
137 | bool try_tls = false; | 137 | bool try_tls = false; |
138 | bool force_tls = false; | 138 | bool force_tls = false; |
139 | 139 | ||
140 | if ( account->ConnectionType() == 2 ) { | 140 | if ( account->ConnectionType() == 2 ) { |
141 | ssl = true; | 141 | ssl = true; |
142 | } | 142 | } |
143 | if (account->ConnectionType()==1) { | 143 | if (account->ConnectionType()==1) { |
144 | force_tls = true; | 144 | force_tls = true; |
145 | } | 145 | } |
146 | 146 | ||
147 | if ( ssl ) { | 147 | if ( ssl ) { |
148 | qDebug("using ssl "); | 148 | qDebug("using ssl "); |
149 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 149 | err = mailimap_ssl_connect( m_imap, (char*)server.latin1(), port ); |
150 | } else { | 150 | } else { |
151 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 151 | err = mailimap_socket_connect( m_imap, (char*)server.latin1(), port ); |
152 | } | 152 | } |
153 | 153 | ||
154 | if ( err != MAILIMAP_NO_ERROR && | 154 | if ( err != MAILIMAP_NO_ERROR && |
155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 155 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 156 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
157 | QString failure = ""; | 157 | QString failure = ""; |
158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | 158 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { |
159 | failure="Connection refused"; | 159 | failure="Connection refused"; |
160 | } else { | 160 | } else { |
161 | failure="Unknown failure"; | 161 | failure="Unknown failure"; |
162 | } | 162 | } |
163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | 163 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); |
164 | mailimap_free( m_imap ); | 164 | mailimap_free( m_imap ); |
165 | m_imap = 0; | 165 | m_imap = 0; |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | 168 | ||
169 | if (!ssl) { | 169 | if (!ssl) { |
170 | try_tls = start_tls(force_tls); | 170 | try_tls = start_tls(force_tls); |
171 | } | 171 | } |
172 | 172 | ||
173 | bool ok = true; | 173 | bool ok = true; |
174 | if (force_tls && !try_tls) { | 174 | if (force_tls && !try_tls) { |
175 | Global::statusMessage(tr("Server has no TLS support!")); | 175 | Global::statusMessage(tr("Server has no TLS support!")); |
176 | ok = false; | 176 | ok = false; |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | /* login */ | 180 | /* login */ |
181 | 181 | ||
182 | if (ok) { | 182 | if (ok) { |
183 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 183 | err = mailimap_login_simple( m_imap, (char*)user.latin1(), (char*)pass.latin1() ); |
184 | if ( err != MAILIMAP_NO_ERROR ) { | 184 | if ( err != MAILIMAP_NO_ERROR ) { |
185 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); | 185 | Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); |
186 | ok = false; | 186 | ok = false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | if (!ok) { | 189 | if (!ok) { |
190 | err = mailimap_close( m_imap ); | 190 | err = mailimap_close( m_imap ); |
191 | mailimap_free( m_imap ); | 191 | mailimap_free( m_imap ); |
192 | m_imap = 0; | 192 | m_imap = 0; |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void IMAPwrapper::logout() | 196 | void IMAPwrapper::logout() |
197 | { | 197 | { |
198 | int err = MAILIMAP_NO_ERROR; | 198 | int err = MAILIMAP_NO_ERROR; |
199 | if (!m_imap) return; | 199 | if (!m_imap) return; |