1<?php 2 3/** 4 * Swift Mailer Address Container (purely for rigid RFC conformance) 5 * Please read the LICENSE file 6 * @copyright Chris Corbyn <chris@w3style.co.uk> 7 * @author Chris Corbyn <chris@w3style.co.uk> 8 * @package Swift 9 * @license GNU Lesser General Public License 10 */ 11 12require_once dirname(__FILE__) . "/ClassLoader.php"; 13Swift_ClassLoader::load("Swift_AddressContainer"); 14 15/** 16 * Swift_Address is just a lone e-mail address reprsented as an object 17 * @package Swift 18 * @author Chris Corbyn <chris@w3style.co.uk> 19 */ 20class Swift_Address extends Swift_AddressContainer 21{ 22 /** 23 * The e-mail address portion 24 * @var string 25 */ 26 protected $address = null; 27 /** 28 * The personal name part 29 * @var string 30 */ 31 protected $name = null; 32 33 /** 34 * Constructor 35 * @param string The address portion 36 * @param string The personal name, optional 37 */ 38 public function __construct($address, $name=null) 39 { 40 $this->setAddress($address); 41 if ($name !== null) $this->setName($name); 42 } 43 /** 44 * Set the email address 45 * @param string 46 */ 47 public function setAddress($address) 48 { 49 $this->address = trim((string)$address); 50 } 51 /** 52 * Get the address portion 53 * @return string 54 */ 55 public function getAddress() 56 { 57 return $this->address; 58 } 59 /** 60 * Set the personal name 61 * @param string 62 */ 63 public function setName($name) 64 { 65 if ($name !== null) $this->name = (string) $name; 66 else $this->name = null; 67 } 68 /** 69 * Get personal name portion 70 * @return string 71 */ 72 public function getName() 73 { 74 return $this->name; 75 } 76 /** 77 * Build the address the way it should be structured 78 * @param boolean If the string will be sent to a SMTP server as an envelope 79 * @return string 80 */ 81 public function build($smtp=false) 82 { 83 if ($smtp) 84 { 85 return "<" . $this->address . ">"; 86 } 87 else 88 { 89 if (($this->name !== null)) 90 { 91 return $this->name . " <" . $this->address . ">"; 92 } 93 else return $this->address; 94 } 95 } 96 /** 97 * PHP's casting conversion 98 * @return string 99 */ 100 public function __toString() 101 { 102 return $this->build(true); 103 } 104} 105