/[suikacvs]/test/cvs
Suika

Diff of /test/cvs

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

revision 1.11 by wakaba, Tue Mar 26 15:19:53 2002 UTC revision 1.32 by wakaba, Sat Jul 6 11:37:01 2002 UTC
# Line 1  Line 1 
1    
2  =head1 NAME  =head1 NAME
3    
4  Message::Header Perl module  Message::Header --- A Perl Module for Internet Message Headers
   
 =head1 DESCRIPTION  
   
 Perl module for RFC 822/2822 message C<header>.  
5    
6  =cut  =cut
7    
8  package Message::Header;  package Message::Header;
9  use strict;  use strict;
10  use vars qw($VERSION %REG %DEFAULT);  use vars qw(%DEFAULT @ISA %REG $VERSION);
11  $VERSION = '1.00';  $VERSION=do{my @r=(q$Revision$=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
12    require Message::Field::Structured;     ## This may seem silly:-)
13    push @ISA, qw(Message::Field::Structured);
14    
15    %REG = %Message::Util::REG;
16            $REG{M_field} = qr/^([^\x3A]+):$REG{FWS}([\x00-\xFF]*)$/;
17            $REG{M_fromline} = qr/^\x3E?From$REG{WSP}+([\x00-\xFF]*)$/;
18            $REG{ftext} = qr/[\x21-\x39\x3B-\x7E]+/;        ## [2]822
19            $REG{NON_ftext} = qr/[^\x21-\x39\x3B-\x7E]/;    ## [2]822
20            $REG{NON_ftext_usefor} = qr/[^0-9A-Za-z-]/;     ## name-character
21            $REG{NON_ftext_http} = $REG{NON_http_token};
22    
23    ## Namespace support
24            our %NS_phname2uri;     ## PH-namespace name -> namespace URI
25            our %NS_uri2package;    ## namespace URI -> Package name
26            our %NS_uri2phpackage;  ## namespace URI -> PH-Package name
27            require Message::Header::Default;       ## Default namespace
28    
29    ## Initialize of this class -- called by constructors
30    %DEFAULT = (
31        -_HASH_NAME => 'value',
32        -_METHODS   => [qw|field field_exist field_type add replace count delete subject id is|],
33        -_MEMBERS   => [qw|value|],
34        -_VALTYPE_DEFAULT   => ':default',
35        -by => 'name',
36        -field_format_pattern       => '%s: %s',
37        -field_name_case_sensible   => 0,
38        -field_name_unsafe_rule     => 'NON_ftext',
39        -field_name_validation      => 0,
40        -field_sort => 0,
41        -format     => 'mail-rfc2822',
42        -header_default_charset     => 'iso-2022-int-1',
43        -header_default_charset_input       => 'iso-2022-int-1',
44        -linebreak_strict   => 0,
45        -line_length_max    => 60,  ## For folding
46        #ns_default_phuri
47        -output_bcc => 0,
48        -output_folding     => 1,
49        -output_mail_from   => 0,
50        #parse_all
51        -translate_underscore       => 1,
52        #uri_mailto_safe
53        -uri_mailto_safe_level      => 4,
54        -use_folding        => 1,
55        #value_type
56    );
57    
58  use overload '@{}' => sub {shift->_delete_empty_field()->{field}},  ## taken from L<HTTP::Header>
59               '""' => sub {shift->stringify};  # "Good Practice" order of HTTP message headers:
60    #    - General-Headers
61    #    - Request-Headers
62    #    - Response-Headers
63    #    - Entity-Headers
64    # (From draft-ietf-http-v11-spec-rev-01, Nov 21, 1997)
65    my @header_order = qw(
66      mail-from x-envelope-from relay-version path status
67    
68       cache-control connection date pragma transfer-encoding upgrade trailer via
69    
70       accept accept-charset accept-encoding accept-language
71       authorization expect from host
72       if-modified-since if-match if-none-match if-range if-unmodified-since
73       max-forwards proxy-authorization range referer te user-agent
74    
75       accept-ranges age location proxy-authenticate retry-after server vary
76       warning www-authenticate
77    
78       mime-version
79       allow content-base content-encoding content-language content-length
80       content-location content-md5 content-range content-type
81       etag expires last-modified content-style-type content-script-type
82       link
83    
84  $REG{WSP}     = qr/[\x09\x20]/;    xref
85  $REG{FWS}     = qr/[\x09\x20]*/;  );
86  $REG{M_field} = qr/^([^\x3A]+):$REG{FWS}([\x00-\xFF]*)$/;  my %header_order;
 $REG{M_fromline} = qr/^\x3E?From$REG{WSP}+([\x00-\xFF]*)$/;  
 $REG{UNSAFE_field_name} = qr/[\x00-\x20\x3A\x7F-\xFF]/;  
87    
88  =head2 options  =head1 CONSTRUCTORS
89    
90  These options can be getten/set by C<get_option>/C<set_option>  The following methods construct new C<Message::Header> objects:
 method.  
91    
92  =head3 capitalize = 0/1  =over 4
93    
94  (First character of) C<field-name> is capitalized  =cut
95  when C<stringify>.  (Default = 1)  
96    sub _init ($;%) {
97      my $self = shift;
98      my %options = @_;
99      my $DEFAULT = Message::Util::make_clone (\%DEFAULT);
100      $self->SUPER::_init (%$DEFAULT, %options);
101      $self->{value} = [];
102      $self->_ns_load_ph ('default');
103      $self->_ns_load_ph ('x-rfc822');
104      $self->_ns_load_ph ('x-http');
105      $self->{option}->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'}
106        unless $self->{option}->{ns_default_phuri};
107      
108      ## For text/rfc822-headers
109      if (ref $options{entity_header}) {
110        $self->{entity_header} = $options{entity_header};
111        delete $options{entity_header};
112      }
113      my @new_fields = ();
114      for my $name (keys %options) {
115        unless (substr ($name, 0, 1) eq '-') {
116          push @new_fields, ($name => $options{$name});
117        }
118      }
119      $self->_init_by_format ($self->{option}->{format}, $self->{option});
120      # Make alternative representations of @header_order.  This is used
121      # for sorting.
122      my $i = 1;
123      for (@header_order) {
124          $header_order{$_} = $i++ unless $header_order{$_};
125      }
126      
127      $self->add (@new_fields, -parse => $self->{option}->{parse_all})
128        if $#new_fields > -1;
129    }
130    
131    sub _init_by_format ($$\%) {
132      my $self = shift;
133      my ($format, $option) = @_;
134      if ($format =~ /http/) {
135        $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'};
136        if ($format =~ /cgi/) {
137          unshift @header_order, qw(content-type location);
138          $option->{field_sort} = 'good-practice';
139          $option->{use_folding} = 0;
140        } else {
141          $option->{field_sort} = 'good-practice';
142        }
143      } else {      ## RFC 822
144        $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'};
145      }
146      if ($format =~ /uri-url-mailto/) {
147        $option->{output_bcc} = 0;
148        $option->{field_format_pattern} = '%s=%s';
149        $option->{output_folding} = sub {
150          $_[1] =~ s/([^:@+\$A-Za-z0-9\-_.!~*])/sprintf('%%%02X', ord $1)/ge;
151          $_[1];
152        };  ## Yes, this is not folding!
153      }
154    }
155    
156  =head3 fold_length = numeric value  =item $msg = Message::Header->new ([%initial-fields/options])
157    
158  Length of line used to fold.  (Default = 70)  Constructs a new C<Message::Headers> object.  You might pass some initial
159    C<field-name>-C<field-body> pairs and/or options as parameters to the constructor.
160    
161  =head3 mail_from = 0/1  Example:
162    
163  Outputs "From " line (known as Un*x From, Mail-From, and so on)   $hdr = new Message::Headers
164  when C<stringify>.  (Default = 0)          Date         => 'Thu, 03 Feb 1994 00:00:00 +0000',
165            Content_Type => 'text/html',
166            Content_Location => 'http://www.foo.example/',
167            -format => 'mail-rfc2822'       ## not to be header field
168            ;
169    
170  =cut  =cut
171    
172  %DEFAULT = (  ## Inherited
   capitalize    => 1,  
   fold_length   => 70,  
   field_type    => {':DEFAULT' => 'Message::Field::Unstructured'},  
   mail_from     => -1,  
   output_bcc    => -1,  
   parse_all     => -1,  
 );  
 my @field_type_Structured = qw(cancel-lock  
   importance mime-version path precedence x-cite  
   x-face x-mail-count x-msmail-priority x-priority x-uidl xref);  
 for (@field_type_Structured)  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}  
 my @field_type_Address = qw(approved bcc cc delivered-to disposition-notification-to  
   envelope-to  
   errors-to fcc from mail-followup-to mail-followup-cc mail-from reply-to resent-bcc  
   resent-cc resent-to resent-from resent-sender return-path  
   return-receipt-to sender to x-approved x-beenthere  
   x-complaints-to x-envelope-from x-envelope-sender  
   x-envelope-to x-ml-address x-ml-command x-ml-to x-nfrom x-nto);  
 for (@field_type_Address)  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Address'}  
 my @field_type_Date = qw(date date-received delivery-date expires  
   expire-date nntp-posting-date posted reply-by resent-date x-tcup-date);  
 for (@field_type_Date)  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Date'}  
 my @field_type_MsgID = qw(content-id in-reply-to message-id  
   references resent-message-id see-also supersedes);  
 for (@field_type_MsgID)  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::MsgID'}  
 for (qw(received x-received))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Received'}  
 $DEFAULT{field_type}->{'content-type'} = 'Message::Field::ContentType';  
 $DEFAULT{field_type}->{'content-disposition'} = 'Message::Field::ContentDisposition';  
 for (qw(x-face-type))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::ValueParams'}  
 for (qw(accept accept-charset accept-encoding accept-language  
   content-language  
   content-transfer-encoding encrypted followup-to keywords newsgroups  
   x-brother x-daughter x-respect x-moe x-syster x-wife))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::CSV'}  
 my @field_type_URI = qw(list-archive list-help list-owner  
   list-post list-subscribe list-unsubscribe uri url x-home-page x-http_referer  
   x-info x-pgp-key x-ml-url x-uri x-url x-web);  
 for (@field_type_URI)  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}  
 for (qw(list-id))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}  
 for (qw(subject title x-nsubject))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::Subject'}  
 for (qw(list-software user-agent server))  
   {$DEFAULT{field_type}->{$_} = 'Message::Field::UA'}  
