2013-08-05 17:11:46 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PasteReplyHandler extends PhabricatorMailReplyHandler {
|
|
|
|
|
|
|
|
public function validateMailReceiver($mail_receiver) {
|
|
|
|
if (!($mail_receiver instanceof PhabricatorPaste)) {
|
|
|
|
throw new Exception('Mail receiver is not a PhabricatorPaste.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPrivateReplyHandlerEmailAddress(
|
|
|
|
PhabricatorObjectHandle $handle) {
|
|
|
|
return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'P');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPublicReplyHandlerEmailAddress() {
|
|
|
|
return $this->getDefaultPublicReplyHandlerEmailAddress('P');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
|
|
|
|
$actor = $this->getActor();
|
|
|
|
$paste = $this->getMailReceiver();
|
|
|
|
|
2013-10-14 12:29:41 -07:00
|
|
|
$body_data = $mail->parseBody();
|
|
|
|
$body = $body_data['body'];
|
2013-08-05 17:11:46 -07:00
|
|
|
$body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
|
|
|
|
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_EMAIL,
|
|
|
|
array(
|
|
|
|
'id' => $mail->getID(),
|
|
|
|
));
|
|
|
|
|
|
|
|
$lines = explode("\n", trim($body));
|
|
|
|
$first_line = head($lines);
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
2015-03-31 16:48:27 -07:00
|
|
|
$commands = $body_data['commands'];
|
|
|
|
foreach ($commands as $command) {
|
|
|
|
switch (head($command)) {
|
|
|
|
case 'unsubscribe':
|
|
|
|
$xaction = id(new PhabricatorPasteTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
|
|
|
|
->setNewValue(array('-' => array($actor->getPHID())));
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
break;
|
|
|
|
}
|
2013-08-05 17:11:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorPasteTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new PhabricatorPasteTransactionComment())
|
|
|
|
->setContent($body));
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorPasteEditor())
|
|
|
|
->setActor($actor)
|
|
|
|
->setContentSource($content_source)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setIsPreview(false);
|
|
|
|
|
2015-03-31 16:48:27 -07:00
|
|
|
$editor->applyTransactions($paste, $xactions);
|
2013-08-05 17:11:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|