Make the sender address easily accessibly through Message::getAddresses('sender').

This commit is contained in:
Aaron van Geffen 2014-12-01 21:57:54 +01:00
parent 501d5d0974
commit cc8631581b

View File

@ -121,6 +121,13 @@ class Message
*/ */
protected $from; protected $from;
/**
* This is an array containing information about the address the email was sent from.
*
* @var string
*/
protected $sender;
/** /**
* This is an array of arrays that contains information about the addresses the email was sent to. * This is an array of arrays that contains information about the addresses the email was sent to.
* *
@ -240,6 +247,9 @@ class Message
if (isset($headers->bcc)) if (isset($headers->bcc))
$this->bcc = $this->processAddressObject($headers->bcc); $this->bcc = $this->processAddressObject($headers->bcc);
if (isset($headers->sender))
$this->sender = $this->processAddressObject($headers->sender);
$this->from = isset($headers->from) ? $this->processAddressObject($headers->from) : array(''); $this->from = isset($headers->from) ? $this->processAddressObject($headers->from) : array('');
$this->replyTo = isset($headers->reply_to) ? $this->processAddressObject($headers->reply_to) : $this->from; $this->replyTo = isset($headers->reply_to) ? $this->processAddressObject($headers->reply_to) : $this->from;
@ -367,14 +377,14 @@ class Message
* This function returns either an array of email addresses and names or, optionally, a string that can be used in * This function returns either an array of email addresses and names or, optionally, a string that can be used in
* mail headers. * mail headers.
* *
* @param string $type Should be 'to', 'cc', 'bcc', 'from', or 'reply-to'. * @param string $type Should be 'to', 'cc', 'bcc', 'from', 'sender', or 'reply-to'.
* @param bool $asString * @param bool $asString
* @return array|string|bool * @return array|string|bool
*/ */
public function getAddresses($type, $asString = false) public function getAddresses($type, $asString = false)
{ {
$type = ( $type == 'reply-to' ) ? 'replyTo' : $type; $type = ( $type == 'reply-to' ) ? 'replyTo' : $type;
$addressTypes = array('to', 'cc', 'bcc', 'from', 'replyTo'); $addressTypes = array('to', 'cc', 'bcc', 'from', 'sender', 'replyTo');
if (!in_array($type, $addressTypes) || !isset($this->$type) || count($this->$type) < 1) if (!in_array($type, $addressTypes) || !isset($this->$type) || count($this->$type) < 1)
return false; return false;
@ -382,6 +392,8 @@ class Message
if (!$asString) { if (!$asString) {
if ($type == 'from') if ($type == 'from')
return $this->from[0]; return $this->from[0];
elseif ($type == 'sender')
return $this->sender[0];
return $this->$type; return $this->$type;
} else { } else {