Skip to content

Commit d675b60

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-71696
# Conflicts: # app/code/Magento/AdminNotification/Controller/Adminhtml/Notification/AjaxMarkAsRead.php # app/code/Magento/Checkout/Controller/Cart/Addgroup.php # app/code/Magento/Customer/Block/CustomerScopeData.php # app/code/Magento/Sales/Controller/Adminhtml/Order/Create/Reorder.php # app/code/Magento/Sitemap/Helper/Data.php # app/code/Magento/Sitemap/Model/Sitemap.php # dev/tests/static/testsuite/Magento/Test/Js/_files/jshint/blacklist/core.txt # lib/internal/Magento/Framework/Mail/Message.php # lib/internal/Magento/Framework/Mail/Transport.php # lib/internal/Magento/Framework/Mail/TransportInterface.php
1 parent 513faa8 commit d675b60

File tree

2 files changed

+46
-61
lines changed

2 files changed

+46
-61
lines changed

app/code/Magento/Email/Model/Transport.php

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
use Magento\Framework\Exception\MailException;
1010
use Magento\Framework\Mail\MessageInterface;
1111
use Magento\Framework\Mail\TransportInterface;
12+
use Magento\Framework\Phrase;
1213
use Magento\Store\Model\ScopeInterface;
14+
use Zend\Mail\Message;
15+
use Zend\Mail\Transport\Sendmail;
1316

