summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-24 11:29:53 (UTC)
committer zautrix <zautrix>2005-03-24 11:29:53 (UTC)
commitb9e83e4536ee4fc34b882fb88b8e5fd00bfdf929 (patch) (unidiff)
treea0a5565360abc8e79d417b2e55f9b179ad615b87
parent1dff93853802953ed92b24ac18ebf57f39dcbcfe (diff)
downloadkdepimpi-b9e83e4536ee4fc34b882fb88b8e5fd00bfdf929.zip
kdepimpi-b9e83e4536ee4fc34b882fb88b8e5fd00bfdf929.tar.gz
kdepimpi-b9e83e4536ee4fc34b882fb88b8e5fd00bfdf929.tar.bz2
ompi smtp fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp
index 448a2e9..a6c12e4 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.cpp
+++ b/kmicromail/libmailwrapper/smtpwrapper.cpp
@@ -174,142 +174,152 @@ int SMTPwrapper::start_smtp_tls()
174 mailstream_low * low; 174 mailstream_low * low;
175 mailstream_low * new_low; 175 mailstream_low * new_low;
176 low = mailstream_get_low(m_smtp->stream); 176 low = mailstream_get_low(m_smtp->stream);
177 if (!low) { 177 if (!low) {
178 return MAILSMTP_ERROR_IN_PROCESSING; 178 return MAILSMTP_ERROR_IN_PROCESSING;
179 } 179 }
180 int fd = mailstream_low_get_fd(low); 180 int fd = mailstream_low_get_fd(low);
181 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 181 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
182 mailstream_low_free(low); 182 mailstream_low_free(low);
183 mailstream_set_low(m_smtp->stream, new_low); 183 mailstream_set_low(m_smtp->stream, new_low);
184 } else { 184 } else {
185 return MAILSMTP_ERROR_IN_PROCESSING; 185 return MAILSMTP_ERROR_IN_PROCESSING;
186 } 186 }
187 return err; 187 return err;
188} 188}
189 189
190void SMTPwrapper::connect_server() 190void SMTPwrapper::connect_server()
191{ 191{
192 QString server, user, pass; 192 QString server, user, pass;
193 bool ssl; 193 bool ssl;
194 uint16_t port; 194 uint16_t port;
195 ssl = false; 195 ssl = false;
196 bool try_tls = false; 196 bool try_tls = false;
197 bool force_tls=false; 197 bool force_tls=false;
198 QString failuretext = ""; 198 QString failuretext = "";
199 199
200 if (m_smtp || !m_SmtpAccount) { 200 if (m_smtp || !m_SmtpAccount) {
201 return; 201 return;
202 } 202 }
203 server = m_SmtpAccount->getServer(); 203 server = m_SmtpAccount->getServer();
204 if ( m_SmtpAccount->ConnectionType() == 3 ) { 204 if ( m_SmtpAccount->ConnectionType() == 3 ) {
205 ssl = true; 205 ssl = true;
206 try_tls = false; 206 try_tls = false;
207 } else if (m_SmtpAccount->ConnectionType() == 2) { 207 } else if (m_SmtpAccount->ConnectionType() == 2) {
208 force_tls = true; 208 force_tls = true;
209 try_tls = true; 209 try_tls = true;
210 } else if (m_SmtpAccount->ConnectionType() == 1) { 210 } else if (m_SmtpAccount->ConnectionType() == 1) {
211 try_tls = true; 211 try_tls = true;
212 } 212 }
213 int result = 1; 213 int result = 1;
214 port = m_SmtpAccount->getPort().toUInt(); 214 port = m_SmtpAccount->getPort().toUInt();
215 215
216 m_smtp = mailsmtp_new( 20, &progress ); 216 m_smtp = mailsmtp_new( 20, &progress );
217 if ( m_smtp == NULL ) { 217 if ( m_smtp == NULL ) {
218 /* no failure message cause this happens when problems with memory - than we 218 /* no failure message cause this happens when problems with memory - than we
219 we can not display any messagebox */ 219 we can not display any messagebox */
220 return; 220 return;
221 } 221 }
222 //m_smtp->auth = MAILSMTP_AUTH_LOGIN;
222 223
223 int err = MAILSMTP_NO_ERROR; 224 int err = MAILSMTP_NO_ERROR;
224 ; // odebug << "Servername " << server << " at port " << port << "" << oendl; 225 ; // odebug << "Servername " << server << " at port " << port << "" << oendl;
225 if ( ssl ) { 226 if ( ssl ) {
226 qDebug("smtp: ssl_connect "); 227 qDebug("smtp: ssl_connect ");
227 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); 228 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port );
228 } else { 229 } else {
229 ; // odebug << "No SSL session" << oendl; 230 ; // odebug << "No SSL session" << oendl;
230 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); 231 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port );
231 } 232 }
232 if ( err != MAILSMTP_NO_ERROR ) { 233 if ( err != MAILSMTP_NO_ERROR ) {
233 qDebug("Error init SMTP connection" ); 234 qDebug("Error init SMTP connection" );
234 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 235 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
235 result = 0; 236 result = 0;
236 } 237 }
237 238
238 qDebug("SMTP connection inited "); 239 qDebug("SMTP connection inited ");
239 /* switch to tls after init 'cause there it will send the ehlo */ 240 /* switch to tls after init 'cause there it will send the ehlo */
240 if (result) { 241 if (result) {
241 err = mailsmtp_init( m_smtp ); 242 err = mailsmtp_init( m_smtp );
242 if (err != MAILSMTP_NO_ERROR) { 243 if (err != MAILSMTP_NO_ERROR) {
243 result = 0; 244 result = 0;
244 qDebug("Error init SMTP connection "); 245 qDebug("Error init SMTP connection ");
245 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 246 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
246 } 247 }
247 } 248 }
248 if (result && try_tls) { 249 if (result && try_tls) {
249 qDebug("Smpt: Try TLS... "); 250 qDebug("Smpt: Try TLS... ");
250 err = start_smtp_tls(); 251 err = start_smtp_tls();
251 if (err != MAILSMTP_NO_ERROR) { 252 if (err != MAILSMTP_NO_ERROR) {
252 try_tls = false; 253 try_tls = false;
253 qDebug("Smpt: No TLS possible "); 254 qDebug("Smpt: No TLS possible ");
254 } else { 255 } else {
255 err = mailesmtp_ehlo(m_smtp); 256 qDebug("Smpt: Using TLS ");
256 if ( err != MAILSMTP_NO_ERROR )
257 result = 0;
258 else
259 qDebug("Smpt: Using TLS ");
260 } 257 }
261 } 258 }
259
262 //qDebug("mailesmtp_ehlo %d ",err ); 260 //qDebug("mailesmtp_ehlo %d ",err );
263 if (!try_tls && force_tls) { 261 if (!try_tls && force_tls) {
264 result = 0; 262 result = 0;
265 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err)); 263 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err));
264 }
265 if ( mailesmtp_ehlo(m_smtp) != MAILSMTP_NO_ERROR ) {
266 qDebug("Smpt: ehlo failed ");
267 result = 0;
266 } 268 }
267 269 else {
270 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN);
271 if ( m_smtp->auth & MAILSMTP_AUTH_LOGIN && m_smtp->auth & MAILSMTP_AUTH_PLAIN ) {
272 qDebug("Smpt: Using MAILSMTP_AUTH_LOGIN ");
273 m_smtp->auth -= MAILSMTP_AUTH_PLAIN;
274 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN);
275 }
276 }
277
268 if (result==1 && m_SmtpAccount->getLogin() ) { 278 if (result==1 && m_SmtpAccount->getLogin() ) {
269 ; // odebug << "smtp with auth" << oendl; 279 ; // odebug << "smtp with auth" << oendl;
270 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 280 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
271 // get'em 281 // get'em
272 LoginDialog login( m_SmtpAccount->getUser(), 282 LoginDialog login( m_SmtpAccount->getUser(),
273 m_SmtpAccount->getPassword(), NULL, 0, true ); 283 m_SmtpAccount->getPassword(), NULL, 0, true );
274 login.show(); 284 login.show();
275 if ( QDialog::Accepted == login.exec() ) { 285 if ( QDialog::Accepted == login.exec() ) {
276 // ok 286 // ok
277 user = login.getUser(); 287 user = login.getUser();
278 pass = login.getPassword(); 288 pass = login.getPassword();
279 } else { 289 } else {
280 result = 0; 290 result = 0;
281 failuretext=i18n("Login aborted - \nstoring mail to localfolder"); 291 failuretext=i18n("Login aborted - \nstoring mail to localfolder");
282 } 292 }
283 } else { 293 } else {
284 user = m_SmtpAccount->getUser(); 294 user = m_SmtpAccount->getUser();
285 pass = m_SmtpAccount->getPassword(); 295 pass = m_SmtpAccount->getPassword();
286 } 296 }
287 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; 297 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl;
288 if (result) { 298 if (result) {
289 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); 299 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() );
290 if ( err == MAILSMTP_NO_ERROR ) { 300 if ( err == MAILSMTP_NO_ERROR ) {
291 qDebug("Smtp authentification ok "); 301 qDebug("Smtp authentification ok ");
292 } else { 302 } else {
293 failuretext = i18n("Authentification failed"); 303 failuretext = i18n("Authentification failed");
294 result = 0; 304 result = 0;
295 } 305 }
296 } 306 }
297 } 307 }
298 if ( result == 0 ) { 308 if ( result == 0 ) {
299 mailsmtp_free(m_smtp); 309 mailsmtp_free(m_smtp);
300 m_smtp = 0; 310 m_smtp = 0;
301 } 311 }
302} 312}
303 313
304void SMTPwrapper::disc_server() 314void SMTPwrapper::disc_server()
305{ 315{
306 if (m_smtp) { 316 if (m_smtp) {
307 mailsmtp_quit( m_smtp ); 317 mailsmtp_quit( m_smtp );
308 mailsmtp_free( m_smtp ); 318 mailsmtp_free( m_smtp );
309 m_smtp = 0; 319 m_smtp = 0;
310 } 320 }
311} 321}
312 322
313int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 323int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
314{ 324{
315 int err,result; 325 int err,result;