[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class FileCreateMailReceiver extends PhabricatorMailReceiver { 4 5 public function isEnabled() { 6 $app_class = 'PhabricatorFilesApplication'; 7 return PhabricatorApplication::isClassInstalled($app_class); 8 } 9 10 public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) { 11 $config_key = 'metamta.files.public-create-email'; 12 $create_address = PhabricatorEnv::getEnvConfig($config_key); 13 if (!$create_address) { 14 return false; 15 } 16 17 foreach ($mail->getToAddresses() as $to_address) { 18 if ($this->matchAddresses($create_address, $to_address)) { 19 return true; 20 } 21 } 22 23 return false; 24 } 25 26 protected function processReceivedMail( 27 PhabricatorMetaMTAReceivedMail $mail, 28 PhabricatorUser $sender) { 29 30 $attachment_phids = $mail->getAttachments(); 31 if (empty($attachment_phids)) { 32 throw new PhabricatorMetaMTAReceivedMailProcessingException( 33 MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION, 34 'Ignoring email to create files that did not include attachments.'); 35 } 36 $first_phid = head($attachment_phids); 37 $mail->setRelatedPHID($first_phid); 38 39 $attachment_count = count($attachment_phids); 40 if ($attachment_count > 1) { 41 $subject = pht('You successfully uploaded %d files.', $attachment_count); 42 } else { 43 $subject = pht('You successfully uploaded a file.'); 44 } 45 $subject_prefix = 46 PhabricatorEnv::getEnvConfig('metamta.files.subject-prefix'); 47 48 $file_uris = array(); 49 foreach ($attachment_phids as $phid) { 50 $file_uris[] = 51 PhabricatorEnv::getProductionURI('/file/info/'.$phid.'/'); 52 } 53 54 $body = new PhabricatorMetaMTAMailBody(); 55 $body->addRawSection($subject); 56 $body->addTextSection(pht('FILE LINKS'), implode("\n", $file_uris)); 57 58 id(new PhabricatorMetaMTAMail()) 59 ->addTos(array($sender->getPHID())) 60 ->setSubject($subject) 61 ->setSubjectPrefix($subject_prefix) 62 ->setFrom($sender->getPHID()) 63 ->setRelatedPHID($first_phid) 64 ->setBody($body->render()) 65 ->saveAndSend(); 66 } 67 68 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |