1 |
wakaba |
1.1 |
|
2 |
|
|
=head1 NAME |
3 |
|
|
|
4 |
wakaba |
1.2 |
Message::Field::Unstructured Perl module |
5 |
wakaba |
1.1 |
|
6 |
|
|
=head1 DESCRIPTION |
7 |
|
|
|
8 |
wakaba |
1.2 |
Perl module for RFC 822/2822 Unstructured C<field>s. |
9 |
wakaba |
1.1 |
|
10 |
|
|
=cut |
11 |
|
|
|
12 |
|
|
package Message::Field::Unstructured; |
13 |
|
|
require 5.6.0; |
14 |
|
|
use strict; |
15 |
|
|
use re 'eval'; |
16 |
|
|
use vars qw(%REG $VERSION); |
17 |
|
|
$VERSION = '1.00'; |
18 |
|
|
|
19 |
|
|
use overload '""' => sub {shift->stringify}; |
20 |
|
|
|
21 |
|
|
=head2 Message::Field::Address->new () |
22 |
|
|
|
23 |
|
|
Return empty address object. |
24 |
|
|
|
25 |
|
|
=cut |
26 |
|
|
|
27 |
wakaba |
1.2 |
sub new ($;%) { |
28 |
wakaba |
1.1 |
bless {}, shift; |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
=head2 Message::Field::Address->parse ($unfolded_field_body) |
32 |
|
|
|
33 |
|
|
Parse structured C<field-body> contain of C<address-list>. |
34 |
|
|
|
35 |
|
|
=cut |
36 |
|
|
|
37 |
wakaba |
1.2 |
sub parse ($$;%) { |
38 |
wakaba |
1.1 |
my $self = bless {}, shift; |
39 |
|
|
my $field_body = shift; |
40 |
|
|
$self->{field_body} = $field_body; |
41 |
|
|
$self; |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
sub stringify ($) { |
45 |
|
|
my $self = shift; |
46 |
|
|
$self->{field_body}; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
sub as_plain_string ($) { |
50 |
|
|
my $self = shift; |
51 |
|
|
$self->{field_body}; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
=head1 EXAMPLE |
55 |
|
|
|
56 |
|
|
## Compose field-body for To: field. |
57 |
|
|
|
58 |
|
|
use Message::Field::Address; |
59 |
|
|
my $addr = new Message::Field::Address; |
60 |
|
|
$addr->add ('foo@example.org', name => 'Mr. foo bar'); |
61 |
|
|
$addr->add ('webmaster@example.org', group => 'administrators'); |
62 |
|
|
$addr->add ('postmaster@example.org', group => 'administrators'); |
63 |
|
|
|
64 |
|
|
my $field_body = $addr->stringify (); |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
## Output parsed address-list tree. |
68 |
|
|
|
69 |
|
|
use Message::Field::Address; |
70 |
|
|
my $addr = Message::Field::Address->parse ($field_body); |
71 |
|
|
|
72 |
|
|
for my $i (@$addr) { |
73 |
|
|
if ($i->{type} eq 'group') { |
74 |
|
|
print "\x40 $i->{display_name}: \n"; |
75 |
|
|
for my $j (@{$i->{address}}) { |
76 |
|
|
print "\t- $j->{display_name} <$j->{route}$j->{addr_spec}>\n"; |
77 |
|
|
} |
78 |
|
|
} else { |
79 |
|
|
print "- $i->{display_name} <$i->{route}$i->{addr_spec}>\n"; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
=head1 LICENSE |
84 |
|
|
|
85 |
|
|
Copyright 2002 wakaba E<lt>w@suika.fam.cxE<gt>. |
86 |
|
|
|
87 |
|
|
This program is free software; you can redistribute it and/or modify |
88 |
|
|
it under the terms of the GNU General Public License as published by |
89 |
|
|
the Free Software Foundation; either version 2 of the License, or |
90 |
|
|
(at your option) any later version. |
91 |
|
|
|
92 |
|
|
This program is distributed in the hope that it will be useful, |
93 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
94 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
95 |
|
|
GNU General Public License for more details. |
96 |
|
|
|
97 |
|
|
You should have received a copy of the GNU General Public License |
98 |
|
|
along with this program; see the file COPYING. If not, write to |
99 |
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
100 |
|
|
Boston, MA 02111-1307, USA. |
101 |
|
|
|
102 |
|
|
=head1 CHANGE |
103 |
|
|
|
104 |
|
|
See F<ChangeLog>. |
105 |
|
|
|
106 |
|
|
=cut |
107 |
|
|
|
108 |
|
|
1; |