File Coverage

blib/lib/Mail/BIMI/Error.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 29 29 100.0


line stmt bran cond sub pod time code
1             package Mail::BIMI::Error;
2             # ABSTRACT: Class to represent an error condition
3             our $VERSION = '3.20210301'; # VERSION
4 30     30   419 use 5.20.0;
  30         98  
5 30     30   157 use Moose;
  30         67  
  30         206  
6 30     30   187036 use Moose::Util::TypeConstraints;
  30         69  
  30         272  
7 30     30   61661 use Mail::BIMI::Prelude;
  30         76  
  30         233  
8              
9             my %ERROR_MAP = (
10             BIMI_INVALID => { description => 'Invalid BIMI Record' },
11             BIMI_NOT_ENABLED => { description => 'Domain is not BIMI enabled' },
12             CODE_MISSING_AUTHORITY => { description => 'No authority specified', result => 'temperror' },
13             CODE_MISSING_LOCATION => { description => 'No location specified', result => 'temperror' },
14             CODE_NOTHING_TO_VALIDATE => { description => 'Nothing To Validate', result => 'temperror' },
15             CODE_NO_DATA => { description => 'No Data', result => 'temperror' },
16             DMARC_NOT_ENFORCING => { description => 'DMARC Policy is not at enforcement', result => 'skipped' },
17             DMARC_NOT_PASS => { description => 'DMARC did not pass', result => 'skipped' },
18             DNS_ERROR => { description => 'DNS query error', result => 'temperror' },
19             DUPLICATE_KEY => { description => 'Duplicate key in record' },
20             EMPTY_L_TAG => { description => 'Domain declined to participate', result => 'declined' },
21             EMPTY_V_TAG => { description => 'Empty v tag' },
22             INVALID_TRANSPORT_A => { description => 'Invalid transport in authority' },
23             INVALID_TRANSPORT_L => { description => 'Invalid transport in location' },
24             INVALID_V_TAG => { description => 'Invalid v tag' },
25             MISSING_L_TAG => { description => 'Missing l tag' },
26             MISSING_V_TAG => { description => 'Missing v tag' },
27             MULTIPLE_AUTHORITIES => { description => 'Multiple entries for a found' },
28             MULTIPLE_LOCATIONS => { description => 'Multiple entries for l found' },
29             MULTI_BIMI_RECORD => { description => 'Multiple BIMI records found' },
30             NO_BIMI_RECORD => { description => 'No BIMI records found', result => 'none' },
31             NO_DMARC => { description => 'No DMARC', result => 'skipped' },
32             SPF_PLUS_ALL => { description => 'SPF +all detected', result => 'skipped' },
33             SVG_FETCH_ERROR => { description => 'Could not fetch SVG', result => 'temperror' },
34             SVG_GET_ERROR => { description => 'Could not fetch SVG', result => 'temperror' },
35             SVG_INVALID_XML => { description => 'Invalid XML in SVG' },
36             SVG_MISMATCH => { description => 'SVG in bimi-location did not match SVG in VMC' },
37             SVG_SIZE => { description => 'SVG Document exceeds maximum size' },
38             SVG_UNZIP_ERROR => { description => 'Error unzipping SVG' },
39             SVG_VALIDATION_ERROR => { description => 'SVG did not validate' },
40             VMC_EXPIRED => { description => 'VMC has expired' },
41             VMC_FETCH_ERROR => { description => 'Could not fetch VMC', result => 'temperror' },
42             VMC_PARSE_ERROR => { description => 'Could not parse VMC' },
43             VMC_REQUIRED => { description => 'VMC is required' },
44             VMC_VALIDATION_ERROR => { description => 'VMC did not validate' },
45             );
46              
47             has code => ( is => 'ro', isa => enum([sort keys %ERROR_MAP]), required => 1,
48             documentation => 'inputs: Error code', );
49             has detail => ( is => 'ro', isa => 'Str', required => 0,
50             documentation => 'inputs: Human readable details', );
51              
52              
53 58     58 1 115 sub description($self) {
  58         95  
  58         85  
54 58         1308 return $ERROR_MAP{$self->code}->{description};
55             }
56              
57              
58 13     13 1 45 sub result($self) {
  13         29  
  13         26  
59 13 100       325 return exists $ERROR_MAP{$self->code}->{result} ? $ERROR_MAP{$self->code}->{result} : 'fail';
60             }
61              
62              
63             1;
64              
65             __END__
66              
67             =pod
68              
69             =encoding UTF-8
70              
71             =head1 NAME
72              
73             Mail::BIMI::Error - Class to represent an error condition
74              
75             =head1 VERSION
76              
77             version 3.20210301
78              
79             =head1 DESCRIPTION
80              
81             Class for representing an error condition
82              
83             =head1 INPUTS
84              
85             These values are used as inputs for lookups and verifications, they are typically set by the caller based on values found in the message being processed
86              
87             =head2 code
88              
89             is=ro required
90              
91             Error code
92              
93             =head2 detail
94              
95             is=ro
96              
97             Human readable details
98              
99             =head1 EXTENDS
100              
101             =over 4
102              
103             =item * L<Moose::Object>
104              
105             =back
106              
107             =head1 METHODS
108              
109             =head2 I<description()>
110              
111             Return the human readable description for this class of error
112              
113             =head2 I<result()>
114              
115             Return the Authentication-Results bimi= result for this class of error
116              
117             =head1 REQUIRES
118              
119             =over 4
120              
121             =item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude>
122              
123             =item * L<Moose|Moose>
124              
125             =item * L<Moose::Util::TypeConstraints|Moose::Util::TypeConstraints>
126              
127             =back
128              
129             =head1 AUTHOR
130              
131             Marc Bradshaw <marc@marcbradshaw.net>
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is copyright (c) 2020 by Marc Bradshaw.
136              
137             This is free software; you can redistribute it and/or modify it under
138             the same terms as the Perl 5 programming language system itself.
139              
140             =cut