/[suikacvs]/messaging/bunshin/Bunshin.pm
Suika

Diff of /messaging/bunshin/Bunshin.pm

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

revision 1.2 by wakaba, Sun Jun 16 10:46:29 2002 UTC revision 1.4 by wakaba, Wed Jul 24 12:12:34 2002 UTC
# Line 67  sub set_elements ($$@) { Line 67  sub set_elements ($$@) {
67  sub set_source ($%) {  sub set_source ($%) {
68    my $self = shift;    my $self = shift;
69    my %option = @_;    my %option = @_;
70      ($self->{source}, $self->{meta_info}) = $self->_get_resource (%option);
71      $self->default_parameter (base_uri => $option{uri}) if $option{uri};
72            ## BUG: Doesn't support redirection
73      if ($option{uri} || $option{file}) {
74        my $c = $self->{hook_code_conversion} || \&_code_conversion;
75        $self->{source} = &$c ($self, $self->{source}, \%option, $self->{meta_info});
76      }
77      $self->{source} =~ s/\x0D(?!\x0A)/\x0D\x0A/g;
78      $self->{source} =~ s/(?<!\x0D)\x0A/\x0D\x0A/g;
79      $self;
80    }
81    
82    sub _get_resource ($%) {
83      my $self = shift;
84      my %option = @_;
85      my ($resource, $meta);
86    if (defined $option{value}) {    if (defined $option{value}) {
87      $self->{source} = $option{value};      $resource = $option{value};
88    } elsif ($option{uri}) {    } elsif ($option{uri}) {
89      require Message::Field::UA;      require Message::Field::UA;
90      require LWP::UserAgent;      require LWP::UserAgent;
# Line 79  sub set_source ($%) { Line 95  sub set_source ($%) {
95      $lwp->agent ($ua->stringify);      $lwp->agent ($ua->stringify);
96      my $req = HTTP::Request->new (GET => $option{uri});      my $req = HTTP::Request->new (GET => $option{uri});
97      my $res = $lwp->request ($req);      my $res = $lwp->request ($req);
98      my $c = $self->{hook_code_conversion} || \&_code_conversion;      $resource = $res->content;
99      $self->{source} = &$c ($self, $res->content, \%option);      $meta = parse Message::Header $res->headers_as_string,
100      $self->default_parameter (base_uri => $option{uri});        -parse_all => 0, -format => 'http-response',
101        ;
102    } elsif ($option{file}) {    } elsif ($option{file}) {
103      my $f = new FileHandle $option{file} => 'r';      my $f = new FileHandle $option{file} => 'r';
104      Carp::croak "set_source: $option{file}: $!" unless defined $f;      Carp::croak "set_source: $option{file}: $!" unless defined $f;
105      my $c = $self->{hook_code_conversion} || \&_code_conversion;      my $c = $self->{hook_code_conversion} || \&_code_conversion;
106      local $/ = undef;      local $/ = undef;
107      $self->{source} = &$c ($self, $f->getline, \%option);      $resource = $f->getline;
108    } else {    } else {
109      Carp::croak "set_source: $_[0]: Unsupported data source type";      Carp::croak "_get_resource: $_[0]: Unsupported data source type";
110    }    }
111    $self->{source} =~ s/\x0D(?!\x0A)/\x0D\x0A/g;    ($resource, $meta);
   $self->{source} =~ s/(?<!\x0D)\x0A/\x0D\x0A/g;  
   $self;  
112  }  }
113    
114  ## $self->_code_conversion ($string, \%option)  ## $self->_code_conversion ($string, \%option, $meta_info)
115  sub _code_conversion ($$\%) {  sub _code_conversion ($$\%$) {
116    $_[1];    $_[1];
117  }  }
118    
# Line 140  sub _make_a_msg ($@) { Line 155  sub _make_a_msg ($@) {
155    ;    ;
156    my $hdr = $msg->header;    my $hdr = $msg->header;
157    ## Originator and date    ## Originator and date
158      my $from = $hdr->field ('from')->add ($p{from_mail});      my $from = $hdr->field ('from')->add ($p{from_mail} || 'foo@bar.invalid');
159      $from->display_name ($p{from_name}) if length $p{from_name};      $from->display_name ($p{from_name}) if length $p{from_name};
160      my $date = $hdr->field ('date');      my $date = $hdr->field ('date');
161      $p{date_year} ||= (gmtime)[5];      $p{date_year} ||= (gmtime)[5];
162      $date->set_datetime (@p{qw/date_year date_month      $date->set_datetime (@p{qw/date_year date_month
163        date_day date_hour date_minute date_second/},        date_day date_hour date_minute date_second/},
164        zone => $p{date_zone});        zone => $p{date_zone});
165      $hdr->add ('x-uri' => $p{from_uri}) if $p{from_uri};      $hdr->add (x_uri => $p{from_uri}) if $p{from_uri};
166      if ($p{from_face}) {      if ($p{from_face}) {
167        $msg->header->field ('x-face')->value ($p{from_face});        $msg->header->field ('x-face')->value ($p{from_face});
168      } elsif ($p{faces}->{$p{from_mail}}) {      } elsif ($p{faces}->{$p{from_mail}}) {
# Line 158  sub _make_a_msg ($@) { Line 173  sub _make_a_msg ($@) {
173    ## Message attribute    ## Message attribute
174      if (length $p{msg_id}) {      if (length $p{msg_id}) {
175        $hdr->add ('message-id' => $p{msg_id});        $hdr->add ('message-id' => $p{msg_id});
176      } else {      } elsif ($p{msg_id_from} || $p{msg_id_right} || $p{list_id}) {
       my $id_right = $p{msg_id_right} || $p{list_id};  
177        my $c = $p{msg_count};        my $c = $p{msg_count};
178        $c = '.d'.(0+$date) unless defined $p{msg_count};        $c = '.d'.(0+$date) unless defined $p{msg_count};
179        my $mid = sprintf '<msg%s.BS%%list@%s>', $c, $id_right;        my $mid;
180        $mid = sprintf '<msg%s.BS%%%s>', $c, $p{msg_id_from} if $p{msg_id_from};        if ($p{msg_id_from}) {
181            $mid = sprintf '<msg%s.BS%%%s%%%s>', $c, $p{list_id}, $p{msg_id_from};
182          } elsif ($p{msg_id_right}) {
183            $mid = sprintf '<msg%s.BS%%%s%%list@%s>', $c, $p{list_id}, $p{msg_id_right};
184          } else { #if ($p{list_id}) {
185            $mid = sprintf '<msg%s.BS%%list@%s>', $c, $p{list_id};
186          }
187        $hdr->add (($DEBUG?'x-':'').'message-id' => $mid);        $hdr->add (($DEBUG?'x-':'').'message-id' => $mid);
188      }      }
189      $hdr->add (subject => $p{subject}) if length $p{subject};      if (length $p{subject}) {
190          $hdr->add (subject => $p{subject});
191        } elsif (length $p{DEFAULT_subject}) {
192          $hdr->add (subject => $p{DEFAULT_subject});
193        }
194      my $a;      my $a;
195      for (grep {/^misc_/} keys %p) {      for (grep {/^misc_/} keys %p) {
196        $a = $hdr->field ('content-x-properties') unless ref $a;        $a = $hdr->field ('content-x-properties') unless ref $a;
# Line 188  sub _make_a_msg ($@) { Line 212  sub _make_a_msg ($@) {
212        $lid->value ($p{list_id});        $lid->value ($p{list_id});
213        $lid->display_name ($p{list_name}) if length $p{list_name};        $lid->display_name ($p{list_name}) if length $p{list_name};
214      }      }
215      $hdr->add ('x-mail-count' => $p{msg_count}) if defined $p{msg_count};      $hdr->add (x_mail_count => $p{msg_count}) if defined $p{msg_count};
216      $hdr->add ('x-ml-info' => $p{list_info}) if defined $p{list_info};      $hdr->add (x_ml_info => $p{list_info}) if defined $p{list_info};
217      if ($p{base_uri}) {      if ($p{base_uri}) {
218        my $uri = $hdr->add (x_uri => '');        my $uri = $hdr->add (x_uri => '');
219        $uri->value ($p{base_uri});        $uri->value ($p{base_uri});
# Line 201  sub _make_a_msg ($@) { Line 225  sub _make_a_msg ($@) {
225          date_time       => $date->unix_time,          date_time       => $date->unix_time,
226          zone    => $date->zone,          zone    => $date->zone,
227          fmt2str => $self->{fmt2str},          fmt2str => $self->{fmt2str},
228        });        }, \%p);
229        $hdr->add ('x-uri')->value ($urn);        $hdr->add ('x-uri')->value ($urn);
230      }      }
231    ## Additional information    ## Additional information
# Line 231  sub default_parameter ($@) { Line 255  sub default_parameter ($@) {
255    $self;    $self;
256  }  }
257    
258    =head1 $meta = $b->meta_information
259    
260    Gets meta information from resource requesting protocol.
261    Usually returned value is Message::Header object.
262    When resource is getten via HTTP, its content is HTTP response
263    header.
264    
265    =cut
266    
267    sub meta_information ($) {
268      my $self = shift;
269      $self->{meta_info};
270    }
271    
272  =head1 LICENSE  =head1 LICENSE
273    
274  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.2  
changed lines
  Added in v.1.4

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24