line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Pyzor::Digest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2018 cPanel, LLC. |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
# http://cpanel.net |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the |
8
|
|
|
|
|
|
|
# Apache 2.0 license. |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
172039
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding utf-8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Mail::Pyzor::Digest |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $digest = Mail::Pyzor::Digest::get( $mime_text ); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
A reimplementation of L. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
608
|
use Email::MIME (); |
|
1
|
|
|
|
|
58885
|
|
|
1
|
|
|
|
|
26
|
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
491
|
use Mail::Pyzor::Digest::Pieces (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
34
|
1
|
|
|
1
|
|
454
|
use Mail::Pyzor::SHA (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
216
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#---------------------------------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 FUNCTIONS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 $hex = get( $MSG ) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This takes an email message in raw MIME text format (i.e., as saved in the |
43
|
|
|
|
|
|
|
standard mbox format) and returns the message’s Pyzor digest in lower-case |
44
|
|
|
|
|
|
|
hexadecimal. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The output from this function should normally be identical to that of |
47
|
|
|
|
|
|
|
the C script’s C command. It is suitable for use in |
48
|
|
|
|
|
|
|
L’s request methods. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub get { |
53
|
0
|
|
|
0
|
1
|
|
return Mail::Pyzor::SHA::sha1_hex( ${ _get_predigest( $_[0] ) } ); |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# NB: This is called from the test. |
57
|
|
|
|
|
|
|
sub _get_predigest { ## no critic qw(RequireArgUnpacking) |
58
|
0
|
|
|
0
|
|
|
my ($msg_text_sr) = \$_[0]; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $parsed = Email::MIME->new($$msg_text_sr); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my @lines; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $payloads_ar = Mail::Pyzor::Digest::Pieces::digest_payloads($parsed); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
for my $payload (@$payloads_ar) { |
67
|
0
|
|
|
|
|
|
my @p_lines = Mail::Pyzor::Digest::Pieces::splitlines($payload); |
68
|
0
|
|
|
|
|
|
for my $line (@p_lines) { |
69
|
0
|
|
|
|
|
|
Mail::Pyzor::Digest::Pieces::normalize($line); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
next if !Mail::Pyzor::Digest::Pieces::should_handle_line($line); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Make sure we have an octet string. |
74
|
0
|
0
|
|
|
|
|
utf8::encode($line) if utf8::is_utf8($line); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
push @lines, $line; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $digest_sr = Mail::Pyzor::Digest::Pieces::assemble_lines( \@lines ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $digest_sr; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |