/[suikacvs]/test/cvs
Suika

Diff of /test/cvs

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

revision 1.24 by wakaba, Tue Jun 11 13:01:21 2002 UTC revision 1.35 by wakaba, Mon Jul 8 12:39:39 2002 UTC
# Line 22  push @ISA, qw(Message::Field::Structured Line 22  push @ISA, qw(Message::Field::Structured
22    
23  ## Namespace support  ## Namespace support
24          our %NS_phname2uri;     ## PH-namespace name -> namespace URI          our %NS_phname2uri;     ## PH-namespace name -> namespace URI
25          our %NS_uri2phpackage;  ## namespace URI -> PH-package name          our %NS_uri2package;    ## namespace URI -> Package name
26            our %NS_uri2phpackage;  ## namespace URI -> PH-Package name
27          require Message::Header::Default;       ## Default namespace          require Message::Header::Default;       ## Default namespace
28    
29  ## Initialize of this class -- called by constructors  ## Initialize of this class -- called by constructors
# Line 30  push @ISA, qw(Message::Field::Structured Line 31  push @ISA, qw(Message::Field::Structured
31      -_HASH_NAME => 'value',      -_HASH_NAME => 'value',
32      -_METHODS   => [qw|field field_exist field_type add replace count delete subject id is|],      -_METHODS   => [qw|field field_exist field_type add replace count delete subject id is|],
33      -_MEMBERS   => [qw|value|],      -_MEMBERS   => [qw|value|],
     -M_namsepace_prefix_regex => qr/(?!)/,  
