Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Dmitriy Chizhov Fixed #1 issue f546878 Feb 15, 2019
0 contributors

Users who have contributed to this file

232 lines (193 sloc) 4.67 KB
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the commercial license
* that is bundled with this package in the file LICENSE.txt.
*
* @category Extait
* @package Extait_Attachment
* @copyright Copyright (c) 2016-2018 Extait, Inc. (http://www.extait.com)
*/
namespace Extait\Attachment\Mail;
use Zend\Mime\Mime;
use Zend\Mime\PartFactory;
use Zend\Mail\MessageFactory as MailMessageFactory;
use Zend\Mime\MessageFactory as MimeMessageFactory;
class Message implements \Magento\Framework\Mail\MailMessageInterface
{
/**
* @var \Zend\Mime\PartFactory
*/
protected $partFactory;
/**
* @var \Zend\Mime\MessageFactory
*/
protected $mimeMessageFactory;
/**
* @var \Zend\Mail\Message
*/
private $zendMessage;
/**
* @var \Zend\Mime\Part[]
*/
protected $parts = [];
/**
* Message constructor.
*
* @param \Zend\Mime\PartFactory $partFactory
* @param \Zend\Mime\MessageFactory $mimeMessageFactory
* @param string $charset
*/
public function __construct(PartFactory $partFactory, MimeMessageFactory $mimeMessageFactory, $charset = 'utf-8')
{
$this->partFactory = $partFactory;
$this->mimeMessageFactory = $mimeMessageFactory;
$this->zendMessage = MailMessageFactory::getInstance();
$this->zendMessage->setEncoding($charset);
}
/**
* Add the HTML mime part to the message.
*
* @param string $content
* @return $this
*/
public function setBodyText($content)
{
$textPart = $this->partFactory->create();
$textPart->setContent($content)
->setType(Mime::TYPE_TEXT)
->setCharset($this->zendMessage->getEncoding());
$this->parts[] = $textPart;
return $this;
}
/**
* Add the text mime part to the message.
*
* @param string $content
* @return $this
*/
public function setBodyHtml($content)
{
$htmlPart = $this->partFactory->create();
$htmlPart->setContent($content)
->setType(Mime::TYPE_HTML)
->setCharset($this->zendMessage->getEncoding());
$this->parts[] = $htmlPart;
return $this;
}
/**
* Add the attachment mime part to the message.
*
* @param string $content
* @param string $fileName
* @param string $fileType
* @return $this
*/
public function setBodyAttachment($content, $fileName, $fileType)
{
$attachmentPart = $this->partFactory->create();
$attachmentPart->setContent($content)
->setType($fileType)
->setFileName($fileName)
->setDisposition(Mime::DISPOSITION_ATTACHMENT)
->setEncoding(Mime::ENCODING_BASE64);
$this->parts[] = $attachmentPart;
return $this;
}
/**
* Set parts to Zend message body.
*
* @return $this
*/
public function setPartsToBody()
{
$mimeMessage = $this->mimeMessageFactory->create();
$mimeMessage->setParts($this->parts);
$this->zendMessage->setBody($mimeMessage);
return $this;
}
/**
* {@inheritdoc}
*/
public function setBody($body)
{
return $this;
}
/**
* {@inheritdoc}
*/
public function setSubject($subject)
{
$this->zendMessage->setSubject($subject);
return $this;
}
/**
* {@inheritdoc}
*/
public function getSubject()
{
return $this->zendMessage->getSubject();
}
/**
* {@inheritdoc}
*/
public function getBody()
{
return $this->zendMessage->getBody();
}
/**
* {@inheritdoc}
*/
public function setFrom($fromAddress)
{
$this->zendMessage->setFrom($fromAddress);
return $this;
}
/**
* {@inheritdoc}
*/
public function addTo($toAddress)
{
$this->zendMessage->addTo($toAddress);
return $this;
}
/**
* {@inheritdoc}
*/
public function addCc($ccAddress)
{
$this->zendMessage->addCc($ccAddress);
return $this;
}
/**
* {@inheritdoc}
*/
public function addBcc($bccAddress)
{
$this->zendMessage->addBcc($bccAddress);
return $this;
}
/**
* {@inheritdoc}
*/
public function setReplyTo($replyToAddress)
{
$this->zendMessage->setReplyTo($replyToAddress);
return $this;
}
/**
* {@inheritdoc}
*/
public function getRawMessage()
{
return $this->zendMessage->toString();
}
/**
* @inheritDoc
*/
public function setMessageType($type)
{
return $this;
}
}
You can’t perform that action at this time.