Skip to content

Commit

Permalink
fix: do not remove contents from Schleuder ML messages
Browse files Browse the repository at this point in the history
Before this fix actual contents of the message
reposted by Schleuder is considered a mailing list footer and removed,
not visible even in the "Show Full Message..." view.

With this change there will be two message bubbles,
one for header and one for the contents,
but it is still better than losing the contents completely.

Attempting to parse header part is out of scope for this change.
  • Loading branch information
link2xt committed Jan 5, 2024
1 parent 3bcdd17 commit da11542
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/headerdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub enum HeaderDef {
/// Mailing list ID defined in [RFC 2919](https://tools.ietf.org/html/rfc2919).
ListId,
ListPost,

/// List-Help header defined in [RFC 2369](https://datatracker.ietf.org/doc/html/rfc2369).
ListHelp,
References,

/// In-Reply-To header containing Message-ID of the parent message.
Expand Down
35 changes: 34 additions & 1 deletion src/mimeparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,15 @@ impl MimeMessage {
self.get_mailinglist_header().is_some()
}

/// Detects Schleuder mailing list by List-Help header.
pub(crate) fn is_schleuder_message(&self) -> bool {
if let Some(list_help) = self.get_header(HeaderDef::ListHelp) {
list_help == "<https://schleuder.org/>"
} else {
false
}
}

pub fn replace_msg_by_error(&mut self, error_msg: &str) {
self.is_system_message = SystemMessage::Unknown;
if let Some(part) = self.parts.first_mut() {
Expand Down Expand Up @@ -1593,8 +1602,12 @@ impl MimeMessage {
/// eg. when the user-edited-content is html.
/// As these footers would appear as repeated, separate text-bubbles,
/// we remove them.
///
/// We make an exception for Schleuder mailing lists
/// because they typically create messages with two text parts,
/// one for headers and one for the actual contents.
fn maybe_remove_inline_mailinglist_footer(&mut self) {
if self.is_mailinglist_message() {
if self.is_mailinglist_message() && !self.is_schleuder_message() {
let text_part_cnt = self
.parts
.iter()
Expand Down Expand Up @@ -3786,4 +3799,24 @@ Content-Disposition: reaction\n\

Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_schleuder() -> Result<()> {
let context = TestContext::new_alice().await;
let raw = include_bytes!("../test-data/message/schleuder.eml");

let msg = MimeMessage::from_bytes(&context.ctx, &raw[..], None)
.await
.unwrap();
assert_eq!(msg.parts.len(), 2);

// Header part.
assert_eq!(msg.parts[0].typ, Viewtype::Text);

// Actual contents part.
assert_eq!(msg.parts[1].typ, Viewtype::Text);
assert_eq!(msg.parts[1].msg, "hello,\nbye");

Ok(())
}
}
66 changes: 66 additions & 0 deletions test-data/message/schleuder.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Return-Path: <[email protected]>
Delivered-To: [email protected]
Date: Tue, 02 Jan 2024 05:00:00 +0000
From: [email protected]
Sender: [email protected]
To: [email protected]
Message-ID: <[email protected]>
In-Reply-To:
References:
Subject: [REPOST] Some subject
Mime-Version: 1.0
Content-Type: multipart/signed;
boundary="--==_mimepart_65938a80866e8_663a2abed9b585c064398";
micalg=pgp-sha1;
protocol="application/pgp-signature"
Content-Transfer-Encoding: 7bit
List-Id: <mailing-list.example.org>
List-Owner: <mailto:[email protected]> (Use list's public
key)
List-Help: <https://schleuder.org/>
List-Post: <mailto:[email protected]>

This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
----==_mimepart_65938a80866e8_663a2abed9b585c064398
Content-Type: multipart/mixed;
boundary="--==_mimepart_65938a8086476_663a2abed9b585c0642c7";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_65938a8086476_663a2abed9b585c0642c7
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
From: [email protected]
To: [email protected]
Cc:
Date: Tue, 02 Jan 2024 05:00:00 +0000
Sig: Unsigned
Enc: Unencrypted
----==_mimepart_65938a8086476_663a2abed9b585c0642c7
Content-Type: text/plain;
charset=utf-8
Content-Transfer-Encoding: quoted-printable
hello,
bye
----==_mimepart_65938a8086476_663a2abed9b585c0642c7--

----==_mimepart_65938a80866e8_663a2abed9b585c064398
Content-Type: application/pgp-signature;
name=signature.asc
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Description: OpenPGP digital signature
-----BEGIN PGP SIGNATURE-----

REDACTED
-----END PGP SIGNATURE-----

----==_mimepart_65938a80866e8_663a2abed9b585c064398--

0 comments on commit da11542

Please sign in to comment.