34      -_VALTYPE_DEFAULT   => ':default',      -_VALTYPE_DEFAULT   => ':default',
35      -by => 'name',      ## (Reserved for method level option)      -by => 'name',
36      -field_format_pattern       => '%s: %s',      -field_format_pattern       => '%s: %s',
37      -field_name_case_sensible   => 0,      -field_name_case_sensible   => 0,
38      -field_name_unsafe_rule     => 'NON_ftext',      -field_name_unsafe_rule     => 'NON_ftext',
39      -field_name_validation      => 1,   ## Method level option.      -field_name_validation      => 0,
40      -field_sort => 0,      -field_sort => 0,
41      #-format    => 'mail-rfc2822',      -format     => 'mail-rfc2822',
42      -linebreak_strict   => 0,   ## Not implemented completely      -header_default_charset     => 'iso-2022-int-1',
43        -header_default_charset_input       => 'iso-2022-int-1',
44        -hook_init_fill_options     => sub {},
45        -hook_stringify_fill_fields => sub {},
46        -linebreak_strict   => 0,
47      -line_length_max    => 60,  ## For folding      -line_length_max    => 60,  ## For folding
48      -ns_default_uri     => $Message::Header::Default::OPTION{namespace_uri},      #ns_default_phuri
49      -output_bcc => 0,      -output_bcc => 0,
50      -output_folding     => 1,      -output_folding     => 1,
51      -output_mail_from   => 0,      -output_mail_from   => 0,
52      #-parse_all => 0,      #parse_all
53      -translate_underscore       => 1,      -translate_underscore       => 1,
54      #-uri_mailto_safe      #uri_mailto_safe
55      -uri_mailto_safe_level      => 4,      -uri_mailto_safe_level      => 4,
56      -use_folding        => 1,      -use_folding        => 1,
57      #-value_type      #value_type
 );  
   
 $DEFAULT{-value_type} = {  
         ':default'      => ['Message::Field::Unstructured'],  
           
         p3p     => ['Message::Field::Params'],  
         link    => ['Message::Field::ValueParams'],  
           
         'list-software' => ['Message::Field::UA'],  
         'user-agent'    => ['Message::Field::UA'],  
         server  => ['Message::Field::UA'],  
 };  
 for (qw(pics-label list-id status))  
   {$DEFAULT{-value_type}->{$_} = ['Message::Field::Structured']}  
         ## Not supported yet, but to be supported...  
         # x-list: unstructured, ml name  
 for (qw(date expires))  
   {$DEFAULT{-value_type}->{$_} = ['Message::Field::Date']}  
 for (qw(accept accept-charset accept-encoding accept-language uri))  
   {$DEFAULT{-value_type}->{$_} = ['Message::Field::CSV']}  
 for (qw(location referer))  
   {$DEFAULT{-value_type}->{$_} = ['Message::Field::URI']}  
   
 my %header_goodcase = (  
         'article-i.d.'  => 'Article-I.D.',  
         etag    => 'ETag',  
         'pics-label'    => 'PICS-Label',  
         te      => 'TE',  
         url     => 'URL',  
         'www-authenticate'      => 'WWW-Authenticate',  
58  );  );
59    
60  ## taken from L<HTTP::Header>  ## taken from L<HTTP::Header>
# Line 128  sub _init ($;%) { Line 102  sub _init ($;%) {
102    $self->SUPER::_init (%$DEFAULT, %options);    $self->SUPER::_init (%$DEFAULT, %options);
103    $self->{value} = [];    $self->{value} = [];
104    $self->_ns_load_ph ('default');    $self->_ns_load_ph ('default');
105    $self->{ns}->{default_phuri} = $self->{ns}->{phname2uri}->{'default'};    $self->_ns_load_ph ('x-rfc822');
106    $self->_ns_load_ph ('rfc822');    $self->_ns_load_ph ('x-http');
107    $self->{ns}->{default_phuri} = $self->{ns}->{phname2uri}->{'rfc822'};    $self->{option}->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'}
108        unless $self->{option}->{ns_default_phuri};
109        
110      ## For text/rfc822-headers
111      if (ref $options{entity_header}) {
112        $self->{entity_header} = $options{entity_header};
113        delete $options{entity_header};
114      }
115    my @new_fields = ();    my @new_fields = ();
116    for my $name (keys %options) {    for my $name (keys %options) {
117      unless (substr ($name, 0, 1) eq '-') {      unless (substr ($name, 0, 1) eq '-') {
118        push @new_fields, ($name => $options{$name});        push @new_fields, ($name => $options{$name});
119      }      }
120    }    }
121      &{ $self->{option}->{hook_init_fill_options} } ($self, $self->{option});
122    $self->_init_by_format ($self->{option}->{format}, $self->{option});    $self->_init_by_format ($self->{option}->{format}, $self->{option});
123    # Make alternative representations of @header_order.  This is used    # Make alternative representations of @header_order.  This is used
124    # for sorting.    # for sorting.
# Line 153  sub _init ($;%) { Line 134  sub _init ($;%) {
134  sub _init_by_format ($$\%) {  sub _init_by_format ($$\%) {
135    my $self = shift;    my $self = shift;
136    my ($format, $option) = @_;    my ($format, $option) = @_;
137    if ($format =~ /cgi/) {    return if $format eq $option->{format};
138      unshift @header_order, qw(content-type location);    if ($format =~ /http/) {
139      $option->{field_sort} = 'good-practice';      $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'};
140      $option->{use_folding} = 0;      if ($format =~ /cgi/) {
141    } elsif ($format =~ /http/) {        unshift @header_order, qw(content-type location);
142      $option->{field_sort} = 'good-practice';        $option->{field_sort} = 'good-practice';
143          $option->{use_folding} = 0;
144        } else {
145          $option->{field_sort} = 'good-practice';
146        }
147      } elsif ($format =~ /mail|news/) {    ## RFC 822
148        $option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'};
149    }    }
150    if ($format =~ /uri-url-mailto/) {    if ($format =~ /uri-url-mailto/) {
151      $option->{output_bcc} = 0;      $option->{output_bcc} = 0;
# Line 200  sub parse ($$;%) { Line 187  sub parse ($$;%) {
187    my $class = shift;    my $class = shift;
188    my $header = shift;    my $header = shift;
189    my $self = bless {}, $class;    my $self = bless {}, $class;
190    $self->_init (@_);    ## BUG: don't check linebreak_strict    $self->_init (@_);
191    $header =~ s/\x0D?\x0A$REG{WSP}/\x20/gos if $self->{option}->{use_folding};    if ($self->{option}->{linebreak_strict}) {
192        $header =~ s/\x0D\x0A$REG{WSP}/\x20/gos if $self->{option}->{use_folding};
193      } else {
194        $header =~ s/\x0D?\x0A$REG{WSP}/\x20/gos if $self->{option}->{use_folding};
195      }
196      my %option = (%{ $self->{option} });
197      $option{parse_all} = 0;
198    for my $field (split /\x0D?\x0A/, $header) {    for my $field (split /\x0D?\x0A/, $header) {
199      if ($field =~ /$REG{M_fromline}/) {      if ($field =~ /$REG{M_fromline}/) {
200        my ($s,undef,$value) = $self->_value_to_arrayitem        my ($s,undef,$value) = $self->_value_to_arrayitem
201          ('mail-from' => $1, $self->{option});          ('mail-from' => $1, \%option);
202        push @{$self->{value}}, $value if $s;        push @{$self->{value}}, $value if $s;
203      } elsif ($field =~ /$REG{M_field}/) {      } elsif ($field =~ /$REG{M_field}/) {
204        my ($name, $body) = ($1, $2);        my ($name, $body) = ($1, $2);
205        $body =~ s/$REG{WSP}+$//;        $body =~ s/$REG{WSP}+$//;
206        my ($s,undef,$value) = $self->_value_to_arrayitem        my ($s,undef,$value) = $self->_value_to_arrayitem
207          ($name => $body, $self->{option});          ($name => $body, \%option);
208        push @{$self->{value}}, $value if $s;        push @{$self->{value}}, $value if $s;
209      } elsif (length $field) {      } elsif (length $field) {
210        my ($s,undef,$value) = $self->_value_to_arrayitem        my ($s,undef,$value) = $self->_value_to_arrayitem
211          ('x-unknown' => $field, $self->{option});          ('x-unknown' => $field, \%option);
212        push @{$self->{value}}, $value if $s;        push @{$self->{value}}, $value if $s;
213      }      }
214    }    }
215      $self->_ns_associate_numerical_prefix;        ## RFC 2774 namespace
216      for (@{ $self->{value} }) {
217        no strict 'refs';
218        $_->{name}
219          = &{ ${ &_NS_uri2package ($_->{ns}).'::OPTION' }{n11n_name} }
220          ($self, &_NS_uri2package ($_->{ns}), $_->{name});
221        $_->{body} = $self->_parse_value ($_->{name} => $_->{body}, ns => $_->{ns})
222          if $self->{option}->{parse_all};
223      }
224    $self;    $self;
225  }  }
226    
# Line 271  sub parse_array ($\@;%) { Line 273  sub parse_array ($\@;%) {
273      }      }
274      last if $#$header < 0;      last if $#$header < 0;
275    }    }
276      $self->_ns_associate_numerical_prefix;        ## RFC 2774 namespace
277    $self;    $self;
278  }  }
279    
# Line 296  sub _item_match ($$\$\%\%) { Line 299  sub _item_match ($$\$\%\%) {
299    my ($by, $i, $list, $option) = @_;    my ($by, $i, $list, $option) = @_;
300    return 0 unless ref $$i;  ## Already removed    return 0 unless ref $$i;  ## Already removed
301    if ($by eq 'name') {    if ($by eq 'name') {
302      my %o = %$option; $o{parse} = 0;      my %o = %$option; #$o{parse} = 0;
303      my %l;      my %l;
304      for (keys %$list) {      for (keys %$list) {
305        my ($s, undef, $v) = $self->_value_to_arrayitem ($_, '', %o);        my ($s, undef, $v) = $self->_value_to_arrayitem ($_, '', \%o);
306        if ($s) {        if ($s) {
307          $l{$v->{name} . ':' . ( $option->{ns} || $v->{ns} ) } = 1;          $l{$v->{name} . ':' . ( $option->{ns} || $v->{ns} ) } = 1;
308        } else {        } else {
309          $l{$v->{name} .':'. ( $option->{ns} || $self->{ns}->{default_phuri} ) } = 1;          $l{$v->{name} .':'. ( $option->{ns} || $self->{option}->{ns_default_phuri} ) } = 1;
310        }        }
311      }      }
312      return 1 if $l{$$i->{name} . ':' . $$i->{ns}};      return 1 if $l{$$i->{name} . ':' . $$i->{ns}};
313    } elsif ($by eq 'ns') {    } elsif ($by eq 'ns') {
314      my %o = %$option; $o{parse} = 0;      return 1 if $list->{ $$i->{ns} };
315      my %l;    } elsif ($by eq 'http-ns-define') {
316      for (keys %$list) {      if ($$i->{ns} eq $self->{ns}->{phname2uri}->{'x-http'}
317        my ($s, undef, $v) = $self->_value_to_arrayitem ($_, '', %o);       || $$i->{ns} eq $self->{ns}->{phname2uri}->{'x-http-c'}) {
318        if ($s) {        my $n = $$i->{name};
319          $l{ $v->{ns} } = 1;        if ($n eq 'opt' || $n eq 'c-opt' || $n eq 'man' || $n eq 'c-man') {
320        } else {          $option->{parse} = 0;
321          $l{ $self->{ns}->{default_phuri} } = 1;          $$i->{body} = $self->_parse_value ($$i->{name} => $$i->{body}, ns => $$i->{ns});
322            for my $j (0..$$i->{body}->count-1) {
323              return 1 if $list->{ ($$i->{body}->value ($j))[0]->value };
324            }
325        }        }
326      }      }
     return 1 if $l{ $$i->{ns} };  
327    }    }
328    0;    0;
329  }  }
# Line 334  sub _item_return_value ($\$\%) { Line 339  sub _item_return_value ($\$\%) {
339      ${$_[1]}->{body};      ${$_[1]}->{body};
340    }    }
341  }  }
342    *_add_return_value = \&_item_return_value;
343    *_replace_return_value = \&_item_return_value;
344    
345  ## Returns returned (new created) item value    $name, \%option  ## Returns returned (new created) item value    $name, \%option
346  sub _item_new_value ($$\%) {  sub _item_new_value ($$\%) {
347      my ($s,undef,$value) = $_[0]->_value_to_arrayitem    my $self = shift;
348          ($_[1] => '', $_[2]);    my ($name, $option) = @_;
349      if ($option->{by} eq 'http-ns-define') {
350        my $value = $self->_parse_value (opt => '', ns => $self->{ns}->{phname2uri}->{'x-http'});
351        ($value->value (0))[0]->value ($name);
352        {name => 'opt', body => $value, ns => $self->{ns}->{phname2uri}->{'x-http'}};
353      } else {
354        my ($s,undef,$value) = $self->_value_to_arrayitem
355            ($name => '', $option);
356      $s? $value: undef;      $s? $value: undef;
357      }
358  }  }
359    
360    
# Line 351  sub _parse_value ($$$;%) { Line 366  sub _parse_value ($$$;%) {
366    my $value = shift;  return $value if ref $value;    my $value = shift;  return $value if ref $value;
367    my %option = @_;    my %option = @_;
368    my $vtype; { no strict 'refs';    my $vtype; { no strict 'refs';
369      $vtype = ${&_NS_uri2phpackage ($option{ns}).'::OPTION'}{value_type};      my $vt = ${&_NS_uri2package ($option{ns}).'::OPTION'}{value_type};
370      if (ref $vtype) { $vtype = $vtype->{$name} }      if (ref $vt) {
371      unless (ref $vtype) { $vtype = $vtype->{$self->{option}->{_VALTYPE_DEFAULT}} }        $vtype = $vt->{$name} || $vt->{$self->{option}->{_VALTYPE_DEFAULT}};
372        }
373      ## For compatiblity.      ## For compatiblity.
374      unless (ref $vtype) { $vtype = $self->{option}->{value_type}->{$name}      unless (ref $vtype) { $vtype = $self->{option}->{value_type}->{$name}
375        || $self->{option}->{value_type}->{$self->{option}->{_VALTYPE_DEFAULT}} }        || $self->{option}->{value_type}->{$self->{option}->{_VALTYPE_DEFAULT}} }
# Line 368  sub _parse_value ($$$;%) { Line 384  sub _parse_value ($$$;%) {
384        -format   => $self->{option}->{format},        -format   => $self->{option}->{format},
385        -field_ns => $option{ns},        -field_ns => $option{ns},
386        -field_name       => $name,        -field_name       => $name,
387        -header_default_charset     => $self->{option}->{header_default_charset},
388        -header_default_charset_input       => $self->{option}->{header_default_charset_input},
389        -parse_all        => $self->{option}->{parse_all},        -parse_all        => $self->{option}->{parse_all},
390      %vopt);      %vopt);
391    } else {    } else {
# Line 376  sub _parse_value ($$$;%) { Line 394  sub _parse_value ($$$;%) {
394        -format   => $self->{option}->{format},        -format   => $self->{option}->{format},
395        -field_ns => $option{ns},        -field_ns => $option{ns},
396        -field_name       => $name,        -field_name       => $name,
397        -header_default_charset     => $self->{option}->{header_default_charset},
398        -header_default_charset_input       => $self->{option}->{header_default_charset_input},
399        -parse_all        => $self->{option}->{parse_all},        -parse_all        => $self->{option}->{parse_all},
400      %vopt);      %vopt);
401    }    }
402  }  }
403    
404    ## Defined for text/rfc822-headers
405    sub entity_header ($;$) {
406      my $self = shift;
407      my $new_header = shift;
408      if (ref $new_header) {
409        $self->{header} = $new_header;
410      }
411      $self->{header};
412    }
413    
414  =head2 $self->field_name_list ()  =head2 $self->field_name_list ()
415    
416  Returns list of all C<field-name>s.  (Even if there are two  Returns list of all C<field-name>s.  (Even if there are two
# Line 399  sub namespace_ph_default ($;$) { Line 429  sub namespace_ph_default ($;$) {
429    my $self = shift;    my $self = shift;
430    if (defined $_[0]) {    if (defined $_[0]) {
431      no strict 'refs';      no strict 'refs';
432      $self->{ns}->{default_phuri} = $_[0];      $self->{option}->{ns_default_phuri} = $_[0];
433      $self->_ns_load_ph (${&_NS_uri2phpackage ($self->{ns}->{default_phuri}).'::OPTION'}{namespace_phname});      $self->_ns_load_ph (${&_NS_uri2package ($self->{option}->{ns_default_phuri}).'::OPTION'}{namespace_phname});
434    }    }
435    $self->{ns}->{default_phuri};    $self->{option}->{ns_default_phuri};
436  }  }
437    
438  =item $hdr->add ($field-name, $field-body, [$name, $body, ...])  =item $hdr->add ($field-name, $field-body, [$name, $body, ...])
# Line 441  sub _value_to_arrayitem ($$$\%) { Line 471  sub _value_to_arrayitem ($$$\%) {
471    if (ref $value eq 'ARRAY') {    if (ref $value eq 'ARRAY') {
472      ($value, %$value_option) = @$value;      ($value, %$value_option) = @$value;
473    }    }
474    my $nsuri = $self->{ns}->{default_phuri};    my $default_ns = $option->{ns_default_phuri};
475      my $nsuri = $default_ns;
476      $name =~ s/^$REG{WSP}+//;  $name =~ s/$REG{WSP}+$//;
477      
478    no strict 'refs';    no strict 'refs';
479    if ($option->{ns}) {    if ($value_option->{ns}) {
480        $nsuri = $value_option->{ns};
481      } elsif ($option->{ns}) {
482      $nsuri = $option->{ns};      $nsuri = $option->{ns};
483    } elsif ($name =~ s/^([Xx]-[A-Za-z]+|[A-Za-z]+)-//) {    } elsif (($default_ns eq $self->{ns}->{uri2phname}->{'x-http'}
484      my $oprefix = $1;         && $name =~ s/^([0-9]+)-//)
485        || ($name =~ s/^x-http-([0-9]+)-//i)) {     ## Numric namespace prefix, RFC 2774
486        my $prefix = 0+$1;
487        $nsuri = $self->{ns}->{number2uri}->{ $prefix };
488        unless ($nsuri) {
489          $self->{ns}->{number2uri}->{ $prefix } = 'urn:x-suika-fam-cx:msgpm:header:x-temp:'.$prefix;
490          $nsuri = $self->{ns}->{number2uri}->{ $prefix };
491        }
492      } elsif (
493        ${ &_NS_uri2package ($default_ns).'::OPTION' }{use_ph_namespace}
494        && (
495           ($name =~ s/^([Xx]-[A-Za-z0-9]+|[A-Za-z]*[A-WYZa-wyz0-9][A-Za-z0-9]*)-
496                        ([Xx]-[A-Za-z0-9]+|[A-Za-z0-9]*[A-WYZa-wyz0-9][A-Za-z0-9]*)-//x)
497         || $name =~ s/^([Xx]-[A-Za-z0-9]+|[A-Za-z0-9]*[A-WYZa-wyz0-9][A-Za-z0-9]*)-//
498        )) {
499        my ($prefix1, $prefix2) = ($1, $2);
500        my $original_prefix = $&;  my $one_prefix = 0;
501        unless ($prefix2) {
502          $prefix2 = $prefix1;
503          $prefix1 = $self->{ns}->{uri2phname}->{ $default_ns };
504          $one_prefix = 1;
505        }
506      my $prefix      my $prefix
507        = &{${&_NS_uri2phpackage ($nsuri).'::OPTION'}{n11n_prefix}}        = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
508          ($self, &_NS_uri2phpackage ($nsuri), $oprefix);          ($self, &_NS_uri2package ($nsuri), $prefix1.'-'.$prefix2);
509      $self->_ns_load_ph ($prefix);      $self->_ns_load_ph ($prefix);
510      $nsuri = $self->{ns}->{phname2uri}->{$prefix};      $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
511      unless ($nsuri) {      unless ($nsuri) {
512        $name = $oprefix . '-' . $name;        $nsuri = $default_ns;
513        $nsuri = $self->{ns}->{default_phuri};        $prefix
514            = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} }
515              ($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2: $prefix1);
516          $self->_ns_load_ph ($prefix);
517          $nsuri = $self->{ns}->{phname2uri}->{ $prefix };
518          if ($nsuri) {
519            $name = $prefix2 . '-' . $name unless $one_prefix;
520          } else {
521            $name = $original_prefix . $name;
522            $nsuri = $default_ns;
523          }
524      }      }
525    }    }
526    $name    $name
527      = &{${&_NS_uri2phpackage ($nsuri).'::OPTION'}{n11n_name}}      = &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_name} }
528        ($self, &_NS_uri2phpackage ($nsuri), $name);        ($self, &_NS_uri2package ($nsuri), $name);
529    Carp::croak "$name: invalid field-name"    Carp::croak "$name: invalid field-name"
530      if $option->{field_name_validation}      if $option->{field_name_validation}
531        && $name =~ /$REG{$option->{field_name_unsafe_rule}}/;        && $name =~ /$REG{ $option->{field_name_unsafe_rule} }/;
532    $value = $self->_parse_value ($name => $value, ns => $nsuri) if $$option{parse};    $value = $self->_parse_value ($name => $value, ns => $nsuri)
533    $$option{parse} = 0;      if $option->{parse} || $option->{parse_all};
534      $option->{parse} = 0;
535    (1, $name.':'.$nsuri => {name => $name, body => $value, ns => $nsuri});    (1, $name.':'.$nsuri => {name => $name, body => $value, ns => $nsuri});
536  }  }
537  *_add_hash_check = \&_value_to_arrayitem;  *_add_hash_check = \&_value_to_arrayitem;
# Line 571  sub _scan_sort ($\@\%) { Line 638  sub _scan_sort ($\@\%) {
638  }  }
639    
640  sub _n11n_field_name ($$) {  sub _n11n_field_name ($$) {
641      no strict 'refs';
642    my $self = shift;    my $self = shift;
643    my $s = shift;    my $s = shift;
644    $s =~ s/^$REG{WSP}+//; $s =~ s/$REG{WSP}+$//;    $s =~ s/^$REG{WSP}+//; $s =~ s/$REG{WSP}+$//;
645    $s = lc $s ;#unless $self->{option}->{field_name_case_sensible};    $s = lc $s unless ${&_NS_uri2package ($self->{option}->{ns_default_phuri}).'::OPTION'}{case_sensible};
646    $s;    $s;
647  }  }
648    
# Line 606  sub stringify ($;%) { Line 674  sub stringify ($;%) {
674    $option{format} = $params{-format} if $params{-format};    $option{format} = $params{-format} if $params{-format};
675    $self->_init_by_format ($option{format}, \%option);    $self->_init_by_format ($option{format}, \%option);
676    for (grep {/^-/} keys %params) {$option{substr ($_, 1)} = $params{$_}}    for (grep {/^-/} keys %params) {$option{substr ($_, 1)} = $params{$_}}
677      ## Fill required fields
678        my %exist;
679        for ($self->field_name_list) {$exist{$_} = 1}
680        &{ $option{hook_stringify_fill_fields} } ($self, \%exist, \%option);
681    my @ret;    my @ret;
682      ## RFC 2774 numerical field name prefix
683      my %nprefix;
684      {no strict 'refs';
685        %nprefix = reverse %{ $self->{ns}->{number2uri} };
686        my $i = (sort { $a <=> $b } keys %{ $self->{ns}->{number2uri} })[-1] + 1;
687        $i = 10 if $i < 10;
688        my $hprefix = ${ &_NS_uri2package
689                           ($self->{ns}->{phname2uri}->{'x-http'})
690                           .'::OPTION' } {namespace_phname_goodcase};
691        for my $uri (keys %nprefix) {
692          if ($nprefix{ $uri } < 10) {
693            $nprefix{ $uri } = $i++;
694          }
695          my $nsfs = $self->item ($uri, -by => 'http-ns-define');
696          for my $i (0..$nsfs->count-1) {
697            my $nsf = ($nsfs->value ($i))[0];
698            if ($nsf->value eq $uri) {
699              $nsf->replace (ns => $nprefix{ $uri });
700              $nprefix{ $uri } = $hprefix . '-' . $nprefix{ $uri };
701              last;
702            }
703          }
704        }
705      }
706    my $_stringify = sub {    my $_stringify = sub {
707      no strict 'refs';      no strict 'refs';
708        my ($name, $body, $nsuri) = ($_[1]->{name}, $_[1]->{body}, $_[1]->{ns});        my ($name, $body, $nsuri) = ($_[1]->{name}, $_[1]->{body}, $_[1]->{ns});
709        return unless length $name;        return unless length $name;
710        return if $option{output_mail_from} && $name eq 'mail-from';        return if $option{output_mail_from} && $name eq 'mail-from';
711        return if !$option{output_bcc} && ($name eq 'bcc' || $name eq 'resent-bcc');        $body = '' if !$option{output_bcc} && $name eq 'bcc';
712        my $nspackage = &_NS_uri2phpackage ($nsuri);        my $nspackage = &_NS_uri2package ($nsuri);
713        my $oname;        ## Outputed field-name        my $oname;        ## Outputed field-name
714        my $prefix = ${$nspackage.'::OPTION'} {namespace_phname_goodcase}        my $prefix = $nprefix{ $nsuri }
715                  || $self->{ns}->{uri2phname}->{$nsuri};                  || ${$nspackage.'::OPTION'} {namespace_phname_goodcase}
716        $prefix = undef if $nsuri eq $self->{ns}->{default_phuri};                  || $self->{ns}->{uri2phname}->{ $nsuri };
717          my $default_prefix = ${ &_NS_uri2package ($option{ns_default_phuri})
718                                  .'::OPTION'} {namespace_phname_goodcase};
719          $prefix = '' if $prefix eq $default_prefix;
720          $prefix =~ s/^\Q$default_prefix\E-//;
721        my $gc = ${$nspackage.'::OPTION'} {to_be_goodcase};        my $gc = ${$nspackage.'::OPTION'} {to_be_goodcase};
722        if (ref $gc) { $oname = &$gc ($self, $nspackage, $name, \%option) }        if (ref $gc) { $oname = &$gc ($self, $nspackage, $name, \%option) }
723        else { $oname = $name }        else { $oname = $name }
# Line 642  sub stringify ($;%) { Line 742  sub stringify ($;%) {
742        } else {        } else {
743          $fbody = $body;          $fbody = $body;
744        }        }
745        return unless length $fbody;        unless (${$nspackage.'::OPTION'} {field}->{$name}->{empty_body}) {
746            return unless length $fbody;
747          }
748        unless ($option{linebreak_strict}) {        unless ($option{linebreak_strict}) {
749          ## bare \x0D and bare \x0A are unsafe          ## bare \x0D and bare \x0A are unsafe
750          $fbody =~ s/\x0D(?=[^\x09\x0A\x20])/\x0D\x20/g;          $fbody =~ s/\x0D(?=[^\x09\x0A\x20])/\x0D\x20/g;
# Line 728  sub _fold ($$;%) { Line 830  sub _fold ($$;%) {
830    $max = 20 if $max < 20;    $max = 20 if $max < 20;
831        
832    my $l = $option{-initial_length} || 0;    my $l = $option{-initial_length} || 0;
833      $l += length $1 if $string =~ /^([^\x09\x20]+)/;
834    $string =~ s{([\x09\x20][^\x09\x20]+)}{    $string =~ s{([\x09\x20][^\x09\x20]+)}{
835      my $s = $1;      my $s = $1;
836      if ($l + length $s > $max) {      if (($l + length $s) > $max) {
837        $s = "\x0D\x0A\x20" . $s;        $s = "\x0D\x0A\x20" . $s;
838        $l = length ($s) - 2;        $l = 1 + length $s;
839      } else { $l += length $s }      } else { $l += length $s }
840      $s;      $s;
841    }gex;    }gex;
# Line 748  sub _ns_load_ph ($$) { Line 851  sub _ns_load_ph ($$) {
851    $self->{ns}->{uri2phname}->{$self->{ns}->{phname2uri}->{$name}} = $name;    $self->{ns}->{uri2phname}->{$self->{ns}->{phname2uri}->{$name}} = $name;
852  }  }
853    
854    sub _ns_associate_numerical_prefix ($) {
855      my $self = shift;
856      $self->scan (sub {shift;
857        my $f = shift;  return unless $f->{name};
858        if ($f->{ns} eq $self->{ns}->{phname2uri}->{'x-http'}
859         || $f->{ns} eq $self->{ns}->{phname2uri}->{'x-http-c'}) {
860          my $fn = $f->{name};
861          if ($fn eq 'opt' || $fn eq 'man') {
862            $f->{body} = $self->_parse_value ($fn => $f->{body}, ns => $f->{ns});
863            for ($f->{body}->value (0..$f->{body}->count-1)) {
864              my ($nsuri, $number) = ($_->value, $_->item ('ns'));
865              if ($number && $nsuri) {
866                $self->{ns}->{number2uri}->{ $number } = $nsuri;
867              }
868            }
869          }
870        }
871      });
872      $self->scan (sub {shift;
873        my $f = shift;
874        if ($f->{ns} =~ /urn:x-suika-fam-cx:msgpm:header:x-temp:([0-9]+)$/ && $self->{ns}->{number2uri}->{ $1 }) {
875          $f->{ns} = $self->{ns}->{number2uri}->{ $1 };
876        }
877      });
878    }
879    
880    ## $package_name = Message::Header::_NS_uri2phpackage ($nsuri)
881    ## (For internal use of Message::* modules)
882  sub _NS_uri2phpackage ($) {  sub _NS_uri2phpackage ($) {
883    $NS_uri2phpackage{$_[0]}    $NS_uri2phpackage{$_[0]}
884    || $NS_uri2phpackage{$Message::Header::Default::OPTION{namespace_uri}};    || $NS_uri2phpackage{$Message::Header::Default::OPTION{namespace_uri}};
885  }  }
886    sub _NS_uri2package ($) {
887      $NS_uri2package{$_[0]}
888      || $NS_uri2phpackage{$_[0]}
889      || $NS_uri2phpackage{$Message::Header::Default::OPTION{namespace_uri}};
890    }
891    
892  =head2 $self->clone ()  =head2 $self->clone ()
893    

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.35

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24