Add some create mail handlers for paste and files
Summary: Fixes T1144. Though actually I think T1144 wanted some handy way to email from the command-line / arc, this is cooler. :D Test Plan: set conf properly and then ./bin/mail receive-test --as btrahan --to pasties@phabricator.dev | README --> it worked...! couldn't test files as easily but verified exception thrown when I tried to test. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1144 Differential Revision: https://secure.phabricator.com/D6622
This commit is contained in:
@@ -589,6 +589,7 @@ phutil_register_library_map(array(
|
|||||||
'FeedPublisherHTTPWorker' => 'applications/feed/worker/FeedPublisherHTTPWorker.php',
|
'FeedPublisherHTTPWorker' => 'applications/feed/worker/FeedPublisherHTTPWorker.php',
|
||||||
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
|
'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php',
|
||||||
'FeedPushWorker' => 'applications/feed/worker/FeedPushWorker.php',
|
'FeedPushWorker' => 'applications/feed/worker/FeedPushWorker.php',
|
||||||
|
'FilesCreateMailReceiver' => 'applications/files/mail/FilesCreateMailReceiver.php',
|
||||||
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
|
'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php',
|
||||||
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
|
'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php',
|
||||||
'HarbormasterRunnerWorker' => 'applications/harbormaster/worker/HarbormasterRunnerWorker.php',
|
'HarbormasterRunnerWorker' => 'applications/harbormaster/worker/HarbormasterRunnerWorker.php',
|
||||||
@@ -756,6 +757,7 @@ phutil_register_library_map(array(
|
|||||||
'PackageDeleteMail' => 'applications/owners/mail/PackageDeleteMail.php',
|
'PackageDeleteMail' => 'applications/owners/mail/PackageDeleteMail.php',
|
||||||
'PackageMail' => 'applications/owners/mail/PackageMail.php',
|
'PackageMail' => 'applications/owners/mail/PackageMail.php',
|
||||||
'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php',
|
'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php',
|
||||||
|
'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php',
|
||||||
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
|
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
|
||||||
'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php',
|
'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php',
|
||||||
'PhabricatorAWSConfigOptions' => 'applications/config/option/PhabricatorAWSConfigOptions.php',
|
'PhabricatorAWSConfigOptions' => 'applications/config/option/PhabricatorAWSConfigOptions.php',
|
||||||
@@ -1362,6 +1364,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php',
|
'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php',
|
||||||
'PhabricatorPagedFormExample' => 'applications/uiexample/examples/PhabricatorPagedFormExample.php',
|
'PhabricatorPagedFormExample' => 'applications/uiexample/examples/PhabricatorPagedFormExample.php',
|
||||||
'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php',
|
'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php',
|
||||||
|
'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php',
|
||||||
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
|
'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php',
|
||||||
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
|
'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php',
|
||||||
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
|
'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php',
|
||||||
@@ -2591,6 +2594,7 @@ phutil_register_library_map(array(
|
|||||||
'FeedPublisherHTTPWorker' => 'FeedPushWorker',
|
'FeedPublisherHTTPWorker' => 'FeedPushWorker',
|
||||||
'FeedPublisherWorker' => 'FeedPushWorker',
|
'FeedPublisherWorker' => 'FeedPushWorker',
|
||||||
'FeedPushWorker' => 'PhabricatorWorker',
|
'FeedPushWorker' => 'PhabricatorWorker',
|
||||||
|
'FilesCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||||
'HarbormasterDAO' => 'PhabricatorLiskDAO',
|
'HarbormasterDAO' => 'PhabricatorLiskDAO',
|
||||||
'HarbormasterObject' => 'HarbormasterDAO',
|
'HarbormasterObject' => 'HarbormasterDAO',
|
||||||
'HarbormasterRunnerWorker' => 'PhabricatorWorker',
|
'HarbormasterRunnerWorker' => 'PhabricatorWorker',
|
||||||
@@ -2761,6 +2765,7 @@ phutil_register_library_map(array(
|
|||||||
'PackageDeleteMail' => 'PackageMail',
|
'PackageDeleteMail' => 'PackageMail',
|
||||||
'PackageMail' => 'PhabricatorMail',
|
'PackageMail' => 'PhabricatorMail',
|
||||||
'PackageModifyMail' => 'PackageMail',
|
'PackageModifyMail' => 'PackageMail',
|
||||||
|
'PasteCreateMailReceiver' => 'PhabricatorMailReceiver',
|
||||||
'PasteEmbedView' => 'AphrontView',
|
'PasteEmbedView' => 'AphrontView',
|
||||||
'Phabricator404Controller' => 'PhabricatorController',
|
'Phabricator404Controller' => 'PhabricatorController',
|
||||||
'PhabricatorAWSConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorAWSConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
@@ -3401,6 +3406,7 @@ phutil_register_library_map(array(
|
|||||||
1 => 'PhabricatorTokenReceiverInterface',
|
1 => 'PhabricatorTokenReceiverInterface',
|
||||||
2 => 'PhabricatorPolicyInterface',
|
2 => 'PhabricatorPolicyInterface',
|
||||||
),
|
),
|
||||||
|
'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
'PhabricatorPasteController' => 'PhabricatorController',
|
'PhabricatorPasteController' => 'PhabricatorController',
|
||||||
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorPasteDAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
|
'PhabricatorPasteEditController' => 'PhabricatorPasteController',
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ final class PhabricatorConfigEditController
|
|||||||
->setConfigKey($this->key)
|
->setConfigKey($this->key)
|
||||||
->setNamespace('default')
|
->setNamespace('default')
|
||||||
->setIsDeleted(true);
|
->setIsDeleted(true);
|
||||||
|
$config_entry->setPHID($config_entry->generatePHID());
|
||||||
}
|
}
|
||||||
|
|
||||||
$e_value = null;
|
$e_value = null;
|
||||||
|
|||||||
@@ -154,6 +154,11 @@ final class PhabricatorFilesConfigOptions
|
|||||||
"Specify this limit in bytes, or using a 'K', 'M', or 'G' ".
|
"Specify this limit in bytes, or using a 'K', 'M', or 'G' ".
|
||||||
"suffix."))
|
"suffix."))
|
||||||
->addExample('10M', pht("Allow Uploads 10MB or Smaller")),
|
->addExample('10M', pht("Allow Uploads 10MB or Smaller")),
|
||||||
|
$this->newOption(
|
||||||
|
'metamta.files.public-create-email',
|
||||||
|
'string',
|
||||||
|
null)
|
||||||
|
->setDescription(pht('Allow uploaded files via email.')),
|
||||||
$this->newOption('files.enable-imagemagick', 'bool', false)
|
$this->newOption('files.enable-imagemagick', 'bool', false)
|
||||||
->setBoolOptions(
|
->setBoolOptions(
|
||||||
array(
|
array(
|
||||||
|
|||||||
71
src/applications/files/mail/FilesCreateMailReceiver.php
Normal file
71
src/applications/files/mail/FilesCreateMailReceiver.php
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group files
|
||||||
|
*/
|
||||||
|
final class FilesCreateMailReceiver
|
||||||
|
extends PhabricatorMailReceiver {
|
||||||
|
|
||||||
|
public function isEnabled() {
|
||||||
|
$app_class = 'PhabricatorApplicationFiles';
|
||||||
|
return PhabricatorApplication::isClassInstalled($app_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processReceivedMail(
|
||||||
|
PhabricatorMetaMTAReceivedMail $mail,
|
||||||
|
PhabricatorUser $sender) {
|
||||||
|
|
||||||
|
$attachment_phids = $mail->getAttachments();
|
||||||
|
if (empty($attachment_phids)) {
|
||||||
|
throw new PhabricatorMetaMTAReceivedMailProcessingException(
|
||||||
|
MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION,
|
||||||
|
'Ignoring email to create files that did not include attachments.');
|
||||||
|
}
|
||||||
|
$first_phid = head($attachment_phids);
|
||||||
|
$mail->setRelatedPHID($first_phid);
|
||||||
|
|
||||||
|
$attachment_count = count($attachment_phids);
|
||||||
|
if ($attachment_count > 1) {
|
||||||
|
$subject = pht(
|
||||||
|
'You successfully uploaded %d files.',
|
||||||
|
$attachment_count);
|
||||||
|
} else {
|
||||||
|
$subject = pht('You successfully uploaded a file.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$file_uris = array();
|
||||||
|
foreach ($attachment_phids as $phid) {
|
||||||
|
$file_uris[] =
|
||||||
|
PhabricatorEnv::getProductionURI('/file/info/'.$phid.'/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$body = new PhabricatorMetaMTAMailBody();
|
||||||
|
$body->addRawSection($subject);
|
||||||
|
$body->addTextSection(pht('FILE LINKS'), implode("\n", $file_uris));
|
||||||
|
|
||||||
|
id(new PhabricatorMetaMTAMail())
|
||||||
|
->addTos(array($sender->getPHID()))
|
||||||
|
->setSubject('[Files] '.$subject)
|
||||||
|
->setFrom($sender->getPHID())
|
||||||
|
->setRelatedPHID($first_phid)
|
||||||
|
->setBody($body->render())
|
||||||
|
->saveAndSend();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group paste
|
||||||
|
*/
|
||||||
|
final class PhabricatorPasteConfigOptions
|
||||||
|
extends PhabricatorApplicationConfigOptions {
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return pht('Paste');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDescription() {
|
||||||
|
return pht('Configure Paste.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOptions() {
|
||||||
|
return array(
|
||||||
|
$this->newOption(
|
||||||
|
'metamta.paste.public-create-email',
|
||||||
|
'string',
|
||||||
|
null)
|
||||||
|
->setDescription(pht('Allow creating pastes via email.'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
72
src/applications/paste/mail/PasteCreateMailReceiver.php
Normal file
72
src/applications/paste/mail/PasteCreateMailReceiver.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group paste
|
||||||
|
*/
|
||||||
|
final class PasteCreateMailReceiver
|
||||||
|
extends PhabricatorMailReceiver {
|
||||||
|
|
||||||
|
public function isEnabled() {
|
||||||
|
$app_class = 'PhabricatorApplicationPaste';
|
||||||
|
return PhabricatorApplication::isClassInstalled($app_class);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processReceivedMail(
|
||||||
|
PhabricatorMetaMTAReceivedMail $mail,
|
||||||
|
PhabricatorUser $sender) {
|
||||||
|
|
||||||
|
$title = $mail->getSubject();
|
||||||
|
if (!$title) {
|
||||||
|
$title = pht('Pasted via email.');
|
||||||
|
}
|
||||||
|
$paste_file = PhabricatorFile::newFromFileData(
|
||||||
|
$mail->getCleanTextBody(),
|
||||||
|
array(
|
||||||
|
'name' => $title,
|
||||||
|
'mime-type' => 'text/plain; charset=utf-8',
|
||||||
|
'authorPHID' => $sender->getPHID(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$paste = id(new PhabricatorPaste())
|
||||||
|
->setAuthorPHID($sender->getPHID())
|
||||||
|
->setTitle($title)
|
||||||
|
->setFilePHID($paste_file->getPHID())
|
||||||
|
->setLanguage('') // auto-detect
|
||||||
|
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
|
||||||
|
->save();
|
||||||
|
|
||||||
|
$mail->setRelatedPHID($paste->getPHID());
|
||||||
|
|
||||||
|
$subject = pht('You successfully created a paste.');
|
||||||
|
$paste_uri = PhabricatorEnv::getProductionURI($paste->getURI());
|
||||||
|
$body = new PhabricatorMetaMTAMailBody();
|
||||||
|
$body->addRawSection($subject);
|
||||||
|
$body->addTextSection(pht('PASTE LINK'), $paste_uri);
|
||||||
|
|
||||||
|
id(new PhabricatorMetaMTAMail())
|
||||||
|
->addTos(array($sender->getPHID()))
|
||||||
|
->setSubject('[Paste] '.$subject)
|
||||||
|
->setFrom($sender->getPHID())
|
||||||
|
->setRelatedPHID($paste->getPHID())
|
||||||
|
->setBody($body->render())
|
||||||
|
->saveAndSend();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user