This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-mail-headers-messageid' of https://github.com/d…
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mail | ||
*/ | ||
|
||
namespace Zend\Mail\Header; | ||
|
||
use Zend\Mail\Headers; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mail | ||
* @subpackage Header | ||
*/ | ||
class MessageId implements HeaderInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $messageId; | ||
|
||
|
||
public static function fromString($headerLine) | ||
{ | ||
list($name, $value) = explode(': ', $headerLine, 2); | ||
|
||
// check to ensure proper header type for this factory | ||
if (strtolower($name) !== 'message-id') { | ||
throw new Exception\InvalidArgumentException('Invalid header line for Message-ID string'); | ||
} | ||
|
||
$header = new static(); | ||
$header->setId($value); | ||
|
||
return $header; | ||
} | ||
|
||
public function getFieldName() | ||
{ | ||
return 'Message-ID'; | ||
} | ||
|
||
public function getFieldValue($format = HeaderInterface::FORMAT_RAW) | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
public function setEncoding($encoding) | ||
{ | ||
// This header must be always in US-ASCII | ||
return $this; | ||
} | ||
|
||
public function getEncoding() | ||
{ | ||
return 'ASCII'; | ||
} | ||
|
||
public function toString() | ||
{ | ||
return 'Message-ID: ' . $this->getFieldValue(); | ||
} | ||
|
||
/** | ||
* Set the message id | ||
* | ||
* @return MessageId | ||
*/ | ||
public function setId($id = null) | ||
{ | ||
if ($id === null) { | ||
$id = $this->createMessageId(); | ||
} | ||
|
||
$id = sprintf('<%s>', $id); | ||
$this->messageId = $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve the message id | ||
* | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->messageId; | ||
} | ||
|
||
/** | ||
* Creates the Message-ID | ||
* | ||
* @return string | ||
*/ | ||
public function createMessageId() { | ||
|
||
$time = time(); | ||
|
||
if (isset($_SERVER['REMOTE_ADDR'])) { | ||
$user = $_SERVER['REMOTE_ADDR']; | ||
} else { | ||
$user = getmypid(); | ||
} | ||
|
||
$rand = mt_rand(); | ||
|
||
if (isset($_SERVER["SERVER_NAME"])) { | ||
$hostName = $_SERVER["SERVER_NAME"]; | ||
} else { | ||
$hostName = php_uname('n'); | ||
} | ||
|
||
return sha1($time . $user . $rand) . '@' . $hostName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mail | ||
*/ | ||
|
||
namespace ZendTest\Mail\Header; | ||
|
||
use Zend\Mail\Header; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mail | ||
* @subpackage UnitTests | ||
* @group Zend_Mail | ||
*/ | ||
class MessageIdTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testSettingManually() | ||
{ | ||
$id = "CALTvGe4_oYgf9WsYgauv7qXh2-6=KbPLExmJNG7fCs9B=1nOYg@mail.example.com"; | ||
$messageid = new Header\MessageId(); | ||
$messageid->setId($id); | ||
|
||
$expected = sprintf('<%s>', $id); | ||
$this->assertEquals($expected, $messageid->getFieldValue()); | ||
} | ||
|
||
public function testAutoGeneration() | ||
{ | ||
$messageid = new Header\MessageId(); | ||
$messageid->setId(); | ||
|
||
$this->assertContains('@', $messageid->getFieldValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ Subject: multipart | |
Date: Sun, 01 Jan 2000 00:00:00 +0000 | ||
From: =?UTF-8?Q?"Peter M=C3=BCller"?= <[email protected]> | ||
ContENT-type: multipart/alternative; boUNDary="crazy-multipart" | ||
Message-ID: <CALTvGe4_oYgf9WsYgauv7qXh2-6=KbPLExmJNG7fCs9B=1nOYg@mail.example.com> | ||
MIME-version: 1.0 | ||
|
||
multipart message | ||
|