| 1 |
wakaba |
1.1 |
|
| 2 |
|
|
=head1 NAME
|
| 3 |
|
|
|
| 4 |
|
|
Message::Partial --- Perl module for partial message defined by MIME
|
| 5 |
|
|
(message/partial)
|
| 6 |
|
|
|
| 7 |
|
|
=cut
|
| 8 |
|
|
|
| 9 |
|
|
package Message::Partial;
|
| 10 |
|
|
use strict;
|
| 11 |
|
|
use vars qw(%OPTION $VERSION);
|
| 12 |
|
|
$VERSION=do{my @r=(q$Revision: 1.17 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
|
| 13 |
|
|
|
| 14 |
|
|
require Message::Entity;
|
| 15 |
|
|
require Message::Header;
|
| 16 |
|
|
require Message::Field::MsgID;
|
| 17 |
|
|
|
| 18 |
|
|
%OPTION = (
|
| 19 |
|
|
-part_length => 1024,
|
| 20 |
|
|
-subject_format_pattern => '%s (%d/%d)',
|
| 21 |
|
|
);
|
| 22 |
|
|
|
| 23 |
|
|
sub fragmentate ($;%) {
|
| 24 |
|
|
my $msg = shift;
|
| 25 |
|
|
my %params = @_;
|
| 26 |
|
|
my %option = %OPTION;
|
| 27 |
|
|
for (grep {/^-/} keys %params) {$option{$_} = $params{$_}}
|
| 28 |
|
|
|
| 29 |
|
|
if (ref $msg) {
|
| 30 |
|
|
$msg = $msg->clone;
|
| 31 |
|
|
} else {
|
| 32 |
|
|
$msg = parse Message::Entity $msg;
|
| 33 |
|
|
}
|
| 34 |
|
|
my @copy_field;
|
| 35 |
|
|
my %cf = (subject => 1, encrypted => 1, 'mime-version' => 1, 'message-id' => 1);
|
| 36 |
|
|
$msg->option (force_mime_entity => 1);
|
| 37 |
|
|
$msg->stringify; ## Make fill_* work
|
| 38 |
|
|
$msg->header->scan (sub {
|
| 39 |
|
|
my $i = $_[1];
|
| 40 |
|
|
my $rfc822 = $Message::Header::NS_phname2uri{rfc822};
|
| 41 |
|
|
if ($_[1]->{ns} eq $Message::Header::NS_phname2uri{content}) {
|
| 42 |
|
|
push @copy_field, {%{$_[1]}};
|
| 43 |
|
|
$_[1]->{name} = undef;
|
| 44 |
|
|
} elsif ($_[1]->{ns} eq $rfc822 && $cf{$_[1]->{name}}) {
|
| 45 |
|
|
#push @copy_field, Message::Util::make_clone ($_[1]);
|
| 46 |
|
|
##$_[1]->{name} = undef; ## Don't remove to keep compatible w/ RFC 1341/1521
|
| 47 |
|
|
push @copy_field, {%{$_[1]}};
|
| 48 |
|
|
$_[1]->{name} = undef;
|
| 49 |
|
|
}
|
| 50 |
|
|
});
|
| 51 |
|
|
my $outer_header = $msg->header;
|
| 52 |
|
|
my $inner_header = new Message::Header;
|
| 53 |
|
|
$inner_header->{value} = \@copy_field; ## Warning: direct access to internal structure!
|
| 54 |
|
|
$msg->header ($inner_header);
|
| 55 |
|
|
my @msg = split /\x0D\x0A/, $msg->stringify (-accept_cte => '7bit');
|
| 56 |
|
|
my @pbody = ('');
|
| 57 |
|
|
for (@msg) {
|
| 58 |
|
|
if (length $pbody[$#pbody] > $option{-part_length}) {
|
| 59 |
|
|
push @pbody, '';
|
| 60 |
|
|
}
|
| 61 |
|
|
$pbody[$#pbody] .= $_."\x0D\x0A";
|
| 62 |
|
|
}
|
| 63 |
|
|
my @pmsg;
|
| 64 |
|
|
my $subject = $inner_header->field ('subject', -new_item_unless_exist => 0);
|
| 65 |
|
|
my $ct = $outer_header->field ('content-type');
|
| 66 |
|
|
$ct->media_type ('message/partial');
|
| 67 |
|
|
my $as = $outer_header->field ('resent-from', -new_item_unless_exist => 0)
|
| 68 |
|
|
|| $outer_header->field ('from', -new_item_unless_exist => 0);
|
| 69 |
|
|
$as = $as->addr_spec if ref $as;
|
| 70 |
|
|
$as ||= '[email protected]';
|
| 71 |
|
|
my $pid = Message::Field::MsgID->new (addr_spec => $as);
|
| 72 |
|
|
$ct->parameter (id => $pid->content);
|
| 73 |
|
|
my $first_mid;
|
| 74 |
|
|
for my $i (0..$#pbody) {
|
| 75 |
|
|
$pmsg[$i] = new Message::Entity;
|
| 76 |
|
|
$pmsg[$i]->header ($outer_header->clone);
|
| 77 |
|
|
my $hdr = $pmsg[$i]->header;
|
| 78 |
|
|
$hdr->replace (subject
|
| 79 |
|
|
=> sprintf ($option{-subject_format_pattern}, $subject, $i+1, $#pbody+1));
|
| 80 |
|
|
my $ct = $hdr->field ('content-type');
|
| 81 |
|
|
$ct->parameter (number => $i +1);
|
| 82 |
|
|
$ct->parameter (total => $#pbody +1);
|
| 83 |
|
|
$pmsg[$i]->body ($pbody[$i]);
|
| 84 |
|
|
if ($i == 0) {
|
| 85 |
|
|
$pmsg[$i]->stringify;
|
| 86 |
|
|
$first_mid = $hdr->field ('message-id');
|
| 87 |
|
|
} else {
|
| 88 |
|
|
$hdr->field ('references')->add ($first_mid);
|
| 89 |
|
|
}
|
| 90 |
|
|
}
|
| 91 |
|
|
@pmsg;
|
| 92 |
|
|
}
|
| 93 |
|
|
|
| 94 |
|
|
=head1 SEE ALSO
|
| 95 |
|
|
|
| 96 |
|
|
L<Message::Entity>
|
| 97 |
|
|
|
| 98 |
|
|
RFC 1341 E<lt>urn:ietf:rfc:1341E<gt>,
|
| 99 |
|
|
RFC 1521 E<lt>urn:ietf:rfc:1521E<gt>,
|
| 100 |
|
|
RFC 2046 E<lt>urn:ietf:rfc:2046E<gt>
|
| 101 |
|
|
|
| 102 |
|
|
RFC 822 E<lt>urn:ietf:rfc:822E<gt>,
|
| 103 |
|
|
RFC 2822 E<lt>urn:ietf:rfc:2822E<gt>
|
| 104 |
|
|
|
| 105 |
|
|
=head1 LICENSE
|
| 106 |
|
|
|
| 107 |
|
|
Copyright 2002 wakaba E<lt>[email protected]<gt>.
|
| 108 |
|
|
|
| 109 |
|
|
This program is free software; you can redistribute it and/or modify
|
| 110 |
|
|
it under the terms of the GNU General Public License as published by
|
| 111 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
| 112 |
|
|
(at your option) any later version.
|
| 113 |
|
|
|
| 114 |
|
|
This program is distributed in the hope that it will be useful,
|
| 115 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 116 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 117 |
|
|
GNU General Public License for more details.
|
| 118 |
|
|
|
| 119 |
|
|
You should have received a copy of the GNU General Public License
|
| 120 |
|
|
along with this program; see the file COPYING. If not, write to
|
| 121 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
| 122 |
|
|
Boston, MA 02111-1307, USA.
|
| 123 |
|
|
|
| 124 |
|
|
=head1 CHANGE
|
| 125 |
|
|
|
| 126 |
|
|
See F<ChangeLog>.
|
| 127 |
|
|
$Date: 2002/06/01 05:40:55 $
|
| 128 |
|
|
|
| 129 |
|
|
=cut
|
| 130 |
|
|
|
| 131 |
|
|
1;
|