fix(headers): propagate the Content-Language header

This commit is contained in:
Phil Booth 2018-11-15 07:14:34 +00:00
Родитель 3e27866763
Коммит 67ebf3fe77
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 36FBB106F9C32516
4 изменённых файлов: 22 добавлений и 4 удалений

Просмотреть файл

@ -87,6 +87,7 @@ fn build_multipart_mime<'a>(
fn set_custom_header(message: MessageBuilder, name: &str, value: &str) -> MessageBuilder {
let lowercase_name = name.to_lowercase();
match lowercase_name.as_str() {
"content-language" => message.header(ContentLanguage::new(value.to_owned())),
"x-device-id" => message.header(DeviceId::new(value.to_owned())),
"x-email-sender" => message.header(EmailSender::new(value.to_owned())),
"x-email-service" => message.header(EmailService::new(value.to_owned())),

Просмотреть файл

@ -34,11 +34,14 @@ fn build_mime_without_optional_data() {
#[test]
fn build_mime_with_cc_headers() {
let mut headers = HashMap::new();
headers.insert("Content-Language".to_owned(), "en-gb".to_owned());
headers.insert("x-verify-code".to_owned(), "wibble".to_owned());
let message = build_multipart_mime(
"a@a.com",
"b@b.com",
&["c@c.com", "d@d.com"],
None,
Some(&headers),
"subject",
"body",
None,
@ -54,9 +57,15 @@ fn build_mime_with_cc_headers() {
assert_eq!("Subject: subject", &message[3]);
assert_eq!("MIME-Version: 1.0", &message[4]);
assert_eq!("Cc: c@c.com, d@d.com", &message[5]);
assert_eq!("Content-Transfer-Encoding: quoted-printable", &message[12]);
assert_eq!("Content-Type: text/plain; charset=utf-8", &message[13]);
assert_eq!("body", &message[15]);
if message[6] == "Content-Language: en-gb" {
assert_eq!("X-Verify-Code: wibble", &message[7]);
} else {
assert_eq!("X-Verify-Code: wibble", &message[6]);
assert_eq!("Content-Language: en-gb", &message[7]);
}
assert_eq!("Content-Transfer-Encoding: quoted-printable", &message[14]);
assert_eq!("Content-Type: text/plain; charset=utf-8", &message[15]);
assert_eq!("body", &message[17]);
}
#[test]

Просмотреть файл

@ -73,6 +73,7 @@ macro_rules! custom_header {
};
}
custom_header!(ContentLanguage, "Content-Language");
custom_header!(DeviceId, "X-Device-Id");
custom_header!(EmailSender, "X-Email-Sender");
custom_header!(EmailService, "X-Email-Service");

Просмотреть файл

@ -4,6 +4,13 @@
use super::*;
#[test]
fn content_language() {
let header = ContentLanguage::new("en-gb".to_owned());
assert_eq!(header.to_string(), "en-gb");
assert_eq!(ContentLanguage::header_name(), "Content-Language");
}
#[test]
fn device_id() {
let header = DeviceId::new("wibble".to_owned());