/[suikacvs]/test/cvs
Suika

Diff of /test/cvs

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

revision 1.7 by wakaba, Thu Mar 21 04:21:28 2002 UTC revision 1.11 by wakaba, Tue Mar 26 15:19:53 2002 UTC
# Line 47  when C<stringify>.  (Default = 0) Line 47  when C<stringify>.  (Default = 0)
47  %DEFAULT = (  %DEFAULT = (
48    capitalize    => 1,    capitalize    => 1,
49    fold_length   => 70,    fold_length   => 70,
   mail_from     => 0,  
50    field_type    => {':DEFAULT' => 'Message::Field::Unstructured'},    field_type    => {':DEFAULT' => 'Message::Field::Unstructured'},
51      mail_from     => -1,
52      output_bcc    => -1,
53      parse_all     => -1,
54  );  );
55  my @field_type_Structured = qw(cancel-lock  my @field_type_Structured = qw(cancel-lock
56    importance mime-version path precedence user-agent x-cite    importance mime-version path precedence x-cite
57    x-face x-mail-count x-msmail-priority x-priority x-uidl xref);    x-face x-mail-count x-msmail-priority x-priority x-uidl xref);
58  for (@field_type_Structured)  for (@field_type_Structured)
59    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}
60  my @field_type_Address = qw(approved bcc cc delivered-to envelope-to  my @field_type_Address = qw(approved bcc cc delivered-to disposition-notification-to
61      envelope-to
62    errors-to fcc from mail-followup-to mail-followup-cc mail-from reply-to resent-bcc    errors-to fcc from mail-followup-to mail-followup-cc mail-from reply-to resent-bcc
63    resent-cc resent-to resent-from resent-sender return-path    resent-cc resent-to resent-from resent-sender return-path
64    return-receipt-to sender to x-approved x-beenthere    return-receipt-to sender to x-approved x-beenthere
# Line 73  for (@field_type_MsgID) Line 76  for (@field_type_MsgID)
76    {$DEFAULT{field_type}->{$_} = 'Message::Field::MsgID'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::MsgID'}
77  for (qw(received x-received))  for (qw(received x-received))
78    {$DEFAULT{field_type}->{$_} = 'Message::Field::Received'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::Received'}
79    $DEFAULT{field_type}->{'content-type'} = 'Message::Field::ContentType';
80    $DEFAULT{field_type}->{'content-disposition'} = 'Message::Field::ContentDisposition';
81    for (qw(x-face-type))
82      {$DEFAULT{field_type}->{$_} = 'Message::Field::ValueParams'}
83  for (qw(accept accept-charset accept-encoding accept-language  for (qw(accept accept-charset accept-encoding accept-language
84    content-disposition content-language    content-language
85    content-transfer-encoding content-type encrypted followup-to keywords newsgroups    content-transfer-encoding encrypted followup-to keywords newsgroups
86    x-brother x-daughter x-face-type x-respect x-moe    x-brother x-daughter x-respect x-moe x-syster x-wife))
   x-syster x-wife))  
87    {$DEFAULT{field_type}->{$_} = 'Message::Field::CSV'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::CSV'}
88  my @field_type_URI = qw(list-archive list-help list-owner  my @field_type_URI = qw(list-archive list-help list-owner
89    list-post list-subscribe list-unsubscribe uri url x-home-page x-http_referer    list-post list-subscribe list-unsubscribe uri url x-home-page x-http_referer
# Line 86  for (@field_type_URI) Line 92  for (@field_type_URI)
92    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}
93  for (qw(list-id))  for (qw(list-id))
94    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::Structured'}
95  for (qw(content-description subject title x-nsubject))  for (qw(subject title x-nsubject))
96    {$DEFAULT{field_type}->{$_} = 'Message::Field::Subject'}    {$DEFAULT{field_type}->{$_} = 'Message::Field::Subject'}
97    for (qw(list-software user-agent server))
98      {$DEFAULT{field_type}->{$_} = 'Message::Field::UA'}
99    
100  =head2 Message::Header->new ([%option])  =head2 Message::Header->new ([%option])
101    
# Line 118  sub parse ($$;%) { Line 126  sub parse ($$;%) {
126    $header =~ s/\x0D?\x0A$REG{WSP}+/\x20/gos;    ## unfold    $header =~ s/\x0D?\x0A$REG{WSP}+/\x20/gos;    ## unfold
127    for my $field (split /\x0D?\x0A/, $header) {    for my $field (split /\x0D?\x0A/, $header) {
128      if ($field =~ /$REG{M_fromline}/) {      if ($field =~ /$REG{M_fromline}/) {
129        push @{$self->{field}}, {name => 'mail-from', body => $1};        my $body = $1;
130          $body = $self->_field_body ($body, 'mail-from')
131            if $self->{option}->{parse_all}>0;
132          push @{$self->{field}}, {name => 'mail-from', body => $body};
133      } elsif ($field =~ /$REG{M_field}/) {      } elsif ($field =~ /$REG{M_field}/) {
134        my ($name, $body) = ($1, $2);        my ($name, $body) = (lc $1, $2);
135        $name =~ s/$REG{WSP}+$//;        $name =~ s/$REG{WSP}+$//;
136        $body =~ s/$REG{WSP}+$//;        $body =~ s/$REG{WSP}+$//;
137        push @{$self->{field}}, {name => lc $name, body => $body};        $body = $self->_field_body ($body, $name) if $self->{option}->{parse_all}>0;
138          push @{$self->{field}}, {name => $name, body => $body};
139      }      }
140    }    }
141    $self;    $self;
# Line 153  sub field ($$) { Line 165  sub field ($$) {
165        }        }
166      }      }
167    }    }
168      if ($#ret < 0) {
169        return $self->add ($name);
170      }
171    @ret;    @ret;
172  }  }
173    
174    sub field_exist ($$) {
175      my $self = shift;
176      my $name = lc shift;
177      my @ret;
178      for my $field (@{$self->{field}}) {
179        return 1 if ($field->{name} eq $name);
180      }
181      0;
182    }
183    
184  =head2 $self->field_name ($index)  =head2 $self->field_name ($index)
185    
186  Returns C<field-name> of $index'th C<field>.  Returns C<field-name> of $index'th C<field>.
# Line 216  If you don't want duplicated C<field>s, Line 241  If you don't want duplicated C<field>s,
241    
242  =cut  =cut
243    
244  sub add ($$$) {  sub add ($$;$%) {
245    my $self = shift;    my $self = shift;
246    my ($name, $body) = (lc shift, shift);    my ($name, $body) = (lc shift, shift);
247      my %option = @_;
248    return 0 if $name =~ /$REG{UNSAFE_field_name}/;    return 0 if $name =~ /$REG{UNSAFE_field_name}/;
249    $body = $self->_field_body ($body, $name);    $body = $self->_field_body ($body, $name);
250    push @{$self->{field}}, {name => $name, body => $body};    if ($option{prepend}) {
251        unshift @{$self->{field}}, {name => $name, body => $body};
252      } else {
253        push @{$self->{field}}, {name => $name, body => $body};
254      }
255    $body;    $body;
256  }  }
257    
# Line 239  sub replace ($$$) { Line 269  sub replace ($$$) {
269    my $self = shift;    my $self = shift;
270    my ($name, $body) = (lc shift, shift);    my ($name, $body) = (lc shift, shift);
271    return 0 if $name =~ /$REG{UNSAFE_field_name}/;    return 0 if $name =~ /$REG{UNSAFE_field_name}/;
272      $body = $self->_field_body ($body, $name);
273    for my $field (@{$self->{field}}) {    for my $field (@{$self->{field}}) {
274      if ($field->{name} eq $name) {      if ($field->{name} eq $name) {
275        $field->{body} = $body;        $field->{body} = $body;
276        return $self;        return $body;
277      }      }
278    }    }
279    push @{$self->{field}}, {name => $name, body => $body};    push @{$self->{field}}, {name => $name, body => $body};
280    $self;    $body;
281  }  }
282    
283  =head2 $self->delete ($field_name, [$index])  =head2 $self->delete ($field_name, [$index])
# Line 310  sub stringify ($;%) { Line 341  sub stringify ($;%) {
341    my @ret;    my @ret;
342    $OPT{capitalize} ||= $self->{option}->{capitalize};    $OPT{capitalize} ||= $self->{option}->{capitalize};
343    $OPT{mail_from} ||= $self->{option}->{mail_from};    $OPT{mail_from} ||= $self->{option}->{mail_from};
344    push @ret, 'From '.$self->field ('mail-from') if $OPT{mail_from};    $OPT{output_bcc} ||= $self->{option}->{output_bcc};
345      push @ret, 'From '.$self->field ('mail-from') if $OPT{mail_from}>0;
346    for my $field (@{$self->{field}}) {    for my $field (@{$self->{field}}) {
347      my $name = $field->{name};      my $name = $field->{name};
348      next unless $field->{name};      next unless $name;
349      next if !$OPT{mail_from} && $name eq 'mail-from';      next if $OPT{mail_from}<0 && $name eq 'mail-from';
350        next if $OPT{output_bcc}<0 && ($name eq 'bcc' || $name eq 'resent-bcc');
351      my $fbody = scalar $field->{body};      my $fbody = scalar $field->{body};
352      next unless $fbody;      next unless $fbody;
353        $fbody =~ s/\x0D([^\x09\x0A\x20])/\x0D\x20$1/g;
354        $fbody =~ s/\x0A([^\x09\x20])/\x0A\x20$1/g;
355      $name =~ s/((?:^|-)[a-z])/uc($1)/ge if $OPT{capitalize};      $name =~ s/((?:^|-)[a-z])/uc($1)/ge if $OPT{capitalize};
356      push @ret, $name.': '.$self->fold ($fbody);      push @ret, $name.': '.$self->fold ($fbody);
357    }    }
# Line 385  sub fold ($$;$) { Line 420  sub fold ($$;$) {
420       # next split a whitespace       # next split a whitespace
421       # else we are looking at a single word and probably don't want to split       # else we are looking at a single word and probably don't want to split
422       my $x = "";       my $x = "";
423       $x .= "$1\n    "       $x .= "$1\n "
424         while($string =~ s/^$REG{WSP}*(         while($string =~ s/^$REG{WSP}*(
425                            [^"]{$min,$max}?[\,\;]                            [^"]{$min,$max}?[\,\;]
426                            |[^"]{1,$max}$REG{WSP}                            |[^"]{1,$max}$REG{WSP}

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24