i18n: encode subject in mails, if necessary

This commit is contained in:
Vincent Breitmoser 2019-10-03 17:19:36 +02:00
parent cdc1afb6d1
commit 5704ac4434
No known key found for this signature in database
GPG Key ID: 7BD18320DEADFA11
7 changed files with 25 additions and 14 deletions

7
Cargo.lock generated
View File

@ -645,6 +645,7 @@ dependencies = [
"multipart 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rfc2047 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1656,6 +1657,11 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rfc2047"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ring"
version = "0.13.5"
@ -2498,6 +2504,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e"
"checksum rfc2047 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6986b5de4fa30c92b50020fdedf45bf9296d9842df4355b62f92dcc18bcdee15"
"checksum ring 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2c4db68a2e35f3497146b7e4563df7d4773a2433230c5e4b448328e31740458a"
"checksum rocket 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "42c1e9deb3ef4fa430d307bfccd4231434b707ca1328fae339c43ad1201cc6f7"
"checksum rocket_codegen 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "79aa1366f9b2eccddc05971e17c5de7bb75a5431eb12c2b5c66545fd348647f4"

View File

@ -39,6 +39,7 @@ gettext-macros = "0.5"
gettext = "0.4"
runtime-fmt = "0.4"
glob = "0.3"
rfc2047 = "0.1"
[dependencies.lettre]
version = "0.9"

View File

@ -15,15 +15,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: src/mail.rs:104
#: src/mail.rs:106
msgid "Verify {} for your key on {}"
msgstr "Bestätige {} für deinen Schlüssel auf {}"
#: src/mail.rs:131
#: src/mail.rs:133
msgid "Manage your key on {}"
msgstr "Schlüssel-Verwaltung auf {}"
#: src/mail.rs:158
#: src/mail.rs:160
msgid "Your key upload on {}"
msgstr "Hochgeladener Schlüssel auf {}"

View File

@ -12,15 +12,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: src/mail.rs:104
#: src/mail.rs:106
msgid "Verify {} for your key on {}"
msgstr "Verify {} for your key on {}"
#: src/mail.rs:131
#: src/mail.rs:133
msgid "Manage your key on {}"
msgstr "Manage your key on {}"
#: src/mail.rs:158
#: src/mail.rs:160
msgid "Your key upload on {}"
msgstr "Your key upload on {}"

View File

@ -12,15 +12,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
#: src/mail.rs:104
#: src/mail.rs:106
msgid "Verify {} for your key on {}"
msgstr ""
#: src/mail.rs:131
#: src/mail.rs:133
msgid "Manage your key on {}"
msgstr ""
#: src/mail.rs:158
#: src/mail.rs:160
msgid "Your key upload on {}"
msgstr ""

View File

@ -12,6 +12,8 @@ use crate::counters;
use rocket_i18n::I18n;
use gettext_macros::i18n;
use rfc2047::rfc2047_encode;
use crate::template_helpers;
use crate::database::types::Email;
@ -197,7 +199,7 @@ impl Service {
let email = EmailBuilder::new()
.from(self.from.clone())
.subject(subject)
.subject(rfc2047_encode(subject))
.alternative(html, txt)
.message_id(format!("<{}@{}>", Uuid::new_v4(), self.domain));

View File

@ -796,9 +796,10 @@ pub mod tests {
tpk.serialize(&mut tpk_serialized).unwrap();
let token = vks_publish_submit_get_token(&client, &tpk_serialized);
check_verify_link(&client, &token, "foo@invalid.example.com", "de, en");
check_verify_link(&client, &token, "foo@invalid.example.com", "de");
let mail_content = pop_mail(&filemail_into).unwrap().unwrap();
assert!(mail_content.contains("dies ist eine automatisierte Nachricht"))
assert!(mail_content.contains("dies ist eine automatisierte Nachricht"));
assert!(mail_content.contains("Subject: =?utf-8?q?Best=C3=A4tige?= foo@invalid.example.com\r\n\t=?utf-8?q?f=C3=BCr?= deinen =?utf-8?q?Schl=C3=BCssel?= auf local.connection"));
}
#[test]
@ -1177,7 +1178,6 @@ pub mod tests {
fn pop_mail_capture_pattern(filemail_path: &Path, pattern: &str) -> String {
let mail_content = pop_mail(filemail_path).unwrap().unwrap();
println!("{}", mail_content);
let capture_re = regex::bytes::Regex::new(pattern).unwrap();
let capture_content = capture_re.captures(mail_content.as_ref()).unwrap()
@ -1194,7 +1194,8 @@ pub mod tests {
let fh = fs::File::open(entry.path())?;
fs::remove_file(entry.path())?;
let mail: SerializableEmail = ::serde_json::from_reader(fh)?;
return Ok(Some(String::from_utf8_lossy(&mail.message).to_string()));
let body = String::from_utf8_lossy(&mail.message).to_string();
return Ok(Some(body));
}
}
Ok(None)