rustfmt email.rs

This commit is contained in:
nobody 2024-08-07 03:59:45 +02:00 committed by murmeldin
parent 62d12e314c
commit a454914b1f

View file

@ -66,7 +66,8 @@ pub struct SimpleEmail {
impl SimpleEmail { impl SimpleEmail {
pub fn new(base: Email, from: &str, to: &str, in_reply_to: Option<String>) -> Self { pub fn new(base: Email, from: &str, to: &str, in_reply_to: Option<String>) -> Self {
let recipients = to.split('\n').map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).collect(); let recipients =
to.split('\n').map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).collect();
Self { base: base.clone(), from: from.to_string(), to: recipients, in_reply_to } Self { base: base.clone(), from: from.to_string(), to: recipients, in_reply_to }
} }
pub fn send_email(&self, subject: String, body: String) -> Result<String, Box<dyn Error>> { pub fn send_email(&self, subject: String, body: String) -> Result<String, Box<dyn Error>> {
@ -88,14 +89,14 @@ impl Email {
} }
pub fn send_email( pub fn send_email(
&self, from: String, to: &[String], subject: String, body: String, in_reply_to: Option<String>, &self, from: String, to: &[String], subject: String, body: String,
in_reply_to: Option<String>,
) -> Result<String, Box<dyn Error>> { ) -> Result<String, Box<dyn Error>> {
let message_id = Uuid::new_v4().to_string() + &self.message_id_suffix; let message_id = Uuid::new_v4().to_string() + &self.message_id_suffix;
let mut email = Message::builder() let mut email = Message::builder().from(from.parse().unwrap());
.from(from.parse().unwrap());
for recipient in to { for recipient in to {
email = email.to(recipient.parse().unwrap()); email = email.to(recipient.parse().unwrap());
}; }
email = email.message_id(Some(message_id.clone())); email = email.message_id(Some(message_id.clone()));
let email = let email =
if in_reply_to.is_some() { email.in_reply_to(in_reply_to.unwrap()) } else { email } if in_reply_to.is_some() { email.in_reply_to(in_reply_to.unwrap()) } else { email }