| 1 | package Mail::DKIM::MessageParser; | ||||||||||||||
| 2 | 15 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 15 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 15 | our $VERSION = '1.20240923'; # VERSION | |||||||||||||
| 5 | # ABSTRACT: Signs/verifies Internet mail with DKIM/DomainKey signatures | ||||||||||||||
| 6 | |||||||||||||||
| 7 | # Copyright 2005 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 | 15 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 1245 | ▶ | sub new_object { | ||||||||||||
|
Subroutine
new_object: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 17 | 1245 | my $class = shift; | |||||||||||||
| 18 | 1245 | return $class->TIEHANDLE(@_); | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | sub new_handle { | ||||||||||||
|
Subroutine
new_handle: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 22 | 0 | my $class = shift; | |||||||||||||
| 23 | 0 | local *TMP; | |||||||||||||
| 24 | 0 | tie *TMP, $class, @_; | |||||||||||||
| 25 | 0 | return *TMP; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 1245 | ▶ | sub TIEHANDLE { | ||||||||||||
|
Subroutine
TIEHANDLE: called CC=1 SCAR=0.0
| |||||||||||||||
| 29 | 1245 | my $class = shift; | |||||||||||||
| 30 | 1245 | my %args = @_; | |||||||||||||
| 31 | 1245 | my $self = bless \%args, $class; | |||||||||||||
| 32 | 1245 | $self->init; | |||||||||||||
| 33 | 1243 | return $self; | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 1245 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 37 | 1245 | my $self = shift; | |||||||||||||
| 38 | |||||||||||||||
| 39 | 1245 | my $buf = ''; | |||||||||||||
| 40 | 1245 | $self->{buf_ref} = \$buf; | |||||||||||||
| 41 | 1245 | $self->{in_header} = 1; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 296 | ▶ | sub PRINT { | ||||||||||||
|
Subroutine
PRINT: called CC=9 SCAR=22.0
| |||||||||||||||
| 45 | 296 | my $self = shift; | |||||||||||||
| 46 | 296 | my $buf_ref = $self->{buf_ref}; | |||||||||||||
| 47 | 296 | ▶ | $$buf_ref .= @_ == 1 ? $_[0] : join( '', @_ ) if @_; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 296 | ▶ | if ( $self->{in_header} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 296 | local $1; # avoid polluting a global $1 | |||||||||||||
| 51 | 296 | ▶ | while ( $$buf_ref ne '' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | 3688 | ▶ | if ( substr( $$buf_ref, 0, 2 ) eq "\015\012" ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 291 | substr( $$buf_ref, 0, 2 ) = ''; | |||||||||||||
| 54 | 291 | $self->finish_header(); | |||||||||||||
| 55 | 291 | $self->{in_header} = 0; | |||||||||||||
| 56 | 291 | last; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | 3397 | ▶ | if ( $$buf_ref !~ /^(.+?\015\012)[^\ \t]/s ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 4 | last; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | 3393 | my $header = $1; | |||||||||||||
| 62 | 3393 | $self->add_header($header); | |||||||||||||
| 63 | 3393 | substr( $$buf_ref, 0, length($header) ) = ''; | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 296 | ▶ | if ( !$self->{in_header} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 291 | my $j = rindex( $$buf_ref, "\015\012" ); | |||||||||||||
| 69 | 291 | ▶ | if ( $j >= 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | |||||||||||||||
| 71 | # avoid copying a large buffer: the unterminated | ||||||||||||||
| 72 | # last line is typically short compared to the rest | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 290 | my $carry = substr( $$buf_ref, $j + 2 ); | |||||||||||||
| 75 | 290 | substr( $$buf_ref, $j + 2 ) = ''; # shrink to last CRLF | |||||||||||||
| 76 | 290 | $self->add_body($$buf_ref); # must end on CRLF | |||||||||||||
| 77 | 290 | $$buf_ref = $carry; # restore unterminated last line | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | } | ||||||||||||||
| 80 | 296 | return 1; | |||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | 296 | ▶ | sub CLOSE { | ||||||||||||
|
Subroutine
CLOSE: called CC=4 SCAR=13.9
| |||||||||||||||
| 84 | 296 | my $self = shift; | |||||||||||||
| 85 | 296 | my $buf_ref = $self->{buf_ref}; | |||||||||||||
| 86 | |||||||||||||||
| 87 | 296 | ▶ | if ( $self->{in_header} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 88 | 5 | ▶ | if ( $$buf_ref ne '' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | |||||||||||||||
| 90 | # A line of header text ending CRLF would not have been | ||||||||||||||
| 91 | # processed yet since before we couldn't tell if it was | ||||||||||||||
| 92 | # the complete header. Now that we're in CLOSE, we can | ||||||||||||||
| 93 | # finish the header... | ||||||||||||||
| 94 | 4 | $$buf_ref =~ s/\015\012\z//s; | |||||||||||||
| 95 | 4 | $self->add_header("$$buf_ref\015\012"); | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | 5 | $self->finish_header; | |||||||||||||
| 98 | 5 | $self->{in_header} = 0; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | else { | ||||||||||||||
| 101 | 291 | ▶ | if ( $$buf_ref ne '' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | 0 | $self->add_body($$buf_ref); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | } | ||||||||||||||
| 105 | 296 | $$buf_ref = ''; | |||||||||||||
| 106 | 296 | $self->finish_body; | |||||||||||||
| 107 | 296 | return 1; | |||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 0 | ▶ | sub add_header { | ||||||||||||
|
Subroutine
add_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 111 | 0 | die 'add_header not implemented'; | |||||||||||||
| 112 | } | ||||||||||||||
| 113 | |||||||||||||||
| 114 | 0 | ▶ | sub finish_header { | ||||||||||||
|
Subroutine
finish_header: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 115 | 0 | die 'finish_header not implemented'; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 0 | ▶ | sub add_body { | ||||||||||||
|
Subroutine
add_body: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 119 | 0 | die 'add_body not implemented'; | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 0 | ▶ | sub finish_body { | ||||||||||||
|
Subroutine
finish_body: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 123 | |||||||||||||||
| 124 | # do nothing by default | ||||||||||||||
| 125 | } | ||||||||||||||
| 126 | |||||||||||||||
| 127 | 0 | ▶ | sub reset { | ||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 128 | 0 | carp 'reset not implemented'; | |||||||||||||
| 129 | } | ||||||||||||||
| 130 | |||||||||||||||
| 131 | 15 | 1; | |||||||||||||
| 132 | |||||||||||||||
| 133 | __END__ | ||||||||||||||