Store Smtp.error as Option<String>

Without this change, when SMTP password is incorrect,
as_str(sock.error) is called with a null pointer,
and as_str panics.

Now it does not crash when the error is not set.
This commit is contained in:
Alexander Krotov
2019-09-05 05:28:57 +03:00
parent f78f0079c1
commit c8d945db56
2 changed files with 5 additions and 5 deletions

View File

@@ -156,7 +156,7 @@ impl Job {
let mut sock = context.smtp.lock().unwrap(); let mut sock = context.smtp.lock().unwrap();
if 0 == sock.send(context, recipients_list, body) { if 0 == sock.send(context, recipients_list, body) {
sock.disconnect(); sock.disconnect();
self.try_again_later(-1i32, Some(as_str(sock.error))); self.try_again_later(-1i32, sock.error.clone());
} else { } else {
dc_delete_file(context, filename); dc_delete_file(context, filename);
if 0 != self.foreign_id { if 0 != self.foreign_id {
@@ -189,9 +189,9 @@ impl Job {
} }
// this value does not increase the number of tries // this value does not increase the number of tries
fn try_again_later(&mut self, try_again: libc::c_int, pending_error: Option<&str>) { fn try_again_later(&mut self, try_again: libc::c_int, pending_error: Option<String>) {
self.try_again = try_again; self.try_again = try_again;
self.pending_error = pending_error.map(|s| s.to_string()); self.pending_error = pending_error;
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]

View File

@@ -12,7 +12,7 @@ pub struct Smtp {
transport_connected: bool, transport_connected: bool,
/// Email address we are sending from. /// Email address we are sending from.
from: Option<EmailAddress>, from: Option<EmailAddress>,
pub error: *mut libc::c_char, pub error: Option<String>,
} }
impl Smtp { impl Smtp {
@@ -22,7 +22,7 @@ impl Smtp {
transport: None, transport: None,
transport_connected: false, transport_connected: false,
from: None, from: None,
error: std::ptr::null_mut(), error: None,
} }
} }