« blib/lib/Mail/AuthenticationResults/Parser.pm
↑ Summary
blib/lib/Mail/AuthenticationResults/Header/Base.pm »
| 1 | package Mail::AuthenticationResults::Token::String; | ||
| 2 | # ABSTRACT: Class for modelling AuthenticationResults Header parts detected as strings | ||
| 3 | |||
| 4 | require 5.008; | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | our $VERSION = '2.20260216'; # VERSION | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | use base 'Mail::AuthenticationResults::Token'; | ||
| 11 | |||
| 12 | |||
| 13 | sub is { | ||
| 14 | my ( $self ) = @_; | ||
| 15 | return 'string'; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub parse { | ||
| 19 | my ($self) = @_; | ||
| 20 | |||
| 21 | my $header = $self->{ 'header' }; | ||
| 22 | my $value = q{}; | ||
| 23 | |||
| 24 | croak 'Not a string' if $header =~ /^"/; | ||
| 25 | croak 'Not a string' if $header =~ /^\(/; | ||
| 26 | |||
| 27 | # Parse differently if we are post assignment (we are a value) or not (we are likely a key or key part) | ||
| 28 | my $is_value = 0; | ||
| 29 | my $is_first = 0; | ||
| 30 | if ( exists ( $self->{ 'args' }->{ 'last_non_comment_type' } ) ) { | ||
| 31 | if ( $self->{ 'args' }->{ 'last_non_comment_type' }->is() eq 'assignment' ) { | ||
| 32 | if ( $self->{ 'args' }->{ 'last_non_comment_type' }->value() eq '=' ) { | ||
| 33 | $is_value = 1; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
| 37 | else { | ||
| 38 | $is_first = 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | while ( length $header > 0 ) { | ||
| 42 | my $first = substr( $header,0,1 ); | ||
| 43 | last if $first =~ /\s/; | ||
| 44 | last if $first eq ';'; | ||
| 45 | last if $first eq '"' && ! $is_value && ! $is_first; | ||
| 46 | last if $first eq '(' && ! $is_value && ! $is_first; | ||
| 47 | last if $first eq '=' && ! $is_value && ! $is_first; | ||
| 48 | last if $first eq '/' && ! $is_value && ! $is_first; | ||
| 49 | last if $first eq '.' && ! $is_value && ! $is_first; | ||
| 50 | |||
| 51 | $value .= $first; | ||
| 52 | $header = substr( $header,1 ); | ||
| 53 | } | ||
| 54 | |||
| 55 | croak 'Not a string' if $value eq q{}; | ||
| 56 | |||
| 57 | $self->{ 'value' } = $value; | ||
| 58 | $self->{ 'header' } = $header; | ||
| 59 | |||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | 1; | ||
| 64 | |||
| 65 | __END__ |