1417
/**
1518
* Class that responsible for filling some message data before transporting it.
16-
* @see Zend_Mail_Transport_Sendmail is used for transport
19+
* @see \Zend\Mail\Transport\Sendmail is used for transport
1720
*/
1821
class Transport implements TransportInterface
1922
{
@@ -29,79 +32,59 @@ class Transport implements TransportInterface
2932
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email';
3033

3134
/**
32-
* Object for sending eMails
33-
*
34-
* @var \Zend_Mail_Transport_Sendmail
35+
* @var Sendmail
3536
*/
36-
private $transport;
37+
private $zendTransport;
3738

3839
/**
39-
* Email message object that should be instance of \Zend_Mail
40-
*
4140
* @var MessageInterface
4241
*/
4342
private $message;
4443

4544
/**
46-
* Core store config
47-
*
48-
* @var ScopeConfigInterface
49-
*/
50-
private $scopeConfig;
51-
52-
/**
53-
* @param \Zend_Mail_Transport_Sendmail $transport
5445
* @param MessageInterface $message Email message object
5546
* @param ScopeConfigInterface $scopeConfig Core store config
56-
* @param string|array|\Zend_Config|null $parameters Config options for sendmail parameters
57-
*
58-
* @throws \InvalidArgumentException when $message is not an instance of \Zend_Mail
47+
* @param null|string|array|\Traversable $parameters Config options for sendmail parameters
5948
*/
6049
public function __construct(
61-
\Zend_Mail_Transport_Sendmail $transport,
6250
MessageInterface $message,
63-
ScopeConfigInterface $scopeConfig
51+
ScopeConfigInterface $scopeConfig,
52+
$parameters = null
6453
) {
65-
if (!$message instanceof \Zend_Mail) {
66-
throw new \InvalidArgumentException('The message should be an instance of \Zend_Mail');
54+
/* configuration of whether return path should be set or no. Possible values are:
55+
* 0 - no
56+
* 1 - yes (set value as FROM address)
57+
* 2 - use custom value
58+
* @see Magento\Config\Model\Config\Source\Yesnocustom
59+
*/
60+
$isSetReturnPath = $scopeConfig->getValue(
61+
self::XML_PATH_SENDING_SET_RETURN_PATH,
62+
ScopeInterface::SCOPE_STORE
63+
);
64+
$returnPathValue = $scopeConfig->getValue(
65+
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
66+
ScopeInterface::SCOPE_STORE
67+
);
68+
69+
if ($isSetReturnPath == '2' && $returnPathValue !== null) {
70+
$parameters .= ' -f' . \escapeshellarg($returnPathValue);
6771
}
68-
$this->transport = $transport;
72+
73+
$this->zendTransport = new Sendmail($parameters);
6974
$this->message = $message;
70-
$this->scopeConfig = $scopeConfig;
7175
}
7276

7377
/**
74-
* Sets Return-Path to email if necessary, and sends email if it is allowed by System Configurations
75-
*
76-
* @return void
77-
* @throws MailException
78+
* @inheritdoc
7879
*/
7980
public function sendMessage()
8081
{
8182
try {
82-
/* configuration of whether return path should be set or no. Possible values are:
83-
* 0 - no
84-
* 1 - yes (set value as FROM address)
85-
* 2 - use custom value
86-
* @see Magento\Config\Model\Config\Source\Yesnocustom
87-
*/
88-
$isSetReturnPath = $this->scopeConfig->getValue(
89-
self::XML_PATH_SENDING_SET_RETURN_PATH,
90-
ScopeInterface::SCOPE_STORE
83+
$this->zendTransport->send(
84+
Message::fromString($this->message->getRawMessage())
9185
);
92-
$returnPathValue = $this->scopeConfig->getValue(
93-
self::XML_PATH_SENDING_RETURN_PATH_EMAIL,
94-
ScopeInterface::SCOPE_STORE
95-
);
96-
97-
if ($isSetReturnPath == '1') {
98-
$this->message->setReturnPath($this->message->getFrom());
99-
} elseif ($isSetReturnPath == '2' && $returnPathValue !== null) {
100-
$this->message->setReturnPath($returnPathValue);
101-
}
102-
$this->transport->send($this->message);
10386
} catch (\Exception $e) {
104-
throw new MailException(__($e->getMessage()), $e);
87+
throw new MailException(new Phrase($e->getMessage()), $e);
10588
}
10689
}
10790

lib/internal/Magento/Framework/Mail/Transport.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,44 @@
55
*/
66
namespace Magento\Framework\Mail;
77

8+
use Magento\Framework\Exception\MailException;
9+
use Magento\Framework\Phrase;
10+
use Zend\Mail\Message;
11+
use Zend\Mail\Transport\Sendmail;
12+
813
class Transport implements \Magento\Framework\Mail\TransportInterface
914
{
1015
/**
11-
* @var \Zend\Mail\Transport\Sendmail
16+
* @var Sendmail
1217
*/
1318
private $zendTransport;
19+
1420
/**
15-
* @var \Magento\Framework\Mail\MessageInterface
21+
* @var MessageInterface
1622
*/
1723
private $message;
1824

1925
/**
2026
* @param MessageInterface $message
21-
* @param null $parameters
22-
* @throws \InvalidArgumentException
27+
* @param null|string|array|\Traversable $parameters
2328
*/
24-
public function __construct(\Magento\Framework\Mail\MessageInterface $message, $parameters = null)
29+
public function __construct(MessageInterface $message, $parameters = null)
2530
{
26-
$this->zendTransport = new \Zend\Mail\Transport\Sendmail($parameters);
31+
$this->zendTransport = new Sendmail($parameters);
2732
$this->message = $message;
2833
}
2934

3035
/**
31-
* Send a mail using this transport
32-
*
33-
* @return void
34-
* @throws \Magento\Framework\Exception\MailException
36+
* @inheritdoc
3537
*/
3638
public function sendMessage()
3739
{
3840
try {
3941
$this->zendTransport->send(
40-
\Zend\Mail\Message::fromString($this->message->getRawMessage())
42+
Message::fromString($this->message->getRawMessage())
4143
);
4244
} catch (\Exception $e) {
43-
throw new \Magento\Framework\Exception\MailException(new \Magento\Framework\Phrase($e->getMessage()), $e);
45+
throw new MailException(new Phrase($e->getMessage()), $e);
4446
}
4547
}
4648

0 commit comments

Comments
 (0)