/[suikacvs]/perl/lib/URI/URL/MID.pm
Suika

Contents of /perl/lib/URI/URL/MID.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Wed Sep 11 09:42:55 2002 UTC (22 years, 2 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
FILE REMOVED
2002-09-11  Wakaba <w@suika.fam.cx>

	* MID.pm: Removed.

1 wakaba 1.1
2     =head1 NAME
3    
4     URI::URL::MID Perl module
5    
6     =head1 DESCRIPTION
7    
8     Perl module for Message-ID URL scheme (C<mid:>),
9     defined by RFC 2111, RFC 2392.
10    
11     =cut
12    
13     package URI::URL::MID;
14     use strict;
15     use vars qw($VERSION);
16     $VERSION=do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
17     use overload '""' => sub {shift->stringify};
18     use Message::Field::MsgID::MsgID;
19    
20     =head2 URI::URL::MID->new ()
21    
22     Makes new C<mid:> URI.
23    
24     =cut
25    
26     sub new ($;%) {
27     my $self = bless {}, shift;
28     $self;
29     }
30    
31     =head2 URI::URL::MID->parse ($uri)
32    
33     Parses C<mid:> URI.
34    
35     =cut
36    
37     sub parse ($$;%) {
38     my $self = bless {}, shift;
39     my $uri = shift;
40     if ($uri =~ s/^[Cc][Ii][Dd]://) {
41     $self->{cid} = Message::Field::MsgID::MsgID->parse ($uri, field_name => 'cid');
42     } elsif ($uri =~ s/^[Mm][Ii][Dd]://) {
43     my ($mid, $cid) = split q{/}, $uri, 2;
44     $mid =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr(hex($1))/eg;
45     $cid =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/chr(hex($1))/eg;
46     $self->{mid} = Message::Field::MsgID::MsgID->parse ($mid) if $mid;
47     $self->{cid} = Message::Field::MsgID::MsgID->parse ($cid, field_name => 'cid')
48     if $cid;
49     }
50     $self;
51     }
52    
53     sub message_id ($;$) {
54     my $self = shift;
55     my $new_mid = shift;
56     if (ref $new_mid) {
57     $self->{mid} = $new_mid;
58     } elsif ($new_mid) {
59     $self->{mid} = Message::Field::MsgID::MsgID->parse ($new_mid);
60     }
61     $self->{mid};
62     }
63    
64     sub content_id ($;$) {
65     my $self = shift;
66     my $new_cid = shift;
67     if (ref $new_cid) {
68     $self->{cid} = $new_cid;
69     } elsif ($new_cid) {
70     $self->{cid} = parse Message::Field::MsgID::MsgID ($new_cid);
71     }
72     $self->{cid};
73     }
74    
75     sub stringify ($;%) {
76     my $self = shift;
77     my %option = @_;
78     my ($mid, $cid) = ($self->{mid}, $self->{cid});
79     undef $mid if $option{scheme} eq 'cid';
80     $mid = $mid->content if ref $mid;
81     $cid = $cid->content if ref $cid;
82     return '' if !$mid && !$cid;
83     $mid =~ s/([^;?:@=+\$,A-Za-z0-9\-_.!~*()])/sprintf('%%%02X', ord $1)/ge;
84     $cid =~ s/([^;?:@=+\$,A-Za-z0-9\-_.!~*()])/sprintf('%%%02X', ord $1)/ge;
85     return 'cid:'.$cid unless $mid;
86     'mid:'.$mid.($cid? '/'.$cid: '');
87     }
88     sub as_string ($;%) {shift->stringify (@_)}
89    
90     =head1 EXAMPLE
91    
92     use URI::URL::MID;
93    
94     ## Message-ID -> URI
95     my $mid1 = new URI::URL::MID;
96     $mid1->message_id ('<foo1@bar.example>');
97     $mid1->content_id ('<foo2@bar.example>');
98     print $mid1;
99    
100     ## URI -> Message-ID
101     my $mid2 = URI::URL::MID->parse ('mid:foo3@bar.example');
102     print $mid2->message_id;
103    
104     =head1 LICENSE
105    
106     Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>.
107    
108     This program is free software; you can redistribute it and/or modify
109     it under the terms of the GNU General Public License as published by
110     the Free Software Foundation; either version 2 of the License, or
111     (at your option) any later version.
112    
113     This program is distributed in the hope that it will be useful,
114     but WITHOUT ANY WARRANTY; without even the implied warranty of
115     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
116     GNU General Public License for more details.
117    
118     You should have received a copy of the GNU General Public License
119     along with this program; see the file COPYING. If not, write to
120     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
121     Boston, MA 02111-1307, USA.
122    
123     =head1 CHANGE
124    
125     See F<ChangeLog>.
126 wakaba 1.2 $Date: 2002/03/20 11:41:25 $
127 wakaba 1.1
128     =cut
129    
130     1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24