9
9
use Magento \Framework \Exception \MailException ;
10
10
use Magento \Framework \Mail \MessageInterface ;
11
11
use Magento \Framework \Mail \TransportInterface ;
12
+ use Magento \Framework \Phrase ;
12
13
use Magento \Store \Model \ScopeInterface ;
14
+ use Zend \Mail \Message ;
15
+ use Zend \Mail \Transport \Sendmail ;
13
16
14
17
/**
15
18
* 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
17
20
*/
18
21
class Transport implements TransportInterface
19
22
{
@@ -29,79 +32,59 @@ class Transport implements TransportInterface
29
32
const XML_PATH_SENDING_RETURN_PATH_EMAIL = 'system/smtp/return_path_email ' ;
30
33
31
34
/**
32
- * Object for sending eMails
33
- *
34
- * @var \Zend_Mail_Transport_Sendmail
35
+ * @var Sendmail
35
36
*/
36
- private $ transport ;
37
+ private $ zendTransport ;
37
38
38
39
/**
39
- * Email message object that should be instance of \Zend_Mail
40
- *
41
40
* @var MessageInterface
42
41
*/
43
42
private $ message ;
44
43
45
44
/**
46
- * Core store config
47
- *
48
- * @var ScopeConfigInterface
49
- */
50
- private $ scopeConfig ;
51
-
52
- /**
53
- * @param \Zend_Mail_Transport_Sendmail $transport
54
45
* @param MessageInterface $message Email message object
55
46
* @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
59
48
*/
60
49
public function __construct (
61
- \Zend_Mail_Transport_Sendmail $ transport ,
62
50
MessageInterface $ message ,
63
- ScopeConfigInterface $ scopeConfig
51
+ ScopeConfigInterface $ scopeConfig ,
52
+ $ parameters = null
64
53
) {
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 );
67
71
}
68
- $ this ->transport = $ transport ;
72
+
73
+ $ this ->zendTransport = new Sendmail ($ parameters );
69
74
$ this ->message = $ message ;
70
- $ this ->scopeConfig = $ scopeConfig ;
71
75
}
72
76
73
77
/**
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
78
79
*/
79
80
public function sendMessage ()
80
81
{
81
82
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 ())
91
85
);
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 );
103
86
} catch (\Exception $ e ) {
104
- throw new MailException (__ ($ e ->getMessage ()), $ e );
87
+ throw new MailException (new Phrase ($ e ->getMessage ()), $ e );
105
88
}
106
89
}
107
90
0 commit comments