47 |
%DEFAULT = ( |
%DEFAULT = ( |
48 |
capitalize => 1, |
capitalize => 1, |
49 |
fold_length => 70, |
fold_length => 70, |
|
mail_from => 0, |
|
50 |
field_type => {':DEFAULT' => 'Message::Field::Unstructured'}, |
field_type => {':DEFAULT' => 'Message::Field::Unstructured'}, |
51 |
|
mail_from => -1, |
52 |
|
output_bcc => -1, |
53 |
|
parse_all => -1, |
54 |
); |
); |
55 |
my @field_type_Structured = qw(cancel-lock |
my @field_type_Structured = qw(cancel-lock |
56 |
importance mime-version path precedence user-agent x-cite |
importance mime-version path precedence x-cite |
57 |
x-face x-mail-count x-msmail-priority x-priority x-uidl xref); |
x-face x-mail-count x-msmail-priority x-priority x-uidl xref); |
58 |
for (@field_type_Structured) |
for (@field_type_Structured) |
59 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
60 |
my @field_type_Address = qw(approved bcc cc delivered-to envelope-to |
my @field_type_Address = qw(approved bcc cc delivered-to disposition-notification-to |
61 |
|
envelope-to |
62 |
errors-to fcc from mail-followup-to mail-followup-cc mail-from reply-to resent-bcc |
errors-to fcc from mail-followup-to mail-followup-cc mail-from reply-to resent-bcc |
63 |
resent-cc resent-to resent-from resent-sender return-path |
resent-cc resent-to resent-from resent-sender return-path |
64 |
return-receipt-to sender to x-approved x-beenthere |
return-receipt-to sender to x-approved x-beenthere |
76 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::MsgID'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::MsgID'} |
77 |
for (qw(received x-received)) |
for (qw(received x-received)) |
78 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Received'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Received'} |
79 |
|
$DEFAULT{field_type}->{'content-type'} = 'Message::Field::ContentType'; |
80 |
|
$DEFAULT{field_type}->{'content-disposition'} = 'Message::Field::ContentDisposition'; |
81 |
|
for (qw(x-face-type)) |
82 |
|
{$DEFAULT{field_type}->{$_} = 'Message::Field::ValueParams'} |
83 |
for (qw(accept accept-charset accept-encoding accept-language |
for (qw(accept accept-charset accept-encoding accept-language |
84 |
content-disposition content-language |
content-language |
85 |
content-transfer-encoding content-type encrypted followup-to keywords newsgroups |
content-transfer-encoding encrypted followup-to keywords newsgroups |
86 |
x-brother x-daughter x-face-type x-respect x-moe |
x-brother x-daughter x-respect x-moe x-syster x-wife)) |
|
x-syster x-wife)) |
|
87 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::CSV'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::CSV'} |
88 |
my @field_type_URI = qw(list-archive list-help list-owner |
my @field_type_URI = qw(list-archive list-help list-owner |
89 |
list-post list-subscribe list-unsubscribe uri url x-home-page x-http_referer |
list-post list-subscribe list-unsubscribe uri url x-home-page x-http_referer |
92 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
93 |
for (qw(list-id)) |
for (qw(list-id)) |
94 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'} |
95 |
for (qw(content-description subject title x-nsubject)) |
for (qw(subject title x-nsubject)) |
96 |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Subject'} |
{$DEFAULT{field_type}->{$_} = 'Message::Field::Subject'} |
97 |
|
for (qw(list-software user-agent server)) |
98 |
|
{$DEFAULT{field_type}->{$_} = 'Message::Field::UA'} |
99 |
|
|
100 |
=head2 Message::Header->new ([%option]) |
=head2 Message::Header->new ([%option]) |
101 |
|
|
126 |
$header =~ s/\x0D?\x0A$REG{WSP}+/\x20/gos; ## unfold |
$header =~ s/\x0D?\x0A$REG{WSP}+/\x20/gos; ## unfold |
127 |
for my $field (split /\x0D?\x0A/, $header) { |
for my $field (split /\x0D?\x0A/, $header) { |
128 |
if ($field =~ /$REG{M_fromline}/) { |
if ($field =~ /$REG{M_fromline}/) { |
129 |
push @{$self->{field}}, {name => 'mail-from', body => $1}; |
my $body = $1; |
130 |
|
$body = $self->_field_body ($body, 'mail-from') |
131 |
|
if $self->{option}->{parse_all}>0; |
132 |
|
push @{$self->{field}}, {name => 'mail-from', body => $body}; |
133 |
} elsif ($field =~ /$REG{M_field}/) { |
} elsif ($field =~ /$REG{M_field}/) { |
134 |
my ($name, $body) = ($1, $2); |
my ($name, $body) = (lc $1, $2); |
135 |
$name =~ s/$REG{WSP}+$//; |
$name =~ s/$REG{WSP}+$//; |
136 |
$body =~ s/$REG{WSP}+$//; |
$body =~ s/$REG{WSP}+$//; |
137 |
push @{$self->{field}}, {name => lc $name, body => $body}; |
$body = $self->_field_body ($body, $name) if $self->{option}->{parse_all}>0; |
138 |
|
push @{$self->{field}}, {name => $name, body => $body}; |
139 |
} |
} |
140 |
} |
} |
141 |
$self; |
$self; |
165 |
} |
} |
166 |
} |
} |
167 |
} |
} |
168 |
|
if ($#ret < 0) { |
169 |
|
return $self->add ($name); |
170 |
|
} |
171 |
@ret; |
@ret; |
172 |
} |
} |
173 |
|
|
174 |
|
sub field_exist ($$) { |
175 |
|
my $self = shift; |
176 |
|
my $name = lc shift; |
177 |
|
my @ret; |
178 |
|
for my $field (@{$self->{field}}) { |
179 |
|
return 1 if ($field->{name} eq $name); |
180 |
|
} |
181 |
|
0; |
182 |
|
} |
183 |
|
|
184 |
=head2 $self->field_name ($index) |
=head2 $self->field_name ($index) |
185 |
|
|
186 |
Returns C<field-name> of $index'th C<field>. |
Returns C<field-name> of $index'th C<field>. |
241 |
|
|
242 |
=cut |
=cut |
243 |
|
|
244 |
sub add ($$$) { |
sub add ($$;$%) { |
245 |
my $self = shift; |
my $self = shift; |
246 |
my ($name, $body) = (lc shift, shift); |
my ($name, $body) = (lc shift, shift); |
247 |
|
my %option = @_; |
248 |
return 0 if $name =~ /$REG{UNSAFE_field_name}/; |
return 0 if $name =~ /$REG{UNSAFE_field_name}/; |
249 |
$body = $self->_field_body ($body, $name); |
$body = $self->_field_body ($body, $name); |
250 |
push @{$self->{field}}, {name => $name, body => $body}; |
if ($option{prepend}) { |
251 |
|
unshift @{$self->{field}}, {name => $name, body => $body}; |
252 |
|
} else { |
253 |
|
push @{$self->{field}}, {name => $name, body => $body}; |
254 |
|
} |
255 |
$body; |
$body; |
256 |
} |
} |
257 |
|
|
269 |
my $self = shift; |
my $self = shift; |
270 |
my ($name, $body) = (lc shift, shift); |
my ($name, $body) = (lc shift, shift); |
271 |
return 0 if $name =~ /$REG{UNSAFE_field_name}/; |
return 0 if $name =~ /$REG{UNSAFE_field_name}/; |
272 |
|
$body = $self->_field_body ($body, $name); |
273 |
for my $field (@{$self->{field}}) { |
for my $field (@{$self->{field}}) { |
274 |
if ($field->{name} eq $name) { |
if ($field->{name} eq $name) { |
275 |
$field->{body} = $body; |
$field->{body} = $body; |
276 |
return $self; |
return $body; |
277 |
} |
} |
278 |
} |
} |
279 |
push @{$self->{field}}, {name => $name, body => $body}; |
push @{$self->{field}}, {name => $name, body => $body}; |
280 |
$self; |
$body; |
281 |
} |
} |
282 |
|
|
283 |
=head2 $self->delete ($field_name, [$index]) |
=head2 $self->delete ($field_name, [$index]) |
341 |
my @ret; |
my @ret; |
342 |
$OPT{capitalize} ||= $self->{option}->{capitalize}; |
$OPT{capitalize} ||= $self->{option}->{capitalize}; |
343 |
$OPT{mail_from} ||= $self->{option}->{mail_from}; |
$OPT{mail_from} ||= $self->{option}->{mail_from}; |
344 |
push @ret, 'From '.$self->field ('mail-from') if $OPT{mail_from}; |
$OPT{output_bcc} ||= $self->{option}->{output_bcc}; |
345 |
|
push @ret, 'From '.$self->field ('mail-from') if $OPT{mail_from}>0; |
346 |
for my $field (@{$self->{field}}) { |
for my $field (@{$self->{field}}) { |
347 |
my $name = $field->{name}; |
my $name = $field->{name}; |
348 |
next unless $field->{name}; |
next unless $name; |
349 |
next if !$OPT{mail_from} && $name eq 'mail-from'; |
next if $OPT{mail_from}<0 && $name eq 'mail-from'; |
350 |
|
next if $OPT{output_bcc}<0 && ($name eq 'bcc' || $name eq 'resent-bcc'); |
351 |
my $fbody = scalar $field->{body}; |
my $fbody = scalar $field->{body}; |
352 |
next unless $fbody; |
next unless $fbody; |
353 |
|
$fbody =~ s/\x0D([^\x09\x0A\x20])/\x0D\x20$1/g; |
354 |
|
$fbody =~ s/\x0A([^\x09\x20])/\x0A\x20$1/g; |
355 |
$name =~ s/((?:^|-)[a-z])/uc($1)/ge if $OPT{capitalize}; |
$name =~ s/((?:^|-)[a-z])/uc($1)/ge if $OPT{capitalize}; |
356 |
push @ret, $name.': '.$self->fold ($fbody); |
push @ret, $name.': '.$self->fold ($fbody); |
357 |
} |
} |