Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14104265
D12236.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
D12236.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1248,7 +1248,7 @@
'PasteDefaultViewCapability' => 'applications/paste/capability/PasteDefaultViewCapability.php',
'PasteEmbedView' => 'applications/paste/view/PasteEmbedView.php',
'PasteInfoConduitAPIMethod' => 'applications/paste/conduit/PasteInfoConduitAPIMethod.php',
- 'PasteMockMailReceiver' => 'applications/paste/mail/PasteMockMailReceiver.php',
+ 'PasteMailReceiver' => 'applications/paste/mail/PasteMailReceiver.php',
'PasteQueryConduitAPIMethod' => 'applications/paste/conduit/PasteQueryConduitAPIMethod.php',
'PasteReplyHandler' => 'applications/paste/mail/PasteReplyHandler.php',
'PeopleBrowseUserDirectoryCapability' => 'applications/people/capability/PeopleBrowseUserDirectoryCapability.php',
@@ -1310,6 +1310,7 @@
'PhabricatorApplicationTransactionNoEffectException' => 'applications/transactions/exception/PhabricatorApplicationTransactionNoEffectException.php',
'PhabricatorApplicationTransactionNoEffectResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionNoEffectResponse.php',
'PhabricatorApplicationTransactionQuery' => 'applications/transactions/query/PhabricatorApplicationTransactionQuery.php',
+ 'PhabricatorApplicationTransactionReplyHandler' => 'applications/transactions/replyhandler/PhabricatorApplicationTransactionReplyHandler.php',
'PhabricatorApplicationTransactionResponse' => 'applications/transactions/response/PhabricatorApplicationTransactionResponse.php',
'PhabricatorApplicationTransactionShowOlderController' => 'applications/transactions/controller/PhabricatorApplicationTransactionShowOlderController.php',
'PhabricatorApplicationTransactionStructureException' => 'applications/transactions/exception/PhabricatorApplicationTransactionStructureException.php',
@@ -4512,9 +4513,9 @@
'PasteDefaultViewCapability' => 'PhabricatorPolicyCapability',
'PasteEmbedView' => 'AphrontView',
'PasteInfoConduitAPIMethod' => 'PasteConduitAPIMethod',
- 'PasteMockMailReceiver' => 'PhabricatorObjectMailReceiver',
+ 'PasteMailReceiver' => 'PhabricatorObjectMailReceiver',
'PasteQueryConduitAPIMethod' => 'PasteConduitAPIMethod',
- 'PasteReplyHandler' => 'PhabricatorMailReplyHandler',
+ 'PasteReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PeopleBrowseUserDirectoryCapability' => 'PhabricatorPolicyCapability',
'PeopleCreateUsersCapability' => 'PhabricatorPolicyCapability',
'PeopleUserLogGarbageCollector' => 'PhabricatorGarbageCollector',
@@ -4579,6 +4580,7 @@
'PhabricatorApplicationTransactionNoEffectException' => 'Exception',
'PhabricatorApplicationTransactionNoEffectResponse' => 'AphrontProxyResponse',
'PhabricatorApplicationTransactionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorApplicationTransactionReplyHandler' => 'PhabricatorMailReplyHandler',
'PhabricatorApplicationTransactionResponse' => 'AphrontProxyResponse',
'PhabricatorApplicationTransactionShowOlderController' => 'PhabricatorApplicationTransactionController',
'PhabricatorApplicationTransactionStructureException' => 'Exception',
diff --git a/src/applications/paste/mail/PasteMockMailReceiver.php b/src/applications/paste/mail/PasteMailReceiver.php
rename from src/applications/paste/mail/PasteMockMailReceiver.php
rename to src/applications/paste/mail/PasteMailReceiver.php
--- a/src/applications/paste/mail/PasteMockMailReceiver.php
+++ b/src/applications/paste/mail/PasteMailReceiver.php
@@ -1,6 +1,6 @@
<?php
-final class PasteMockMailReceiver extends PhabricatorObjectMailReceiver {
+final class PasteMailReceiver extends PhabricatorObjectMailReceiver {
public function isEnabled() {
$app_class = 'PhabricatorPasteApplication';
diff --git a/src/applications/paste/mail/PasteReplyHandler.php b/src/applications/paste/mail/PasteReplyHandler.php
--- a/src/applications/paste/mail/PasteReplyHandler.php
+++ b/src/applications/paste/mail/PasteReplyHandler.php
@@ -1,6 +1,7 @@
<?php
-final class PasteReplyHandler extends PhabricatorMailReplyHandler {
+final class PasteReplyHandler
+ extends PhabricatorApplicationTransactionReplyHandler {
public function validateMailReceiver($mail_receiver) {
if (!($mail_receiver instanceof PhabricatorPaste)) {
@@ -8,35 +9,14 @@
}
}
- public function getPrivateReplyHandlerEmailAddress(
- PhabricatorObjectHandle $handle) {
- return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'P');
+ public function getObjectPrefix() {
+ return 'P';
}
- public function getPublicReplyHandlerEmailAddress() {
- return $this->getDefaultPublicReplyHandlerEmailAddress('P');
- }
-
- protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
- $actor = $this->getActor();
- $paste = $this->getMailReceiver();
-
- $body_data = $mail->parseBody();
- $body = $body_data['body'];
- $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);
+ protected function processMailCommands(array $commands) {
+ $actor = $this->getActor();
$xactions = array();
-
- $commands = $body_data['commands'];
foreach ($commands as $command) {
switch (head($command)) {
case 'unsubscribe':
@@ -48,19 +28,7 @@
}
}
- $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);
-
- $editor->applyTransactions($paste, $xactions);
+ return $xactions;
}
}
diff --git a/src/applications/transactions/replyhandler/PhabricatorApplicationTransactionReplyHandler.php b/src/applications/transactions/replyhandler/PhabricatorApplicationTransactionReplyHandler.php
new file mode 100644
--- /dev/null
+++ b/src/applications/transactions/replyhandler/PhabricatorApplicationTransactionReplyHandler.php
@@ -0,0 +1,92 @@
+<?php
+
+abstract class PhabricatorApplicationTransactionReplyHandler
+ extends PhabricatorMailReplyHandler {
+
+ abstract public function getObjectPrefix();
+
+ public function getPrivateReplyHandlerEmailAddress(
+ PhabricatorObjectHandle $handle) {
+ return $this->getDefaultPrivateReplyHandlerEmailAddress(
+ $handle,
+ $this->getObjectPrefix());
+ }
+
+ public function getPublicReplyHandlerEmailAddress() {
+ return $this->getDefaultPublicReplyHandlerEmailAddress(
+ $this->getObjectPrefix());
+ }
+
+ private function newEditor(PhabricatorMetaMTAReceivedMail $mail) {
+ $content_source = PhabricatorContentSource::newForSource(
+ PhabricatorContentSource::SOURCE_EMAIL,
+ array(
+ 'id' => $mail->getID(),
+ ));
+
+ $editor = $this->getMailReceiver()
+ ->getApplicationTransactionEditor()
+ ->setActor($this->getActor())
+ ->setContentSource($content_source)
+ ->setContinueOnMissingFields(true)
+ ->setParentMessageID($mail->getMessageID())
+ ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs());
+
+ if ($this->getApplicationEmail()) {
+ $editor->setApplicationEmail($this->getApplicationEmail());
+ }
+
+ return $editor;
+ }
+
+ private function newTransaction() {
+ return $this->getMailReceiver()->getApplicationTransactionTemplate();
+ }
+
+ final protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) {
+ $viewer = $this->getActor();
+ $object = $this->getMailReceiver();
+
+ $body_data = $mail->parseBody();
+
+ $xactions = $this->processMailCommands($body_data['commands']);
+
+ // If this object is subscribable, subscribe all the users who were
+ // CC'd on the message.
+ if ($object instanceof PhabricatorSubscribableInterface) {
+ $subscriber_phids = $mail->loadCCPHIDs();
+ if ($subscriber_phids) {
+ $xactions[] = $this->newTransaction()
+ ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS)
+ ->setNewValue(
+ array(
+ '+' => array($viewer->getPHID()),
+ ));
+ }
+ }
+
+ $body = $body_data['body'];
+ $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
+
+ $comment = $this
+ ->newTransaction()
+ ->getApplicationTransactionCommentObject()
+ ->setContent($body);
+
+ $xactions[] = $this->newTransaction()
+ ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
+ ->attachComment($comment);
+
+ $target = $object->getApplicationTransactionObject();
+
+ $this->newEditor($mail)
+ ->setContinueOnNoEffect(true)
+ ->applyTransactions($target, $xactions);
+ }
+
+ protected function processMailCommands(array $commands) {
+ // TODO: Modularize this.
+ return array();
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 12:07 AM (8 h, 36 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6797332
Default Alt Text
D12236.diff (9 KB)
Attached To
Mode
D12236: Lift common code for transaction-based reply handlers into parent class
Attached
Detach File
Event Timeline
Log In to Comment