diff --git a/src/mailgun/invoices.rs b/src/mailgun/invoices.rs index 7ac21d0..12e5223 100644 --- a/src/mailgun/invoices.rs +++ b/src/mailgun/invoices.rs @@ -1,21 +1,40 @@ use super::MailgunClient; use crate::api::invoices::Invoice; use crate::error::Error; +use crate::merge::merge_pdf; use typst::model::Document; impl MailgunClient { - #[allow(dead_code)] pub async fn send_mail(self, invoice: Invoice) -> Result<(), Error> { let document: Document = invoice.to_owned().try_into()?; let pdf = typst_pdf::pdf(&document, typst::foundations::Smart::Auto, None); + let mut pdfs = vec![pdf]; + pdfs.extend_from_slice( + invoice + .attachments + .clone() + .into_iter() + .map(|a| a.bytes) + .collect::>() + .as_slice(), + ); + + let pdf = merge_pdf(pdfs)?; + let invoice_recipient = format!("{} <{}>", invoice.recipient_name, invoice.recipient_email); let form = reqwest::multipart::Form::new() .text("from", self.from) .text("to", self.default_to) .text("cc", invoice_recipient) - .text("subject", format!("Uusi lasku {}", invoice.recipient_name)) - .text("html", format!("Uusi lasku {}", invoice.recipient_name)) + .text( + "subject", + format!("Uusi lasku, lähettäjä {}", invoice.recipient_name), + ) + .text( + "html", + format!("Uusi lasku, lähettäjä {}", invoice.recipient_name), + ) .part( "attachment", reqwest::multipart::Part::bytes(pdf).file_name("invoice.pdf"), diff --git a/src/merge.rs b/src/merge.rs index 0d51abc..bb746ae 100644 --- a/src/merge.rs +++ b/src/merge.rs @@ -3,7 +3,6 @@ use std::collections::BTreeMap; use lopdf::{Document, Object, ObjectId}; -#[allow(dead_code)] // Mostly copied from https://github.com/J-F-Liu/lopdf/blob/master/README.md merge example pub fn merge_pdf(documents: Vec>) -> Result, Error> { let documents = documents