| 1 | package Mail::TLSRPT::Failure; | ||
| 2 | # ABSTRACT: TLSRPT failure object | ||
| 3 | our $VERSION = '1.20200303.1'; # VERSION | ||
| 4 | use 5.20.0; | ||
| 5 | use Moo; | ||
| 6 | use Carp; | ||
| 7 | use Types::Standard qw{Str Int HashRef ArrayRef}; | ||
| 8 | use Type::Utils qw{class_type}; | ||
| 9 | use Mail::TLSRPT::Pragmas; | ||
| 10 | has result_type => (is => 'rw', isa => Str); | ||
| 11 | has sending_mta_ip => (is => 'rw', isa => Str); | ||
| 12 | has receiving_mx_hostname => (is => 'rw', isa => Str); | ||
| 13 | has receiving_mx_helo => (is => 'rw', isa => Str); | ||
| 14 | has failed_session_count => (is => 'rw', isa => Int); | ||
| 15 | has additional_information => (is => 'rw', isa => Str); | ||
| 16 | has failure_reason_code => (is => 'rw', isa => Str); | ||
| 17 | |||
| 18 | sub new_from_data($class,$data) { | ||
| 19 | my $self = $class->new( | ||
| 20 | result_type => $data->{'result-type'} // '', | ||
| 21 | sending_mta_ip => $data->{'sending-mta-ip'} // '', | ||
| 22 | receiving_mx_hostname => $data->{'receiving-mx-hostname'} // '', | ||
| 23 | receiving_mx_helo => $data->{'receiving-mx-helo'} // '', | ||
| 24 | failed_session_count => $data->{'failed-session-count'} // 0, | ||
| 25 | additional_information => $data->{'additional-information'} // '', | ||
| 26 | failure_reason_code => $data->{'failure-reason-code'} // '', | ||
| 27 | ); | ||
| 28 | return $self; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub as_string($self) { | ||
| 32 | return join( "\n", | ||
| 33 | ' Failure:', | ||
| 34 | ' Result-Type: '.$self->result_type, | ||
| 35 | ' Sending-MTA-IP: '.$self->sending_mta_ip, | ||
| 36 | ' Receiving-MX-Hostname: '.$self->receiving_mx_hostname, | ||
| 37 | ' Receiving-MX-HELO: '.$self->receiving_mx_helo, | ||
| 38 | ' Failed-Session-Count: '.$self->failed_session_count, | ||
| 39 | ' Additional-Information: '.$self->additional_information, | ||
| 40 | ' Failure-Reason-Code: '.$self->failure_reason_code, | ||
| 41 | ); | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 |