line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#############################################################################
|
2
|
|
|
|
|
|
|
## Name: Base64.pm
|
3
|
|
|
|
|
|
|
## Purpose: Mail::SendEasy::Base64
|
4
|
|
|
|
|
|
|
## Author: Graciliano M. P.
|
5
|
|
|
|
|
|
|
## Modified by:
|
6
|
|
|
|
|
|
|
## Created: 25/5/2003
|
7
|
|
|
|
|
|
|
## RCS-ID:
|
8
|
|
|
|
|
|
|
## Copyright: (c) 2003 Graciliano M. P.
|
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or
|
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself
|
11
|
|
|
|
|
|
|
#############################################################################
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Mail::SendEasy::Base64 ;
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use strict qw(vars) ;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
16
|
1
|
|
|
1
|
|
5
|
no warnings ;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
38
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA) ;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
688
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.0' ;
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
require Exporter;
|
22
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw(encode_base64 decode_base64) ;
|
25
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT ;
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ($BASE64_PM) ;
|
28
|
1
|
|
|
1
|
|
990
|
eval("use MIME::Base64 ()") ;
|
|
1
|
|
|
|
|
834
|
|
|
1
|
|
|
|
|
11
|
|
29
|
|
|
|
|
|
|
if ( defined &MIME::Base64::encode_base64 ) { $BASE64_PM = 1 ;}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#################
|
32
|
|
|
|
|
|
|
# ENCODE_BASE64 #
|
33
|
|
|
|
|
|
|
#################
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode_base64 {
|
36
|
0
|
0
|
|
0
|
0
|
|
if ( $BASE64_PM ) { return &MIME::Base64::encode_base64($_[0]) ;}
|
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
else { return &_encode_base64_pure_perl($_[0]) ;}
|
38
|
|
|
|
|
|
|
}
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
############################
|
41
|
|
|
|
|
|
|
# _ENCODE_BASE64_PURE_PERL #
|
42
|
|
|
|
|
|
|
############################
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _encode_base64_pure_perl {
|
45
|
0
|
|
|
0
|
|
|
my $res = "";
|
46
|
0
|
|
|
|
|
|
my $eol = $_[1];
|
47
|
0
|
0
|
|
|
|
|
$eol = "\n" unless defined $eol;
|
48
|
0
|
|
|
|
|
|
pos($_[0]) = 0; # ensure start at the beginning
|
49
|
0
|
|
|
|
|
|
while ($_[0] =~ /(.{1,45})/gs) {
|
50
|
0
|
|
|
|
|
|
$res .= substr(pack('u', $1), 1);
|
51
|
0
|
|
|
|
|
|
chop($res);
|
52
|
|
|
|
|
|
|
}
|
53
|
0
|
|
|
|
|
|
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
|
54
|
|
|
|
|
|
|
# fix padding at the end
|
55
|
0
|
|
|
|
|
|
my $padding = (3 - length($_[0]) % 3) % 3;
|
56
|
0
|
0
|
|
|
|
|
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
|
|
0
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# break encoded string into lines of no more than 76 characters each
|
58
|
0
|
0
|
|
|
|
|
if (length $eol) {
|
59
|
0
|
|
|
|
|
|
$res =~ s/(.{1,76})/$1$eol/g;
|
60
|
|
|
|
|
|
|
}
|
61
|
0
|
|
|
|
|
|
$res;
|
62
|
|
|
|
|
|
|
}
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#################
|
65
|
|
|
|
|
|
|
# DECODE_BASE64 #
|
66
|
|
|
|
|
|
|
#################
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub decode_base64 {
|
69
|
0
|
0
|
|
0
|
0
|
|
if ( $BASE64_PM ) { return &MIME::Base64::decode_base64($_[0]) ;}
|
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
else { return &_decode_base64_pure_perl($_[0]) ;}
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
############################
|
75
|
|
|
|
|
|
|
# _DECODE_BASE64_PURE_PERL #
|
76
|
|
|
|
|
|
|
############################
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _decode_base64_pure_perl {
|
79
|
0
|
|
|
0
|
|
|
local($^W) = 0 ;
|
80
|
0
|
|
|
|
|
|
my $str = shift ;
|
81
|
0
|
|
|
|
|
|
my $res = "";
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$str =~ tr|A-Za-z0-9+=/||cd; # remove non-base64 chars
|
84
|
0
|
0
|
|
|
|
|
if (length($str) % 4) {
|
85
|
|
|
|
|
|
|
#require Carp;
|
86
|
|
|
|
|
|
|
#Carp::carp("Length of base64 data not a multiple of 4")
|
87
|
|
|
|
|
|
|
}
|
88
|
0
|
|
|
|
|
|
$str =~ s/=+$//; # remove padding
|
89
|
0
|
|
|
|
|
|
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
|
90
|
0
|
|
|
|
|
|
while ($str =~ /(.{1,60})/gs) {
|
91
|
0
|
|
|
|
|
|
my $len = chr(32 + length($1)*3/4); # compute length byte
|
92
|
0
|
|
|
|
|
|
$res .= unpack("u", $len . $1 ); # uudecode
|
93
|
|
|
|
|
|
|
}
|
94
|
0
|
|
|
|
|
|
$res;
|
95
|
|
|
|
|
|
|
}
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#######
|
98
|
|
|
|
|
|
|
# END #
|
99
|
|
|
|
|
|
|
#######
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1;
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|