Module: Gravaty::Utils::Rfc5322

Defined in:
lib/gravaty/utils/rfc5322.rb

Overview

This module is a simple wrapper container for Peter R. Marreck’s gist.

Author

Peter R. Marreck

rubocop:disable Style/AsciiComments

Copyright

Copyleft (©) 2013, Peter R. Marreck

rubocop:enable Style/AsciiComments

License

This work is released under the BSD 3-Clause License

choosealicense.com/licenses/bsd-3-clause/

Constant Summary collapse

EMAIL =

This work is released under the BSD 3-Clause License choosealicense.com/licenses/bsd-3-clause/ rubocop:disable Style/AsciiComments Copyleft (©) 2013, Peter R. Marreck rubocop:enable Style/AsciiComments All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

%r{
    (?<addr_spec> (?> \g<local_part> @ \g<domain> ) ){0}
    (?<local_part> (?> \g<dot_atom> | \g<quoted_string> | \g<obs_local_part> ) ){0}
    (?<domain> (?> \g<dot_atom> | \g<domain_literal> | \g<obs_domain> ) ){0}
    (?<domain_literal> (?> \g<CFWS>? \[ (?: \g<FWS>? \g<dtext> )* \g<FWS>? \] \g<CFWS>? ) ){0}
    (?<dtext> (?> [\x21-\x5a] | [\x5e-\x7e] | \g<obs_dtext> ) ){0}
    (?<quoted_pair> (?> \\ (?: \g<VCHAR> | \g<WSP> ) | \g<obs_qp> ) ){0}
    (?<dot_atom> (?> \g<CFWS>? \g<dot_atom_text> \g<CFWS>? ) ){0}
    (?<dot_atom_text> (?> \g<atext> (?: \. \g<atext> )* ) ){0}
    (?<atext> (?> [a-zA-Z0-9!\#\$%&'*\+/\=\?\^_`{\|}~\-]+ ) ){0}
    (?<atom> (?> \g<CFWS>? \g<atext> \g<CFWS>? ) ){0}
    (?<word> (?> \g<atom> | \g<quoted_string> ) ){0}
    (?<quoted_string> (?> \g<CFWS>? " (?: \g<FWS>? \g<qcontent> )* \g<FWS>? " \g<CFWS>? ) ){0}
    (?<qcontent> (?> \g<qtext> | \g<quoted_pair> ) ){0}
    (?<qtext> (?> \x21 | [\x23-\x5b] | [\x5d-\x7e] | \g<obs_qtext> ) ){0}

    # comments and whitespace
    (?<FWS> (?> (?: \g<WSP>* \r\n )? \g<WSP>+ | \g<obs_FWS> ) ){0}
    (?<CFWS> (?> (?: \g<FWS>? \g<comment> )+ \g<FWS>? | \g<FWS> ) ){0}
    (?<comment> (?> \( (?: \g<FWS>? \g<ccontent> )* \g<FWS>? \) ) ){0}
    (?<ccontent> (?>\g<ctext> | \g<quoted_pair> | \g<comment> ) ){0}
    (?<ctext> (?> [\x21-\x27] | [\x2a-\x5b] | [\x5d-\x7e] | \g<obs_ctext> ) ){0}

    # obsolete tokens
    (?<obs_domain> (?> \g<atom> (?: \. \g<atom> )* ) ){0}
    (?<obs_local_part> (?> \g<word> (?: \. \g<word> )* ) ){0}
    (?<obs_dtext> (?> \g<obs_NO_WS_CTL> | \g<quoted_pair> ) ){0}
    (?<obs_qp> (?> \\ (?: \x00 | \g<obs_NO_WS_CTL> | \n | \r ) ) ){0}
    (?<obs_FWS> (?> \g<WSP>+ (?: \r\n \g<WSP>+ )* ) ){0}
    (?<obs_ctext> (?> \g<obs_NO_WS_CTL> ) ){0}
    (?<obs_qtext> (?> \g<obs_NO_WS_CTL> ) ){0}
    (?<obs_NO_WS_CTL> (?> [\x01-\x08] | \x0b | \x0c | [\x0e-\x1f] | \x7f ) ){0}

    # character class definitions
    (?<VCHAR> (?> [\x21-\x7E] ) ){0}
    (?<WSP> [ \t] ){0}
  \g<addr_spec>
}uix