41 |
-format => 'mail-rfc2822', |
-format => 'mail-rfc2822', |
42 |
-header_default_charset => 'iso-2022-int-1', |
-header_default_charset => 'iso-2022-int-1', |
43 |
-header_default_charset_input => 'iso-2022-int-1', |
-header_default_charset_input => 'iso-2022-int-1', |
44 |
|
-hook_init_fill_options => sub {}, |
45 |
|
-hook_stringify_fill_fields => sub {}, |
46 |
-linebreak_strict => 0, |
-linebreak_strict => 0, |
47 |
-line_length_max => 60, ## For folding |
-line_length_max => 60, ## For folding |
48 |
#ns_default_phuri |
#ns_default_phuri |
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. |
134 |
sub _init_by_format ($$\%) { |
sub _init_by_format ($$\%) { |
135 |
my $self = shift; |
my $self = shift; |
136 |
my ($format, $option) = @_; |
my ($format, $option) = @_; |
137 |
|
return if $format eq $option->{format}; |
138 |
if ($format =~ /http/) { |
if ($format =~ /http/) { |
139 |
$option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'}; |
$option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-http'}; |
140 |
if ($format =~ /cgi/) { |
if ($format =~ /cgi/) { |
144 |
} else { |
} else { |
145 |
$option->{field_sort} = 'good-practice'; |
$option->{field_sort} = 'good-practice'; |
146 |
} |
} |
147 |
} else { ## RFC 822 |
} elsif ($format =~ /mail|news/) { ## RFC 822 |
148 |
$option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'}; |
$option->{ns_default_phuri} = $self->{ns}->{phname2uri}->{'x-rfc822'}; |
149 |
} |
} |
150 |
if ($format =~ /uri-url-mailto/) { |
if ($format =~ /uri-url-mailto/) { |
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 { |
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->{option}->{ns_default_phuri}; |
my $default_ns = $option->{ns_default_phuri}; |
475 |
|
my $nsuri = $default_ns; |
476 |
$name =~ s/^$REG{WSP}+//; $name =~ s/$REG{WSP}+$//; |
$name =~ s/^$REG{WSP}+//; $name =~ s/$REG{WSP}+$//; |
477 |
|
|
478 |
no strict 'refs'; |
no strict 'refs'; |
480 |
$nsuri = $value_option->{ns}; |
$nsuri = $value_option->{ns}; |
481 |
} elsif ($option->{ns}) { |
} elsif ($option->{ns}) { |
482 |
$nsuri = $option->{ns}; |
$nsuri = $option->{ns}; |
483 |
} elsif (($option->{ns_default_phuri} eq $self->{ns}->{uri2phname}->{'x-http'} |
} elsif (($default_ns eq $self->{ns}->{uri2phname}->{'x-http'} |
484 |
&& $name =~ s/^([0-9]+)-//) |
&& $name =~ s/^([0-9]+)-//) |
485 |
|| ($name =~ s/^x-http-([0-9]+)-//i)) { ## Numric namespace prefix, RFC 2774 |
|| ($name =~ s/^x-http-([0-9]+)-//i)) { ## Numric namespace prefix, RFC 2774 |
486 |
my $prefix = 0+$1; |
my $prefix = 0+$1; |
489 |
$self->{ns}->{number2uri}->{ $prefix } = 'urn:x-suika-fam-cx:msgpm:header:x-temp:'.$prefix; |
$self->{ns}->{number2uri}->{ $prefix } = 'urn:x-suika-fam-cx:msgpm:header:x-temp:'.$prefix; |
490 |
$nsuri = $self->{ns}->{number2uri}->{ $prefix }; |
$nsuri = $self->{ns}->{number2uri}->{ $prefix }; |
491 |
} |
} |
492 |
} elsif (($name =~ s/^([Xx]-[A-Za-z0-9]+|[A-Za-z]*[A-WYZa-wyz0-9][A-Za-z0-9]*)- |
} elsif ( |
493 |
([Xx]-[A-Za-z0-9]+|[A-Za-z0-9]*[A-WYZa-wyz0-9][A-Za-z0-9]*)-//x) |
${ &_NS_uri2package ($default_ns).'::OPTION' }{use_ph_namespace} |
494 |
|| $name =~ s/^([Xx]-[A-Za-z0-9]+|[A-Za-z0-9]*[A-WYZa-wyz0-9][A-Za-z0-9]*)-//) { |
&& ( |
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); |
my ($prefix1, $prefix2) = ($1, $2); |
500 |
my $original_prefix = $&; my $one_prefix = 0; |
my $original_prefix = $&; my $one_prefix = 0; |
501 |
unless ($prefix2) { |
unless ($prefix2) { |
502 |
$prefix2 = $prefix1; |
$prefix2 = $prefix1; |
503 |
$prefix1 = $self->{ns}->{uri2phname}->{ $option->{ns_default_phuri} }; |
$prefix1 = $self->{ns}->{uri2phname}->{ $default_ns }; |
504 |
$one_prefix = 1; |
$one_prefix = 1; |
505 |
} |
} |
506 |
my $prefix |
my $prefix |
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 |
$nsuri = $self->{option}->{ns_default_phuri}; |
$nsuri = $default_ns; |
513 |
$prefix |
$prefix |
514 |
= &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} } |
= &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_prefix} } |
515 |
($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2: $prefix1); |
($self, &_NS_uri2package ($nsuri), $one_prefix? $prefix2: $prefix1); |
519 |
$name = $prefix2 . '-' . $name unless $one_prefix; |
$name = $prefix2 . '-' . $name unless $one_prefix; |
520 |
} else { |
} else { |
521 |
$name = $original_prefix . $name; |
$name = $original_prefix . $name; |
522 |
$nsuri = $self->{option}->{ns_default_phuri}; |
$nsuri = $default_ns; |
523 |
} |
} |
524 |
} |
} |
525 |
} |
} |
526 |
$name |
$name |
527 |
= &{${&_NS_uri2package ($nsuri).'::OPTION'}{n11n_name}} |
= &{ ${ &_NS_uri2package ($nsuri).'::OPTION' }{n11n_name} } |
528 |
($self, &_NS_uri2package ($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) |
$value = $self->_parse_value ($name => $value, ns => $nsuri) |
533 |
if $$option{parse} || $$option{parse_all}; |
if $option->{parse} || $option->{parse_all}; |
534 |
$$option{parse} = 0; |
$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; |
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 |
## RFC 2774 numerical field name prefix |
683 |
my %nprefix; |
my %nprefix; |