1Mail::Address(3) User Contributed Perl Documentation Mail::Address(3)
2
3
4
6 Mail::Address - Parse mail addresses
7
9 use Mail::Address;
10
11 my @addrs = Mail::Address->parse($line);
12
13 foreach $addr (@addrs) {
14 print $addr->format,"\n";
15 }
16
18 "Mail::Address" extracts and manipulates email addresses from a message
19 header. It cannot be used to extract addresses from some random text.
20 You can use this module to create RFC822 compliant fields.
21
22 Although "Mail::Address" is a very popular subject for books, and is
23 used in many applications, it does a very poor job on the more complex
24 message fields. It does only handle simple address formats (which cov‐
25 ers about 95% of what can be found). Problems are with
26
27 · no support for address groups, even not with the semi-colon as sep‐
28 arator between addresses
29
30 · Limitted support for escapes in phrases and comments. There are
31 cases where it can get wrong.
32
33 · You have to take care of most escaping when you create an address
34 yourself: "Mail::Address" does not do that for you.
35
36 Often requests are made to improve this situation, but this is not a
37 good idea, where it will break zillions of existing applications. If
38 you wish for a fully RFC2822 compliant implementation you may take a
39 look at Mail::Message::Field::Full, part of MailBox.
40
41 Example:
42
43 my $s = Mail::Message::Field::Full->parse($header);
44 # ref $s isa Mail::Message::Field::Addresses;
45
46 my @g = $s->groups; # all groups, at least one
47 # ref $g[0] isa Mail::Message::Field::AddrGroup;
48 my $ga = $g[0]->addresses; # group addresses
49
50 my @a = $s->addresses; # all addresses
51 # ref $a[0] isa Mail::Message::Field::Address;
52
54 new( PHRASE, ADDRESS, [ COMMENT ])
55 Mail::Address->new("Perl5 Porters", "perl5-porters@africa.nicoh.com");
56
57 Create a new "Mail::Address" object which represents an address
58 with the elements given. In a message these 3 elements would be
59 seen like:
60
61 PHRASE <ADDRESS> (COMMENT)
62 ADDRESS (COMMENT)
63
64 parse( LINE )
65 Mail::Address->parse($line);
66
67 Parse the given line a return a list of extracted "Mail::Address"
68 objects. The line would normally be one taken from a To,Cc or Bcc
69 line in a message
70
72 phrase ()
73 Return the phrase part of the object.
74
75 address ()
76 Return the address part of the object.
77
78 comment ()
79 Return the comment part of the object
80
81 format ()
82 Return a string representing the address in a suitable form to be
83 placed on a To,Cc or Bcc line of a message
84
85 name ()
86 Using the information contained within the object attempt to iden‐
87 tify what the person or groups name is
88
89 host ()
90 Return the address excluding the user id and '@'
91
92 user ()
93 Return the address excluding the '@' and the mail domain
94
95 path ()
96 Unimplemented yet but should return the UUCP path for the message
97
98 canon ()
99 Unimplemented yet but should return the UUCP canon for the message
100
102 Graham Barr. Maintained by Mark Overmeer <mailtools@overmeer.net>
103
105 Copyright (c) 2002-2005 Mark Overmeer, 1995-2001 Graham Barr. All
106 rights reserved. This program is free software; you can redistribute it
107 and/or modify it under the same terms as Perl itself.
108
109
110
111perl v5.8.8 2007-05-11 Mail::Address(3)