1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Add Ponder Question mail create receiver

Summary: Fixes T11115, but unclear how to test this. I think I've asked this in the past.

Test Plan:
 - Visit Applications -> Ponder
 - Configure external email
 - Test External Email
 - See new Question

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Maniphest Tasks: T11115

Differential Revision: https://secure.phabricator.com/D16084
This commit is contained in:
Chad Little 2016-06-08 14:43:27 -07:00
parent 72d554aa9b
commit e808963eae
4 changed files with 67 additions and 0 deletions

View file

@ -4062,6 +4062,7 @@ phutil_register_library_map(array(
'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
'PonderQuestionCreateMailReceiver' => 'applications/ponder/mail/PonderQuestionCreateMailReceiver.php',
'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php',
'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php',
'PonderQuestionFulltextEngine' => 'applications/ponder/search/PonderQuestionFulltextEngine.php',
@ -9013,6 +9014,7 @@ phutil_register_library_map(array(
'PhabricatorFulltextInterface',
),
'PonderQuestionCommentController' => 'PonderController',
'PonderQuestionCreateMailReceiver' => 'PhabricatorMailReceiver',
'PonderQuestionEditController' => 'PonderController',
'PonderQuestionEditor' => 'PonderEditor',
'PonderQuestionFulltextEngine' => 'PhabricatorFulltextEngine',

View file

@ -34,6 +34,21 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
);
}
public function supportsEmailIntegration() {
return true;
}
public function getAppEmailBlurb() {
return pht(
'Send email to these addresses to create questions. %s',
phutil_tag(
'a',
array(
'href' => $this->getInboundEmailSupportLink(),
),
pht('Learn More')));
}
public function getRoutes() {
return array(
'/Q(?P<id>[1-9]\d*)'

View file

@ -0,0 +1,49 @@
<?php
final class PonderQuestionCreateMailReceiver extends PhabricatorMailReceiver {
public function isEnabled() {
$app_class = 'PhabricatorPonderApplication';
return PhabricatorApplication::isClassInstalled($app_class);
}
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
$ponder_app = new PhabricatorPonderApplication();
return $this->canAcceptApplicationMail($ponder_app, $mail);
}
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());
}
}

View file

@ -48,6 +48,7 @@ final class PonderQuestion extends PonderDAO
->setViewPolicy($view_policy)
->setStatus(PonderQuestionStatus::STATUS_OPEN)
->setAnswerCount(0)
->setAnswerWiki('')
->setSpacePHID($actor->getDefaultSpacePHID());
}