1
1
<?php
2
2
3
- /**
4
- * TODO: Should be final, but inherited by SES.
5
- *
6
- * @concrete-extensible
7
- */
8
- class PhabricatorMailSendmailAdapter
3
+ final class PhabricatorMailSendmailAdapter
9
4
extends PhabricatorMailAdapter {
10
5
11
6
const ADAPTERTYPE = 'sendmail ' ;
12
7
13
- protected $ mailer ;
8
+
9
+ public function getSupportedMessageTypes () {
10
+ return array (
11
+ PhabricatorMailEmailMessage::MESSAGETYPE ,
12
+ );
13
+ }
14
+
15
+ public function supportsMessageIDHeader () {
16
+ return true ;
17
+ }
14
18
15
19
protected function validateOptions (array $ options ) {
16
20
PhutilTypeSpec::checkMap (
@@ -29,97 +33,13 @@ public function newDefaultOptions() {
29
33
/**
30
34
* @phutil-external-symbol class PHPMailerLite
31
35
*/
32
- public function prepareForSend ( ) {
36
+ public function sendMessage ( PhabricatorMailExternalMessage $ message ) {
33
37
$ root = phutil_get_library_root ('phabricator ' );
34
38
$ root = dirname ($ root );
35
39
require_once $ root .'/externals/phpmailer/class.phpmailer-lite.php ' ;
36
- $ this ->mailer = new PHPMailerLite ($ use_exceptions = true );
37
- $ this ->mailer ->CharSet = 'utf-8 ' ;
38
-
39
- $ encoding = $ this ->getOption ('encoding ' );
40
- $ this ->mailer ->Encoding = $ encoding ;
41
-
42
- // By default, PHPMailerLite sends one mail per recipient. We handle
43
- // combining or separating To and Cc higher in the stack, so tell it to
44
- // send mail exactly like we ask.
45
- $ this ->mailer ->SingleTo = false ;
46
- }
47
-
48
- public function supportsMessageIDHeader () {
49
- return true ;
50
- }
51
-
52
- public function setFrom ($ email , $ name = '' ) {
53
- $ this ->mailer ->SetFrom ($ email , $ name , $ crazy_side_effects = false );
54
- return $ this ;
55
- }
56
-
57
- public function addReplyTo ($ email , $ name = '' ) {
58
- $ this ->mailer ->AddReplyTo ($ email , $ name );
59
- return $ this ;
60
- }
61
-
62
- public function addTos (array $ emails ) {
63
- foreach ($ emails as $ email ) {
64
- $ this ->mailer ->AddAddress ($ email );
65
- }
66
- return $ this ;
67
- }
68
-
69
- public function addCCs (array $ emails ) {
70
- foreach ($ emails as $ email ) {
71
- $ this ->mailer ->AddCC ($ email );
72
- }
73
- return $ this ;
74
- }
75
-
76
- public function addAttachment ($ data , $ filename , $ mimetype ) {
77
- $ this ->mailer ->AddStringAttachment (
78
- $ data ,
79
- $ filename ,
80
- 'base64 ' ,
81
- $ mimetype );
82
- return $ this ;
83
- }
84
-
85
- public function addHeader ($ header_name , $ header_value ) {
86
- if (strtolower ($ header_name ) == 'message-id ' ) {
87
- $ this ->mailer ->MessageID = $ header_value ;
88
- } else {
89
- $ this ->mailer ->AddCustomHeader ($ header_name .': ' .$ header_value );
90
- }
91
- return $ this ;
92
- }
93
-
94
- public function setBody ($ body ) {
95
- $ this ->mailer ->Body = $ body ;
96
- $ this ->mailer ->IsHTML (false );
97
- return $ this ;
98
- }
99
-
100
-
101
- /**
102
- * Note: phpmailer-lite does NOT support sending messages with mixed version
103
- * (plaintext and html). So for now lets just use HTML if it's available.
104
- * @param $html
105
- */
106
- public function setHTMLBody ($ html_body ) {
107
- $ this ->mailer ->Body = $ html_body ;
108
- $ this ->mailer ->IsHTML (true );
109
- return $ this ;
110
- }
111
-
112
- public function setSubject ($ subject ) {
113
- $ this ->mailer ->Subject = $ subject ;
114
- return $ this ;
115
- }
116
-
117
- public function hasValidRecipients () {
118
- return true ;
119
- }
120
40
121
- public function send () {
122
- return $ this -> mailer ->Send ();
41
+ $ mailer = PHPMailerLite:: newFromMessage ( $ message );
42
+ $ mailer ->Send ();
123
43
}
124
44
125
45
}
0 commit comments