173    
174  =head2 Message::Header->new ([%option])  =item $msg = Message::Header->parse ($header, [%initial-fields/options])
175    
176  Returns new Message::Header instance.  Some options can be  Parses given C<header> and constructs a new C<Message::Headers>
177  specified as hash.  object.  You might pass some additional C<field-name>-C<field-body> pairs
178    or/and initial options as parameters to the constructor.
179    
180  =cut  =cut
181    
182  sub new ($;%) {  sub parse ($$;%) {
183    my $class = shift;    my $class = shift;
184    my $self = bless {option => {@_}}, $class;    my $header = shift;
185    for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}}    my $self = bless {}, $class;
186      $self->_init (@_);
187      if ($self->{option}->{linebreak_strict}) {
188        $header =~ s/\x0D\x0A$REG{WSP}/\x20/gos if $self->{option}->{use_folding};
189      } else {
190        $header =~ s/\x0D?\x0A$REG{WSP}/\x20/gos if $self->{option}->{use_folding};
191      }
192      my %option = (%{ $self->{option} });
193      $option{parse_all} = 0;
194      for my $field (split /\x0D?\x0A/, $header) {
195        if ($field =~ /$REG{M_fromline}/) {
196          my ($s,undef,$value) = $self->_value_to_arrayitem
197            ('mail-from' => $1, \%option);
198          push @{$self->{value}}, $value if $s;
199        } elsif ($field =~ /$REG{M_field}/) {
200          my ($name, $body) = ($1, $2);
201          $body =~ s/$REG{WSP}+$//;
202          my ($s,undef,$value) = $self->_value_to_arrayitem
203            ($name => $body, \%option);
204          push @{$self->{value}}, $value if $s;
205        } elsif (length $field) {
206          my ($s,undef,$value) = $self->_value_to_arrayitem
207            ('x-unknown' => $field, \%option);
208          push @{$self->{value}}, $value if $s;
209        }
210      }
211      $self->_ns_associate_numerical_prefix;        ## RFC 2774 namespace
212      for (@{ $self->{value} }) {
213        no strict 'refs';
214        $_->{name}
215          = &{ ${ &_NS_uri2package ($_->{ns}).'::OPTION' }{n11n_name} }
216          ($self, &_NS_uri2package ($_->{ns}), $_->{name});
217        $_->{body} = $self->_parse_value ($_->{name} => $_->{body}, ns => $_->{ns})
218          if $self->{option}->{parse_all};
219      }
220    $self;    $self;
221  }  }
222    
223  =head2 Message::Header->parse ($header, [%option])  =item $msg = Message::Header->parse_array (\@header, [%initial-fields/options])
224    
225  Parses given C<header> and return a new Message::Header  Parses given C<header> and constructs a new C<Message::Headers>
226  object.  Some options can be specified as hash.  object.  Same as C<Message::Header-E<lt>parse> but this method
227    is given an array reference.  You might pass some additional
228    C<field-name>-C<field-body> pairs or/and initial options
229    as parameters to the constructor.
230    
231  =cut  =cut
232    
233  sub parse ($$;%) {  sub parse_array ($\@;%) {
234    my $class = shift;    my $class = shift;
235    my $header = shift;    my $header = shift;
236    my $self = bless {option => {@_}}, $class;    Carp::croak "parse_array: first argument is not an array reference"
237    for (keys %DEFAULT) {$self->{option}->{$_} ||= $DEFAULT{$_}}      unless ref $header eq 'ARRAY';
238    $header =~ s/\x0D?\x0A$REG{WSP}+/\x20/gos;    ## unfold    my $self = bless {}, $class;
239    for my $field (split /\x0D?\x0A/, $header) {    $self->_init (@_);
240      while (1) {
241        my $field = shift @$header;
242        if ($self->{option}->{use_folding}) {
243          while (1) {
244            if ($$header[0] =~ /^$REG{WSP}/) {
245              $field .= shift @$header;
246            } else {last}
247          }
248        }
249        if ($self->{option}->{linebreak_strict}) {
250          $field =~ s/\x0D\x0A//g;
251        } else {
252          $field =~ tr/\x0D\x0A//d;
253        }
254        local $self->{option}->{parse} = $self->{option}->{parse_all};
255      if ($field =~ /$REG{M_fromline}/) {      if ($field =~ /$REG{M_fromline}/) {
256        my $body = $1;        my ($s,undef,$value) = $self->_value_to_arrayitem
257        $body = $self->_field_body ($body, 'mail-from')          ('mail-from' => $1, $self->{option});
258          if $self->{option}->{parse_all}>0;        push @{$self->{value}}, $value if $s;
       push @{$self->{field}}, {name => 'mail-from', body => $body};  
259      } elsif ($field =~ /$REG{M_field}/) {      } elsif ($field =~ /$REG{M_field}/) {
260        my ($name, $body) = (lc $1, $2);        my ($name, $body) = ($self->_n11n_field_name ($1), $2);
       $name =~ s/$REG{WSP}+$//;  
261        $body =~ s/$REG{WSP}+$//;        $body =~ s/$REG{WSP}+$//;
262        $body = $self->_field_body ($body, $name) if $self->{option}->{parse_all}>0;        my ($s,undef,$value) = $self->_value_to_arrayitem
263        push @{$self->{field}}, {name => $name, body => $body};          ($name => $body, $self->{option});
264          push @{$self->{value}}, $value if $s;
265        } elsif (length $field) {
266          my ($s,undef,$value) = $self->_value_to_arrayitem
267            ('x-unknown' => $field, $self->{option});
268          push @{$self->{value}}, $value if $s;
269      }      }
270        last if $#$header < 0;
271    }    }
272      $self->_ns_associate_numerical_prefix;        ## RFC 2774 namespace
273    $self;    $self;
274  }  }
275    
276    =back
277    
278    =head1 METHODS
279    
280  =head2 $self->field ($field_name)  =head2 $self->field ($field_name)
281    
282  Returns C<field-body> of given C<field-name>.  Returns C<field-body> of given C<field-name>.
# Line 150  context, only first one is returned.) Line 286  context, only first one is returned.)
286    
287  =cut  =cut
288    
289  sub field ($$) {  sub field ($@) {shift->SUPER::item (@_)}
290    sub field_exist ($@) {shift->SUPER::item_exist (@_)}
291    
292    ## item-by?, \$checked-item, {item-key => 1}, \%option
293    sub _item_match ($$\$\%\%) {
294    my $self = shift;    my $self = shift;
295    my $name = lc shift;    my ($by, $i, $list, $option) = @_;
296    my @ret;    return 0 unless ref $$i;  ## Already removed
297    for my $field (@{$self->{field}}) {    if ($by eq 'name') {
298      if ($field->{name} eq $name) {      my %o = %$option; #$o{parse} = 0;
299        unless (wantarray) {      my %l;
300          $field->{body} = $self->_field_body ($field->{body}, $name);      for (keys %$list) {
301          return $field->{body};        my ($s, undef, $v) = $self->_value_to_arrayitem ($_, '', %o);
302          if ($s) {
303            $l{$v->{name} . ':' . ( $option->{ns} || $v->{ns} ) } = 1;
304        } else {        } else {
305          $field->{body} = $self->_field_body ($field->{body}, $name);          $l{$v->{name} .':'. ( $option->{ns} || $self->{option}->{ns_default_phuri} ) } = 1;
306          push @ret, $field->{body};        }
307        }
308        return 1 if $l{$$i->{name} . ':' . $$i->{ns}};
309      } elsif ($by eq 'ns') {
310        return 1 if $list->{ $$i->{ns} };
311      } elsif ($by eq 'http-ns-define') {
312        if ($$i->{ns} eq $self->{ns}->{phname2uri}->{'x-http'}
313         || $$i->{ns} eq $self->{ns}->{phname2uri}->{'x-http-c'}) {
314          my $n = $$i->{name};
315          if ($n eq 'opt' || $n eq 'c-opt' || $n eq 'man' || $n eq 'c-man') {
316            $option->{parse} = 0;
317            $$i->{body} = $self->_parse_value ($$i->{name} => $$i->{body}, ns => $$i->{ns});
318            for my $j (0..$$i->{body}->count-1) {
319              return 1 if $list->{ ($$i->{body}->value ($j))[0]->value };
320            }
321        }        }
322      }      }
323    }    }
324    if ($#ret < 0) {    0;
     return $self->add ($name);  
   }  
   @ret;  
325  }  }
326    *_delete_match = \&_item_match;
327    
328  sub field_exist ($$) {  ## Returns returned item value    \$item-value, \%option
329    my $self = shift;  sub _item_return_value ($\$\%) {
330    my $name = lc shift;    if (ref ${$_[1]}->{body}) {
331    my @ret;      ${$_[1]}->{body};
332    for my $field (@{$self->{field}}) {    } else {
333      return 1 if ($field->{name} eq $name);      ${$_[1]}->{body} = $_[0]->_parse_value (${$_[1]}->{name} => ${$_[1]}->{body},
334          ns => ${$_[1]}->{ns});
335        ${$_[1]}->{body};
336      }
337    }
338    *_add_return_value = \&_item_return_value;
339    *_replace_return_value = \&_item_return_value;
340    
341    ## Returns returned (new created) item value    $name, \%option
342    sub _item_new_value ($$\%) {
343      my $self = shift;
344      my ($name, $option) = @_;
345      if ($option->{by} eq 'http-ns-define') {
346        my $value = $self->_parse_value (opt => '', ns => $self->{ns}->{phname2uri}->{'x-http'});
347        ($value->value (0))[0]->value ($name);
348        {name => 'opt', body => $value, ns => $self->{ns}->{phname2uri}->{'x-http'}};
349      } else {
350        my ($s,undef,$value) = $self->_value_to_arrayitem
351            ($name => '', $option);
352        $s? $value: undef;
353    }    }
   0;  
354  }  }
355    
 =head2 $self->field_name ($index)  
   
 Returns C<field-name> of $index'th C<field>.  
   
 =head2 $self->field_body ($index)  
