[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class LegalpadReplyHandler extends PhabricatorMailReplyHandler { 4 5 public function validateMailReceiver($mail_receiver) { 6 if (!($mail_receiver instanceof LegalpadDocument)) { 7 throw new Exception('Mail receiver is not a LegalpadDocument!'); 8 } 9 } 10 11 public function getPrivateReplyHandlerEmailAddress( 12 PhabricatorObjectHandle $handle) { 13 return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'L'); 14 } 15 16 public function getPublicReplyHandlerEmailAddress() { 17 return $this->getDefaultPublicReplyHandlerEmailAddress('L'); 18 } 19 20 public function getReplyHandlerDomain() { 21 return PhabricatorEnv::getEnvConfig( 22 'metamta.reply-handler-domain'); 23 } 24 25 public function getReplyHandlerInstructions() { 26 if ($this->supportsReplies()) { 27 return pht('Reply to comment or !unsubscribe.'); 28 } else { 29 return null; 30 } 31 } 32 33 protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { 34 $actor = $this->getActor(); 35 $document = $this->getMailReceiver(); 36 37 $body_data = $mail->parseBody(); 38 $body = $body_data['body']; 39 $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); 40 41 $content_source = PhabricatorContentSource::newForSource( 42 PhabricatorContentSource::SOURCE_EMAIL, 43 array( 44 'id' => $mail->getID(), 45 )); 46 47 48 $xactions = array(); 49 $command = $body_data['command']; 50 51 switch ($command) { 52 case 'unsubscribe': 53 $xaction = id(new LegalpadTransaction()) 54 ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 55 ->setNewValue(array('-' => array($actor->getPHID()))); 56 $xactions[] = $xaction; 57 break; 58 } 59 60 $xactions[] = id(new LegalpadTransaction()) 61 ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 62 ->attachComment( 63 id(new LegalpadTransactionComment()) 64 ->setDocumentID($document->getID()) 65 ->setLineNumber(0) 66 ->setLineLength(0) 67 ->setContent($body)); 68 69 $editor = id(new LegalpadDocumentEditor()) 70 ->setActor($actor) 71 ->setContentSource($content_source) 72 ->setContinueOnNoEffect(true) 73 ->setIsPreview(false); 74 75 try { 76 $xactions = $editor->applyTransactions($document, $xactions); 77 } catch (PhabricatorApplicationTransactionNoEffectException $ex) { 78 // just do nothing, though unclear why you're sending a blank email 79 return true; 80 } 81 82 $head_xaction = head($xactions); 83 return $head_xaction->getID(); 84 } 85 86 }
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 |