1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::{future::Future, pin::Pin};
use melib::smtp::*;
use crate::{errors::*, Connection, QueueEntry};
type ResultFuture<T> = Result<Pin<Box<dyn Future<Output = Result<T>> + Send + 'static>>>;
impl Connection {
pub fn new_smtp_connection(&self) -> ResultFuture<SmtpConnection> {
if let crate::SendMail::Smtp(ref smtp_conf) = &self.conf().send_mail {
let smtp_conf = smtp_conf.clone();
Ok(Box::pin(async move {
Ok(SmtpConnection::new_connection(smtp_conf).await?)
}))
} else {
Err("No SMTP configuration found: use the shell command instead.".into())
}
}
pub async fn submit(
smtp_connection: &mut melib::smtp::SmtpConnection,
message: &QueueEntry,
dry_run: bool,
) -> Result<()> {
let QueueEntry {
ref comment,
ref to_addresses,
ref from_address,
ref subject,
ref message,
..
} = message;
log::info!(
"Sending message from {from_address} to {to_addresses} with subject {subject:?} and \
comment {comment:?}",
);
let recipients = melib::Address::list_try_from(to_addresses)
.context(format!("Could not parse {to_addresses:?}"))?;
if dry_run {
log::warn!("Dry run is true, not actually submitting anything to SMTP server.");
} else {
smtp_connection
.mail_transaction(&String::from_utf8_lossy(message), Some(&recipients))
.await?;
}
Ok(())
}
}