man-pages/man3/Mail::Address.3pm.html
2021-03-31 01:06:50 +01:00

292 lines
6.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Mail::Address</TITLE>
</HEAD><BODY>
<H1>Mail::Address</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2019-07-25<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Mail::Address - parse mail addresses
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use Mail::Address;
my @addrs = Mail::Address-&gt;parse($line);
foreach $addr (@addrs) {
print $addr-&gt;format,&quot;\n&quot;;
}
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<TT>&quot;Mail::Address&quot;</TT> extracts and manipulates email addresses from a message
header. It cannot be used to extract addresses from some random text.
You can use this module to create <FONT SIZE="-1">RFC822</FONT> compliant fields.
<P>
Although <TT>&quot;Mail::Address&quot;</TT> is a very popular subject for books, and is
used in many applications, it does a very poor job on the more complex
message fields. It does only handle simple address formats (which
covers about 95% of what can be found). Problems are with
<DL COMPACT>
<DT id="1">&bull;<DD>
no support for address groups, even not with the semi-colon as
separator between addresses;
<DT id="2">&bull;<DD>
limited support for escapes in phrases and comments. There are
cases where it can get wrong; and
<DT id="3">&bull;<DD>
you have to take care of most escaping when you create an address yourself:
<TT>&quot;Mail::Address&quot;</TT> does not do that for you.
</DL>
<P>
Often requests are made to the maintainers of this code improve this
situation, but this is not a good idea, where it will break zillions
of existing applications. If you wish for a fully <FONT SIZE="-1">RFC2822</FONT> compliant
implementation you may take a look at Mail::Message::Field::Full,
part of MailBox.
<P>
<B>. Example</B>
<P>
<PRE>
my $s = Mail::Message::Field::Full-&gt;new($from_header);
# ref $s isa Mail::Message::Field::Addresses;
my @g = $s-&gt;groups; # all groups, at least one
# ref $g[0] isa Mail::Message::Field::AddrGroup;
my $ga = $g[0]-&gt;addresses; # group addresses
my @a = $s-&gt;addresses; # all addresses
# ref $a[0] isa Mail::Message::Field::Address;
</PRE>
<A NAME="lbAE">&nbsp;</A>
<H2>METHODS</H2>
<A NAME="lbAF">&nbsp;</A>
<H3>Constructors</H3>
<DL COMPACT>
<DT id="4">Mail::Address-&gt;<B>new</B>( $phrase, $address, [ $comment ] )<DD>
Create a new <TT>&quot;Mail::Address&quot;</TT> object which represents an address with the
elements given. In a message these 3 elements would be seen like:
<P>
<PRE>
PHRASE &lt;ADDRESS&gt; (COMMENT)
ADDRESS (COMMENT)
</PRE>
<P>
example:
<P>
<PRE>
Mail::Address-&gt;new(&quot;Perl5 Porters&quot;, &quot;<A HREF="mailto:perl5-porters@africa.nicoh.com">perl5-porters@africa.nicoh.com</A>&quot;);
</PRE>
<DT id="5">$obj-&gt;<B>parse</B>($line)<DD>
Parse the given line a return a list of extracted <TT>&quot;Mail::Address&quot;</TT> objects.
The line would normally be one taken from a To,Cc or Bcc line in a message
<P>
example:
<P>
<PRE>
my @addr = Mail::Address-&gt;parse($line);
</PRE>
</DL>
<A NAME="lbAG">&nbsp;</A>
<H3>Accessors</H3>
<DL COMPACT>
<DT id="6">$obj-&gt;<B>address</B>()<DD>
Return the address part of the object.
<DT id="7">$obj-&gt;<B>comment</B>()<DD>
Return the comment part of the object
<DT id="8">$obj-&gt;<B>format</B>(@addresses)<DD>
Return a string representing the address in a suitable form to be placed
on a <TT>&quot;To&quot;</TT>, <TT>&quot;Cc&quot;</TT>, or <TT>&quot;Bcc&quot;</TT> line of a message. This method is called on
the first address to be used; other specified addresses will be appended,
separated by commas.
<DT id="9">$obj-&gt;<B>phrase</B>()<DD>
Return the phrase part of the object.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H3>Smart accessors</H3>
<DL COMPACT>
<DT id="10">$obj-&gt;<B>host</B>()<DD>
Return the address excluding the user id and '@'
<DT id="11">$obj-&gt;<B>name</B>()<DD>
Using the information contained within the object attempt to identify what
the person or groups name is.
<P>
<B>Note:</B> This function tries to be smart with the ``phrase'' of the
email address, which is probably a very bad idea. Consider to use
<B>phrase()</B> itself.
<DT id="12">$obj-&gt;<B>user</B>()<DD>
Return the address excluding the '@' and the mail domain
</DL>
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
This module is part of the MailTools distribution,
<I><A HREF="http://perl.overmeer.net/mailtools/">http://perl.overmeer.net/mailtools/</A></I>.
<A NAME="lbAJ">&nbsp;</A>
<H2>AUTHORS</H2>
The MailTools bundle was developed by Graham Barr. Later, Mark
Overmeer took over maintenance without commitment to further development.
<P>
Mail::Cap by Gisle Aas &lt;<A HREF="mailto:aas@oslonett.no">aas@oslonett.no</A>&gt;.
Mail::Field::AddrList by Peter Orbaek &lt;<A HREF="mailto:poe@cit.dk">poe@cit.dk</A>&gt;.
Mail::Mailer and Mail::Send by Tim Bunce &lt;<A HREF="mailto:Tim.Bunce@ig.co.uk">Tim.Bunce@ig.co.uk</A>&gt;.
For other contributors see ChangeLog.
<A NAME="lbAK">&nbsp;</A>
<H2>LICENSE</H2>
Copyrights 1995-2000 Graham Barr &lt;<A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A>&gt; and
2001-2017 Mark Overmeer &lt;<A HREF="mailto:perl@overmeer.net">perl@overmeer.net</A>&gt;.
<P>
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See <I><A HREF="http://www.perl.com/perl/misc/Artistic.html">http://www.perl.com/perl/misc/Artistic.html</A></I>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="13"><A HREF="#lbAB">NAME</A><DD>
<DT id="14"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="15"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="16"><A HREF="#lbAE">METHODS</A><DD>
<DL>
<DT id="17"><A HREF="#lbAF">Constructors</A><DD>
<DT id="18"><A HREF="#lbAG">Accessors</A><DD>
<DT id="19"><A HREF="#lbAH">Smart accessors</A><DD>
</DL>
<DT id="20"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="21"><A HREF="#lbAJ">AUTHORS</A><DD>
<DT id="22"><A HREF="#lbAK">LICENSE</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:47 GMT, March 31, 2021
</BODY>
</HTML>