356    
 Returns C<field-body> of $index'th C<field>.  
   
 =cut  
357    
358  sub field_name ($$) {  ## $self->_parse_value ($type, $value, %options);
359    sub _parse_value ($$$;%) {
360    my $self = shift;    my $self = shift;
361    $self->{field}->[shift]->{name};    my $name = shift ;#|| $self->{option}->{_VALTYPE_DEFAULT};
362  }    my $value = shift;  return $value if ref $value;
363  sub field_body ($$) {    my %option = @_;
364    my $self = shift;    my $vtype; { no strict 'refs';
365    my $i = shift;      my $vt = ${&_NS_uri2package ($option{ns}).'::OPTION'}{value_type};
366    $self->{field}->[$i]->{body}      if (ref $vt) {
367     = $self->_field_body ($self->{field}->[$i]->{body}, $self->{field}->[$i]->{name});        $vtype = $vt->{$name} || $vt->{$self->{option}->{_VALTYPE_DEFAULT}};
368    $self->{field}->[$i]->{body};      }
369        ## For compatiblity.
370        unless (ref $vtype) { $vtype = $self->{option}->{value_type}->{$name}
371          || $self->{option}->{value_type}->{$self->{option}->{_VALTYPE_DEFAULT}} }
372      }
373      my $vpackage = $vtype->[0];
374      my %vopt = %{$vtype->[1]} if ref $vtype->[1];
375      if ($vpackage eq ':none:') {
376        return $value;
377      } elsif (defined $value) {
378        eval "require $vpackage" or Carp::croak qq{<parse>: $vpackage: Can't load package: $@};
379        return $vpackage->parse ($value,
380          -format   => $self->{option}->{format},
381          -field_ns => $option{ns},
382          -field_name       => $name,
383        -header_default_charset     => $self->{option}->{header_default_charset},
384        -header_default_charset_input       => $self->{option}->{header_default_charset_input},
385          -parse_all        => $self->{option}->{parse_all},
386        %vopt);
387      } else {
388        eval "require $vpackage" or Carp::croak qq{<parse>: $vpackage: Can't load package: $@};
389        return $vpackage->new (
390          -format   => $self->{option}->{format},
391          -field_ns => $option{ns},
392          -field_name       => $name,
393        -header_default_charset     => $self->{option}->{header_default_charset},
394        -header_default_charset_input       => $self->{option}->{header_default_charset_input},
395          -parse_all        => $self->{option}->{parse_all},
396        %vopt);
397      }
398  }  }
399    
400  sub _field_body ($$$) {  ## Defined for text/rfc822-headers
401    my $self = shift;  sub entity_header ($;$) {
402    my ($body, $name) = @_;    my $self = shift;
403    unless (ref $body) {    my $new_header = shift;
404      my $type = $self->{option}->{field_type}->{$name}    if (ref $new_header) {
405              || $self->{option}->{field_type}->{':DEFAULT'};      $self->{header} = $new_header;
     eval "require $type";  
     unless ($body) {  
       $body = $type->new (field_name => $name);  
     } else {  
       $body = $type->parse ($body, field_name => $name);  
     }  
406    }    }
407    $body;    $self->{header};
408  }  }
409    
410  =head2 $self->field_name_list ()  =head2 $self->field_name_list ()
# Line 229  returns ALL names.) Line 417  returns ALL names.)
417    
418  sub field_name_list ($) {  sub field_name_list ($) {
419    my $self = shift;    my $self = shift;
420    $self->_delete_empty_field ();    $self->_delete_empty ();
421    map {$_->{name}} @{$self->{field}};    map { $_->{name} . ':' . $_->{ns} } @{$self->{value}};
422  }  }
423    
424  =head2 $self->add ($field_name, $field_body)  sub namespace_ph_default ($;$) {
425      my $self = shift;
426      if (defined $_[0]) {
427        no strict 'refs';
428        $self->{option}->{ns_default_phuri} = $_[0];
429        $self->_ns_load_ph (${&_NS_uri2package ($self->{option}->{ns_default_phuri}).'::OPTION'}{namespace_phname});
430      }
431      $self->{option}->{ns_default_phuri};
432    }
433    
434    =item $hdr->add ($field-name, $field-body, [$name, $body, ...])
435    
436    Adds some field name/body pairs.  Even if there are
437    one or more fields named given C<$field-name>,
438    given name/body pairs are ADDed.  Use C<replace>
439    to remove same-name-fields.
440    
441    Instead of field name-body pair, you might pass some options.
442    Four options are available for this method.
443    
444    C<-parse>: Parses and validates C<field-body>, and returns
445    C<field-body> object.  (When multiple C<field-body>s are
446    added, returns only last one.)  (Default: C<defined wantarray>)
447    
448  Adds an new C<field>.  It is not checked whether  C<-prepend>: New fields are not appended,
449  the field which named $field_body is already exist or not.  but prepended to current fields.  (Default: C<0>)
450  If you don't want duplicated C<field>s, use C<replace> method.  
451    C<-translate-underscore>: Do C<field-name> =~ tr/_/-/.  (Default: C<1>)
452    
453    C<-validate>: Checks whether C<field-name> is valid or not.
454    
455  =cut  =cut
456    
457  sub add ($$;$%) {  ## [Name: Value] pair -> internal array item
458    ## $self->_value_to_arrayitem ($name => $value, {%options})
459    ## or
460    ## $self->_value_to_arrayitem ($name => [$value, %value_options], {%options})
461    ##
462    ## Return: ((1 = success / 0 = failue), $full_name, $arrayitem)
463    sub _value_to_arrayitem ($$$\%) {
464    my $self = shift;    my $self = shift;
465    my ($name, $body) = (lc shift, shift);    my ($name, $value, $option) = @_;
466    my %option = @_;    my $value_option = {};
467    return 0 if $name =~ /$REG{UNSAFE_field_name}/;    if (ref $value eq 'ARRAY') {
468    $body = $self->_field_body ($body, $name);      ($value, %$value_option) = @$value;
469    if ($option{prepend}) {    }
470      unshift @{$self->{field}}, {name => $name, body => $body};    my $nsuri = $self->{option}->{ns_default_phuri};
471    } else {    $name =~ s/^$REG{WSP}+//;  $name =~ s/$REG{WSP}+$//;
472      push @{$self->{field}}, {name => $name, body => $body};    
473      no strict 'refs';
474      if ($value_option->{ns}) {
475        $nsuri = $value_option->{ns};
476      } elsif ($option->{ns}) {
477        $nsuri = $option->{ns};
478      } elsif (($option->{ns_default_phuri} eq $self->{ns}->{uri2phname}->{'x-http'}
479           && $name =~ s/^([0-9]+)-//)
480        || ($name =~ s/^x-http-([0-9]+)-//i)) {     ## Numric namespace prefix, RFC 2774
481        my $prefix = 0+$1;
482        $nsuri = $self->{ns}->{number2uri}->{ $prefix };
483        unless ($nsuri) {
484          $self->{ns}->{number2uri}->{ $prefix } = 'urn:x-suika-fam-cx:msgpm:header:x-temp:'.$prefix;
485          $nsuri = $self->{ns}->{number2uri}->{ $prefix };
486        }
487      } elsif (($name =~ s/^([Xx]-[A-Za-z]+|[A-YZa-yz][A-Za-z]*)-
488                           ([Xx]-[A-Za-z]+|[A-YZa-yz][A-Za-z]*)-//x)
489        || $name =~ s/^([Xx]-[A-Za-z]+|[A-Za-z]+)-//) {
490        my ($prefix1, $prefix2) = ($1, $2);
491        my $original_prefix = $&;  my $one_prefix = 0;
492        unless ($prefix2) {
493          $prefix2 = $prefix1;
494          $prefix1 = $self->{ns}->{uri2phname}->{ $option->{ns_default_phuri} };
495          $one_prefix = 1;
496        }
497        my $prefix
498          = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
499            ($self, &_NS_uri2package ($nsuri), $prefix1.'-'.$prefix2);
500        $self->_ns_load_ph ($prefix);
501        $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
502        unless ($nsuri) {
503          $nsuri = $self->{option}->{ns_default_phuri};
504          $prefix
505            = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
506              ($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2: $prefix1);
507          $self->_ns_load_ph ($prefix);
508          $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
509          if ($nsuri) {
510            $name = $prefix2 . '-' . $name unless $one_prefix;
511          } else {
512            $name = $original_prefix . $name;
513            $nsuri = $self->{option}->{ns_default_phuri};
514          }
515        }
516    }    }
517    $body;    $name
518        = &{${&_NS_uri2package ($nsuri).'::OPTION'}{n11n_name}}
519          ($self, &_NS_uri2package ($nsuri), $name);
520      Carp::croak "$name: invalid field-name"
521        if $option->{field_name_validation}
522          && $name =~ /$REG{$option->{field_name_unsafe_rule}}/;
523      $value = $self->_parse_value ($name => $value, ns => $nsuri)
524        if $$option{parse} || $$option{parse_all};
525      $$option{parse} = 0;
526      (1, $name.':'.$nsuri => {name => $name, body => $value, ns => $nsuri});
527  }  }
528    *_add_hash_check = \&_value_to_arrayitem;
529    *_replace_hash_check = \&_value_to_arrayitem;
530    
531  =head2 $self->relace ($field_name, $field_body)  =head2 $self->relace ($field_name, $field_body)
532    
# Line 265  first one is used and the others are not Line 538  first one is used and the others are not
538    
539  =cut  =cut
540    
541  sub replace ($$$) {  sub _replace_hash_shift ($\%$\%) {
542    my $self = shift;    shift; my $r = shift;  my $n = $_[0]->{name} . ':' . $_[0]->{ns};
543    my ($name, $body) = (lc shift, shift);    if ($$r{$n}) {
544    return 0 if $name =~ /$REG{UNSAFE_field_name}/;      my $d = $$r{$n};
545    $body = $self->_field_body ($body, $name);      delete $$r{$n};
546    for my $field (@{$self->{field}}) {      return $d;
     if ($field->{name} eq $name) {  
       $field->{body} = $body;  
       return $body;  
     }  
547    }    }
548    push @{$self->{field}}, {name => $name, body => $body};    undef;
   $body;  
549  }  }
550    
551  =head2 $self->delete ($field_name, [$index])  =head2 $self->delete ($field-name, [$name, ...])
552    
553  Deletes C<field> named as $field_name.  Deletes C<field> named as $field_name.
 If $index is specified, only $index'th C<field> is deleted.  
 If not, ($index == 0), all C<field>s that have the C<field-name>  
 $field_name are deleted.  
554    
555  =cut  =cut
556    
 sub delete ($$;$) {  
   my $self = shift;  
   my ($name, $index) = (lc shift, shift);  
   my $i = 0;  
   for my $field (@{$self->{field}}) {  
     if ($field->{name} eq $name) {  
       $i++;  
       if ($index == 0 || $i == $index) {  
         undef $field;  
         return $self if $i == $index;  
       }  
     }  
   }  
   $self;  
 }  
557    
558  =head2 $self->count ([$field_name])  =head2 $self->count ([$field_name])
559    
# Line 313  of fields.  (Same as $#$self+1) Line 563  of fields.  (Same as $#$self+1)
563    
564  =cut  =cut
565    
566  sub count ($;$) {  sub _count_by_name ($$\%) {
567    my $self = shift;    my $self = shift;
568    my ($name) = (lc shift);    my ($array, $option) = @_;
569    unless ($name) {    my $name = $self->_n11n_field_name ($$option{-name});
570      $self->_delete_empty_field ();    my @a = grep {$_->{name} eq $name} @{$self->{$array}};
571      return $#{$self->{field}}+1;    $#a + 1;
   }  
   my $count = 0;  
   for my $field (@{$self->{field}}) {  
     if ($field->{name} eq $name) {  
       $count++;  
     }  
   }  
   $count;  
572  }  }
573    
574  =head2 $self->stringify ([%option])  ## Delete empty items
575    sub _delete_empty ($) {
576      my $self = shift;
577      my $array = $self->{option}->{_HASH_NAME};
578      $self->{$array} = [grep {ref $_ && length $_->{name}} @{$self->{$array}}];
579    }
580    
581  Returns the C<header> as a string.  =head2 $self->rename ($field-name, $new-name, [$old, $new,...])
582    
583    Renames C<$field-name> as C<$new-name>.
584    
585  =cut  =cut
586    
587  sub stringify ($;%) {  sub rename ($%) {
588    my $self = shift;    my $self = shift;
589    my %OPT = @_;    my %params = @_;
590    my @ret;    my %option = %{$self->{option}};
591    $OPT{capitalize} ||= $self->{option}->{capitalize};    for (grep {/^-/} keys %params) {$option{substr ($_, 1)} = $params{$_}}
592    $OPT{mail_from} ||= $self->{option}->{mail_from};    my %new_name;
593    $OPT{output_bcc} ||= $self->{option}->{output_bcc};    for (grep {/^[^-]/} keys %params) {
594    push @ret, 'From '.$self->field ('mail-from') if $OPT{mail_from}>0;      my ($old => $new)
595    for my $field (@{$self->{field}}) {        = ($self->_n11n_field_name ($_) => $self->_n11n_field_name ($params{$_}));
596      my $name = $field->{name};      $old =~ tr/_/-/ if $option{translate_underscore};
597      next unless $name;      $new =~ tr/_/-/ if $option{translate_underscore};
598      next if $OPT{mail_from}<0 && $name eq 'mail-from';      Carp::croak "rename: $new: invalid field-name"
599      next if $OPT{output_bcc}<0 && ($name eq 'bcc' || $name eq 'resent-bcc');        if $option{field_name_validation}
600      my $fbody = scalar $field->{body};          && $new =~ /$REG{$option{field_name_unsafe_rule}}/;
601      next unless $fbody;      $new_name{$old} = $new;
     $fbody =~ s/\x0D([^\x09\x0A\x20])/\x0D\x20$1/g;  
     $fbody =~ s/\x0A([^\x09\x20])/\x0A\x20$1/g;  
     $name =~ s/((?:^|-)[a-z])/uc($1)/ge if $OPT{capitalize};  
     push @ret, $name.': '.$self->fold ($fbody);  
602    }    }
603    my $ret = join ("\n", @ret);    for my $field (@{$self->{value}}) {
604    $ret? $ret."\n": "";      if (length $new_name{$field->{name}}) {
605          $field->{name} = $new_name{$field->{name}};
606        }
607      }
608      $self if defined wantarray;
609  }  }
610    
 =head2 $self->get_option ($option_name)  
   
 Returns value of the option.  
611    
612  =head2 $self->set_option ($option_name, $option_value)  =item $self->scan(\&doit)
613    
614  Set new value of the option.  Apply a subroutine to each header field in turn.  The callback routine is
615    called with two parameters; the name of the field and a single value.
616    If the header has more than one value, then the routine is called once
617    for each value.
618    
619  =cut  =cut
620    
621  sub get_option ($$) {  sub _scan_sort ($\@\%) {
622    my $self = shift;    my $self = shift;
623    my ($name) = @_;    my ($array, $option) = @_;
624    $self->{option}->{$name};    my $sort;
625      $sort = \&_header_cmp if $option->{field_sort} eq 'good-practice';
626      $sort = {$a cmp $b} if $option->{field_sort} eq 'alphabetic';
627      return ( sort $sort @$array ) if ref $sort;
628      @$array;
629  }  }
630  sub set_option ($$$) {  
631    sub _n11n_field_name ($$) {
632      no strict 'refs';
633    my $self = shift;    my $self = shift;
634    my ($name, $value) = @_;    my $s = shift;
635    $self->{option}->{$name} = $value;    $s =~ s/^$REG{WSP}+//; $s =~ s/$REG{WSP}+$//;
636    $self;    $s = lc $s unless ${&_NS_uri2package ($self->{option}->{ns_default_phuri}).'::OPTION'}{case_sensible};
637      $s;
638    }
639    
640    # Compare function which makes it easy to sort headers in the
641    # recommended "Good Practice" order.
642    ## taken from HTTP::Header
643    sub _header_cmp
644    {
645      my ($na, $nb) = ($a->{name}, $b->{name});
646        # Unknown headers are assign a large value so that they are
647        # sorted last.  This also helps avoiding a warning from -w
648        # about comparing undefined values.
649        $header_order{$na} = 999 unless defined $header_order{$na};
650        $header_order{$nb} = 999 unless defined $header_order{$nb};
651    
652        $header_order{$na} <=> $header_order{$nb} || $na cmp $nb;
653  }  }
654    
655  sub field_type ($$;$) {  =head2 $self->stringify ([%option])
656    
657    Returns the C<header> as a string.
658    
659    =cut
660    
661    sub stringify ($;%) {
662    my $self = shift;    my $self = shift;
663    my $field_name = shift;    my %params = @_;
664    my $new_field_type = shift;    my %option = %{$self->{option}};
665    if ($new_field_type) {    $option{format} = $params{-format} if $params{-format};
666      $self->{option}->{field_type}->{$field_name} = $new_field_type;    $self->_init_by_format ($option{format}, \%option);
667      for (grep {/^-/} keys %params) {$option{substr ($_, 1)} = $params{$_}}
668      my @ret;
669      ## RFC 2774 numerical field name prefix
670      my %nprefix;
671      {no strict 'refs';
672        %nprefix = reverse %{ $self->{ns}->{number2uri} };
673        my $i = (sort { $a <=> $b } keys %{ $self->{ns}->{number2uri} })[-1] + 1;
674        $i = 10 if $i < 10;
675        my $hprefix = ${ &_NS_uri2package
676                           ($self->{ns}->{phname2uri}->{'x-http'})
677                           .'::OPTION' } {namespace_phname_goodcase};
678        for my $uri (keys %nprefix) {
679          if ($nprefix{ $uri } < 10) {
680            $nprefix{ $uri } = $i++;
681          }
682          my $nsfs = $self->item ($uri, -by => 'http-ns-define');
683          for my $i (0..$nsfs->count-1) {
684            my $nsf = ($nsfs->value ($i))[0];
685            if ($nsf->value eq $uri) {
686              $nsf->replace (ns => $nprefix{ $uri });
687              $nprefix{ $uri } = $hprefix . '-' . $nprefix{ $uri };
688              last;
689            }
690          }
691        }
692      }
693      my $_stringify = sub {
694        no strict 'refs';
695          my ($name, $body, $nsuri) = ($_[1]->{name}, $_[1]->{body}, $_[1]->{ns});
696          return unless length $name;
697          return if $option{output_mail_from} && $name eq 'mail-from';
698          $body = '' if !$option{output_bcc} && $name eq 'bcc';
699          my $nspackage = &_NS_uri2package ($nsuri);
700          my $oname;        ## Outputed field-name
701          my $prefix = $nprefix{ $nsuri }
702                    || ${$nspackage.'::OPTION'} {namespace_phname_goodcase}
703                    || $self->{ns}->{uri2phname}->{ $nsuri };
704          my $default_prefix = ${ &_NS_uri2package ($option{ns_default_phuri})
705                                  .'::OPTION'} {namespace_phname_goodcase};
706          $prefix = '' if $prefix eq $default_prefix;
707          $prefix =~ s/^\Q$default_prefix\E-//;
708          my $gc = ${$nspackage.'::OPTION'} {to_be_goodcase};
709          if (ref $gc) { $oname = &$gc ($self, $nspackage, $name, \%option) }
710          else { $oname = $name }
711          if ($prefix) { $oname = $prefix . '-' . $oname }
712          if ($option{format} =~ /uri-url-mailto/) {
713            return if (( ${$nspackage.'::OPTION'} {uri_mailto_safe}->{$name}
714                      || ${$nspackage.'::OPTION'} {uri_mailto_safe}->{':default'})
715                      < $option{uri_mailto_safe_level});
716            if ($name eq 'to') {
717              $body = $self->field ('to', -new_item_unless_exist => 0);
718              if (ref $body && $body->have_group) {
719                #
720              } elsif (ref $body && $body->count > 1) {
721                $body = $body->clone;
722                $body->delete ({-by => 'index'}, 0);
723              }
724            }
725          }
726          my $fbody;
727          if (ref $body) {
728            $fbody = $body->stringify (-format => $option{format});
729          } else {
730            $fbody = $body;
731          }
732          unless (${$nspackage.'::OPTION'} {field}->{$name}->{empty_body}) {
733            return unless length $fbody;
734          }
735          unless ($option{linebreak_strict}) {
736            ## bare \x0D and bare \x0A are unsafe
737            $fbody =~ s/\x0D(?=[^\x09\x0A\x20])/\x0D\x20/g;
738            $fbody =~ s/\x0A(?=[^\x09\x20])/\x0A\x20/g;
739          } else {
740            $fbody =~ s/\x0D\x0A(?=[^\x09\x20])/\x0D\x0A\x20/g;
741          }
742          if ($option{use_folding}) {
743            if (ref $option{output_folding}) {
744              $fbody = &{$option{output_folding}} ($self, $fbody,
745                -initial_length => length ($oname) +2);
746            } elsif ($option{output_folding}) {
747              $fbody = $self->_fold ($fbody, -initial_length => length ($oname) +2);
748            }
749          }
750          push @ret, sprintf $option{field_format_pattern}, $oname, $fbody;
751        };
752      if ($option{format} =~ /uri-url-mailto/) {
753        if ($option{format} =~ /uri-url-mailto-to/) {
754          my $to = $self->field ('to', -new_item_unless_exist => 0);
755          if ($to) {
756            unless ($to->have_group) {
757              my $fbody = $to->stringify (-format => $option{format}, -max => 1);
758              return &{$option{output_folding}} ($self, $fbody);
759            }
760          }
761          '';
762        } elsif ($option{format} =~ /uri-url-mailto-rfc1738/) {
763          my $to = $self->field ('to', -new_item_unless_exist => 0);
764          if ($to) {
765            my $fbody = $to->addr_spec (-format => $option{format});
766            return &{$option{output_folding}} ($self, $fbody);
767          }
768          '';
769        } else {
770          $self->scan ($_stringify);
771          my $ret = join ('&', @ret);
772          $ret;
773        }
774      } else {
775        if ($option{output_mail_from}) {
776          my $fromline = $self->field ('mail-from', -new_item_unless_exist => 0);
777          push @ret, 'From '.$fromline if $fromline;
778        }
779        $self->scan ($_stringify);
780        my $ret = join ("\x0D\x0A", @ret);
781        $ret? $ret."\x0D\x0A": '';
782    }    }
   $self->{option}->{field_type}->{$field_name}  
   || $self->{option}->{field_type}->{':DEFAULT'};  
783  }  }
784    *as_string = \&stringify;
785    
786    =head2 $self->option ($option_name, [$option_value])
787    
788    Set/gets new value of the option.
789    
790  sub _delete_empty_field ($) {  =cut
791    
792    sub option ($@) {
793    my $self = shift;    my $self = shift;
794    my @ret;    if (@_ == 1) {
795    for my $field (@{$self->{field}}) {      return $self->{option}->{ shift (@_) };
796      push @ret, $field if $field->{name};    }
797      while (my ($name, $value) = splice (@_, 0, 2)) {
798        $self->{option}->{$name} = $value;
799        if ($name eq 'format') {
800          for my $f (@{$self->{field}}) {
801            if (ref $f->{body}) {
802              $f->{body}->option (-format => $value);
803            }
804          }
805        }
806    }    }
   $self->{field} = \@ret;  
   $self;  
807  }  }
808    
809  sub fold ($$;$) {  sub field_type ($@) {shift->SUPER::value_type (@_)}
810    
811    ## $self->_fold ($string, %option = (-max, -initial_length(for field-name)) )
812    sub _fold ($$;%) {
813    my $self = shift;    my $self = shift;
814    my $string = shift;    my $string = shift;
815    my $len = shift || $self->{option}->{fold_length};    my %option = @_;
816    $len = 60 if $len < 60;    my $max = $self->{option}->{line_length_max};
817        $max = 20 if $max < 20;
   ## This code is taken from Mail::Header 1.43 in MailTools,  
   ## by Graham Barr (Maintained by Mark Overmeer <mailtools@overmeer.net>).  
   my $max = int($len - 5);         # 4 for leading spcs + 1 for [\,\;]  
   my $min = int($len * 4 / 5) - 4;  
   my $ml = $len;  
818        
819    if (length($string) > $ml) {    my $l = $option{-initial_length} || 0;
820       #Split the line up    $l += length $1 if $string =~ /^([^\x09\x20]+)/;
821       # first bias towards splitting at a , or a ; >4/5 along the line    $string =~ s{([\x09\x20][^\x09\x20]+)}{
822       # next split a whitespace      my $s = $1;
823       # else we are looking at a single word and probably don't want to split      if (($l + length $s) > $max) {
824       my $x = "";        $s = "\x0D\x0A\x20" . $s;
825       $x .= "$1\n "        $l = 1 + length $s;
826         while($string =~ s/^$REG{WSP}*(      } else { $l += length $s }
827                            [^"]{$min,$max}?[\,\;]      $s;
828                            |[^"]{1,$max}$REG{WSP}    }gex;
                           |[^\s"]*(?:"[^"]*"[^\s"]*)+$REG{WSP}  
                           |[^\s"]+$REG{WSP}  
                           )  
                         //x);  
      $x .= $string;  
      $string = $x;  
      $string =~ s/(\A$REG{WSP}+|$REG{WSP}+\Z)//sog;  
      $string =~ s/\s+\n/\n/sog;  
   }  
829    $string;    $string;
830  }  }
831    
832    sub _ns_load_ph ($$) {
833      my $self = shift;
834      my $name = shift;     ## normalized prefix (without HYPHEN-MINUS)
835      return if $self->{ns}->{phname2uri}->{$name};
836      $self->{ns}->{phname2uri}->{$name} = $NS_phname2uri{$name};
837      return unless $self->{ns}->{phname2uri}->{$name};
838      $self->{ns}->{uri2phname}->{$self->{ns}->{phname2uri}->{$name}} = $name;
839    }
840    
841    sub _ns_associate_numerical_prefix ($) {
842      my $self = shift;
843      $self->scan (sub {shift;
844        my $f = shift;  return unless $f->{name};
845        if ($f->{ns} eq $self->{ns}->{phname2uri}->{'x-http'}
846         || $f->{ns} eq $self->{ns}->{phname2uri}->{'x-http-c'}) {
847          my $fn = $f->{name};
848          if ($fn eq 'opt' || $fn eq 'man') {
849            $f->{body} = $self->_parse_value ($fn => $f->{body}, ns => $f->{ns});
850            for ($f->{body}->value (0..$f->{body}->count-1)) {
851              my ($nsuri, $number) = ($_->value, $_->item ('ns'));
852              if ($number && $nsuri) {
853                $self->{ns}->{number2uri}->{ $number } = $nsuri;
854              }
855            }
856          }
857        }
858      });
859      $self->scan (sub {shift;
860        my $f = shift;
861        if ($f->{ns} =~ /urn:x-suika-fam-cx:msgpm:header:x-temp:([0-9]+)$/ && $self->{ns}->{number2uri}->{ $1 }) {
862          $f->{ns} = $self->{ns}->{number2uri}->{ $1 };
863        }
864      });
865    }
866    
867    ## $package_name = Message::Header::_NS_uri2phpackage ($nsuri)
868    ## (For internal use of Message::* modules)
869    sub _NS_uri2phpackage ($) {
870      $NS_uri2phpackage{$_[0]}
871      || $NS_uri2phpackage{$Message::Header::Default::OPTION{namespace_uri}};
872    }
873    sub _NS_uri2package ($) {
874      $NS_uri2package{$_[0]}
875      || $NS_uri2phpackage{$_[0]}
876      || $NS_uri2phpackage{$Message::Header::Default::OPTION{namespace_uri}};
877    }
878    
879    =head2 $self->clone ()
880    
881    Returns a copy of Message::Header object.
882    
883    =cut
884    
885    ## Inhreited
886    
887    =head1 NOTE
888    
889    =head2 C<field-name>
890    
891    The header field name is not case sensitive.  To make the life
892    easier for perl users who wants to avoid quoting before the => operator,
893    you can use '_' as a synonym for '-' in header field names
894    (this behaviour can be suppressed by setting
895    C<translate_underscore> option to C<0> value).
896    
897  =head1 EXAMPLE  =head1 EXAMPLE
898    
899    ## Print field list    ## Print field list
# Line 443  sub fold ($$;$) { Line 901  sub fold ($$;$) {
901    use Message::Header;    use Message::Header;
902    my $header = Message::Header->parse ($header);    my $header = Message::Header->parse ($header);
903        
   ## Next sample is better.  
   #for my $field (@$header) {  
   #  print $field->{name}, "\t=> ", $field->{body}, "\n";  
   #}  
     
904    for my $i (0..$#$header) {    for my $i (0..$#$header) {
905      print $header->field_name ($i), "\t=> ", $header->field_body ($i), "\n";      print $header->field_name ($i), "\t=> ", $header->field_body ($i), "\n";
906    }    }
# Line 470  sub fold ($$;$) { Line 923  sub fold ($$;$) {
923    $header->add ('References' => '<hoge.msgid%foo@foo.example>');    $header->add ('References' => '<hoge.msgid%foo@foo.example>');
924    print $header;    print $header;
925    
926    =head1 ACKNOWLEDGEMENTS
927    
928    Some of codes are taken from other modules such as
929    HTTP::Header, Mail::Header.
930    
931  =head1 LICENSE  =head1 LICENSE
932    
933  Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.  Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.32

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24