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');
|
|
|
|
}
|
|
|
|
|
2011-05-10 01:31:26 +02:00
|
|
|
public function getReplyHandlerDomain() {
|
|
|
|
return PhabricatorEnv::getEnvConfig(
|
|
|
|
'metamta.maniphest.reply-handler-domain');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getReplyHandlerInstructions() {
|
|
|
|
if ($this->supportsReplies()) {
|
2014-04-04 20:14:21 +02:00
|
|
|
return pht(
|
2014-06-09 20:36:49 +02:00
|
|
|
'Reply to comment or attach files, or !close, !claim, '.
|
|
|
|
'!unsubscribe or !assign <username>.');
|
2011-05-10 01:31:26 +02:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
2011-07-04 18:45:42 +02:00
|
|
|
|
|
|
|
$is_new_task = !$task->getID();
|
|
|
|
|
2011-05-16 21:31:18 +02:00
|
|
|
$user = $this->getActor();
|
|
|
|
|
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
|
|
|
|
2011-07-04 18:45:42 +02:00
|
|
|
$xactions = array();
|
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
|
|
|
|
2013-05-13 17:10:02 +02:00
|
|
|
$is_unsub = false;
|
2011-07-04 18:45:42 +02:00
|
|
|
if ($is_new_task) {
|
2014-08-12 21:25:47 +02:00
|
|
|
$task = ManiphestTask::initializeNewTask($user);
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_STATUS)
|
|
|
|
->setNewValue(ManiphestTaskStatus::getDefaultStatus());
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_TITLE)
|
|
|
|
->setNewValue(nonempty($mail->getSubject(), pht('Untitled Task')));
|
|
|
|
|
|
|
|
$xactions[] = id(new ManiphestTransaction())
|
|
|
|
->setTransactionType(ManiphestTransaction::TYPE_DESCRIPTION)
|
|
|
|
->setNewValue($body);
|
2011-07-04 18:45:42 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2013-10-14 21:29:41 +02:00
|
|
|
$command = $body_data['command'];
|
|
|
|
$command_value = $body_data['command_value'];
|
2011-05-16 21:31:18 +02:00
|
|
|
|
Migrate all Maniphest transaction data to new storage
Summary:
Ref T2217. This is the risky, hard part; everything after this should be smooth sailing. This is //mostly// clean, except:
- The old format would opportunistically combine a comment with some other transaction type if it could. We no longer do that, so:
- When migrating, "edit" + "comment" transactions need to be split in two.
- When editing now, we should no longer combine these transaction types.
- These changes are pretty straightforward and low-impact.
- This migration promotes "auxiliary field" data to the new CustomField/StandardField format, so that's not a straight migration either. The formats are very similar, though.
Broadly, this takes the same attack that the auth migration did: proxy all the code through to the new storage. `ManiphestTransaction` is now just an API on top of `ManiphestTransactionPro`, which is the new storage format. The two formats are very similar, so this was mostly a straight copy from one table to the other.
Test Plan:
- Without performing the migration, made a bunch of edits and comments on tasks and verified the new code works correctly.
- Droped the test data and performed the migration.
- Looked at the resulting data for obvious discrepancies.
- Looked at a bunch of tasks and their transaction history.
- Used Conduit to pull transaction data.
- Edited task description and clicked "View Details" on transaction.
- Used batch editor.
- Made a bunch more edits.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2217
Differential Revision: https://secure.phabricator.com/D7068
2013-09-23 23:25:28 +02:00
|
|
|
$ttype = PhabricatorTransactions::TYPE_COMMENT;
|
2011-07-04 18:45:42 +02:00
|
|
|
$new_value = null;
|
|
|
|
switch ($command) {
|
|
|
|
case 'close':
|
2013-09-25 20:16:43 +02:00
|
|
|
$ttype = ManiphestTransaction::TYPE_STATUS;
|
2014-03-25 21:47:42 +01:00
|
|
|
$new_value = ManiphestTaskStatus::getDefaultClosedStatus();
|
2011-07-04 18:45:42 +02:00
|
|
|
break;
|
|
|
|
case 'claim':
|
2013-09-25 20:16:43 +02:00
|
|
|
$ttype = ManiphestTransaction::TYPE_OWNER;
|
2011-07-04 18:45:42 +02:00
|
|
|
$new_value = $user->getPHID();
|
|
|
|
break;
|
2013-10-14 21:29:41 +02:00
|
|
|
case 'assign':
|
|
|
|
$ttype = ManiphestTransaction::TYPE_OWNER;
|
|
|
|
if ($command_value) {
|
|
|
|
$assign_users = id(new PhabricatorPeopleQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withUsernames(array($command_value))
|
|
|
|
->execute();
|
|
|
|
if ($assign_users) {
|
|
|
|
$assign_user = head($assign_users);
|
|
|
|
$new_value = $assign_user->getPHID();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// assign to the user by default
|
|
|
|
if (!$new_value) {
|
|
|
|
$new_value = $user->getPHID();
|
|
|
|
}
|
|
|
|
break;
|
2011-07-04 18:45:42 +02:00
|
|
|
case 'unsubscribe':
|
2013-05-13 17:10:02 +02:00
|
|
|
$is_unsub = true;
|
2014-12-11 01:27:30 +01:00
|
|
|
$ttype = PhabricatorTransactions::TYPE_SUBSCRIBERS;
|
|
|
|
$ccs = $task->getSubscriberPHIDs();
|
2011-07-04 18:45:42 +02:00
|
|
|
foreach ($ccs as $k => $phid) {
|
|
|
|
if ($phid == $user->getPHID()) {
|
|
|
|
unset($ccs[$k]);
|
|
|
|
}
|
|
|
|
}
|
2014-12-11 01:27:30 +01:00
|
|
|
$new_value = array('=' => array_values($ccs));
|
2011-07-04 18:45:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-23 23:32:51 +02:00
|
|
|
if ($ttype != PhabricatorTransactions::TYPE_COMMENT) {
|
|
|
|
$xaction = clone $template;
|
|
|
|
$xaction->setTransactionType($ttype);
|
|
|
|
$xaction->setNewValue($new_value);
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($body)) {
|
|
|
|
$xaction = clone $template;
|
|
|
|
$xaction->setTransactionType(PhabricatorTransactions::TYPE_COMMENT);
|
|
|
|
$xaction->attachComment(
|
|
|
|
id(new ManiphestTransactionComment())
|
|
|
|
->setContent($body));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
}
|
2011-05-16 21:31:18 +02:00
|
|
|
}
|
|
|
|
|
2012-11-01 23:18:06 +01:00
|
|
|
$ccs = $mail->loadCCPHIDs();
|
2014-12-11 01:27:30 +01:00
|
|
|
$old_ccs = $task->getSubscriberPHIDs();
|
2013-05-13 17:10:02 +02:00
|
|
|
$new_ccs = array_merge($old_ccs, $ccs);
|
|
|
|
if (!$is_unsub) {
|
|
|
|
$new_ccs[] = $user->getPHID();
|
|
|
|
}
|
|
|
|
$new_ccs = array_unique($new_ccs);
|
|
|
|
|
|
|
|
if (array_diff($new_ccs, $old_ccs)) {
|
2012-11-01 23:18:06 +01:00
|
|
|
$cc_xaction = clone $template;
|
2014-12-11 01:27:30 +01:00
|
|
|
$cc_xaction->setTransactionType(
|
|
|
|
PhabricatorTransactions::TYPE_SUBSCRIBERS);
|
|
|
|
$cc_xaction->setNewValue(array('=' => $new_ccs));
|
2012-11-01 23:18:06 +01:00
|
|
|
$xactions[] = $cc_xaction;
|
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,
|
|
|
|
));
|
|
|
|
$event->setUser($user);
|
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())
|
2013-09-23 23:32:51 +02:00
|
|
|
->setActor($user)
|
|
|
|
->setParentMessageID($mail->getMessageID())
|
|
|
|
->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true)
|
|
|
|
->setContentSource($content_source)
|
2015-01-29 23:15:38 +01:00
|
|
|
->setApplicationEmail($this->getApplicationEmail())
|
2013-09-23 23:32:51 +02:00
|
|
|
->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,
|
|
|
|
));
|
|
|
|
$event->setUser($user);
|
|
|
|
PhutilEventEngine::dispatchEvent($event);
|
2011-05-16 21:31:18 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 01:31:26 +02:00
|
|
|
}
|