Skip to content

Commit 6f4e149

Browse files
committed
fix: allow any object as parameters
1 parent a84b2de commit 6f4e149

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/main.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::collections::HashMap;
21
use std::fs;
32

43
use dotenv::dotenv;
54
use lettre::message::header::ContentType;
65
use lettre::message::{Attachment, MultiPart, SinglePart};
76
use lettre::transport::smtp::authentication::Credentials;
87
use lettre::{Message, SmtpTransport, Transport};
8+
use liquid::Object;
99
use rocket::http::Status;
1010
use rocket::serde::json::Json;
1111
use rocket::{get, post, routes};
@@ -17,7 +17,7 @@ struct EmailRequest {
1717
ics_name: Option<String>,
1818
email_address: String,
1919
subject: String,
20-
parameters: HashMap<String, String>,
20+
parameters: Object,
2121
}
2222

2323
#[post("/send?<secret>", format = "json", data = "<data>")]
@@ -81,24 +81,27 @@ fn send(secret: String, data: Json<EmailRequest>) -> Status {
8181
.unwrap()
8282
.parse(&template_file)
8383
.unwrap();
84+
8485
let body = template.render(&data.parameters).unwrap();
8586

8687
// Create email message
8788
let mut multipart = MultiPart::alternative().singlepart(SinglePart::html(body.to_string()));
8889

8990
// Attach ICS file
90-
if let Some(ics_name) = &data.ics_name { match fs::read(format!("ics/{ics_name}.ics")) {
91-
Ok(ics) => {
92-
multipart = multipart.singlepart(
93-
Attachment::new(format!("{}.ics", ics_name))
94-
.body(ics, ContentType::parse("text/calendar").unwrap()),
95-
);
91+
if let Some(ics_name) = &data.ics_name {
92+
match fs::read(format!("ics/{ics_name}.ics")) {
93+
Ok(ics) => {
94+
multipart = multipart.singlepart(
95+
Attachment::new(format!("{}.ics", ics_name))
96+
.body(ics, ContentType::parse("text/calendar").unwrap()),
97+
);
98+
}
99+
Err(e) => {
100+
eprintln!("Error reading ICS file: {:#?}", e);
101+
return Status::InternalServerError;
102+
}
96103
}
97-
Err(e) => {
98-
eprintln!("Error reading ICS file: {:#?}", e);
99-
return Status::InternalServerError;
100-
}
101-
} };
104+
};
102105

103106
// Create email
104107
let email = Message::builder()

0 commit comments

Comments
 (0)