From c89dc199767ee1e04365fb5c404ea895ea731953 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 29 Jan 2015 14:47:32 -0800 Subject: [PATCH] Application emails - move over paste and files Summary: Fixes T3404 (post D11565), fixes T5952. This infrastructure has been getting deployed against Maniphest and its time to get these other two applications going on it. Test Plan: created an email address for paste and used `./bin/mail receive-test` ; a paste was successfully created Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T5952, T3404 Differential Revision: https://secure.phabricator.com/D11570 --- .../20150129.pastefileapplicationemails.php | 38 +++++++++++++++++++ .../PhabricatorFilesApplication.php | 15 ++++++++ .../config/PhabricatorFilesConfigOptions.php | 11 +++++- .../files/mail/FileCreateMailReceiver.php | 15 +------- .../mail/ManiphestCreateMailReceiver.php | 17 +-------- .../receiver/PhabricatorMailReceiver.php | 21 ++++++++++ .../PhabricatorPasteApplication.php | 14 +++++++ .../config/PhabricatorPasteConfigOptions.php | 11 +++++- .../paste/mail/PasteCreateMailReceiver.php | 15 +------- 9 files changed, 113 insertions(+), 44 deletions(-) create mode 100644 resources/sql/autopatches/20150129.pastefileapplicationemails.php diff --git a/resources/sql/autopatches/20150129.pastefileapplicationemails.php b/resources/sql/autopatches/20150129.pastefileapplicationemails.php new file mode 100644 index 0000000000..68c3dd2381 --- /dev/null +++ b/resources/sql/autopatches/20150129.pastefileapplicationemails.php @@ -0,0 +1,38 @@ +setAddress($value_files) + ->setApplicationPHID($files_app->getPHID()) + ->save(); + } catch (AphrontDuplicateKeyQueryException $ex) { + // already migrated? + } +} + +$value_paste = PhabricatorEnv::getEnvConfigIfExists($key_paste); +$paste_app = new PhabricatorPasteApplication(); + +if ($value_paste) { + try { + PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail( + PhabricatorUser::getOmnipotentUser()) + ->setAddress($value_paste) + ->setApplicationPHID($paste_app->getPHID()) + ->save(); + } catch (AphrontDuplicateKeyQueryException $ex) { + // already migrated? + } +} + +echo "Done.\n"; diff --git a/src/applications/files/application/PhabricatorFilesApplication.php b/src/applications/files/application/PhabricatorFilesApplication.php index cd280534c2..cf49fa2fd6 100644 --- a/src/applications/files/application/PhabricatorFilesApplication.php +++ b/src/applications/files/application/PhabricatorFilesApplication.php @@ -44,6 +44,21 @@ final class PhabricatorFilesApplication extends PhabricatorApplication { ); } + public function supportsEmailIntegration() { + return true; + } + + public function getAppEmailBlurb() { + return pht( + 'Send emails with file attachments to these addresses to upload '. + 'files. %s', + phutil_tag( + 'a', + array( + 'href' => $this->getInboundEmailSupportLink(),), + pht('Learn More'))); + } + protected function getCustomCapabilities() { return array( FilesDefaultViewCapability::CAPABILITY => array( diff --git a/src/applications/files/config/PhabricatorFilesConfigOptions.php b/src/applications/files/config/PhabricatorFilesConfigOptions.php index dec0db998e..315ef3c2ff 100644 --- a/src/applications/files/config/PhabricatorFilesConfigOptions.php +++ b/src/applications/files/config/PhabricatorFilesConfigOptions.php @@ -179,7 +179,16 @@ final class PhabricatorFilesConfigOptions 'metamta.files.public-create-email', 'string', null) - ->setDescription(pht('Allow uploaded files via email.')), + ->setLocked(true) + ->setLockedMessage(pht( + 'This configuration is deprecated. See description for details.')) + ->setSummary(pht('DEPRECATED - Allow uploaded files via email.')) + ->setDescription( + pht( + 'This config has been deprecated in favor of [[ '. + '/applications/view/PhabricatorFilesApplication/ | '. + 'application settings ]], which allow for multiple email '. + 'addresses and other functionality.')), $this->newOption( 'metamta.files.subject-prefix', 'string', diff --git a/src/applications/files/mail/FileCreateMailReceiver.php b/src/applications/files/mail/FileCreateMailReceiver.php index 0c29aad61f..9f0fcc157c 100644 --- a/src/applications/files/mail/FileCreateMailReceiver.php +++ b/src/applications/files/mail/FileCreateMailReceiver.php @@ -8,19 +8,8 @@ final class FileCreateMailReceiver extends PhabricatorMailReceiver { } public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { - $config_key = 'metamta.files.public-create-email'; - $create_address = PhabricatorEnv::getEnvConfig($config_key); - if (!$create_address) { - return false; - } - - foreach ($mail->getToAddresses() as $to_address) { - if ($this->matchAddresses($create_address, $to_address)) { - return true; - } - } - - return false; + $files_app = new PhabricatorFilesApplication(); + return $this->canAcceptApplicationMail($files_app, $mail); } protected function processReceivedMail( diff --git a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php index f654ea9a05..d28beb3b74 100644 --- a/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php +++ b/src/applications/maniphest/mail/ManiphestCreateMailReceiver.php @@ -9,22 +9,7 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver { public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { $maniphest_app = new PhabricatorManiphestApplication(); - $application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery()) - ->setViewer($this->getViewer()) - ->withApplicationPHIDs(array($maniphest_app->getPHID())) - ->execute(); - - foreach ($mail->getToAddresses() as $to_address) { - foreach ($application_emails as $application_email) { - $create_address = $application_email->getAddress(); - if ($this->matchAddresses($create_address, $to_address)) { - $this->setApplicationEmail($application_email); - return true; - } - } - } - - return false; + return $this->canAcceptApplicationMail($maniphest_app, $mail); } protected function processReceivedMail( diff --git a/src/applications/metamta/receiver/PhabricatorMailReceiver.php b/src/applications/metamta/receiver/PhabricatorMailReceiver.php index ee309ffe0a..b01a83f5a9 100644 --- a/src/applications/metamta/receiver/PhabricatorMailReceiver.php +++ b/src/applications/metamta/receiver/PhabricatorMailReceiver.php @@ -16,6 +16,27 @@ abstract class PhabricatorMailReceiver { abstract public function isEnabled(); abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail); + final protected function canAcceptApplicationMail( + PhabricatorApplication $app, + PhabricatorMetaMTAReceivedMail $mail) { + + $application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery()) + ->setViewer($this->getViewer()) + ->withApplicationPHIDs(array($app->getPHID())) + ->execute(); + + foreach ($mail->getToAddresses() as $to_address) { + foreach ($application_emails as $application_email) { + $create_address = $application_email->getAddress(); + if ($this->matchAddresses($create_address, $to_address)) { + $this->setApplicationEmail($application_email); + return true; + } + } + } + + return false; + } abstract protected function processReceivedMail( diff --git a/src/applications/paste/application/PhabricatorPasteApplication.php b/src/applications/paste/application/PhabricatorPasteApplication.php index edc1c63c25..6de712a92a 100644 --- a/src/applications/paste/application/PhabricatorPasteApplication.php +++ b/src/applications/paste/application/PhabricatorPasteApplication.php @@ -49,6 +49,20 @@ final class PhabricatorPasteApplication extends PhabricatorApplication { ); } + public function supportsEmailIntegration() { + return true; + } + + public function getAppEmailBlurb() { + return pht( + 'Send email to these addresses to create pastes. %s', + phutil_tag( + 'a', + array( + 'href' => $this->getInboundEmailSupportLink(),), + pht('Learn More'))); + } + protected function getCustomCapabilities() { return array( PasteDefaultViewCapability::CAPABILITY => array( diff --git a/src/applications/paste/config/PhabricatorPasteConfigOptions.php b/src/applications/paste/config/PhabricatorPasteConfigOptions.php index c58f5b1394..81b90d3c3a 100644 --- a/src/applications/paste/config/PhabricatorPasteConfigOptions.php +++ b/src/applications/paste/config/PhabricatorPasteConfigOptions.php @@ -17,7 +17,16 @@ final class PhabricatorPasteConfigOptions 'metamta.paste.public-create-email', 'string', null) - ->setDescription(pht('Allow creating pastes via email.')), + ->setLocked(true) + ->setLockedMessage(pht( + 'This configuration is deprecated. See description for details.')) + ->setSummary(pht('DEPRECATED - Allow creating pastes via email.')) + ->setDescription( + pht( + 'This config has been deprecated in favor of [[ '. + '/applications/view/PhabricatorPasteApplication/ | '. + 'application settings ]], which allow for multiple email '. + 'addresses and other functionality.')), $this->newOption( 'metamta.paste.subject-prefix', 'string', diff --git a/src/applications/paste/mail/PasteCreateMailReceiver.php b/src/applications/paste/mail/PasteCreateMailReceiver.php index 02decaa26e..d0c50d5fcf 100644 --- a/src/applications/paste/mail/PasteCreateMailReceiver.php +++ b/src/applications/paste/mail/PasteCreateMailReceiver.php @@ -8,19 +8,8 @@ final class PasteCreateMailReceiver extends PhabricatorMailReceiver { } public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { - $config_key = 'metamta.paste.public-create-email'; - $create_address = PhabricatorEnv::getEnvConfig($config_key); - if (!$create_address) { - return false; - } - - foreach ($mail->getToAddresses() as $to_address) { - if ($this->matchAddresses($create_address, $to_address)) { - return true; - } - } - - return false; + $paste_app = new PhabricatorPasteApplication(); + return $this->canAcceptApplicationMail($paste_app, $mail); } protected function processReceivedMail(