| 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 |  |  |  |  |  |  | # <@LICENSE> | 
| 8 |  |  |  |  |  |  | # Licensed to the Apache Software Foundation (ASF) under one or more | 
| 9 |  |  |  |  |  |  | # contributor license agreements.  See the NOTICE file distributed with | 
| 10 |  |  |  |  |  |  | # this work for additional information regarding copyright ownership. | 
| 11 |  |  |  |  |  |  | # The ASF licenses this file to you under the Apache License, Version 2.0 | 
| 12 |  |  |  |  |  |  | # (the "License"); you may not use this file except in compliance with | 
| 13 |  |  |  |  |  |  | # the License.  You may obtain a copy of the License at: | 
| 14 |  |  |  |  |  |  | # | 
| 15 |  |  |  |  |  |  | #     http://www.apache.org/licenses/LICENSE-2.0 | 
| 16 |  |  |  |  |  |  | # | 
| 17 |  |  |  |  |  |  | # Unless required by applicable law or agreed to in writing, software | 
| 18 |  |  |  |  |  |  | # distributed under the License is distributed on an "AS IS" BASIS, | 
| 19 |  |  |  |  |  |  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 20 |  |  |  |  |  |  | # See the License for the specific language governing permissions and | 
| 21 |  |  |  |  |  |  | # limitations under the License. | 
| 22 |  |  |  |  |  |  | # @LICENSE> | 
| 23 |  |  |  |  |  |  | # | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 1 |  |  | 1 |  | 136480 | use strict; | 
|  | 1 |  |  |  |  | 8 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 26 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =encoding utf-8 | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 NAME | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | Mail::Pyzor::Digest | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | my $digest = Mail::Pyzor::Digest::get( $mime_text ); | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | A reimplementation of L. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =cut | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  | 1 |  | 499 | use Email::MIME (); | 
|  | 1 |  |  |  |  | 48871 |  | 
|  | 1 |  |  |  |  | 24 |  | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 1 |  |  | 1 |  | 429 | use Mail::Pyzor::Digest::Pieces (); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 17 |  | 
| 49 | 1 |  |  | 1 |  | 379 | use Mail::Pyzor::SHA            (); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 204 |  | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | our $VERSION = '0.06_01'; # TRIAL | 
| 52 |  |  |  |  |  |  | $VERSION =~ tr/_//d; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | #---------------------------------------------------------------------- | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head2 $hex = get( $MSG ) | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | This takes an email message in raw MIME text format (i.e., as saved in the | 
| 61 |  |  |  |  |  |  | standard mbox format) and returns the message’s Pyzor digest in lower-case | 
| 62 |  |  |  |  |  |  | hexadecimal. | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | The output from this function should normally be identical to that of | 
| 65 |  |  |  |  |  |  | the C script’s C command. It is suitable for use in | 
| 66 |  |  |  |  |  |  | L’s request methods. | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =cut | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub get { | 
| 71 | 0 |  |  | 0 | 1 |  | return Mail::Pyzor::SHA::sha1_hex( ${ _get_predigest( $_[0] ) } ); | 
|  | 0 |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | # NB: This is called from the test. | 
| 75 |  |  |  |  |  |  | sub _get_predigest {    ## no critic qw(RequireArgUnpacking) | 
| 76 | 0 |  |  | 0 |  |  | my ($msg_text_sr) = \$_[0]; | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 0 |  |  |  |  |  | my $parsed = Email::MIME->new($$msg_text_sr); | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 0 |  |  |  |  |  | my @lines; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 0 |  |  |  |  |  | my $payloads_ar = Mail::Pyzor::Digest::Pieces::digest_payloads($parsed); | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 0 |  |  |  |  |  | for my $payload (@$payloads_ar) { | 
| 85 | 0 |  |  |  |  |  | my @p_lines = Mail::Pyzor::Digest::Pieces::splitlines($payload); | 
| 86 | 0 |  |  |  |  |  | for my $line (@p_lines) { | 
| 87 | 0 |  |  |  |  |  | Mail::Pyzor::Digest::Pieces::normalize($line); | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 0 | 0 |  |  |  |  | next if !Mail::Pyzor::Digest::Pieces::should_handle_line($line); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | # Make sure we have an octet string. | 
| 92 | 0 | 0 |  |  |  |  | utf8::encode($line) if utf8::is_utf8($line); | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 0 |  |  |  |  |  | push @lines, $line; | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 0 |  |  |  |  |  | my $digest_sr = Mail::Pyzor::Digest::Pieces::assemble_lines( \@lines ); | 
| 99 |  |  |  |  |  |  |  | 
| 100 | 0 |  |  |  |  |  | return $digest_sr; | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | 1; |