From f7fc1d5dfd8f5ca2aac10554ef13f6ecb082f998 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Sat, 5 Dec 2020 00:30:10 +0100 Subject: fix: person to give the gift to AFFECTED AREA: Email body ROOT CAUSE: Printed name of sender FIX: Retrieve name from mapped `HashMap` members --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index a6db4e7..b30231a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,13 +91,18 @@ fn main() { .credentials(creds) .build(); - for (email, name) in members.into_iter() { + for (email, name) in members.iter() { loop { match my_gift_to(&mut emails) { - Some(gift_to) => { - if gift_to.to_string() != email.to_string() - && !done.iter().any(|v| v == gift_to) + Some(gift_to_email) => { + if gift_to_email.to_string() != email.to_string() + && !done.iter().any(|v| v == gift_to_email) { + let gift_to_name; + match members.get(&gift_to_email[..]) { + Some(v) => gift_to_name = v, + None => continue + } let mail = Message::builder() .from( format!("{} <{}>", config_name, config_email) @@ -106,13 +111,13 @@ fn main() { ) .to(format!("{} <{}>", name, email).parse().unwrap()) .subject("Secret Santa!") - .body(format!("You're the Secret Santa of:\n{}", name)) + .body(format!("You're the Secret Santa of:\n{}", gift_to_name)) .unwrap(); match mailer.send(&mail) { Ok(_) => println!("Email sent successfully to {}!", email), Err(e) => panic!("Could not send email: {:?}", e), } - done.push(gift_to.to_string()); + done.push(gift_to_email.to_string()); break; } } -- cgit v1.2.3-18-g5258