Add function to get all header keys from Email object#2
Conversation
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
afrantzis
left a comment
There was a problem hiding this comment.
Thanks for the patch! Adding such a function makes sense. I suggest we go with the following name (to match RFC terminology) and signature (to hide implementation details):
pub fn header_field_names(&self) -> Vec<&str>Also, could you please add a doc comment and test (see tests/test_fields.rs) for this?
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
|
If you're fine with the changes I'll fixup-rebase 😄 |
afrantzis
left a comment
There was a problem hiding this comment.
Thanks for the update. Besides a small test improvement (see inline comment), looks good.
| email.header_field_names() | ||
| .iter() | ||
| .all(|name| email.header_field(name).is_some()) | ||
| ); |
There was a problem hiding this comment.
We also need to check that what's returned by header_field_names is exhaustive (i.e., all field names present in the email are included).
There was a problem hiding this comment.
Doesn't the assertion do this? I mean, if one header_field_name is NOne when asking for header_field(header_field_name), that assert fails, right?
There was a problem hiding this comment.
The current assertion correctly checks that all names returned by header_field_names() are proper/present field names, but not that these names are the full list of names present in the email. For example, if the header contains "To", "Cc", "From" fields, but due to some bug header_field_names() returns only "To" and "Cc", this test will still pass.
This is helpful if the user of the
Emailobject does not know which headers exist.