mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
mimefactory: implement hidden headers
This commit is contained in:
@@ -102,6 +102,12 @@ struct MessageHeaders {
|
|||||||
/// individually over IMAP without downloading the message body. This is why Chat-Version is
|
/// individually over IMAP without downloading the message body. This is why Chat-Version is
|
||||||
/// placed here.
|
/// placed here.
|
||||||
pub unprotected: Vec<Header>,
|
pub unprotected: Vec<Header>,
|
||||||
|
|
||||||
|
/// Headers that MUST NOT go into IMF header section.
|
||||||
|
///
|
||||||
|
/// These are large headers which may hit the header section size limit on the server, such as
|
||||||
|
/// Chat-User-Avatar with a base64-encoded image inside.
|
||||||
|
pub hidden: Vec<Header>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MimeFactory<'a> {
|
impl<'a> MimeFactory<'a> {
|
||||||
@@ -588,13 +594,19 @@ impl<'a> MimeFactory<'a> {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Store protected headers in the inner message.
|
|
||||||
let mut message = headers
|
|
||||||
.protected
|
|
||||||
.into_iter()
|
|
||||||
.fold(message, |message, header| message.header(header));
|
|
||||||
|
|
||||||
let outer_message = if is_encrypted {
|
let outer_message = if is_encrypted {
|
||||||
|
// Store protected headers in the inner message.
|
||||||
|
let message = headers
|
||||||
|
.protected
|
||||||
|
.into_iter()
|
||||||
|
.fold(message, |message, header| message.header(header));
|
||||||
|
|
||||||
|
// Add hidden headers to encrypted payload.
|
||||||
|
let mut message = headers
|
||||||
|
.hidden
|
||||||
|
.into_iter()
|
||||||
|
.fold(message, |message, header| message.header(header));
|
||||||
|
|
||||||
// Add gossip headers in chats with multiple recipients
|
// Add gossip headers in chats with multiple recipients
|
||||||
if peerstates.len() > 1 && self.should_do_gossip(context).await? {
|
if peerstates.len() > 1 && self.should_do_gossip(context).await? {
|
||||||
for peerstate in peerstates.iter().filter_map(|(state, _)| state.as_ref()) {
|
for peerstate in peerstates.iter().filter_map(|(state, _)| state.as_ref()) {
|
||||||
@@ -628,12 +640,6 @@ impl<'a> MimeFactory<'a> {
|
|||||||
"multipart/encrypted; protocol=\"application/pgp-encrypted\"".to_string(),
|
"multipart/encrypted; protocol=\"application/pgp-encrypted\"".to_string(),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Store the unprotected headers on the outer message.
|
|
||||||
let outer_message = headers
|
|
||||||
.unprotected
|
|
||||||
.into_iter()
|
|
||||||
.fold(outer_message, |message, header| message.header(header));
|
|
||||||
|
|
||||||
if std::env::var(crate::DCC_MIME_DEBUG).is_ok() {
|
if std::env::var(crate::DCC_MIME_DEBUG).is_ok() {
|
||||||
info!(context, "mimefactory: outgoing message mime:");
|
info!(context, "mimefactory: outgoing message mime:");
|
||||||
let raw_message = message.clone().build().as_string();
|
let raw_message = message.clone().build().as_string();
|
||||||
@@ -668,12 +674,33 @@ impl<'a> MimeFactory<'a> {
|
|||||||
)
|
)
|
||||||
.header(("Subject".to_string(), "...".to_string()))
|
.header(("Subject".to_string(), "...".to_string()))
|
||||||
} else {
|
} else {
|
||||||
|
let message = if headers.hidden.is_empty() {
|
||||||
|
message
|
||||||
|
} else {
|
||||||
|
// Store hidden headers in the inner unencrypted message.
|
||||||
|
let message = headers
|
||||||
|
.hidden
|
||||||
|
.into_iter()
|
||||||
|
.fold(message, |message, header| message.header(header));
|
||||||
|
|
||||||
|
PartBuilder::new()
|
||||||
|
.message_type(MimeMultipartType::Mixed)
|
||||||
|
.child(message.build())
|
||||||
|
};
|
||||||
|
|
||||||
|
// Store protected headers in the outer message.
|
||||||
headers
|
headers
|
||||||
.unprotected
|
.protected
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(message, |message, header| message.header(header))
|
.fold(message, |message, header| message.header(header))
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Store the unprotected headers on the outer message.
|
||||||
|
let outer_message = headers
|
||||||
|
.unprotected
|
||||||
|
.into_iter()
|
||||||
|
.fold(outer_message, |message, header| message.header(header));
|
||||||
|
|
||||||
let MimeFactory {
|
let MimeFactory {
|
||||||
last_added_location_id,
|
last_added_location_id,
|
||||||
..
|
..
|
||||||
|
|||||||
Reference in New Issue
Block a user