pub struct Headers<'a> { /* private fields */ }
Expand description
A struct that wrapps the header portion of a message and provides utility functions to look up specific headers.
Implementations§
source§impl<'a> Headers<'a>
impl<'a> Headers<'a>
sourcepub fn get_raw_bytes(&self) -> &'a [u8] ⓘ
pub fn get_raw_bytes(&self) -> &'a [u8] ⓘ
Returns the raw, unparsed bytes that make up the header block of the message. This includes everything up to and including the empty line at the end of the header block.
§Examples
use mailparse::{parse_mail, headers::Headers};
let mail = parse_mail(concat!(
"SubJECT : foo\n",
"\n",
"Body starts here").as_bytes())
.unwrap();
assert_eq!(mail.get_headers().get_raw_bytes(), b"SubJECT : foo\n\n");
Trait Implementations§
source§impl<'a> Debug for Headers<'a>
impl<'a> Debug for Headers<'a>
Allows formatting and printing the Headers
struct items.
§Examples
use mailparse::parse_mail;
let mail = parse_mail(concat!(
"Subject: foo\n",
"Another header: bar\n",
"\n",
"Body starts here").as_bytes())
.unwrap();
let mut headers = mail.get_headers();
assert_eq!(format!("{:?}", headers), "Headers { \
headers: [MailHeader { key: \"Subject\", value: \"foo\" }, \
MailHeader { key: \"Another header\", value: \"bar\" }] }");
source§impl<'a> IntoIterator for Headers<'a>
impl<'a> IntoIterator for Headers<'a>
Allows iterating over the individual MailHeader
items in this block of
headers.
§Examples
use mailparse::{parse_mail, headers::Headers};
let mail = parse_mail(concat!(
"Subject: foo\n",
"Another header: bar\n",
"\n",
"Body starts here").as_bytes())
.unwrap();
let mut iter = mail.get_headers().into_iter();
assert_eq!(iter.next().unwrap().get_key(), "Subject");
assert_eq!(iter.next().unwrap().get_key(), "Another header");
source§impl<'a> MailHeaderMap for Headers<'a>
impl<'a> MailHeaderMap for Headers<'a>
source§fn get_first_value(&self, key: &str) -> Option<String>
fn get_first_value(&self, key: &str) -> Option<String>
§Examples
use mailparse::{parse_mail, MailHeaderMap, headers::Headers};
let mail = parse_mail(concat!(
"Subject: Test\n",
"\n",
"This is a test message").as_bytes())
.unwrap();
assert_eq!(mail.get_headers().get_first_value("Subject"), Some("Test".to_string()));
source§fn get_all_values(&self, key: &str) -> Vec<String>
fn get_all_values(&self, key: &str) -> Vec<String>
§Examples
use mailparse::{parse_mail, MailHeaderMap, headers::Headers};
let mail = parse_mail(concat!(
"Key: Value1\n",
"Key: Value2").as_bytes())
.unwrap();
assert_eq!(mail.get_headers().get_all_values("Key"),
vec!["Value1".to_string(), "Value2".to_string()]);
source§fn get_first_header(&self, key: &str) -> Option<&MailHeader<'_>>
fn get_first_header(&self, key: &str) -> Option<&MailHeader<'_>>
Similar to
get_first_value
, except it returns a reference to the
MailHeader struct instead of just extracting the value.source§fn get_all_headers(&self, key: &str) -> Vec<&MailHeader<'_>>
fn get_all_headers(&self, key: &str) -> Vec<&MailHeader<'_>>
Similar to
get_all_values
, except it returns references to the
MailHeader structs instead of just extracting the values.Auto Trait Implementations§
impl<'a> Freeze for Headers<'a>
impl<'a> RefUnwindSafe for Headers<'a>
impl<'a> Send for Headers<'a>
impl<'a> Sync for Headers<'a>
impl<'a> Unpin for Headers<'a>
impl<'a> UnwindSafe for Headers<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more