protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $title = $mail->getSubject();
     if (!$title) {
         $title = pht('Email Paste');
     }
     $file = PhabricatorPasteEditor::initializeFileForPaste($sender, $title, $mail->getCleanTextBody());
     $xactions = array();
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)->setNewValue($file->getPHID());
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)->setNewValue($title);
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)->setNewValue('');
     // auto-detect
     $paste = PhabricatorPaste::initializeNewPaste($sender);
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID()));
     $editor = id(new PhabricatorPasteEditor())->setActor($sender)->setContentSource($content_source)->setContinueOnNoEffect(true);
     $xactions = $editor->applyTransactions($paste, $xactions);
     $mail->setRelatedPHID($paste->getPHID());
     $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.paste.subject-prefix');
     $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($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setRelatedPHID($paste->getPHID())->setBody($body->render())->saveAndSend();
 }
 protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $title = $mail->getSubject();
     if (!strlen($title)) {
         $title = pht('New Question');
     }
     $xactions = array();
     $xactions[] = id(new PonderQuestionTransaction())->setTransactionType(PonderQuestionTransaction::TYPE_TITLE)->setNewValue($title);
     $xactions[] = id(new PonderQuestionTransaction())->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT)->setNewValue($mail->getCleanTextBody());
     $question = PonderQuestion::initializeNewQuestion($sender);
     $content_source = $mail->newContentSource();
     $editor = id(new PonderQuestionEditor())->setActor($sender)->setContentSource($content_source)->setContinueOnNoEffect(true);
     $xactions = $editor->applyTransactions($question, $xactions);
     $mail->setRelatedPHID($question->getPHID());
 }
 protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $attachment_phids = $mail->getAttachments();
     if (empty($attachment_phids)) {
         throw new PhabricatorMetaMTAReceivedMailProcessingException(MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION, pht('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.');
     }
     $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.files.subject-prefix');
     $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($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setRelatedPHID($first_phid)->setBody($body->render())->saveAndSend();
 }