2023-02-13 13:42:08 +01:00
|
|
|
use nu_test_support::nu_with_plugins;
|
2020-04-26 06:26:35 +02:00
|
|
|
|
|
|
|
const TEST_CWD: &str = "tests/fixtures/formats";
|
|
|
|
|
2023-02-13 13:42:08 +01:00
|
|
|
// Note: the tests can only run successfully if nushell binary is in `target/debug/`
|
2020-08-29 18:57:50 +02:00
|
|
|
// The To field in this email is just "to@example.com", which gets parsed out as the Address. The Name is empty.
|
2020-04-26 06:26:35 +02:00
|
|
|
#[test]
|
|
|
|
fn from_eml_get_to_field() {
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 06:26:35 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get To.Address"
|
2020-04-26 06:26:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-29 18:57:50 +02:00
|
|
|
assert_eq!(actual.out, "to@example.com");
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 06:26:35 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get To | get Name"
|
2020-04-26 06:26:35 +02:00
|
|
|
);
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "");
|
2020-04-26 06:26:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-29 18:57:50 +02:00
|
|
|
// The Reply-To field in this email is "replyto@example.com" <replyto@example.com>, meaning both the Name and Address values are identical.
|
2020-04-26 06:26:35 +02:00
|
|
|
#[test]
|
|
|
|
fn from_eml_get_replyto_field() {
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 06:26:35 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Reply-To | get Address"
|
2020-04-26 06:26:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-29 18:57:50 +02:00
|
|
|
assert_eq!(actual.out, "replyto@example.com");
|
2020-04-26 06:26:35 +02:00
|
|
|
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 06:26:35 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Reply-To | get Name"
|
2020-04-26 06:26:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-29 18:57:50 +02:00
|
|
|
assert_eq!(actual.out, "replyto@example.com");
|
2020-04-26 06:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_eml_get_subject_field() {
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 06:26:35 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Subject"
|
2020-04-26 06:26:35 +02:00
|
|
|
);
|
|
|
|
|
2020-08-29 18:57:50 +02:00
|
|
|
assert_eq!(actual.out, "Test Message");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_eml_get_another_header_field() {
|
2023-02-13 13:42:08 +01:00
|
|
|
let actual = nu_with_plugins!(
|
2020-08-29 18:57:50 +02:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 13:42:08 +01:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get MIME-Version"
|
2020-08-29 18:57:50 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.0");
|
2020-04-26 06:26:35 +02:00
|
|
|
}
|