From 8009f220fc43dcafe37d046ff3a13897d38113a8 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 14 Aug 2019 01:11:38 +0200 Subject: [PATCH] hold smtp lock during the full send action --- src/dc_job.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/dc_job.rs b/src/dc_job.rs index e512032ea..d35565808 100644 --- a/src/dc_job.rs +++ b/src/dc_job.rs @@ -351,18 +351,15 @@ unsafe fn dc_job_do_DC_JOB_SEND(context: &Context, job: &mut dc_job_t) { if ok_to_continue1 { /* send message */ let body = std::slice::from_raw_parts(buf as *const u8, buf_bytes).to_vec(); - if 0 == context - .smtp - .lock() - .unwrap() - .send(context, recipients_list, body) - { - context.smtp.lock().unwrap().disconnect(); - dc_job_try_again_later( - job, - -1i32, - (*&mut context.smtp.clone().lock().unwrap()).error, - ); + + // hold the smtp lock during sending of a job and + // its ok/error response processing. Note that if a message + // was sent we need to mark it in the database as we + // otherwise might send it twice. + let mut sock = context.smtp.lock().unwrap(); + if 0 == sock.send(context, recipients_list, body) { + sock.disconnect(); + dc_job_try_again_later(job, -1i32, sock.error); } else { dc_delete_file(context, filename_s); if 0 != job.foreign_id {