2023-02-13 12:42:08 +00:00
|
|
|
use nu_test_support::nu_with_plugins;
|
2023-04-08 18:52:37 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2020-04-26 04:26:35 +00:00
|
|
|
|
|
|
|
const TEST_CWD: &str = "tests/fixtures/formats";
|
|
|
|
|
2023-02-13 12:42:08 +00:00
|
|
|
// Note: the tests can only run successfully if nushell binary is in `target/debug/`
|
2020-08-29 16:57:50 +00: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 04:26:35 +00:00
|
|
|
#[test]
|
|
|
|
fn from_eml_get_to_field() {
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 04:26:35 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get To.Address"
|
2020-04-26 04:26:35 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 16:57:50 +00:00
|
|
|
assert_eq!(actual.out, "to@example.com");
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 04:26:35 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get To | get Name"
|
2020-04-26 04:26:35 +00:00
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "");
|
2020-04-26 04:26:35 +00:00
|
|
|
}
|
|
|
|
|
2020-08-29 16:57:50 +00: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 04:26:35 +00:00
|
|
|
#[test]
|
|
|
|
fn from_eml_get_replyto_field() {
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 04:26:35 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Reply-To | get Address"
|
2020-04-26 04:26:35 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 16:57:50 +00:00
|
|
|
assert_eq!(actual.out, "replyto@example.com");
|
2020-04-26 04:26:35 +00:00
|
|
|
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 04:26:35 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Reply-To | get Name"
|
2020-04-26 04:26:35 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 16:57:50 +00:00
|
|
|
assert_eq!(actual.out, "replyto@example.com");
|
2020-04-26 04:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_eml_get_subject_field() {
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-04-26 04:26:35 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get Subject"
|
2020-04-26 04:26:35 +00:00
|
|
|
);
|
|
|
|
|
2020-08-29 16:57:50 +00:00
|
|
|
assert_eq!(actual.out, "Test Message");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn from_eml_get_another_header_field() {
|
2023-02-13 12:42:08 +00:00
|
|
|
let actual = nu_with_plugins!(
|
2020-08-29 16:57:50 +00:00
|
|
|
cwd: TEST_CWD,
|
2023-02-13 12:42:08 +00:00
|
|
|
plugin: ("nu_plugin_formats"),
|
|
|
|
"open sample.eml | get MIME-Version"
|
2020-08-29 16:57:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.0");
|
2020-04-26 04:26:35 +00:00
|
|
|
}
|