3 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
4 * @license http://ez.no/licenses/new_bsd New BSD License
11 * A container to store a mail address in RFC822 format.
13 * The class ezcMailTools contains methods for transformation between several
20 class ezcMailAddress
extends ezcBaseStruct
23 * The name of the recipient (optional).
30 * The email address of the recipient.
37 * The character set used in the $name property.
39 * The characterset defaults to us-ascii.
44 * Constructs a new ezcMailAddress with the mail address $email and the optional name $name.
46 * @param string $email
48 * @param string $charset
50 public function __construct( $email, $name = '', $charset = 'us-ascii' )
53 $this->email
= $email;
54 $this->charset
= $charset;
58 * Returns a new instance of this class with the data specified by $array.
60 * $array contains all the data members of this class in the form:
61 * array('member_name'=>value).
63 * __set_state makes this class exportable with var_export.
64 * var_export() generates code, that calls this method when it
67 * @param array(string=>mixed) $array
68 * @return ezcMailAddress
70 static public function __set_state( array $array )
72 return new ezcMailAddress( $array['email'], $array['name'] );
76 * Returns string representation of email address on string cast.
78 * Builds a representation in format "Name <email@example.com>", if name
79 * is present, else only "<email@example.com>", if name is not present. You
80 * can simply do echo with an object of type ezcMailAddress or (since PHP
81 * 5.2) explicitly cast it to string using (string) $object.
83 * @return string String representation of the email address.
85 public function __toString()
87 return ( !empty( $this->name
) ?
"{$this->name} " : "" ) . "<{$this->email}>";