10 files changed +96
-15
lines changed Original file line number Diff line number Diff line change 30
30
}
31
31
32
32
phutil_load_library (dirname (__FILE__ ).'/../src/ ' );
33
+
34
+ function phabricator_read_config_file ($ config ) {
35
+ $ root = dirname (dirname (__FILE__ ));
36
+ $ conf = include $ root .'/conf/ ' .$ config .'.conf.php ' ;
37
+ if ($ conf === false ) {
38
+ throw new Exception ("Failed to read config file ' {$ config }'. " );
39
+ }
40
+ return $ conf ;
41
+ }
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env php
2
+ <?php
3
+
4
+ /*
5
+ * Copyright 2011 Facebook, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ $ root = dirname (dirname (dirname (__FILE__ )));
21
+ require_once $ root .'/scripts/__init_script__.php ' ;
22
+
23
+ $ env = getenv ('PHABRICATOR_ENV ' );
24
+ if (!$ env ) {
25
+ echo "Define PHABRICATOR_ENV before running scripts. \n" ;
26
+ exit (1 );
27
+ }
28
+
29
+ $ conf = phabricator_read_config_file ($ env );
30
+ $ conf ['phabricator.env ' ] = $ env ;
31
+
32
+ phutil_require_module ('phabricator ' , 'infrastructure/env ' );
33
+ PhabricatorEnv::setEnvConfig ($ conf );
34
+ phutil_require_module ('phutil ' , 'symbols ' );
35
+
36
+ PhutilSymbolLoader::loadClass ('PhabricatorMetaMTADaemon ' );
37
+ $ daemon = new PhabricatorMetaMTADaemon ();
38
+ $ daemon ->run ();
Original file line number Diff line number Diff line change 196
196
'PhabricatorMailImplementationPHPMailerLiteAdapter ' => 'applications/metamta/adapter/phpmailerlite ' ,
197
197
'PhabricatorMetaMTAController ' => 'applications/metamta/controller/base ' ,
198
198
'PhabricatorMetaMTADAO ' => 'applications/metamta/storage/base ' ,
199
+ 'PhabricatorMetaMTADaemon ' => 'applications/metamta/daemon/mta ' ,
199
200
'PhabricatorMetaMTAListController ' => 'applications/metamta/controller/list ' ,
200
201
'PhabricatorMetaMTAMail ' => 'applications/metamta/storage/mail ' ,
201
202
'PhabricatorMetaMTAMailingList ' => 'applications/metamta/storage/mailinglist ' ,
390
391
'PhabricatorLiskDAO ' => 'LiskDAO ' ,
391
392
'PhabricatorLoginController ' => 'PhabricatorAuthController ' ,
392
393
'PhabricatorLogoutController ' => 'PhabricatorAuthController ' ,
393
- 'PhabricatorMailImplementationAmazonSESAdapter ' => 'PhabricatorMailImplementationAdapter ' ,
394
+ 'PhabricatorMailImplementationAmazonSESAdapter ' => 'PhabricatorMailImplementationPHPMailerLiteAdapter ' ,
394
395
'PhabricatorMailImplementationPHPMailerLiteAdapter ' => 'PhabricatorMailImplementationAdapter ' ,
395
396
'PhabricatorMetaMTAController ' => 'PhabricatorController ' ,
396
397
'PhabricatorMetaMTADAO ' => 'PhabricatorLiskDAO ' ,
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function __construct() {
28
28
$ this ->mailer ->customMailer = $ this ;
29
29
}
30
30
31
- public function executeSend ($ body ) {
31
+ public function executeSend ($ body ) {
32
32
$ key = PhabricatorEnv::getEnvConfig ('amazon-ses.access-key ' );
33
33
$ secret = PhabricatorEnv::getEnvConfig ('amazon-ses.secret-key ' );
34
34
Original file line number Diff line number Diff line change 6
6
7
7
8
8
9
- phutil_require_module ('phabricator ' , 'applications/metamta/adapter/base ' );
9
+ phutil_require_module ('phabricator ' , 'applications/metamta/adapter/phpmailerlite ' );
10
10
phutil_require_module ('phabricator ' , 'infrastructure/env ' );
11
11
12
12
phutil_require_module ('phutil ' , 'moduleutils ' );
13
- phutil_require_module ('phutil ' , 'utils ' );
14
13
15
14
16
15
phutil_require_source ('PhabricatorMailImplementationAmazonSESAdapter.php ' );
Original file line number Diff line number Diff line change @@ -34,9 +34,7 @@ public function processRequest() {
34
34
$ mail ->setIsHTML ($ request ->getInt ('html ' ));
35
35
$ mail ->save ();
36
36
if ($ request ->getInt ('immediately ' )) {
37
- $ mail ->sendNow (
38
- $ force_send = true ,
39
- new PhabricatorMailImplementationPHPMailerLiteAdapter ());
37
+ $ mail ->sendNow ($ force_send = true );
40
38
}
41
39
42
40
return id (new AphrontRedirectResponse ())
Original file line number Diff line number Diff line change 7
7
8
8
9
9
phutil_require_module ('phabricator ' , 'aphront/response/redirect ' );
10
- phutil_require_module ('phabricator ' , 'applications/metamta/adapter/phpmailerlite ' );
11
10
phutil_require_module ('phabricator ' , 'applications/metamta/controller/base ' );
12
11
phutil_require_module ('phabricator ' , 'applications/metamta/storage/mail ' );
13
12
phutil_require_module ('phabricator ' , 'view/form/base ' );
Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
- // Placeholder so I don't forget about this, hopefully.
19
+ class PhabricatorMetaMTADaemon {
20
+
21
+ public function run () {
22
+ echo "OK. Sending mail " ;
23
+ do {
24
+ $ mail = id (new PhabricatorMetaMTAMail ())->loadAllWhere (
25
+ 'status = %s AND nextRetry <= %d LIMIT 10 ' ,
26
+ PhabricatorMetaMTAMail::STATUS_QUEUE ,
27
+ time ());
28
+ foreach ($ mail as $ message ) {
29
+ $ message ->sendNow ();
30
+ echo ". " ;
31
+ }
32
+ sleep (1 );
33
+ } while (true );
34
+ }
35
+
36
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * This file is automatically generated. Lint this module to rebuild it.
4
+ * @generated
5
+ */
6
+
7
+
8
+
9
+ phutil_require_module ('phabricator ' , 'applications/metamta/storage/mail ' );
10
+
11
+ phutil_require_module ('phutil ' , 'utils ' );
12
+
13
+
14
+ phutil_require_source ('PhabricatorMetaMTADaemon.php ' );
Original file line number Diff line number Diff line change @@ -122,19 +122,25 @@ public function save() {
122
122
$ ret = parent ::save ();
123
123
124
124
if ($ try_send ) {
125
- $ class_name = PhabricatorEnv::getEnvConfig ('metamta.mail-adapter ' );
126
- PhutilSymbolLoader::loadClass ($ class_name );
127
- $ mailer = newv ($ class_name , array ());
128
- $ this ->sendNow ($ force_send = false , $ mailer );
125
+ $ this ->sendNow ();
129
126
}
130
127
131
128
return $ ret ;
132
129
}
133
130
131
+ private function buildDefaultMailer () {
132
+ $ class_name = PhabricatorEnv::getEnvConfig ('metamta.mail-adapter ' );
133
+ PhutilSymbolLoader::loadClass ($ class_name );
134
+ return newv ($ class_name , array ());
135
+ }
134
136
135
137
public function sendNow (
136
138
$ force_send = false ,
137
- PhabricatorMailImplementationAdapter $ mailer ) {
139
+ PhabricatorMailImplementationAdapter $ mailer = null ) {
140
+
141
+ if ($ mailer === null ) {
142
+ $ mailer = $ this ->buildDefaultMailer ();
143
+ }
138
144
139
145
if (!$ force_send ) {
140
146
if ($ this ->getStatus () != self ::STATUS_QUEUE ) {
@@ -166,7 +172,7 @@ public function sendNow(
166
172
167
173
$ handles = id (new PhabricatorObjectHandleData ($ phids ))
168
174
->loadHandles ();
169
-
175
+
170
176
$ params = $ this ->parameters ;
171
177
$ default = PhabricatorEnv::getEnvConfig ('metamta.default-address ' );
172
178
if (empty ($ params ['from ' ])) {
0 commit comments