fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Mail / Header / Sender.php
blob2efc23bf6b758b1f3600e8b50072b9c24ee43486
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mail\Header;
12 use Zend\Mail;
13 use Zend\Mime\Mime;
15 /**
16 * Sender header class methods.
18 * @see https://tools.ietf.org/html/rfc2822 RFC 2822
19 * @see https://tools.ietf.org/html/rfc2047 RFC 2047
21 class Sender implements HeaderInterface
23 /**
24 * @var \Zend\Mail\Address\AddressInterface
26 protected $address;
28 /**
29 * Header encoding
31 * @var null|string
33 protected $encoding;
35 public static function fromString($headerLine)
37 list($name, $value) = GenericHeader::splitHeaderLine($headerLine);
38 $value = HeaderWrap::mimeDecodeValue($value);
40 // check to ensure proper header type for this factory
41 if (strtolower($name) !== 'sender') {
42 throw new Exception\InvalidArgumentException('Invalid header line for Sender string');
45 $header = new static();
46 $senderName = '';
47 $senderEmail = '';
49 // Check for address, and set if found
50 if (preg_match('/^(?P<name>.*?)<(?P<email>[^>]+)>$/', $value, $matches)) {
51 $senderName = trim($matches['name']);
52 if (empty($senderName)) {
53 $senderName = null;
55 $senderEmail = $matches['email'];
56 } else {
57 $senderEmail = $value;
60 $header->setAddress($senderEmail, $senderName);
62 return $header;
65 public function getFieldName()
67 return 'Sender';
70 public function getFieldValue($format = HeaderInterface::FORMAT_RAW)
72 if (! $this->address instanceof Mail\Address\AddressInterface) {
73 return '';
76 $email = sprintf('<%s>', $this->address->getEmail());
77 $name = $this->address->getName();
79 if (!empty($name)) {
80 if ($format == HeaderInterface::FORMAT_ENCODED) {
81 $encoding = $this->getEncoding();
82 if ('ASCII' !== $encoding) {
83 $name = HeaderWrap::mimeEncodeValue($name, $encoding);
86 $email = sprintf('%s %s', $name, $email);
89 return $email;
92 public function setEncoding($encoding)
94 $this->encoding = $encoding;
95 return $this;
98 public function getEncoding()
100 if (! $this->encoding) {
101 $this->encoding = Mime::isPrintable($this->getFieldValue(HeaderInterface::FORMAT_RAW))
102 ? 'ASCII'
103 : 'UTF-8';
106 return $this->encoding;
109 public function toString()
111 return 'Sender: ' . $this->getFieldValue(HeaderInterface::FORMAT_ENCODED);
115 * Set the address used in this header
117 * @param string|\Zend\Mail\Address\AddressInterface $emailOrAddress
118 * @param null|string $name
119 * @throws Exception\InvalidArgumentException
120 * @return Sender
122 public function setAddress($emailOrAddress, $name = null)
124 if (is_string($emailOrAddress)) {
125 $emailOrAddress = new Mail\Address($emailOrAddress, $name);
126 } elseif (!$emailOrAddress instanceof Mail\Address\AddressInterface) {
127 throw new Exception\InvalidArgumentException(sprintf(
128 '%s expects a string or AddressInterface object; received "%s"',
129 __METHOD__,
130 (is_object($emailOrAddress) ? get_class($emailOrAddress) : gettype($emailOrAddress))
133 $this->address = $emailOrAddress;
134 return $this;
138 * Retrieve the internal address from this header
140 * @return \Zend\Mail\Address\AddressInterface|null
142 public function getAddress()
144 return $this->address;