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 my @addrs = Mail::Address->parse($line);
11
12 foreach $addr (@addrs) {
13 print $addr->format,"\n";
14 }
15
17 "Mail::Address" extracts and manipulates email addresses from a message
18 header. It cannot be used to extract addresses from some random text.
19 You can use this module to create RFC822 compliant fields.
20
21 Although "Mail::Address" is a very popular subject for books, and is
22 used in many applications, it does a very poor job on the more complex
23 message fields. It does only handle simple address formats (which
24 covers about 95% of what can be found). Problems are with
25
26 · no support for address groups, even not with the semi-colon as
27 separator between addresses;
28
29 · limited support for escapes in phrases and comments. There are
30 cases where it can get wrong; and
31
32 · you have to take care of most escaping when you create an address
33 yourself: "Mail::Address" does not do that for you.
34
35 Often requests are made to the maintainers of this code improve this
36 situation, but this is not a good idea, where it will break zillions of
37 existing applications. If you wish for a fully RFC2822 compliant
38 implementation you may take a look at Mail::Message::Field::Full, part
39 of MailBox.
40
41 . Example
42
43 my $s = Mail::Message::Field::Full->new($from_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 Constructors
55 Mail::Address->new( $phrase, $address, [ $comment ] )
56 Create a new "Mail::Address" object which represents an address
57 with the elements given. In a message these 3 elements would be
58 seen like:
59
60 PHRASE <ADDRESS> (COMMENT)
61 ADDRESS (COMMENT)
62
63 example:
64
65 Mail::Address->new("Perl5 Porters", "perl5-porters@africa.nicoh.com");
66
67 $obj->parse($line)
68 Parse the given line a return a list of extracted "Mail::Address"
69 objects. The line would normally be one taken from a To,Cc or Bcc
70 line in a message
71
72 example:
73
74 my @addr = Mail::Address->parse($line);
75
76 Accessors
77 $obj->address()
78 Return the address part of the object.
79
80 $obj->comment()
81 Return the comment part of the object
82
83 $obj->format(@addresses)
84 Return a string representing the address in a suitable form to be
85 placed on a "To", "Cc", or "Bcc" line of a message. This method is
86 called on the first address to be used; other specified addresses
87 will be appended, separated by commas.
88
89 $obj->phrase()
90 Return the phrase part of the object.
91
92 Smart accessors
93 $obj->host()
94 Return the address excluding the user id and '@'
95
96 $obj->name()
97 Using the information contained within the object attempt to
98 identify what the person or groups name is.
99
100 Note: This function tries to be smart with the "phrase" of the
101 email address, which is probably a very bad idea. Consider to use
102 phrase() itself.
103
104 $obj->user()
105 Return the address excluding the '@' and the mail domain
106
108 This module is part of the MailTools distribution,
109 http://perl.overmeer.net/mailtools/.
110
112 The MailTools bundle was developed by Graham Barr. Later, Mark
113 Overmeer took over maintenance without commitment to further
114 development.
115
116 Mail::Cap by Gisle Aas <aas@oslonett.no>. Mail::Field::AddrList by
117 Peter Orbaek <poe@cit.dk>. Mail::Mailer and Mail::Send by Tim Bunce
118 <Tim.Bunce@ig.co.uk>. For other contributors see ChangeLog.
119
121 Copyrights 1995-2000 Graham Barr <gbarr@pobox.com> and 2001-2017 Mark
122 Overmeer <perl@overmeer.net>.
123
124 This program is free software; you can redistribute it and/or modify it
125 under the same terms as Perl itself. See
126 http://www.perl.com/perl/misc/Artistic.html
127
128
129
130perl v5.26.3 2018-01-22 Mail::Address(3)