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
This commit is contained in:
parent
7d309a8e46
commit
c89dc19976
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$key_files = 'metamta.files.public-create-email';
|
||||||
|
$key_paste = 'metamta.paste.public-create-email';
|
||||||
|
echo "Migrating `$key_files` and `$key_paste` to new application email ".
|
||||||
|
"infrastructure...\n";
|
||||||
|
|
||||||
|
$value_files = PhabricatorEnv::getEnvConfigIfExists($key_files);
|
||||||
|
$files_app = new PhabricatorFilesApplication();
|
||||||
|
|
||||||
|
if ($value_files) {
|
||||||
|
try {
|
||||||
|
PhabricatorMetaMTAApplicationEmail::initializeNewAppEmail(
|
||||||
|
PhabricatorUser::getOmnipotentUser())
|
||||||
|
->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";
|
|
@ -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() {
|
protected function getCustomCapabilities() {
|
||||||
return array(
|
return array(
|
||||||
FilesDefaultViewCapability::CAPABILITY => array(
|
FilesDefaultViewCapability::CAPABILITY => array(
|
||||||
|
|
|
@ -179,7 +179,16 @@ final class PhabricatorFilesConfigOptions
|
||||||
'metamta.files.public-create-email',
|
'metamta.files.public-create-email',
|
||||||
'string',
|
'string',
|
||||||
null)
|
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(
|
$this->newOption(
|
||||||
'metamta.files.subject-prefix',
|
'metamta.files.subject-prefix',
|
||||||
'string',
|
'string',
|
||||||
|
|
|
@ -8,19 +8,8 @@ final class FileCreateMailReceiver extends PhabricatorMailReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||||
$config_key = 'metamta.files.public-create-email';
|
$files_app = new PhabricatorFilesApplication();
|
||||||
$create_address = PhabricatorEnv::getEnvConfig($config_key);
|
return $this->canAcceptApplicationMail($files_app, $mail);
|
||||||
if (!$create_address) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($mail->getToAddresses() as $to_address) {
|
|
||||||
if ($this->matchAddresses($create_address, $to_address)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processReceivedMail(
|
protected function processReceivedMail(
|
||||||
|
|
|
@ -9,22 +9,7 @@ final class ManiphestCreateMailReceiver extends PhabricatorMailReceiver {
|
||||||
|
|
||||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||||
$maniphest_app = new PhabricatorManiphestApplication();
|
$maniphest_app = new PhabricatorManiphestApplication();
|
||||||
$application_emails = id(new PhabricatorMetaMTAApplicationEmailQuery())
|
return $this->canAcceptApplicationMail($maniphest_app, $mail);
|
||||||
->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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processReceivedMail(
|
protected function processReceivedMail(
|
||||||
|
|
|
@ -16,6 +16,27 @@ abstract class PhabricatorMailReceiver {
|
||||||
|
|
||||||
abstract public function isEnabled();
|
abstract public function isEnabled();
|
||||||
abstract public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail);
|
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(
|
abstract protected function processReceivedMail(
|
||||||
|
|
|
@ -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() {
|
protected function getCustomCapabilities() {
|
||||||
return array(
|
return array(
|
||||||
PasteDefaultViewCapability::CAPABILITY => array(
|
PasteDefaultViewCapability::CAPABILITY => array(
|
||||||
|
|
|
@ -17,7 +17,16 @@ final class PhabricatorPasteConfigOptions
|
||||||
'metamta.paste.public-create-email',
|
'metamta.paste.public-create-email',
|
||||||
'string',
|
'string',
|
||||||
null)
|
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(
|
$this->newOption(
|
||||||
'metamta.paste.subject-prefix',
|
'metamta.paste.subject-prefix',
|
||||||
'string',
|
'string',
|
||||||
|
|
|
@ -8,19 +8,8 @@ final class PasteCreateMailReceiver extends PhabricatorMailReceiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
||||||
$config_key = 'metamta.paste.public-create-email';
|
$paste_app = new PhabricatorPasteApplication();
|
||||||
$create_address = PhabricatorEnv::getEnvConfig($config_key);
|
return $this->canAcceptApplicationMail($paste_app, $mail);
|
||||||
if (!$create_address) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($mail->getToAddresses() as $to_address) {
|
|
||||||
if ($this->matchAddresses($create_address, $to_address)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function processReceivedMail(
|
protected function processReceivedMail(
|
||||||
|
|
Loading…
Reference in a new issue