summaryrefslogtreecommitdiffabout
path: root/kmicromail
authorzautrix <zautrix>2005-10-22 14:36:31 (UTC)
committer zautrix <zautrix>2005-10-22 14:36:31 (UTC)
commit2e5c0a288f7c54cce7e0327ddbbd160f242758f1 (patch) (unidiff)
tree91a3d3092d71645b1f9f6a6147825d3b27ae006b /kmicromail
parenta72d70beb381b9cd6f2af301b52ca82cdcafb299 (diff)
downloadkdepimpi-2e5c0a288f7c54cce7e0327ddbbd160f242758f1.zip
kdepimpi-2e5c0a288f7c54cce7e0327ddbbd160f242758f1.tar.gz
kdepimpi-2e5c0a288f7c54cce7e0327ddbbd160f242758f1.tar.bz2
fixes
Diffstat (limited to 'kmicromail') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp
index a6c12e4..7c813cc 100644
--- a/kmicromail/libmailwrapper/smtpwrapper.cpp
+++ b/kmicromail/libmailwrapper/smtpwrapper.cpp
@@ -169,204 +169,205 @@ int SMTPwrapper::start_smtp_tls()
169 if (!m_smtp) { 169 if (!m_smtp) {
170 return MAILSMTP_ERROR_IN_PROCESSING; 170 return MAILSMTP_ERROR_IN_PROCESSING;
171 } 171 }
172 int err = mailesmtp_starttls(m_smtp); 172 int err = mailesmtp_starttls(m_smtp);
173 if (err != MAILSMTP_NO_ERROR) return err; 173 if (err != MAILSMTP_NO_ERROR) return err;
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 //m_smtp->auth = MAILSMTP_AUTH_LOGIN;
223 223
224 int err = MAILSMTP_NO_ERROR; 224 int err = MAILSMTP_NO_ERROR;
225 ; // odebug << "Servername " << server << " at port " << port << "" << oendl; 225 ; // odebug << "Servername " << server << " at port " << port << "" << oendl;
226 if ( ssl ) { 226 if ( ssl ) {
227 qDebug("smtp: ssl_connect "); 227 qDebug("smtp: ssl_connect ");
228 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); 228 err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port );
229 } else { 229 } else {
230 ; // odebug << "No SSL session" << oendl; 230 ; // odebug << "No SSL session" << oendl;
231 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); 231 err = mailsmtp_socket_connect( m_smtp, server.latin1(), port );
232 } 232 }
233 if ( err != MAILSMTP_NO_ERROR ) { 233 if ( err != MAILSMTP_NO_ERROR ) {
234 qDebug("Error init SMTP connection" ); 234 qDebug("Error init SMTP connection" );
235 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 235 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
236 result = 0; 236 result = 0;
237 } 237 }
238 238
239 qDebug("SMTP connection inited "); 239 qDebug("SMTP connection inited ");
240 /* 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 */
241 if (result) { 241 if (result) {
242 err = mailsmtp_init( m_smtp ); 242 err = mailsmtp_init( m_smtp );
243 if (err != MAILSMTP_NO_ERROR) { 243 if (err != MAILSMTP_NO_ERROR) {
244 result = 0; 244 result = 0;
245 qDebug("Error init SMTP connection "); 245 qDebug("Error init SMTP connection ");
246 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err)); 246 failuretext = i18n("Error init SMTP connection:\n%1").arg(mailsmtpError(err));
247 } 247 }
248 } 248 }
249 if (result && try_tls) { 249 if (result && try_tls) {
250 qDebug("Smpt: Try TLS... "); 250 qDebug("Smpt: Try TLS... ");
251 err = start_smtp_tls(); 251 err = start_smtp_tls();
252 if (err != MAILSMTP_NO_ERROR) { 252 if (err != MAILSMTP_NO_ERROR) {
253 try_tls = false; 253 try_tls = false;
254 qDebug("Smpt: No TLS possible "); 254 qDebug("Smpt: No TLS possible ");
255 } else { 255 } else {
256 qDebug("Smpt: Using TLS "); 256 qDebug("Smpt: Using TLS ");
257 } 257 }
258 } 258 }
259 259
260 //qDebug("mailesmtp_ehlo %d ",err ); 260 //qDebug("mailesmtp_ehlo %d ",err );
261 if (!try_tls && force_tls) { 261 if (!try_tls && force_tls) {
262 result = 0; 262 result = 0;
263 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err)); 263 failuretext = i18n("Error init SMTP tls:%1").arg(mailsmtpError(err));
264 } 264 }
265 if ( mailesmtp_ehlo(m_smtp) != MAILSMTP_NO_ERROR ) { 265 //LR 05-10-22 : qDebug("no elo any more ");
266 qDebug("Smpt: ehlo failed "); 266 // if ( false /*mailesmtp_ehlo(m_smtp) != MAILSMTP_NO_ERROR */) {
267 result = 0; 267// qDebug("Smpt: ehlo failed ");
268 } 268// result = 0;
269 else { 269// }
270// else {
270 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN); 271 //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 if ( m_smtp->auth & MAILSMTP_AUTH_LOGIN && m_smtp->auth & MAILSMTP_AUTH_PLAIN ) {
272 qDebug("Smpt: Using MAILSMTP_AUTH_LOGIN "); 273 qDebug("Smpt: Using MAILSMTP_AUTH_LOGIN ");
273 m_smtp->auth -= MAILSMTP_AUTH_PLAIN; 274 m_smtp->auth -= MAILSMTP_AUTH_PLAIN;
274 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN); 275 //qDebug("Smpt: auth is %d -- %d %d",m_smtp->auth, MAILSMTP_AUTH_LOGIN, MAILSMTP_AUTH_PLAIN);
275 } 276 }
276 } 277 // }
277 278
278 if (result==1 && m_SmtpAccount->getLogin() ) { 279 if (result==1 && m_SmtpAccount->getLogin() ) {
279 ; // odebug << "smtp with auth" << oendl; 280 ; // odebug << "smtp with auth" << oendl;
280 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 281 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
281 // get'em 282 // get'em
282 LoginDialog login( m_SmtpAccount->getUser(), 283 LoginDialog login( m_SmtpAccount->getUser(),
283 m_SmtpAccount->getPassword(), NULL, 0, true ); 284 m_SmtpAccount->getPassword(), NULL, 0, true );
284 login.show(); 285 login.show();
285 if ( QDialog::Accepted == login.exec() ) { 286 if ( QDialog::Accepted == login.exec() ) {
286 // ok 287 // ok
287 user = login.getUser(); 288 user = login.getUser();
288 pass = login.getPassword(); 289 pass = login.getPassword();
289 } else { 290 } else {
290 result = 0; 291 result = 0;
291 failuretext=i18n("Login aborted - \nstoring mail to localfolder"); 292 failuretext=i18n("Login aborted - \nstoring mail to localfolder");
292 } 293 }
293 } else { 294 } else {
294 user = m_SmtpAccount->getUser(); 295 user = m_SmtpAccount->getUser();
295 pass = m_SmtpAccount->getPassword(); 296 pass = m_SmtpAccount->getPassword();
296 } 297 }
297 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; 298 ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl;
298 if (result) { 299 if (result) {
299 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); 300 err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() );
300 if ( err == MAILSMTP_NO_ERROR ) { 301 if ( err == MAILSMTP_NO_ERROR ) {
301 qDebug("Smtp authentification ok "); 302 qDebug("Smtp authentification ok ");
302 } else { 303 } else {
303 failuretext = i18n("Authentification failed"); 304 failuretext = i18n("Authentification failed");
304 result = 0; 305 result = 0;
305 } 306 }
306 } 307 }
307 } 308 }
308 if ( result == 0 ) { 309 if ( result == 0 ) {
309 mailsmtp_free(m_smtp); 310 mailsmtp_free(m_smtp);
310 m_smtp = 0; 311 m_smtp = 0;
311 } 312 }
312} 313}
313 314
314void SMTPwrapper::disc_server() 315void SMTPwrapper::disc_server()
315{ 316{
316 if (m_smtp) { 317 if (m_smtp) {
317 mailsmtp_quit( m_smtp ); 318 mailsmtp_quit( m_smtp );
318 mailsmtp_free( m_smtp ); 319 mailsmtp_free( m_smtp );
319 m_smtp = 0; 320 m_smtp = 0;
320 } 321 }
321} 322}
322 323
323int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 324int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
324{ 325{
325 int err,result; 326 int err,result;
326 QString failuretext = ""; 327 QString failuretext = "";
327 328
328 connect_server(); 329 connect_server();
329 330
330 result = 1; 331 result = 1;
331 if (m_smtp) { 332 if (m_smtp) {
332 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 333 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
333 if ( err != MAILSMTP_NO_ERROR ) { 334 if ( err != MAILSMTP_NO_ERROR ) {
334 qDebug("Error sending mail"); 335 qDebug("Error sending mail");
335 failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err)); 336 failuretext=i18n("Error sending mail:\n%1").arg(mailsmtpError(err));
336 result = 0; 337 result = 0;
337 } 338 }
338 } else { 339 } else {
339 result = 0; 340 result = 0;
340 } 341 }
341 342
342 if (!result) { 343 if (!result) {
343 storeFailedMail(data,size,failuretext); 344 storeFailedMail(data,size,failuretext);
344 } else { 345 } else {
345 ; // odebug << "Mail sent." << oendl; 346 ; // odebug << "Mail sent." << oendl;
346 storeMail(data,size,"Sent"); 347 storeMail(data,size,"Sent");
347 } 348 }
348 return result; 349 return result;
349} 350}
350 351
351bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) 352bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later )
352{ 353{
353 mailmime * mimeMail; 354 mailmime * mimeMail;
354 bool result = true; 355 bool result = true;
355 mimeMail = createMimeMail(mail ); 356 mimeMail = createMimeMail(mail );
356 if ( mimeMail == 0 ) { 357 if ( mimeMail == 0 ) {
357 qDebug("SMTP wrapper:Error creating mail! "); 358 qDebug("SMTP wrapper:Error creating mail! ");
358 return false; 359 return false;
359 } else { 360 } else {
360 sendProgress = new progressMailSend(); 361 sendProgress = new progressMailSend();
361 sendProgress->show(); 362 sendProgress->show();
362 sendProgress->setMaxMails(1); 363 sendProgress->setMaxMails(1);
363 result = smtpSend( mimeMail,later); 364 result = smtpSend( mimeMail,later);
364 ; // odebug << "Clean up done" << oendl; 365 ; // odebug << "Clean up done" << oendl;
365 sendProgress->hide(); 366 sendProgress->hide();
366 delete sendProgress; 367 delete sendProgress;
367 sendProgress = 0; 368 sendProgress = 0;
368 mailmime_free( mimeMail ); 369 mailmime_free( mimeMail );
369 if ( m_smtp ) { 370 if ( m_smtp ) {
370 mailsmtp_free(m_smtp); 371 mailsmtp_free(m_smtp);
371 m_smtp = 0; 372 m_smtp = 0;
372 } 373 }