Hide SIJÚ messenger footer

This commit is contained in:
Alexander Krotov
2020-08-07 23:17:08 +03:00
parent 35c250c705
commit ac72280e69
3 changed files with 15 additions and 12 deletions

View File

@@ -2475,7 +2475,7 @@ mod tests {
"haeclirth.sinoenrat@yahoo.com", "haeclirth.sinoenrat@yahoo.com",
"1680295672.3657931.1591783872936@mail.yahoo.com", "1680295672.3657931.1591783872936@mail.yahoo.com",
include_bytes!("../test-data/message/yahoo_ndn.eml"), include_bytes!("../test-data/message/yahoo_ndn.eml"),
"Failure Notice Sorry, we were unable to deliver your message to the following address.\n\n<haeclirth.sinoenrat@yahoo.com>:\n554: delivery error: dd Not a valid recipient - atlas117.free.mail.ne1.yahoo.com" "Failure Notice Sorry, we were unable to deliver your message to the following address.\n\n<haeclirth.sinoenrat@yahoo.com>:\n554: delivery error: dd Not a valid recipient - atlas117.free.mail.ne1.yahoo.com [...]"
) )
.await; .await;
} }
@@ -2499,7 +2499,7 @@ mod tests {
"snaerituhaeirns@gmail.com", "snaerituhaeirns@gmail.com",
"9c9c2a32-056b-3592-c372-d7e8f0bd4bc2@gmx.de", "9c9c2a32-056b-3592-c372-d7e8f0bd4bc2@gmx.de",
include_bytes!("../test-data/message/gmx_ndn.eml"), include_bytes!("../test-data/message/gmx_ndn.eml"),
"Mail delivery failed: returning message to sender This message was created automatically by mail delivery software.\n\nA message that you sent could not be delivered to one or more of\nits recipients. This is a permanent error. The following address(es)\nfailed:\n\nsnaerituhaeirns@gmail.com:\nSMTP error from remote server for RCPT TO command, host: gmail-smtp-in.l.google.com (66.102.1.27) reason: 550-5.1.1 The email account that you tried to reach does not exist. Please\n try\n550-5.1.1 double-checking the recipient\'s email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1 https://support.google.com/mail/?p=NoSuchUser f6si2517766wmc.21\n9 - gsmtp" "Mail delivery failed: returning message to sender This message was created automatically by mail delivery software.\n\nA message that you sent could not be delivered to one or more of\nits recipients. This is a permanent error. The following address(es)\nfailed:\n\nsnaerituhaeirns@gmail.com:\nSMTP error from remote server for RCPT TO command, host: gmail-smtp-in.l.google.com (66.102.1.27) reason: 550-5.1.1 The email account that you tried to reach does not exist. Please\n try\n550-5.1.1 double-checking the recipient\'s email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1 https://support.google.com/mail/?p=NoSuchUser f6si2517766wmc.21\n9 - gsmtp [...]"
) )
.await; .await;
} }

View File

@@ -1007,13 +1007,10 @@ impl MimeMessage {
} }
if let Some(failure_report) = &self.failure_report { if let Some(failure_report) = &self.failure_report {
let error = parts.iter().find(|p| p.typ == Viewtype::Text).map(|p| { let error = parts
let msg = &p.msg; .iter()
msg.find("\n--- ") .find(|p| p.typ == Viewtype::Text)
.and_then(|footer_start| msg.get(..footer_start)) .map(|p| p.msg.clone());
.unwrap_or(msg)
.trim()
});
message::handle_ndn(context, failure_report, error).await message::handle_ndn(context, failure_report, error).await
} }
} }

View File

@@ -46,9 +46,7 @@ fn remove_message_footer<'a>(lines: &'a [&str]) -> &'a [&'a str] {
fn remove_nonstandard_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) { fn remove_nonstandard_footer<'a>(lines: &'a [&str]) -> (&'a [&'a str], bool) {
for (ix, &line) in lines.iter().enumerate() { for (ix, &line) in lines.iter().enumerate() {
if line == "--" if line == "--"
|| line == "---" || line.starts_with("---")
|| line == "----"
|| line.starts_with("-----")
|| line.starts_with("_____") || line.starts_with("_____")
|| line.starts_with("=====") || line.starts_with("=====")
|| line.starts_with("*****") || line.starts_with("*****")
@@ -336,9 +334,17 @@ mod tests {
let (plain, _) = simplify(escaped, true); let (plain, _) = simplify(escaped, true);
assert_eq!(plain, "text\n\n--\ntreated as footer when unescaped"); assert_eq!(plain, "text\n\n--\ntreated as footer when unescaped");
// Nonstandard footer sent by https://siju.es/
let input = "Message text here\n---Desde mi teléfono con SIJÚ\n\nQuote here".to_string();
let (plain, _) = simplify(input.clone(), false);
assert_eq!(plain, "Message text here [...]");
let (plain, _) = simplify(input.clone(), true);
assert_eq!(plain, input);
let input = "--\ntreated as footer when unescaped".to_string(); let input = "--\ntreated as footer when unescaped".to_string();
let (plain, _) = simplify(input.clone(), true); let (plain, _) = simplify(input.clone(), true);
assert_eq!(plain, ""); // see remove_message_footer() for some explanations assert_eq!(plain, ""); // see remove_message_footer() for some explanations
let escaped = escape_message_footer_marks(&input); let escaped = escape_message_footer_marks(&input);
let (plain, _) = simplify(escaped, true); let (plain, _) = simplify(escaped, true);
assert_eq!(plain, "--\ntreated as footer when unescaped"); assert_eq!(plain, "--\ntreated as footer when unescaped");