diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php index a69ac9a5a8..94ab4396da 100644 --- a/scripts/__init_script__.php +++ b/scripts/__init_script__.php @@ -30,3 +30,12 @@ if (!ini_get('date.timezone')) { } phutil_load_library(dirname(__FILE__).'/../src/'); + +function phabricator_read_config_file($config) { + $root = dirname(dirname(__FILE__)); + $conf = include $root.'/conf/'.$config.'.conf.php'; + if ($conf === false) { + throw new Exception("Failed to read config file '{$config}'."); + } + return $conf; +} diff --git a/scripts/daemon/run_daemon.php b/scripts/daemon/run_daemon.php new file mode 100755 index 0000000000..b3cf97ab4d --- /dev/null +++ b/scripts/daemon/run_daemon.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +run(); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 926a6a2d33..b8504d6592 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -196,6 +196,7 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'applications/metamta/adapter/phpmailerlite', 'PhabricatorMetaMTAController' => 'applications/metamta/controller/base', 'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base', + 'PhabricatorMetaMTADaemon' => 'applications/metamta/daemon/mta', 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail', 'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/mailinglist', @@ -390,7 +391,7 @@ phutil_register_library_map(array( 'PhabricatorLiskDAO' => 'LiskDAO', 'PhabricatorLoginController' => 'PhabricatorAuthController', 'PhabricatorLogoutController' => 'PhabricatorAuthController', - 'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationAdapter', + 'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationPHPMailerLiteAdapter', 'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMetaMTAController' => 'PhabricatorController', 'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php b/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php index 32f3be948c..d7b964175b 100644 --- a/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php +++ b/src/applications/metamta/adapter/amazonses/PhabricatorMailImplementationAmazonSESAdapter.php @@ -28,7 +28,7 @@ class PhabricatorMailImplementationAmazonSESAdapter $this->mailer->customMailer = $this; } - public function executeSend($body) { + public function executeSend($body) { $key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key'); $secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-key'); diff --git a/src/applications/metamta/adapter/amazonses/__init__.php b/src/applications/metamta/adapter/amazonses/__init__.php index 5fb8d3710c..5e546c1a3e 100644 --- a/src/applications/metamta/adapter/amazonses/__init__.php +++ b/src/applications/metamta/adapter/amazonses/__init__.php @@ -6,11 +6,10 @@ -phutil_require_module('phabricator', 'applications/metamta/adapter/base'); +phutil_require_module('phabricator', 'applications/metamta/adapter/phpmailerlite'); phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phutil', 'moduleutils'); -phutil_require_module('phutil', 'utils'); phutil_require_source('PhabricatorMailImplementationAmazonSESAdapter.php'); diff --git a/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php b/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php index 07374421b8..f347c09b32 100644 --- a/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php +++ b/src/applications/metamta/controller/send/PhabricatorMetaMTASendController.php @@ -34,9 +34,7 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController { $mail->setIsHTML($request->getInt('html')); $mail->save(); if ($request->getInt('immediately')) { - $mail->sendNow( - $force_send = true, - new PhabricatorMailImplementationPHPMailerLiteAdapter()); + $mail->sendNow($force_send = true); } return id(new AphrontRedirectResponse()) diff --git a/src/applications/metamta/controller/send/__init__.php b/src/applications/metamta/controller/send/__init__.php index 24025389ef..d606f64d0f 100644 --- a/src/applications/metamta/controller/send/__init__.php +++ b/src/applications/metamta/controller/send/__init__.php @@ -7,7 +7,6 @@ phutil_require_module('phabricator', 'aphront/response/redirect'); -phutil_require_module('phabricator', 'applications/metamta/adapter/phpmailerlite'); phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'view/form/base'); diff --git a/scripts/daemons/metamta/metamta_mta.php b/src/applications/metamta/daemon/mta/PhabricatorMetaMTADaemon.php similarity index 59% rename from scripts/daemons/metamta/metamta_mta.php rename to src/applications/metamta/daemon/mta/PhabricatorMetaMTADaemon.php index 6e6b7b9d0f..94b1981eea 100644 --- a/scripts/daemons/metamta/metamta_mta.php +++ b/src/applications/metamta/daemon/mta/PhabricatorMetaMTADaemon.php @@ -16,4 +16,21 @@ * limitations under the License. */ -// Placeholder so I don't forget about this, hopefully. +class PhabricatorMetaMTADaemon { + + public function run() { + echo "OK. Sending mail"; + do { + $mail = id(new PhabricatorMetaMTAMail())->loadAllWhere( + 'status = %s AND nextRetry <= %d LIMIT 10', + PhabricatorMetaMTAMail::STATUS_QUEUE, + time()); + foreach ($mail as $message) { + $message->sendNow(); + echo "."; + } + sleep(1); + } while (true); + } + +} diff --git a/src/applications/metamta/daemon/mta/__init__.php b/src/applications/metamta/daemon/mta/__init__.php new file mode 100644 index 0000000000..ba0aba5b87 --- /dev/null +++ b/src/applications/metamta/daemon/mta/__init__.php @@ -0,0 +1,14 @@ +sendNow($force_send = false, $mailer); + $this->sendNow(); } return $ret; } + private function buildDefaultMailer() { + $class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); + PhutilSymbolLoader::loadClass($class_name); + return newv($class_name, array()); + } public function sendNow( $force_send = false, - PhabricatorMailImplementationAdapter $mailer) { + PhabricatorMailImplementationAdapter $mailer = null) { + + if ($mailer === null) { + $mailer = $this->buildDefaultMailer(); + } if (!$force_send) { if ($this->getStatus() != self::STATUS_QUEUE) { @@ -166,7 +172,7 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { $handles = id(new PhabricatorObjectHandleData($phids)) ->loadHandles(); - + $params = $this->parameters; $default = PhabricatorEnv::getEnvConfig('metamta.default-address'); if (empty($params['from'])) {