mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 03:50:54 +01:00
Allow tweaking of Differential mail by using events
Summary: Allow tweaking Differential mail before sending. Test Plan: Wrote a listener renaming Differential attachments and it worked without problems. Reviewers: epriestley Reviewed By: epriestley CC: aran, epriestley, mareksapota, davidreuss Differential Revision: 1091
This commit is contained in:
parent
802dcd4cfb
commit
b71a55900a
11 changed files with 105 additions and 31 deletions
|
@ -488,6 +488,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/test',
|
||||
'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/base',
|
||||
'PhabricatorMarkupEngine' => 'applications/markup/engine',
|
||||
'PhabricatorMetaMTAAttachment' => 'applications/metamta/storage/mail',
|
||||
'PhabricatorMetaMTAController' => 'applications/metamta/controller/base',
|
||||
'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base',
|
||||
'PhabricatorMetaMTADaemon' => 'applications/metamta/daemon/mta',
|
||||
|
|
|
@ -90,13 +90,7 @@ abstract class DifferentialMail {
|
|||
->setParentMessageID($this->parentMessageID)
|
||||
->addHeader('Thread-Topic', $this->getRevision()->getTitle());
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
$template->addAttachment(
|
||||
$attachment['data'],
|
||||
$attachment['filename'],
|
||||
$attachment['mimetype']
|
||||
);
|
||||
}
|
||||
$template->setAttachments($attachments);
|
||||
|
||||
$template->setThreadID(
|
||||
$this->getThreadID(),
|
||||
|
@ -120,6 +114,16 @@ abstract class DifferentialMail {
|
|||
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||
|
||||
$event = new PhabricatorEvent(
|
||||
PhabricatorEventType::TYPE_DIFFERENTIAL_WILLSENDMAIL,
|
||||
array(
|
||||
'mail' => $template,
|
||||
)
|
||||
);
|
||||
PhabricatorEventEngine::dispatchEvent($event);
|
||||
|
||||
$template = $event->getValue('mail');
|
||||
|
||||
$mails = $reply_handler->multiplexMail(
|
||||
$template,
|
||||
array_select_keys($handles, $to_phids),
|
||||
|
@ -177,14 +181,8 @@ EOTEXT;
|
|||
|
||||
/**
|
||||
* You can override this method in a subclass and return array of attachments
|
||||
* to be sent with the email. Each attachment is a dictionary with 'data',
|
||||
* 'filename' and 'mimetype' keys. For example:
|
||||
*
|
||||
* array(
|
||||
* 'data' => 'some text',
|
||||
* 'filename' => 'example.txt',
|
||||
* 'mimetype' => 'text/plain'
|
||||
* );
|
||||
* to be sent with the email. Each attachment is an instance of
|
||||
* PhabricatorMetaMTAAttachment.
|
||||
*/
|
||||
protected function buildAttachments() {
|
||||
return array();
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
phutil_require_module('phabricator', 'infrastructure/events/constant/type');
|
||||
phutil_require_module('phabricator', 'infrastructure/events/engine');
|
||||
phutil_require_module('phabricator', 'infrastructure/events/event');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
|
|
@ -104,10 +104,10 @@ abstract class DifferentialReviewRequestMail extends DifferentialMail {
|
|||
$bundle = ArcanistBundle::newFromChanges($changes);
|
||||
$unified_diff = $bundle->toUnifiedDiff();
|
||||
|
||||
$attachments[] = array(
|
||||
'data' => $unified_diff,
|
||||
'filename' => $filename,
|
||||
'mimetype' => 'text/x-patch; charset=utf-8'
|
||||
$attachments[] = new PhabricatorMetaMTAAttachment(
|
||||
$unified_diff,
|
||||
$filename,
|
||||
'text/x-patch; charset=utf-8'
|
||||
);
|
||||
}
|
||||
return $attachments;
|
||||
|
|
|
@ -10,6 +10,7 @@ phutil_require_module('arcanist', 'parser/bundle');
|
|||
phutil_require_module('arcanist', 'parser/diff/change');
|
||||
|
||||
phutil_require_module('phabricator', 'applications/differential/mail/base');
|
||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
|
|
|
@ -34,10 +34,11 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
|||
if ($files) {
|
||||
foreach ($files as $phid) {
|
||||
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid);
|
||||
$mail->addAttachment(
|
||||
$mail->addAttachment(new PhabricatorMetaMTAAttachment(
|
||||
$file->loadFileData(),
|
||||
$file->getName(),
|
||||
$file->getMimeType());
|
||||
$file->getMimeType()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
class PhabricatorMetaMTAAttachment {
|
||||
protected $data;
|
||||
protected $filename;
|
||||
protected $mimetype;
|
||||
|
||||
public function __construct($data, $filename, $mimetype) {
|
||||
$this->setData($data);
|
||||
$this->setFileName($filename);
|
||||
$this->setMimeType($mimetype);
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function setData($data) {
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFileName() {
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
public function setFileName($filename) {
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMimeType() {
|
||||
return $this->mimetype;
|
||||
}
|
||||
|
||||
public function setMimeType($mimetype) {
|
||||
$this->mimetype = $mimetype;
|
||||
return $this;
|
||||
}
|
||||
}
|
|
@ -104,12 +104,17 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addAttachment($data, $filename, $mimetype) {
|
||||
$this->parameters['attachments'][] = array(
|
||||
'data' => $data,
|
||||
'filename' => $filename,
|
||||
'mimetype' => $mimetype
|
||||
);
|
||||
public function addAttachment(PhabricatorMetaMTAAttachment $attachment) {
|
||||
$this->parameters['attachments'][] = $attachment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAttachments() {
|
||||
return $this->getParam('attachments');
|
||||
}
|
||||
|
||||
public function setAttachments(array $attachments) {
|
||||
$this->setParam('attachments', $attachments);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -312,9 +317,9 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
|||
case 'attachments':
|
||||
foreach ($value as $attachment) {
|
||||
$mailer->addAttachment(
|
||||
$attachment['data'],
|
||||
$attachment['filename'],
|
||||
$attachment['mimetype']
|
||||
$attachment->getData(),
|
||||
$attachment->getFileName(),
|
||||
$attachment->getMimeType()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -14,4 +14,5 @@ phutil_require_module('phutil', 'symbols');
|
|||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorMetaMTAAttachment.php');
|
||||
phutil_require_source('PhabricatorMetaMTAMail.php');
|
||||
|
|
|
@ -25,3 +25,10 @@ or alter the edit. Data available on this event:
|
|||
- ##new## A boolean indicating if this task is being created.
|
||||
- ##mail## If this edit originates from email, the
|
||||
@{class:PhabricatorMetaMTAReceivedMail} object.
|
||||
|
||||
== PhabricatorEventType::TYPE_DIFFERENTIAL_WILLSENDMAIL ==
|
||||
|
||||
This event is dispatche before Differential sends an email, and allows you to
|
||||
edit the message that will be sent. Data available on this event:
|
||||
|
||||
- ##mail## The {@class:PhabricatorMetaMTAMail} being edited.
|
||||
|
|
|
@ -20,5 +20,6 @@ final class PhabricatorEventType extends PhabricatorEventConstants {
|
|||
|
||||
const TYPE_ALL = '*';
|
||||
const TYPE_MANIPHEST_WILLEDITTASK = 'maniphest.willEditTask';
|
||||
const TYPE_DIFFERENTIAL_WILLSENDMAIL = 'differential.willSendMail';
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue