mimefactory: refactor generation of the To: field

Group all the code responsible for the generation of the To: field
This commit is contained in:
link2xt
2021-12-04 18:52:34 +00:00
parent 607cd23014
commit 8ad9db5572

View File

@@ -458,34 +458,47 @@ impl<'a> MimeFactory<'a> {
self.from_addr.clone(), self.from_addr.clone(),
); );
let mut to = Vec::new(); let undisclosed_recipients = match &self.loaded {
let email_to_remove = if self.msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup { Loaded::Message { chat } => chat.typ == Chattype::Broadcast,
self.msg.param.get(Param::Arg) Loaded::Mdn { .. } => false,
} else {
None
}; };
for (name, addr) in self.recipients.iter() { let mut to = Vec::new();
if let Some(email_to_remove) = email_to_remove { if undisclosed_recipients {
if email_to_remove == addr { to.push(Address::new_group(
continue; "hidden-recipients".to_string(),
Vec::new(),
));
} else {
let email_to_remove =
if self.msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup {
self.msg.param.get(Param::Arg)
} else {
None
};
for (name, addr) in self.recipients.iter() {
if let Some(email_to_remove) = email_to_remove {
if email_to_remove == addr {
continue;
}
}
if name.is_empty() {
to.push(Address::new_mailbox(addr.clone()));
} else {
to.push(Address::new_mailbox_with_name(
name.to_string(),
addr.clone(),
));
} }
} }
if name.is_empty() { if to.is_empty() {
to.push(Address::new_mailbox(addr.clone())); to.push(from.clone());
} else {
to.push(Address::new_mailbox_with_name(
name.to_string(),
addr.clone(),
));
} }
} }
if to.is_empty() {
to.push(from.clone());
}
headers headers
.unprotected .unprotected
.push(Header::new("MIME-Version".into(), "1.0".into())); .push(Header::new("MIME-Version".into(), "1.0".into()));
@@ -584,20 +597,9 @@ impl<'a> MimeFactory<'a> {
render_rfc724_mid(&rfc724_mid), render_rfc724_mid(&rfc724_mid),
)); ));
let undisclosed_recipients = match &self.loaded { headers
Loaded::Message { chat } => chat.typ == Chattype::Broadcast, .unprotected
Loaded::Mdn { .. } => false, .push(Header::new_with_value("To".into(), to).unwrap());
};
if undisclosed_recipients {
headers
.unprotected
.push(Header::new("To".into(), "hidden-recipients: ;".to_string()));
} else {
headers
.unprotected
.push(Header::new_with_value("To".into(), to).unwrap());
}
headers headers
.unprotected .unprotected