2011-05-10 01:31:26 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-14 00:21:04 +01:00
|
|
|
final class ManiphestReplyHandler extends PhabricatorMailReplyHandler {
|
2011-05-10 01:31:26 +02:00
|
|
|
|
|
|
|
public function validateMailReceiver($mail_receiver) {
|
|
|
|
if (!($mail_receiver instanceof ManiphestTask)) {
|
2014-06-09 20:36:49 +02:00
|
|
|
throw new Exception('Mail receiver is not a ManiphestTask!');
|
2011-05-10 01:31:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrivateReplyHandlerEmailAddress(
|
|
|
|
PhabricatorObjectHandle $handle) {
|
|
|
|
return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'T');
|
|
|
|
}
|
|
|
|
|
Allow Phabricator to be configured to use a public Reply-To address
Summary:
We already support this (and Facebook uses it) but it is difficult to configure
and you have to write a bunch of code. Instead, provide a simple flag.
See the documentation changes for details, but when this flag is enabled we send
one email with a reply-to like "D2+public+23hf91fh19fh@phabricator.example.com".
Anyone can reply to this, and we figure out who they are based on their "From"
address instead of a unique hash. This is less secure, but a reasonable tradeoff
in many cases.
This also has the advantage over a naive implementation of at least doing object
hash validation.
@jungejason: I don't think this affects Facebook's implementation but this is an
area where we've had problems in the past, so watch out for it when you deploy.
Also note that you must set "metamta.public-replies" to true since Maniphest now
looks for that key specifically before going into public reply mode; it no
longer just tests for a public reply address being generateable (since it can
always generate one now).
Test Plan:
Swapped my local install in and out of public reply mode and commented on
objects. Got expected email behavior. Replied to public and private email
addresses.
Attacked public addresses by using them when the install was configured to
disallow them and by altering the hash and the from address. All this stuff was
rejected.
Reviewed By: jungejason
Reviewers: moskov, jungejason, tuomaspelkonen, aran
CC: aran, epriestley, moskov, jungejason
Differential Revision: 563
2011-06-30 22:01:35 +02:00
|
|
|
public function getPublicReplyHandlerEmailAddress() {
|
|
|
|
return $this->getDefaultPublicReplyHandlerEmailAddress('T');
|
|
|
|
}
|
|
|
|
|
2012-08-28 23:09:37 +02:00
|
|
|
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
|
2011-07-04 18:45:42 +02:00
|
|
|
// NOTE: We'll drop in here on both the "reply to a task" and "create a
|
|
|
|
// new task" workflows! Make sure you test both if you make changes!
|
2011-05-16 21:31:18 +02:00
|
|
|
$task = $this->getMailReceiver();
|
2015-04-01 02:25:19 +02:00
|
|
|
$viewer = $this->getActor();
|
2011-07-04 18:45:42 +02:00
|
|
|
|
|
|
|
$is_new_task = !$task->getID();
|
|
|
|
|
2013-10-14 21:29:41 +02:00
|
|
|
$body_data = $mail->parseBody();
|
|
|
|
$body = $body_data['body'];
|
2012-11-01 23:18:06 +01:00
|
|
|
$body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
|
2011-05-16 21:31:18 +02:00
|
|
|
|
Track content sources (email, web, conduit, mobile) for replies
Summary:
When an object is updated, record the content source for the update. This mostly
isn't terribly useful but one concrete thing I want to do with it is let admins
audit via-email replies more easily since there are a bunch of options which let
you do hyjinx if you intentionally configure them insecurely. I think having a
little more auditability around this feature is generally good. At some point
I'm going to turn this into a link admins can click to see details.
It also allows us to see how frequently different mechanisms are used, and lets
you see if someone is at their desk or on a mobile or whatever, at least
indirectly.
The "tablet" and "mobile" sources are currently unused but I figured I'd throw
them in anyway. SMS support should definitely happen at some point.
Not 100% sure about the design for this, I might change it to plain text at some
point.
Test Plan: Updated objects and saw update sources rendered.
Reviewers: jungejason, tuomaspelkonen, aran
Reviewed By: jungejason
CC: aran, epriestley, jungejason
Differential Revision: 844
2011-08-22 19:25:45 +02:00
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_EMAIL,
|
|
|
|
array(
|
|
|
|
'id' => $mail->getID(),
|
|
|
|
));
|
|
|
|
|
2013-09-24 19:49:06 +02:00
|
|
|
$template = new ManiphestTransaction();
|
2011-07-04 18:45:42 +02:00
|
|
|
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions = array();
|
2011-07-04 18:45:42 +02:00
|
|
|
if ($is_new_task) {
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
2014-08-12 21:25:47 +02:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_TITLE)
|
|
|
|
->setNewValue(nonempty($mail->getSubject(), pht('Untitled Task')));
|
|
|
|
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
2014-08-12 21:25:47 +02:00
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)
|
|
|
|
->setNewValue($body);
|
2011-07-04 18:45:42 +02:00
|
|
|
} else {
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new ManiphestTransactionComment())
|
|
|
|
->setContent($body));
|
|
|
|
}
|
2011-07-04 18:45:42 +02:00
|
|
|
|
2015-04-01 02:25:19 +02:00
|
|
|
$commands = $body_data['commands'];
|
|
|
|
foreach ($commands as $command_argv) {
|
|
|
|
$command = head($command_argv);
|
|
|
|
$args = array_slice($command_argv, 1);
|
2011-07-04 18:45:42 +02:00
|
|
|
switch ($command) {
|
|
|
|
case 'close':
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_STATUS)
|
|
|
|
->setNewValue(ManiphestTaskStatus::getDefaultClosedStatus());
|
2011-07-04 18:45:42 +02:00
|
|
|
break;
|
|
|
|
case 'claim':
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_OWNER)
|
|
|
|
->setNewValue($viewer->getPHID());
|
2011-07-04 18:45:42 +02:00
|
|
|
break;
|
2013-10-14 21:29:41 +02:00
|
|
|
case 'assign':
|
2015-04-01 02:25:19 +02:00
|
|
|
$assign_to = head($args);
|
|
|
|
if ($assign_to) {
|
|
|
|
$assign_user = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withUsernames(array($assign_to))
|
|
|
|
->executeOne();
|
|
|
|
if ($assign_user) {
|
|
|
|
$assign_phid = $assign_user->getPHID();
|
2013-10-14 21:29:41 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-01 02:25:19 +02:00
|
|
|
|
|
|
|
// Treat bad "!assign" like "!claim".
|
|
|
|
if (!$assign_phid) {
|
|
|
|
$assign_phid = $viewer->getPHID();
|
2013-10-14 21:29:41 +02:00
|
|
|
}
|
2015-04-01 02:25:19 +02:00
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_OWNER)
|
|
|
|
->setNewValue($assign_phid);
|
2013-10-14 21:29:41 +02:00
|
|
|
break;
|
2011-07-04 18:45:42 +02:00
|
|
|
case 'unsubscribe':
|
2015-04-01 02:25:19 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'-' => array($viewer->getPHID()),
|
|
|
|
));
|
2011-07-04 18:45:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-05-16 21:31:18 +02:00
|
|
|
}
|
|
|
|
|
2012-11-01 23:18:06 +01:00
|
|
|
$ccs = $mail->loadCCPHIDs();
|
2015-04-01 02:25:19 +02:00
|
|
|
if ($ccs) {
|
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'+' => array($viewer->getPHID()),
|
|
|
|
));
|
2011-05-29 12:19:06 +02:00
|
|
|
}
|
|
|
|
|
2011-08-31 22:25:13 +02:00
|
|
|
$event = new PhabricatorEvent(
|
|
|
|
PhabricatorEventType::TYPE_MANIPHEST_WILLEDITTASK,
|
|
|
|
array(
|
|
|
|
'task' => $task,
|
|
|
|
'mail' => $mail,
|
|
|
|
'new' => $is_new_task,
|
|
|
|
'transactions' => $xactions,
|
|
|
|
));
|
2015-04-01 02:25:19 +02:00
|
|
|
$event->setUser($viewer);
|
2011-11-10 02:23:33 +01:00
|
|
|
PhutilEventEngine::dispatchEvent($event);
|
2011-08-31 22:25:13 +02:00
|
|
|
|
|
|
|
$task = $event->getValue('task');
|
|
|
|
$xactions = $event->getValue('transactions');
|
|
|
|
|
2013-10-22 01:58:37 +02:00
|
|
|
$editor = id(new ManiphestTransactionEditor())
|
2015-04-01 02:25:19 +02:00
|
|
|
->setActor($viewer)
|
2013-09-23 23:32:51 +02:00
|
|
|
->setParentMessageID($mail->getMessageID())
|
|
|
|
->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
2015-01-29 23:35:22 +01:00
|
|
|
->setContentSource($content_source);
|
2015-04-01 02:25:19 +02:00
|
|
|
|
2015-01-29 23:35:22 +01:00
|
|
|
if ($this->getApplicationEmail()) {
|
|
|
|
$editor->setApplicationEmail($this->getApplicationEmail());
|
|
|
|
}
|
2015-04-01 02:25:19 +02:00
|
|
|
|
2015-01-29 23:35:22 +01:00
|
|
|
$editor->applyTransactions($task, $xactions);
|
2012-04-17 21:09:04 +02:00
|
|
|
|
|
|
|
$event = new PhabricatorEvent(
|
|
|
|
PhabricatorEventType::TYPE_MANIPHEST_DIDEDITTASK,
|
|
|
|
array(
|
|
|
|
'task' => $task,
|
|
|
|
'new' => $is_new_task,
|
|
|
|
'transactions' => $xactions,
|
|
|
|
));
|
2015-04-01 02:25:19 +02:00
|
|
|
$event->setUser($viewer);
|
2012-04-17 21:09:04 +02:00
|
|
|
PhutilEventEngine::dispatchEvent($event);
|
2011-05-16 21:31:18 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 01:31:26 +02:00
|
|
|
}
|