@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<?php
2
3final class FileCreateMailReceiver
4 extends PhabricatorApplicationMailReceiver {
5
6 protected function newApplication() {
7 return new PhabricatorFilesApplication();
8 }
9
10 protected function processReceivedMail(
11 PhabricatorMetaMTAReceivedMail $mail,
12 PhutilEmailAddress $target) {
13 $author = $this->getAuthor();
14
15 $attachment_phids = $mail->getAttachments();
16 if (empty($attachment_phids)) {
17 throw new PhabricatorMetaMTAReceivedMailProcessingException(
18 MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION,
19 pht(
20 'Ignoring email to create files that did not include attachments.'));
21 }
22 $first_phid = head($attachment_phids);
23 $mail->setRelatedPHID($first_phid);
24
25 $sender = $this->getSender();
26 if (!$sender) {
27 return;
28 }
29
30 $attachment_count = count($attachment_phids);
31 if ($attachment_count > 1) {
32 $subject = pht('You successfully uploaded %d files.', $attachment_count);
33 } else {
34 $subject = pht('You successfully uploaded a file.');
35 }
36 $subject_prefix = pht('[File]');
37
38 $file_uris = array();
39 foreach ($attachment_phids as $phid) {
40 $file_uris[] =
41 PhabricatorEnv::getProductionURI('/file/info/'.$phid.'/');
42 }
43
44 $body = new PhabricatorMetaMTAMailBody();
45 $body->addRawSection($subject);
46 $body->addTextSection(pht('FILE LINKS'), implode("\n", $file_uris));
47
48 id(new PhabricatorMetaMTAMail())
49 ->addTos(array($sender->getPHID()))
50 ->setSubject($subject)
51 ->setSubjectPrefix($subject_prefix)
52 ->setFrom($sender->getPHID())
53 ->setRelatedPHID($first_phid)
54 ->setBody($body->render())
55 ->saveAndSend();
56 }
57
58}