mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
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
9 changed files with 113 additions and 44 deletions
|
@ -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() {
|
||||
return array(
|
||||
FilesDefaultViewCapability::CAPABILITY => array(
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue