EmailBodyPart Get from Set

main
Mauro D 2023-06-07 16:33:28 +00:00
parent 952f272d09
commit 5434b2d26e
1 changed files with 31 additions and 6 deletions

View File

@ -167,20 +167,24 @@ impl Email<Set> {
self self
} }
pub fn text_body(&mut self, text_body: EmailBodyPart) -> &mut Self { pub fn text_body(&mut self, text_body: impl Into<EmailBodyPart<Get>>) -> &mut Self {
self.text_body.get_or_insert_with(Vec::new).push(text_body); self.text_body
.get_or_insert_with(Vec::new)
.push(text_body.into());
self self
} }
pub fn html_body(&mut self, html_body: EmailBodyPart) -> &mut Self { pub fn html_body(&mut self, html_body: impl Into<EmailBodyPart<Get>>) -> &mut Self {
self.html_body.get_or_insert_with(Vec::new).push(html_body); self.html_body
.get_or_insert_with(Vec::new)
.push(html_body.into());
self self
} }
pub fn attachment(&mut self, attachment: EmailBodyPart) -> &mut Self { pub fn attachment(&mut self, attachment: impl Into<EmailBodyPart<Get>>) -> &mut Self {
self.attachments self.attachments
.get_or_insert_with(Vec::new) .get_or_insert_with(Vec::new)
.push(attachment); .push(attachment.into());
self self
} }
@ -271,6 +275,27 @@ impl EmailBodyPart {
} }
} }
impl From<EmailBodyPart<Set>> for EmailBodyPart<Get> {
fn from(part: EmailBodyPart<Set>) -> Self {
EmailBodyPart {
part_id: part.part_id,
blob_id: part.blob_id,
size: part.size,
headers: part.headers,
name: part.name,
type_: part.type_,
charset: part.charset,
disposition: part.disposition,
cid: part.cid,
language: part.language,
location: part.location,
sub_parts: part.sub_parts,
header: part.header,
_state: Default::default(),
}
}
}
impl EmailBodyPart<Set> { impl EmailBodyPart<Set> {
pub fn part_id(mut self, part_id: impl Into<String>) -> Self { pub fn part_id(mut self, part_id: impl Into<String>) -> Self {
self.part_id = Some(part_id.into()); self.part_id = Some(part_id.into());