14 |
use strict; |
use strict; |
15 |
use re 'eval'; |
use re 'eval'; |
16 |
use vars qw(%DEFAULT %REG $VERSION); |
use vars qw(%DEFAULT %REG $VERSION); |
17 |
$VERSION = '1.00'; |
$VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
18 |
|
require Message::Util; |
19 |
|
|
20 |
use overload '""' => sub {shift->stringify}; |
use overload '""' => sub {shift->stringify}; |
21 |
$REG{FWS} = qr/[\x09\x20]*/; |
$REG{FWS} = qr/[\x09\x20]*/; |
28 |
$REG{M_was} = qr/\([Ww][Aa][Ss]:? ([\x00-\xFF]+)\)$REG{FWS}$/; |
$REG{M_was} = qr/\([Ww][Aa][Ss]:? ([\x00-\xFF]+)\)$REG{FWS}$/; |
29 |
|
|
30 |
%DEFAULT = ( |
%DEFAULT = ( |
31 |
|
encoding_after_encode => '*default', |
32 |
|
encoding_before_decode => '*default', |
33 |
|
hook_encode_string => #sub {shift; (value => shift, @_)}, |
34 |
|
\&Message::Util::encode_header_string, |
35 |
|
hook_decode_string => #sub {shift; (value => shift, @_)}, |
36 |
|
\&Message::Util::decode_header_string, |
37 |
string_re => 'Re: ', |
string_re => 'Re: ', |
38 |
string_was => ' (was: %s)', |
string_was => ' (was: %s)', |
39 |
); |
); |
68 |
$self->{control} = $1; |
$self->{control} = $1; |
69 |
return $self; |
return $self; |
70 |
} |
} |
71 |
|
my %s = &{$self->{option}->{hook_decode_string}} ($self, $field_body, |
72 |
|
type => 'text'); |
73 |
|
$field_body = $s{value}; |
74 |
$field_body =~ s{^$REG{FWS}($REG{prefix})$REG{FWS}}{ |
$field_body =~ s{^$REG{FWS}($REG{prefix})$REG{FWS}}{ |
75 |
my $prefix = $1; |
my $prefix = $1; |
76 |
$self->{is_reply} = 1 if $prefix =~ /$REG{re}/; |
$self->{is_reply} = 1 if $prefix =~ /$REG{re}/; |
93 |
my %option = @_; |
my %option = @_; |
94 |
$option{string_re} ||= $self->{option}->{string_re}; |
$option{string_re} ||= $self->{option}->{string_re}; |
95 |
$option{string_was} ||= $self->{option}->{string_was}; |
$option{string_was} ||= $self->{option}->{string_was}; |
96 |
($self->{is_reply}>0? $option{string_re}: ''). |
my (%e) = &{$self->{option}->{hook_encode_string}} ($self, |
97 |
$self->{field_body}. |
$self->{field_body}, type => 'text'); |
98 |
(length $self->{was}? sprintf ($option{string_was}, $self->{was}): ''); |
($self->{is_reply}>0? $option{string_re}: '').$e{value} |
99 |
|
.(length $self->{was}? sprintf ($option{string_was}, $self->{was}): ''); |
100 |
} |
} |
101 |
|
sub as_string ($;%) {shift->stringify (@_)} |
102 |
|
|
103 |
sub as_plain_string ($) { |
sub as_plain_string ($;%) { |
104 |
my $self = shift; |
my $self = shift; |
105 |
$self->stringify (@_); |
my %option = @_; |
106 |
|
$option{string_re} ||= $self->{option}->{string_re}; |
107 |
|
$option{string_was} ||= $self->{option}->{string_was}; |
108 |
|
($self->{is_reply}>0? $option{string_re}: '').$self->{field_body} |
109 |
|
.(length $self->{was}? |
110 |
|
sprintf ($option{string_was}, $self->{was}->as_plain_string): ''); |
111 |
} |
} |
112 |
|
|
113 |
sub is ($$;$) { |
sub is ($$;$) { |