| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::Exchange::Attachment; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Mail::Exchange::Attachment - class to handle attachments to messages |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Mail::Exchange::Attachment; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $attachment=Mail::Exchange::Attachment->new("file.dat"); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
A Mail::Exchange::Attachment object reflects the data that |
|
16
|
|
|
|
|
|
|
Mail::Exchange::Message uses to add an attachment to a message. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
|
|
20
|
5
|
|
|
5
|
|
24
|
use strict; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
168
|
|
|
21
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
130
|
|
|
22
|
5
|
|
|
5
|
|
92
|
use 5.008; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
204
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
5
|
|
|
5
|
|
22
|
use Exporter; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
151
|
|
|
25
|
5
|
|
|
5
|
|
22
|
use Encode; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
426
|
|
|
26
|
5
|
|
|
5
|
|
28
|
use Mail::Exchange::ObjectTypes; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
374
|
|
|
27
|
5
|
|
|
5
|
|
33
|
use Mail::Exchange::PidTagDefs; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
594
|
|
|
28
|
5
|
|
|
5
|
|
30
|
use Mail::Exchange::PidTagIDs; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
15218
|
|
|
29
|
5
|
|
|
5
|
|
157
|
use Mail::Exchange::PropertyContainer; |
|
|
5
|
|
|
|
|
18
|
|
|
|
5
|
|
|
|
|
258
|
|
|
30
|
5
|
|
|
5
|
|
39
|
use Mail::Exchange::Time qw(mstime_to_unixtime); |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
317
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
5
|
|
|
5
|
|
28
|
use vars qw($VERSION @ISA); |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
5458
|
|
|
33
|
|
|
|
|
|
|
@ISA=qw(Mail::Exchange::PropertyContainer Exporter); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$VERSION = "0.01"; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new() |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$msg=Mail::Exchange::Attachment->new([$file]) |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Create a message object, and read C<$file> into it, if given. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
|
46
|
0
|
|
|
0
|
1
|
|
my $class=shift; |
|
47
|
0
|
|
|
|
|
|
my $file=shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $self=Mail::Exchange::PropertyContainer->new(); |
|
50
|
0
|
|
|
|
|
|
bless($self, $class); |
|
51
|
0
|
|
|
|
|
|
my $now=Mail::Exchange::Time->new(time()); |
|
52
|
0
|
|
|
|
|
|
$self->set(PidTagObjectType, otAttachment); |
|
53
|
0
|
|
|
|
|
|
$self->set(PidTagAttachMethod, 1, 7); |
|
54
|
0
|
|
|
|
|
|
$self->set(PidTagAccess, 2); |
|
55
|
0
|
|
|
|
|
|
$self->set(PidTagAccessLevel, 1); |
|
56
|
0
|
|
|
|
|
|
$self->set(PidTagRenderingPosition, 0xffffffff); |
|
57
|
0
|
|
|
|
|
|
$self->set(PidTagCreationTime, $now->mstime()); |
|
58
|
0
|
|
|
|
|
|
$self->set(PidTagLastModificationTime, $now->mstime()); |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($file) { |
|
61
|
0
|
|
|
|
|
|
$self->setFile($file); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
0
|
|
|
|
|
|
$self; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 setFile() |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$attach->setFile($filename) |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
setFile reads the file identified by C<$filename>, makes it the content |
|
71
|
|
|
|
|
|
|
object of the attachment, and sets various other attributes accordingly. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub setFile { |
|
76
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
|
77
|
0
|
|
|
|
|
|
my $file=shift; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $fh; |
|
80
|
0
|
0
|
|
|
|
|
die("$file: $!") unless open($fh, "<$file"); |
|
81
|
0
|
|
|
|
|
|
binmode $fh; |
|
82
|
0
|
|
|
|
|
|
local $/; |
|
83
|
0
|
|
|
|
|
|
my $content=<$fh>; |
|
84
|
0
|
|
|
|
|
|
close $fh; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self->setString($content); |
|
87
|
0
|
|
|
|
|
|
$self->setFileInfo($file); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 setFileInfo($filename) |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$attach->setFileInfo($filename) |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
setFileInfo sets various properties of an attachment (filename, extension, |
|
95
|
|
|
|
|
|
|
creation/modification time) to correspond to the local file identified |
|
96
|
|
|
|
|
|
|
by C<$filename><. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub setFileInfo { |
|
101
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
|
102
|
0
|
|
|
|
|
|
my $file=shift; |
|
103
|
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
die("$file: $!") unless my @f=stat($file); |
|
105
|
0
|
|
|
|
|
|
$self->set(PidTagCreationTime, mstime_to_unixtime($f[9])); |
|
106
|
0
|
|
|
|
|
|
$self->set(PidTagLastModificationTime, mstime_to_unixtime($f[10])); |
|
107
|
0
|
|
|
|
|
|
$self->setFileName($file); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 setFileName($filename) |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$attach->setFileName($filename) |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
setFileName sets the various file-related properties of an attachment |
|
115
|
|
|
|
|
|
|
(filename, extension, ...) to correspond with C<$filename>, without |
|
116
|
|
|
|
|
|
|
requiring this file to exist. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub setFileName { |
|
121
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
|
122
|
0
|
|
|
|
|
|
my $file=shift; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
my $filename=$file; |
|
125
|
0
|
|
|
|
|
|
$filename=~s/.*\///; |
|
126
|
0
|
|
|
|
|
|
my $ext; |
|
127
|
0
|
0
|
|
|
|
|
if ($filename =~ /\./) { |
|
128
|
0
|
|
|
|
|
|
($ext=$filename)=~s/.*\././; |
|
129
|
|
|
|
|
|
|
} else { |
|
130
|
0
|
|
|
|
|
|
$ext=""; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
0
|
|
|
|
|
|
my $shortname; |
|
133
|
0
|
0
|
|
|
|
|
if (length($filename) - length($ext) > 8) { |
|
134
|
0
|
|
|
|
|
|
$shortname=substr($filename, 0, 6)."~1"; |
|
135
|
|
|
|
|
|
|
} else { |
|
136
|
0
|
|
|
|
|
|
$shortname=substr($filename, 0, length($filename)-length($ext)) |
|
137
|
|
|
|
|
|
|
} |
|
138
|
0
|
|
|
|
|
|
$shortname.=substr($ext, 0, 4); |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$self->set(PidTagAttachExtension, $ext); |
|
141
|
0
|
|
|
|
|
|
$self->set(PidTagAttachFilename, $shortname); |
|
142
|
0
|
|
|
|
|
|
$self->set(PidTagAttachLongFilename, $filename); |
|
143
|
0
|
|
|
|
|
|
$self->set(PidTagAttachPathname, $file); |
|
144
|
0
|
|
|
|
|
|
$self->set(PidTagDisplayName, $filename); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 setString() |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$attach->setString($content) |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
setString sets the content of the attachment to C<$string>. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub setString { |
|
156
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
|
157
|
0
|
|
|
|
|
|
my $string=shift; |
|
158
|
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
$self->set(PidTagAttachDataBinary, $string); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub OleContainer { |
|
163
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
|
164
|
0
|
|
|
|
|
|
my $no=shift; |
|
165
|
0
|
|
|
|
|
|
my $unicode=shift; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
my $header=pack("V2", 0, 0); |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
$self->set(PidTagAttachNumber, $no); |
|
170
|
0
|
0
|
|
|
|
|
$self->set(PidTagStoreSupportMask, $unicode ? 0x40000 : 0); |
|
171
|
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my @streams=$self->_OlePropertyStreamlist($unicode, $header); |
|
173
|
0
|
|
|
|
|
|
my $dirname=Encode::encode("UCS2LE", sprintf("__attach_version1.0_#%08X", $no)); |
|
174
|
0
|
|
|
|
|
|
my @ltime=localtime(); |
|
175
|
0
|
|
|
|
|
|
my $dir=OLE::Storage_Lite::PPS::Dir->new($dirname, \@ltime, \@ltime, \@streams); |
|
176
|
0
|
|
|
|
|
|
return $dir; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _parseAttachmentProperties { |
|
180
|
0
|
|
|
0
|
|
|
my $self=shift; |
|
181
|
0
|
|
|
|
|
|
my $file=shift; |
|
182
|
0
|
|
|
|
|
|
my $dir=shift; |
|
183
|
0
|
|
|
|
|
|
my $namedProperties=shift; |
|
184
|
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
$self->_parseProperties($file, $dir, 8, $namedProperties); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |