| 1 | package Mail::DKIM::Common; | ||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 13 | our $VERSION = '1.20240923'; # VERSION | |||||||||||||
| 5 | # ABSTRACT: Common class for Mail::DKIM | ||||||||||||||
| 6 | |||||||||||||||
| 7 | # Copyright 2005-2007 Messiah College. All rights reserved. | ||||||||||||||
| 8 | # Jason Long <jlong@messiah.edu> | ||||||||||||||
| 9 | |||||||||||||||
| 10 | # Copyright (c) 2004 Anthony D. Urso. All rights reserved. | ||||||||||||||
| 11 | # This program is free software; you can redistribute it and/or | ||||||||||||||
| 12 | # modify it under the same terms as Perl itself. | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 13 | ▶ | use Mail::Address; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 13 | ▶ | use base 'Mail::DKIM::MessageParser'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 13 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 18 | |||||||||||||||
| 19 | 298 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 20 | 298 | my $class = shift; | |||||||||||||
| 21 | 298 | return $class->new_object(@_); | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 3397 | ▶ | sub add_header { | ||||||||||||
|
Subroutine
add_header: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 25 | 3397 | my $self = shift; | |||||||||||||
| 26 | 3397 | my ($line) = @_; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 3397 | foreach my $algorithm ( @{ $self->{algorithms} } ) { | |||||||||||||
| 29 | 4444 | $algorithm->add_header($line); | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 3397 | ▶ | if ( $line =~ /^([^:]+?)\s*:(.*)/s ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 3395 | my $field_name = lc $1; | |||||||||||||
| 34 | 3395 | my $contents = $2; | |||||||||||||
| 35 | 3395 | $self->handle_header( $field_name, $contents, $line ); | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | 3397 | push @{ $self->{headers} }, $line; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | |||||||||||||||
| 40 | 290 | ▶ | sub add_body { | ||||||||||||
|
Subroutine
add_body: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||
| 41 | 290 | my $self = shift; | |||||||||||||
| 42 | 290 | ▶ | if ( $self->{algorithm} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 0 | $self->{algorithm}->add_body(@_); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | 290 | foreach my $algorithm ( @{ $self->{algorithms} } ) { | |||||||||||||
| 46 | 460 | $algorithm->add_body(@_); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 3395 | ▶ | sub handle_header { | ||||||||||||
|
Subroutine
handle_header: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 51 | 3395 | my $self = shift; | |||||||||||||
| 52 | 3395 | my ( $field_name, $contents, $line ) = @_; | |||||||||||||
| 53 | |||||||||||||||
| 54 | 3395 | push @{ $self->{header_field_names} }, $field_name; | |||||||||||||
| 55 | |||||||||||||||
| 56 | # TODO - detect multiple occurrences of From: or Sender: | ||||||||||||||
| 57 | # header and reject them | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 3395 | $self->{headers_by_name}->{$field_name} = $contents; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 299 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 63 | 299 | my $self = shift; | |||||||||||||
| 64 | 299 | $self->SUPER::init(@_); | |||||||||||||
| 65 | |||||||||||||||
| 66 | #initialize variables | ||||||||||||||
| 67 | 299 | $self->{headers} = []; | |||||||||||||
| 68 | 299 | $self->{headers_by_name} = {}; | |||||||||||||
| 69 | 299 | $self->{header_field_names} = []; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | sub load { | ||||||||||||
|
Subroutine
load: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||
| 74 | 0 | my ($fh) = @_; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | ▶ | while (<$fh>) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 77 | 0 | $self->PRINT($_); | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | 0 | $self->CLOSE; | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | 0 | ▶ | sub message_attributes { | ||||||||||||
|
Subroutine
message_attributes: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||
| 84 | 0 | my @attributes; | |||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | if ( my $message_id = $self->message_id ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 0 | push @attributes, "message-id=<$message_id>"; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | |||||||||||||||
| 90 | 0 | ▶ | if ( my $sig = $self->signature ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 0 | push @attributes, 'signer=<' . $sig->identity . '>'; | |||||||||||||
| 92 | } | ||||||||||||||
| 93 | |||||||||||||||
| 94 | 0 | ▶ | if ( $self->{headers_by_name}->{sender} ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 95 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); | |||||||||||||
| 96 | 0 | ▶ | if ( $list[0] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | 0 | push @attributes, 'sender=<' . $list[0]->address . '>'; | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | } | ||||||||||||||
| 100 | elsif ( $self->{headers_by_name}->{from} ) { | ||||||||||||||
| 101 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 102 | 0 | ▶ | if ( $list[0] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 103 | 0 | push @attributes, 'from=<' . $list[0]->address . '>'; | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | } | ||||||||||||||
| 106 | |||||||||||||||
| 107 | 0 | return @attributes; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | ▶ | sub message_id { | ||||||||||||
|
Subroutine
message_id: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||
| 112 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 113 | |||||||||||||||
| 114 | 0 | ▶ | if ( my $message_id = $self->{headers_by_name}->{'message-id'} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 0 | ▶ | if ( $message_id =~ /^\s*<(.*)>\s*$/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 116 | 0 | return $1; | |||||||||||||
| 117 | } | ||||||||||||||
| 118 | } | ||||||||||||||
| 119 | 0 | return undef; | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | ▶ | sub message_originator { | ||||||||||||
|
Subroutine
message_originator: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||
| 124 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 125 | |||||||||||||||
| 126 | 0 | ▶ | if ( $self->{headers_by_name}->{from} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 127 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 128 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 129 | } | ||||||||||||||
| 130 | 0 | return Mail::Address->new; | |||||||||||||
| 131 | } | ||||||||||||||
| 132 | |||||||||||||||
| 133 | 0 | ▶ | sub message_sender { | ||||||||||||
|
Subroutine
message_sender: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 134 | 0 | my $self = shift; | |||||||||||||
| 135 | 0 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 136 | |||||||||||||||
| 137 | 0 | ▶ | if ( $self->{headers_by_name}->{sender} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 138 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{sender} ); | |||||||||||||
| 139 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 140 | } | ||||||||||||||
| 141 | 0 | ▶ | if ( $self->{headers_by_name}->{from} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 142 | 0 | my @list = Mail::Address->parse( $self->{headers_by_name}->{from} ); | |||||||||||||
| 143 | 0 | ▶ | return $list[0] if @list; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 144 | } | ||||||||||||||
| 145 | 0 | return Mail::Address->new; | |||||||||||||
| 146 | } | ||||||||||||||
| 147 | |||||||||||||||
| 148 | 255 | ▶ | sub result { | ||||||||||||
|
Subroutine
result: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||
| 149 | 255 | my $self = shift; | |||||||||||||
| 150 | 255 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 151 | 255 | return $self->{result}; | |||||||||||||
| 152 | } | ||||||||||||||
| 153 | |||||||||||||||
| 154 | 100 | ▶ | sub result_detail { | ||||||||||||
|
Subroutine
result_detail: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||
| 155 | 100 | my $self = shift; | |||||||||||||
| 156 | 100 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 157 | |||||||||||||||
| 158 | 100 | ▶ | if ( $self->{details} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 159 | 63 | return $self->{result} . ' (' . $self->{details} . ')'; | |||||||||||||
| 160 | } | ||||||||||||||
| 161 | 37 | return $self->{result}; | |||||||||||||
| 162 | } | ||||||||||||||
| 163 | |||||||||||||||
| 164 | 28 | ▶ | sub signature { | ||||||||||||
|
Subroutine
signature: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||
| 165 | 28 | my $self = shift; | |||||||||||||
| 166 | 28 | ▶ | croak 'wrong number of arguments' unless ( @_ == 0 ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 167 | 28 | return $self->{signature}; | |||||||||||||
| 168 | } | ||||||||||||||
| 169 | |||||||||||||||
| 170 | 13 | 1; | |||||||||||||
| 171 | |||||||||||||||
| 172 | __END__ | ||||||||||||||