/[suikacvs]/messaging/manakai/lib/Message/Body/TextPlain.pm
Suika

Contents of /messaging/manakai/lib/Message/Body/TextPlain.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations) (download)
Wed Jul 17 00:33:29 2002 UTC (22 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.9: +3 -3 lines
2002-07-13  Wakaba <w@suika.fam.cx>

	* Util.pm:
	- (get_host_fqdn): New function.
	- (%OPTION): New hash.
	* Entity.pm (stringify): Pass 'format' option
	to the body (when stringify'ing it) with
	-parent_format option, instead of -format option.

1 wakaba 1.1
2     =head1 NAME
3    
4 wakaba 1.5 Message::Body::TextPlain --- Perl Module for Internet Media Type "text/plain"
5 wakaba 1.1
6     =cut
7    
8     package Message::Body::TextPlain;
9     use strict;
10 wakaba 1.5 use vars qw(%DEFAULT @ISA $VERSION);
11 wakaba 1.10 $VERSION=do{my @r=(q$Revision: 1.9 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12 wakaba 1.1
13 wakaba 1.6 require Message::Body::Text;
14     push @ISA, qw(Message::Body::Text);
15    
16     %DEFAULT = (
17     -_METHODS => [qw|value|],
18     -_MEMBERS => [qw|_charset|],
19     -body_default_charset => 'us-ascii',
20     -body_default_charset_input => 'iso-2022-int-1',
21     #encoding_after_encode
22     #encoding_before_decode
23     #fill_ct => 0,
24     #hook_encode_string
25     #hook_decode_string
26     -media_type => 'text',
27     -media_subtype => 'plain',
28     -use_normalization => 1,
29     -use_param_charset => 1,
30     );
31 wakaba 1.5
32     =head1 CONSTRUCTORS
33 wakaba 1.1
34 wakaba 1.5 The following methods construct new C<Message::Field::Structured> objects:
35 wakaba 1.2
36 wakaba 1.5 =over 4
37 wakaba 1.1
38 wakaba 1.5 =cut
39    
40     ## Initialize of this class -- called by constructors
41     sub _init ($;%) {
42     my $self = shift;
43     my $DEFAULT = Message::Util::make_clone (\%DEFAULT);
44     my %option = @_;
45     $self->SUPER::_init (%$DEFAULT, %option);
46    
47 wakaba 1.6 unless (defined $self->{option}->{fill_ct}) {
48 wakaba 1.10 $self->{option}->{fill_ct} = $self->{option}->{format} =~ /rfc2822|news-usefor|http|mime|news-son-of-rfc1036/;
49 wakaba 1.5 }
50 wakaba 1.7 if ($self->{option}->{format} =~ /http/) {
51     $self->{option}->{use_normalization} = 0;
52     } else {
53     $self->{option}->{use_normalization} = 1;
54     }
55 wakaba 1.5 }
56    
57     =item $body = Message::Body::TextPlain->new ([%options])
58    
59     Constructs a new object. You might pass some options as parameters
60     to the constructor.
61 wakaba 1.1
62     =cut
63    
64 wakaba 1.5 ## Inherited
65 wakaba 1.1
66 wakaba 1.5 =item $body = Message::Body::TextPlain->parse ($body, [%options])
67 wakaba 1.1
68 wakaba 1.5 Constructs a new object with given field body. You might pass
69     some options as parameters to the constructor.
70 wakaba 1.1
71     =cut
72    
73     sub parse ($$;%) {
74     my $class = shift;
75 wakaba 1.5 my $self = bless {}, $class;
76 wakaba 1.1 my $body = shift;
77 wakaba 1.5 $self->_init (@_);
78     my $charset;
79     my $ct; $ct = $self->{header}->field ('content-type', -new_item_unless_exist => 0)
80     if ref $self->{header};
81     $charset = $ct->parameter ('charset') if ref $ct;
82     $charset ||= $self->{option}->{encoding_before_decode};
83     my %s = &{$self->{option}->{hook_decode_string}} ($self, $body,
84     type => 'body', charset => $charset);
85     $self->{value} = $s{value};
86     $self->{_charset} = $s{charset}; ## When convertion failed
87 wakaba 1.1 $self;
88     }
89    
90 wakaba 1.5 =back
91    
92     =cut
93    
94     =item $body->header ([$new_header])
95 wakaba 1.1
96    
97     =cut
98    
99 wakaba 1.6 ## Inherited
100 wakaba 1.1
101 wakaba 1.5 =item $body->value ([$new_body])
102 wakaba 1.1
103     Returns C<body> as string unless $new_body.
104     Set $new_body instead of current C<body>.
105    
106     =cut
107    
108 wakaba 1.6 ## Inherited
109 wakaba 1.1
110     =head2 $self->stringify ([%option])
111    
112     Returns the C<body> as a string.
113    
114     =cut
115    
116     sub stringify ($;%) {
117     my $self = shift;
118 wakaba 1.5 my %o = @_; my %option = %{$self->{option}};
119     for (grep {/^-/} keys %o) {$option{substr ($_, 1)} = $o{$_}}
120     my $ct = $self->{header}->field ('content-type', -new_item_unless_exist => 0)
121     if ref $self->{header};
122     my %e;
123     unless ($self->{_charset}) {
124     my $charset; $charset = $ct->parameter ('charset') if ref $ct;
125     $charset ||= $self->{option}->{encoding_after_encode};
126     (%e) = &{$self->{option}->{hook_encode_string}} ($self,
127     $self->{value}, type => 'body',
128     charset => $charset);
129     #$e{charset} ||= $self->{option}->{body_default_charset}
130     # if $self->{option}->{body_default_charset_input}
131     # ne $self->{option}->{body_default_charset};
132     ## Normalize
133     if ($option{use_normalization}) {
134     if ($Message::MIME::Charset::CHARSET{$charset || '*default'}->{mime_text}) {
135     $e{value} =~ s/\x0D(?!\x0A)/\x0D\x0A/gs;
136     $e{value} =~ s/(?<!\x0D)\x0A/\x0D\x0A/gs;
137 wakaba 1.6 #$e{value} .= "\x0D\x0A" unless $e{value} =~ /\x0D\x0A$/s;
138 wakaba 1.5 }
139     }
140     } else {
141     %e = (value => $self->{value}, charset => $self->{_charset});
142     }
143     if (ref $self->{header}) {
144     if ($e{charset}) {
145     unless (ref $ct) {
146     $ct = $self->{header}->field ('content-type');
147 wakaba 1.6 $ct->value ($option{media_type}.'/'.$option{media_subtype});
148 wakaba 1.5 }
149     $ct->replace (charset => $e{charset});
150     } elsif (ref $ct) {
151 wakaba 1.8 $ct->replace (Message::MIME::Charset::name_minimumize ($option{body_default_charset}, $e{value}));
152 wakaba 1.6 } elsif ($option{fill_ct}) {
153     $ct = $self->{header}->field ('content-type');
154     $ct->value ($option{media_type}.'/'.$option{media_subtype});
155 wakaba 1.8 $ct->replace (Message::MIME::Charset::name_minimumize ($option{body_default_charset}, $e{value}));
156 wakaba 1.5 }
157     }
158 wakaba 1.2 $e{value};
159 wakaba 1.1 }
160 wakaba 1.5 *as_string = \&stringify;
161 wakaba 1.1
162 wakaba 1.5 ## Inherited: option, clone
163 wakaba 1.3
164 wakaba 1.1 =head1 SEE ALSO
165    
166     RFC 822 <urn:ietf:rfc:822>,
167     RFC 2046 <urn:ietf:rfc:2046>, RFC 2646 <urn:ietf:rfc:2646>.
168    
169     =head1 LICENSE
170    
171     Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
172    
173     This program is free software; you can redistribute it and/or modify
174     it under the terms of the GNU General Public License as published by
175     the Free Software Foundation; either version 2 of the License, or
176     (at your option) any later version.
177    
178     This program is distributed in the hope that it will be useful,
179     but WITHOUT ANY WARRANTY; without even the implied warranty of
180     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
181     GNU General Public License for more details.
182    
183     You should have received a copy of the GNU General Public License
184     along with this program; see the file COPYING. If not, write to
185     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
186     Boston, MA 02111-1307, USA.
187    
188     =head1 CHANGE
189    
190     See F<ChangeLog>.
191 wakaba 1.10 $Date: 2002/07/14 04:26:07 $
192 wakaba 1.1
193     =cut
194    
195     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24