mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup MIME header email address parsing
This commit is contained in:
parent
443a6df070
commit
4b8ad326fa
4 changed files with 27 additions and 54 deletions
|
|
@ -33,15 +33,6 @@ class EmailCollection extends \MailSo\Base\Collection
|
||||||
parent::append($oEmail, $bToTop);
|
parent::append($oEmail, $bToTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function MergeWithOtherCollection(EmailCollection $oEmails) : self
|
|
||||||
{
|
|
||||||
foreach ($oEmails as $oEmail) {
|
|
||||||
$this->append($oEmail);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Unique() : self
|
public function Unique() : self
|
||||||
{
|
{
|
||||||
$aReturn = array();
|
$aReturn = array();
|
||||||
|
|
|
||||||
|
|
@ -196,11 +196,6 @@ class Header implements \JsonSerializable
|
||||||
return $this->Value();
|
return $this->Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function IsReparsed() : bool
|
|
||||||
{
|
|
||||||
return $this->IsEmail() || $this->IsSubject() || $this->IsParameterized();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[\ReturnTypeWillChange]
|
#[\ReturnTypeWillChange]
|
||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,13 @@ class Message extends Part
|
||||||
$this->oAttachmentCollection = new AttachmentCollection;
|
$this->oAttachmentCollection = new AttachmentCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getHeaderValue(string $name)
|
||||||
|
{
|
||||||
|
return isset($this->aHeadersValue[$name])
|
||||||
|
? $this->aHeadersValue[$name]
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
public function DoesNotAddDefaultXMailer() : void
|
public function DoesNotAddDefaultXMailer() : void
|
||||||
{
|
{
|
||||||
$this->bAddDefaultXMailer = false;
|
$this->bAddDefaultXMailer = false;
|
||||||
|
|
@ -58,8 +65,7 @@ class Message extends Part
|
||||||
|
|
||||||
public function MessageId() : string
|
public function MessageId() : string
|
||||||
{
|
{
|
||||||
return empty($this->aHeadersValue[Enumerations\Header::MESSAGE_ID]) ? ''
|
return $this->getHeaderValue(Enumerations\Header::MESSAGE_ID) ?: '';
|
||||||
: $this->aHeadersValue[Enumerations\Header::MESSAGE_ID];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetMessageId(string $sMessageId) : void
|
public function SetMessageId(string $sMessageId) : void
|
||||||
|
|
@ -79,52 +85,31 @@ class Message extends Part
|
||||||
|
|
||||||
public function GetSubject() : string
|
public function GetSubject() : string
|
||||||
{
|
{
|
||||||
return isset($this->aHeadersValue[Enumerations\Header::SUBJECT]) ?
|
return $this->getHeaderValue(Enumerations\Header::SUBJECT) ?: '';
|
||||||
$this->aHeadersValue[Enumerations\Header::SUBJECT] : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetFrom() : ?Email
|
public function GetFrom() : ?Email
|
||||||
{
|
{
|
||||||
if (isset($this->aHeadersValue[Enumerations\Header::FROM_]) &&
|
$value = $this->getHeaderValue(Enumerations\Header::FROM_);
|
||||||
$this->aHeadersValue[Enumerations\Header::FROM_] instanceof Email)
|
return ($value instanceof Email) ? $value : null;
|
||||||
{
|
|
||||||
return $this->aHeadersValue[Enumerations\Header::FROM_];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
public function GetTo() : ?EmailCollection
|
||||||
}
|
|
||||||
|
|
||||||
public function GetTo() : EmailCollection
|
|
||||||
{
|
{
|
||||||
if (isset($this->aHeadersValue[Enumerations\Header::TO_]) &&
|
$value = $this->getHeaderValue(Enumerations\Header::TO_);
|
||||||
$this->aHeadersValue[Enumerations\Header::TO_] instanceof EmailCollection)
|
return ($value instanceof EmailCollection) ? $value->Unique() : null;
|
||||||
{
|
|
||||||
return $this->aHeadersValue[Enumerations\Header::TO_]->Unique();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new EmailCollection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetCc() : ?EmailCollection
|
public function GetCc() : ?EmailCollection
|
||||||
{
|
{
|
||||||
if (isset($this->aHeadersValue[Enumerations\Header::CC]) &&
|
$value = $this->getHeaderValue(Enumerations\Header::CC);
|
||||||
$this->aHeadersValue[Enumerations\Header::CC] instanceof EmailCollection)
|
return ($value instanceof EmailCollection) ? $value->Unique() : null;
|
||||||
{
|
|
||||||
return $this->aHeadersValue[Enumerations\Header::CC]->Unique();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetBcc() : ?EmailCollection
|
public function GetBcc() : ?EmailCollection
|
||||||
{
|
{
|
||||||
if (isset($this->aHeadersValue[Enumerations\Header::BCC]) &&
|
$value = $this->getHeaderValue(Enumerations\Header::BCC);
|
||||||
$this->aHeadersValue[Enumerations\Header::BCC] instanceof EmailCollection)
|
return ($value instanceof EmailCollection) ? $value->Unique() : null;
|
||||||
{
|
|
||||||
return $this->aHeadersValue[Enumerations\Header::BCC]->Unique();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRcpt() : EmailCollection
|
public function GetRcpt() : EmailCollection
|
||||||
|
|
@ -133,8 +118,9 @@ class Message extends Part
|
||||||
|
|
||||||
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
|
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
if (isset($this->aHeadersValue[$header]) && $this->aHeadersValue[$header] instanceof EmailCollection) {
|
$value = $this->getHeaderValue($header);
|
||||||
foreach ($this->aHeadersValue[$header] as $oEmail) {
|
if ($value instanceof EmailCollection) {
|
||||||
|
foreach ($value as $oEmail) {
|
||||||
$oResult->append($oEmail);
|
$oResult->append($oEmail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -144,8 +130,9 @@ class Message extends Part
|
||||||
$aReturn = array();
|
$aReturn = array();
|
||||||
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
|
$headers = array(Enumerations\Header::TO_, Enumerations\Header::CC, Enumerations\Header::BCC);
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
if (isset($this->aHeadersValue[$header]) && $this->aHeadersValue[$header] instanceof EmailCollection) {
|
$value = $this->getHeaderValue($header);
|
||||||
foreach ($this->aHeadersValue[$header] as $oEmail) {
|
if ($value instanceof EmailCollection) {
|
||||||
|
foreach ($value as $oEmail) {
|
||||||
$oResult->append($oEmail);
|
$oResult->append($oEmail);
|
||||||
$sEmail = $oEmail->GetEmail();
|
$sEmail = $oEmail->GetEmail();
|
||||||
if (!isset($aReturn[$sEmail])) {
|
if (!isset($aReturn[$sEmail])) {
|
||||||
|
|
|
||||||
|
|
@ -806,11 +806,11 @@ trait Messages
|
||||||
|
|
||||||
if ($oSmtpClient->Settings->usePhpMail) {
|
if ($oSmtpClient->Settings->usePhpMail) {
|
||||||
if (\MailSo\Base\Utils::FunctionCallable('mail')) {
|
if (\MailSo\Base\Utils::FunctionCallable('mail')) {
|
||||||
$aToCollection = $oMessage->GetTo();
|
$oToCollection = $oMessage->GetTo();
|
||||||
if ($aToCollection && $oFrom) {
|
if ($oToCollection && $oFrom) {
|
||||||
$sRawBody = \stream_get_contents($rMessageStream);
|
$sRawBody = \stream_get_contents($rMessageStream);
|
||||||
if (!empty($sRawBody)) {
|
if (!empty($sRawBody)) {
|
||||||
$sMailTo = \trim($aToCollection->ToString(true));
|
$sMailTo = \trim($oToCollection->ToString(true));
|
||||||
$sMailSubject = \trim($oMessage->GetSubject());
|
$sMailSubject = \trim($oMessage->GetSubject());
|
||||||
$sMailSubject = \strlen($sMailSubject) ? \MailSo\Base\Utils::EncodeHeaderValue($sMailSubject) : '';
|
$sMailSubject = \strlen($sMailSubject) ? \MailSo\Base\Utils::EncodeHeaderValue($sMailSubject) : '';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue