Struct email::rfc5322::Rfc5322Parser [] [src]

pub struct Rfc5322Parser<'s> {
    // some fields omitted
}

RFC 5322 base parser for parsing atom, dot-atom, quoted-string, phrase, message

This should prove useful for parsing other things that appear in RFC 5322, as most are based off these core items.

It also implements a stack for tracking the position. This allows the simple implementation of backtracking, by pushing the position before a test and popping it if the test should fail. [unstable]

Methods

impl<'s> Rfc5322Parser<'s>

fn new(source: &'s str) -> Rfc5322Parser<'s>

Make a new parser, initialized with the given string. [unstable]

fn push_position(&mut self)

Push the current position onto the stack. [unstable]

fn pop_position(&mut self)

Move the position back to the last entry pushed [unstable]

fn consume_message(&mut self) -> Option<(HeaderMap, String)>

Consume a message from the input.

Returns as a map of the headers and the body text.

A message is defined as:

fields = *field body = text message = fields CRLF body [unstable]

fn consume_header(&mut self) -> Option<Header>

Consume a header from the input.

A header is defined as:

ftext = "!".."9" / ";".."~" field-name = 1*ftext field = field-name *LWSP ":" unstructured [unstable]

fn consume_unstructured(&mut self) -> String

Consume an unstructured from the input. [unstable]

fn consume_folding_whitespace(&mut self) -> bool

Consume folding whitespace.

This is a CRLF followed by one or more whitespace character.

Returns true if whitespace was consume [unstable]

fn consume_word(&mut self, allow_dot_atom: bool) -> Option<String>

Consume a word from the input.

A word is defined as:

word = atom / quoted-string

If allow_dot_atom is true, then atom can be a dot-atom in this phrase. [unstable]

fn consume_phrase(&mut self, allow_dot_atom: bool) -> Option<String>

Consume a phrase from the input.

A phrase is defined as:

phrase = 1*word

If allow_dot_atom is true, then atom can be a dot-atom in this phrase. [unstable]

fn consume_quoted_string(&mut self) -> Option<String>

Consume a quoted string from the input [unstable]

fn consume_atom(&mut self, allow_dot: bool) -> Option<String>

Consume an atom from the input.

If allow_dot is true, then also allow '.' to be considered as an atext character. [unstable]

fn consume_linear_whitespace(&mut self)

Consume LWSP (Linear whitespace) [unstable]

fn consume_char(&mut self) -> Option<char>

Consume a single character from the input. [unstable]

fn consume_linebreak(&mut self) -> bool

[unstable]

fn peek_linebreak(&mut self) -> bool

[unstable]

fn consume_while<F: Fn(char) -> bool>(&mut self, test: F) -> String

Consume a set of characters, each passed to test until this function returns false.

The position after calling this function will be pointing to the character which caused a false result from test.

Returns the string of characters that returned true for the test function. [unstable]

fn peek(&self) -> char

Peek at the current character.

Note that this does not do any bounds checking. [unstable]

fn assert_char(&self, c: char) -> ParsingResult<()>

Check that !self.eof() && self.peek() == c [unstable]

fn assert_not_eof(&self) -> ParsingResult<()>

Check that we have not reached the end of the input. [unstable]

fn peek_to_end(&self) -> &str

Get the unconsumed string. Should only be used for debugging purposes! [unstable]

fn eof(&self) -> bool

Returns true if we have reached the end of the input. [unstable]