private function headers()
 {
     $headers = new Headers();
     $messageId = new MessageId();
     $messageId->setId('testId');
     $headers->addHeader($messageId);
     $addressList = new AddressList();
     $addressList->add('*****@*****.**');
     $from = new From();
     $from->setAddressList($addressList);
     $headers->addHeader($from);
     $to = new To();
     $to->setAddressList($addressList);
     $headers->addHeader($to);
     return $headers;
 }
コード例 #2
0
 /**
  * Sanitize Mail headers:
  *
  * - generate MessageId header in case it is missing
  * - make common fields unique (From, Subject, Message-Id)
  * - or merge them (To, Cc)
  *
  * @param MailMessage $mail
  */
 public function __invoke(MailMessage $mail)
 {
     $headers = $mail->getHeaders();
     // add Message-Id, this needs to be first before we modify more headers
     if (!$headers->has('Message-Id')) {
         // add Message-Id header as it is missing
         $text_headers = rtrim($headers->toString(), Headers::EOL);
         $messageId = Mail_Helper::generateMessageID($text_headers, $mail->getContent());
         $header = new MessageId();
         $headers->addHeader($header->setId(trim($messageId, '<>')));
     }
     // headers to check and whether they need to be unique
     $checkHeaders = array('From' => true, 'Subject' => true, 'Message-Id' => true, 'To' => false, 'Cc' => false);
     // NOTE: the headerClass does not match the format for Message-Id,
     // but luckily Message-Id header is always present (see above)
     foreach ($checkHeaders as $headerName => $unique) {
         $header = $mail->getHeaderByName($headerName, $headerName);
         if ($unique) {
             $this->removeDuplicateHeader($headers, $header);
         } else {
             $this->mergeDuplicateHeader($headers, $header);
         }
     }
 }
コード例 #3
0
 public function testAutoGeneration()
 {
     $messageid = new Header\MessageId();
     $messageid->setId();
     $this->assertContains('@', $messageid->getFieldValue());
 }
コード例 #4
0
ファイル: Message.php プロジェクト: outeredge/edge-zf2
 /**
  * Generate a compliant unique Message-Id string
  *
  * @return string
  */
 public function generateMessageId()
 {
     $header = new MessageId();
     return $header->setId()->getId();
 }
 private function headers()
 {
     $headers = new Headers();
     $messageId = new MessageId();
     $messageId->setId('testId');
     $headers->addHeader($messageId);
     $addressList = new AddressList();
     $addressList->add('*****@*****.**', 'Dummy Name');
     $from = new From();
     $from->setAddressList($addressList);
     $headers->addHeader($from);
     $to = new To();
     $to->setAddressList($addressList);
     $headers->addHeader($to);
     //@todo fix this;
     $contentTransferEncoding = new GenericHeader("Content-Transfer-Encoding", "7bit");
     $headers->addHeader($contentTransferEncoding);
     return $headers;
 }