@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+182
+6
src/__phutil_library_map__.php
··· 589 589 'FeedPublisherHTTPWorker' => 'applications/feed/worker/FeedPublisherHTTPWorker.php', 590 590 'FeedPublisherWorker' => 'applications/feed/worker/FeedPublisherWorker.php', 591 591 'FeedPushWorker' => 'applications/feed/worker/FeedPushWorker.php', 592 + 'FilesCreateMailReceiver' => 'applications/files/mail/FilesCreateMailReceiver.php', 592 593 'HarbormasterDAO' => 'applications/harbormaster/storage/HarbormasterDAO.php', 593 594 'HarbormasterObject' => 'applications/harbormaster/storage/HarbormasterObject.php', 594 595 'HarbormasterRunnerWorker' => 'applications/harbormaster/worker/HarbormasterRunnerWorker.php', ··· 756 757 'PackageDeleteMail' => 'applications/owners/mail/PackageDeleteMail.php', 757 758 'PackageMail' => 'applications/owners/mail/PackageMail.php', 758 759 'PackageModifyMail' => 'applications/owners/mail/PackageModifyMail.php', 760 + 'PasteCreateMailReceiver' => 'applications/paste/mail/PasteCreateMailReceiver.php', 759 761 'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php', 760 762 'Phabricator404Controller' => 'applications/base/controller/Phabricator404Controller.php', 761 763 'PhabricatorAWSConfigOptions' => 'applications/config/option/PhabricatorAWSConfigOptions.php', ··· 1362 1364 'PhabricatorPHPMailerConfigOptions' => 'applications/config/option/PhabricatorPHPMailerConfigOptions.php', 1363 1365 'PhabricatorPagedFormExample' => 'applications/uiexample/examples/PhabricatorPagedFormExample.php', 1364 1366 'PhabricatorPaste' => 'applications/paste/storage/PhabricatorPaste.php', 1367 + 'PhabricatorPasteConfigOptions' => 'applications/paste/config/PhabricatorPasteConfigOptions.php', 1365 1368 'PhabricatorPasteController' => 'applications/paste/controller/PhabricatorPasteController.php', 1366 1369 'PhabricatorPasteDAO' => 'applications/paste/storage/PhabricatorPasteDAO.php', 1367 1370 'PhabricatorPasteEditController' => 'applications/paste/controller/PhabricatorPasteEditController.php', ··· 2591 2594 'FeedPublisherHTTPWorker' => 'FeedPushWorker', 2592 2595 'FeedPublisherWorker' => 'FeedPushWorker', 2593 2596 'FeedPushWorker' => 'PhabricatorWorker', 2597 + 'FilesCreateMailReceiver' => 'PhabricatorMailReceiver', 2594 2598 'HarbormasterDAO' => 'PhabricatorLiskDAO', 2595 2599 'HarbormasterObject' => 'HarbormasterDAO', 2596 2600 'HarbormasterRunnerWorker' => 'PhabricatorWorker', ··· 2761 2765 'PackageDeleteMail' => 'PackageMail', 2762 2766 'PackageMail' => 'PhabricatorMail', 2763 2767 'PackageModifyMail' => 'PackageMail', 2768 + 'PasteCreateMailReceiver' => 'PhabricatorMailReceiver', 2764 2769 'PasteEmbedView' => 'AphrontView', 2765 2770 'Phabricator404Controller' => 'PhabricatorController', 2766 2771 'PhabricatorAWSConfigOptions' => 'PhabricatorApplicationConfigOptions', ··· 3401 3406 1 => 'PhabricatorTokenReceiverInterface', 3402 3407 2 => 'PhabricatorPolicyInterface', 3403 3408 ), 3409 + 'PhabricatorPasteConfigOptions' => 'PhabricatorApplicationConfigOptions', 3404 3410 'PhabricatorPasteController' => 'PhabricatorController', 3405 3411 'PhabricatorPasteDAO' => 'PhabricatorLiskDAO', 3406 3412 'PhabricatorPasteEditController' => 'PhabricatorPasteController',
+1
src/applications/config/controller/PhabricatorConfigEditController.php
··· 64 64 ->setConfigKey($this->key) 65 65 ->setNamespace('default') 66 66 ->setIsDeleted(true); 67 + $config_entry->setPHID($config_entry->generatePHID()); 67 68 } 68 69 69 70 $e_value = null;
+5
src/applications/files/config/PhabricatorFilesConfigOptions.php
··· 154 154 "Specify this limit in bytes, or using a 'K', 'M', or 'G' ". 155 155 "suffix.")) 156 156 ->addExample('10M', pht("Allow Uploads 10MB or Smaller")), 157 + $this->newOption( 158 + 'metamta.files.public-create-email', 159 + 'string', 160 + null) 161 + ->setDescription(pht('Allow uploaded files via email.')), 157 162 $this->newOption('files.enable-imagemagick', 'bool', false) 158 163 ->setBoolOptions( 159 164 array(
+71
src/applications/files/mail/FilesCreateMailReceiver.php
··· 1 + <?php 2 + 3 + /** 4 + * @group files 5 + */ 6 + final class FilesCreateMailReceiver 7 + extends PhabricatorMailReceiver { 8 + 9 + public function isEnabled() { 10 + $app_class = 'PhabricatorApplicationFiles'; 11 + return PhabricatorApplication::isClassInstalled($app_class); 12 + } 13 + 14 + public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { 15 + $config_key = 'metamta.files.public-create-email'; 16 + $create_address = PhabricatorEnv::getEnvConfig($config_key); 17 + if (!$create_address) { 18 + return false; 19 + } 20 + 21 + foreach ($mail->getToAddresses() as $to_address) { 22 + if ($this->matchAddresses($create_address, $to_address)) { 23 + return true; 24 + } 25 + } 26 + 27 + return false; 28 + } 29 + 30 + protected function processReceivedMail( 31 + PhabricatorMetaMTAReceivedMail $mail, 32 + PhabricatorUser $sender) { 33 + 34 + $attachment_phids = $mail->getAttachments(); 35 + if (empty($attachment_phids)) { 36 + throw new PhabricatorMetaMTAReceivedMailProcessingException( 37 + MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION, 38 + 'Ignoring email to create files that did not include attachments.'); 39 + } 40 + $first_phid = head($attachment_phids); 41 + $mail->setRelatedPHID($first_phid); 42 + 43 + $attachment_count = count($attachment_phids); 44 + if ($attachment_count > 1) { 45 + $subject = pht( 46 + 'You successfully uploaded %d files.', 47 + $attachment_count); 48 + } else { 49 + $subject = pht('You successfully uploaded a file.'); 50 + } 51 + 52 + $file_uris = array(); 53 + foreach ($attachment_phids as $phid) { 54 + $file_uris[] = 55 + PhabricatorEnv::getProductionURI('/file/info/'.$phid.'/'); 56 + } 57 + 58 + $body = new PhabricatorMetaMTAMailBody(); 59 + $body->addRawSection($subject); 60 + $body->addTextSection(pht('FILE LINKS'), implode("\n", $file_uris)); 61 + 62 + id(new PhabricatorMetaMTAMail()) 63 + ->addTos(array($sender->getPHID())) 64 + ->setSubject('[Files] '.$subject) 65 + ->setFrom($sender->getPHID()) 66 + ->setRelatedPHID($first_phid) 67 + ->setBody($body->render()) 68 + ->saveAndSend(); 69 + } 70 + 71 + }
+27
src/applications/paste/config/PhabricatorPasteConfigOptions.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PhabricatorPasteConfigOptions 7 + extends PhabricatorApplicationConfigOptions { 8 + 9 + public function getName() { 10 + return pht('Paste'); 11 + } 12 + 13 + public function getDescription() { 14 + return pht('Configure Paste.'); 15 + } 16 + 17 + public function getOptions() { 18 + return array( 19 + $this->newOption( 20 + 'metamta.paste.public-create-email', 21 + 'string', 22 + null) 23 + ->setDescription(pht('Allow creating pastes via email.')) 24 + ); 25 + } 26 + 27 + }
+72
src/applications/paste/mail/PasteCreateMailReceiver.php
··· 1 + <?php 2 + 3 + /** 4 + * @group paste 5 + */ 6 + final class PasteCreateMailReceiver 7 + extends PhabricatorMailReceiver { 8 + 9 + public function isEnabled() { 10 + $app_class = 'PhabricatorApplicationPaste'; 11 + return PhabricatorApplication::isClassInstalled($app_class); 12 + } 13 + 14 + public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { 15 + $config_key = 'metamta.paste.public-create-email'; 16 + $create_address = PhabricatorEnv::getEnvConfig($config_key); 17 + if (!$create_address) { 18 + return false; 19 + } 20 + 21 + foreach ($mail->getToAddresses() as $to_address) { 22 + if ($this->matchAddresses($create_address, $to_address)) { 23 + return true; 24 + } 25 + } 26 + 27 + return false; 28 + } 29 + 30 + protected function processReceivedMail( 31 + PhabricatorMetaMTAReceivedMail $mail, 32 + PhabricatorUser $sender) { 33 + 34 + $title = $mail->getSubject(); 35 + if (!$title) { 36 + $title = pht('Pasted via email.'); 37 + } 38 + $paste_file = PhabricatorFile::newFromFileData( 39 + $mail->getCleanTextBody(), 40 + array( 41 + 'name' => $title, 42 + 'mime-type' => 'text/plain; charset=utf-8', 43 + 'authorPHID' => $sender->getPHID(), 44 + )); 45 + 46 + $paste = id(new PhabricatorPaste()) 47 + ->setAuthorPHID($sender->getPHID()) 48 + ->setTitle($title) 49 + ->setFilePHID($paste_file->getPHID()) 50 + ->setLanguage('') // auto-detect 51 + ->setViewPolicy(PhabricatorPolicies::POLICY_USER) 52 + ->save(); 53 + 54 + $mail->setRelatedPHID($paste->getPHID()); 55 + 56 + $subject = pht('You successfully created a paste.'); 57 + $paste_uri = PhabricatorEnv::getProductionURI($paste->getURI()); 58 + $body = new PhabricatorMetaMTAMailBody(); 59 + $body->addRawSection($subject); 60 + $body->addTextSection(pht('PASTE LINK'), $paste_uri); 61 + 62 + id(new PhabricatorMetaMTAMail()) 63 + ->addTos(array($sender->getPHID())) 64 + ->setSubject('[Paste] '.$subject) 65 + ->setFrom($sender->getPHID()) 66 + ->setRelatedPHID($paste->getPHID()) 67 + ->setBody($body->render()) 68 + ->saveAndSend(); 69 + 70 + } 71 + 72 + }