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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by wakaba, Sat Jun 1 05:30:59 2002 UTC revision 1.6 by wakaba, Sun Jun 9 10:57:16 2002 UTC
# Line 10  use strict; Line 10  use strict;
10  use vars qw(%DEFAULT @ISA $VERSION);  use vars qw(%DEFAULT @ISA $VERSION);
11  $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};  $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12    
13  require Message::Field::Structured;  require Message::Body::Text;
14  push @ISA, qw(Message::Field::Structured);  push @ISA, qw(Message::Body::Text);
15  require Message::Header;  
16  require Message::MIME::Charset;  %DEFAULT = (
17  use overload '""' => sub { $_[0]->stringify },    -_METHODS     => [qw|value|],
18               fallback => 1;    -_MEMBERS     => [qw|_charset|],
19      -body_default_charset => 'us-ascii',
20    %DEFAULT = (    -body_default_charset_input   => 'iso-2022-int-1',
21      -_METHODS   => [qw|value|],    #encoding_after_encode
22      -_MEDIA_TYPE        => 'text/plain',    #encoding_before_decode
23      -_MEMBERS   => [qw|_charset|],    #fill_ct      => 0,
24      -body_default_charset       => 'us-ascii',    #hook_encode_string
25      -body_default_charset_input => 'iso-2022-int-1',    #hook_decode_string
26      #encoding_after_encode    -media_type   => 'text',
27      #encoding_before_decode    -media_subtype        => 'plain',
28      -hook_encode_string => \&Message::Util::encode_body_string,    -use_normalization    => 1,
29      -hook_decode_string => \&Message::Util::decode_body_string,    -use_param_charset    => 1,
30      -parse_all  => 0,  );
     -use_normalization  => 1,  
     -use_param_charset  => 1,  
   );  
31    
32  =head1 CONSTRUCTORS  =head1 CONSTRUCTORS
33    
# Line 47  sub _init ($;%) { Line 44  sub _init ($;%) {
44    my %option = @_;    my %option = @_;
45    $self->SUPER::_init (%$DEFAULT, %option);    $self->SUPER::_init (%$DEFAULT, %option);
46        
47    if (ref $option{header}) {    unless (defined $self->{option}->{fill_ct}) {
48      $self->{header} = $option{header};      $self->{option}->{fill_ct} = $self->{option}->{format} =~ /http|mime/;
   }  
   if ($self->{option}->{format} =~ /http/) {  
     $self->{option}->{use_normalization} = 0;  
49    }    }
50  }  }
51    
# Line 97  sub parse ($$;%) { Line 91  sub parse ($$;%) {
91    
92  =cut  =cut
93    
94  sub header ($;$) {  ## Inherited
   my $self = shift;  
   my $new_header = shift;  
   if (ref $new_header) {  
     $self->{header} = $new_header;  
   #} elsif ($new_header) {  
   #  $self->{header} = Message::Header->parse ($new_header);  
   }  
   #unless ($self->{header}) {  
   #  $self->{header} = new Message::Header;  
   #}  
   $self->{header};  
 }  
95    
96  =item $body->value ([$new_body])  =item $body->value ([$new_body])
97    
# Line 118  Set $new_body instead of current C<body> Line 100  Set $new_body instead of current C<body>
100    
101  =cut  =cut
102    
103  sub value ($;$) {  ## Inherited
   my $self = shift;  
   my $new_body = shift;  
   if ($new_body) {  
     $self->{value} = $new_body;  
   }  
   $self->{value};  
 }  
104    
105  =head2 $self->stringify ([%option])  =head2 $self->stringify ([%option])
106    
# Line 154  sub stringify ($;%) { Line 129  sub stringify ($;%) {
129        if ($Message::MIME::Charset::CHARSET{$charset || '*default'}->{mime_text}) {        if ($Message::MIME::Charset::CHARSET{$charset || '*default'}->{mime_text}) {
130          $e{value} =~ s/\x0D(?!\x0A)/\x0D\x0A/gs;          $e{value} =~ s/\x0D(?!\x0A)/\x0D\x0A/gs;
131          $e{value} =~ s/(?<!\x0D)\x0A/\x0D\x0A/gs;          $e{value} =~ s/(?<!\x0D)\x0A/\x0D\x0A/gs;
132          $e{value} .= "\x0D\x0A" unless $e{value} =~ /\x0D\x0A$/s;          #$e{value} .= "\x0D\x0A" unless $e{value} =~ /\x0D\x0A$/s;
133        }        }
134      }      }
135    } else {    } else {
# Line 164  sub stringify ($;%) { Line 139  sub stringify ($;%) {
139      if ($e{charset}) {      if ($e{charset}) {
140        unless (ref $ct) {        unless (ref $ct) {
141          $ct = $self->{header}->field ('content-type');          $ct = $self->{header}->field ('content-type');
142          $ct->value ($option{_MEDIA_TYPE});          $ct->value ($option{media_type}.'/'.$option{media_subtype});
143        }        }
144        $ct->replace (charset => $e{charset});        $ct->replace (charset => $e{charset});
145      } elsif (ref $ct) {      } elsif (ref $ct) {
146        $ct->replace (charset => $self->{option}->{body_default_charset});        $ct->replace (charset => $self->{option}->{body_default_charset});
147        } elsif ($option{fill_ct}) {
148          $ct = $self->{header}->field ('content-type');
149          $ct->value ($option{media_type}.'/'.$option{media_subtype});
150          $ct->replace (Message::MIME::Charset::name_minimumize ($option{body_default_charset} => $e{value}));
151      }      }
152    }    }
153    $e{value};    $e{value};
154  }  }
155  *as_string = \&stringify;  *as_string = \&stringify;
156    
 =head2 $self->option ($option_name)  
   
 Returns/set (new) value of the option.  
   
 =cut  
   
157  ## Inherited: option, clone  ## Inherited: option, clone
158    
159  =head1 SEE ALSO  =head1 SEE ALSO

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24