Mail
[ ]
[ ]
[ ]
[ ]
[ ]
Source for file mail_address.php
Documentation is available at mail_address.php
1. <?php
2. /**
3. * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
4. * @license http://ez.no/licenses/new_bsd New BSD License
5. * @version 1.4
6. * @filesource
7. * @package Mail
8. */
9.
10. /**
11. * A container to store a mail address in RFC822 format.
12. *
13. * The class ezcMailTools contains methods for transformation between several
14. * formats.
15. *
16. * @package Mail
17. * @version 1.4
18. * @mainclass
19. */
20. class ezcMailAddress extends ezcBaseStruct
21. {
22. /**
23. * The name of the recipient (optional).
24. *
25. * @var string
26. */
27. public $name;
28.
29. /**
30. * The email address of the recipient.
31. *
32. * @var string
33. */
34. public $email;
35.
36. /**
37. * The character set used in the $name property.
38. *
39. * The characterset defaults to us-ascii.
40. */
41. public $charset;
42.
43. /**
44. * Constructs a new ezcMailAddress with the mail address $email and the optional name $name.
45. *
46. * @param string $email
47. * @param string $name
48. * @param string $charset
49. */
50. public function __construct( $email, $name = '', $charset = 'us-ascii' )
51. {
52. $this->name = $name;
53. $this->email = $email;
54. $this->charset = $charset;
55. }
56.
57. /**
58. * Returns a new instance of this class with the data specified by $array.
59. *
60. * $array contains all the data members of this class in the form:
61. * array('member_name'=>value).
62. *
63. * __set_state makes this class exportable with var_export.
64. * var_export() generates code, that calls this method when it
65. * is parsed with PHP.
66. *
67. * @param array(string=>mixed) $array
68. * @return ezcMailAddress
69. */
70. static public function __set_state( array $array )
71. {
72. return new ezcMailAddress( $array['email'], $array['name'] );
73. }
74.
75. /**
76. * Returns string representation of email address on string cast.
77. *
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.
82. *
83. * @return string String representation of the email address.
84. */
85. public function __toString()
86. {
87. return ( !empty( $this->name ) ? "{$this->name} " : "" ) . "<{$this->email}>";
88. }
89. }
90. ?>
Last updated: Mon, 17 Dec 2007