3 final class PhabricatorMetaMTAApplicationEmailEditor
4 extends PhabricatorApplicationTransactionEditor
{
6 public function getEditorApplicationClass() {
7 return pht('PhabricatorMetaMTAApplication');
10 public function getEditorObjectsDescription() {
11 return pht('Application Emails');
14 public function getTransactionTypes() {
15 $types = parent
::getTransactionTypes();
17 $types[] = PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
;
18 $types[] = PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_CONFIG
;
23 protected function getCustomTransactionOldValue(
24 PhabricatorLiskDAO
$object,
25 PhabricatorApplicationTransaction
$xaction) {
27 switch ($xaction->getTransactionType()) {
28 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
:
29 return $object->getAddress();
30 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_CONFIG
:
31 $key = $xaction->getMetadataValue(
32 PhabricatorMetaMTAApplicationEmailTransaction
::KEY_CONFIG
);
33 return $object->getConfigValue($key);
36 return parent
::getCustomTransactionOldValue($object, $xaction);
39 protected function getCustomTransactionNewValue(
40 PhabricatorLiskDAO
$object,
41 PhabricatorApplicationTransaction
$xaction) {
43 switch ($xaction->getTransactionType()) {
44 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
:
45 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_CONFIG
:
46 return $xaction->getNewValue();
49 return parent
::getCustomTransactionNewValue($object, $xaction);
52 protected function applyCustomInternalTransaction(
53 PhabricatorLiskDAO
$object,
54 PhabricatorApplicationTransaction
$xaction) {
56 $new = $xaction->getNewValue();
58 switch ($xaction->getTransactionType()) {
59 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
:
60 $object->setAddress($new);
62 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_CONFIG
:
63 $key = $xaction->getMetadataValue(
64 PhabricatorMetaMTAApplicationEmailTransaction
::KEY_CONFIG
);
65 $object->setConfigValue($key, $new);
69 return parent
::applyCustomInternalTransaction($object, $xaction);
72 protected function applyCustomExternalTransaction(
73 PhabricatorLiskDAO
$object,
74 PhabricatorApplicationTransaction
$xaction) {
76 switch ($xaction->getTransactionType()) {
77 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
:
78 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_CONFIG
:
82 return parent
::applyCustomExternalTransaction($object, $xaction);
85 protected function validateTransaction(
86 PhabricatorLiskDAO
$object,
90 $errors = parent
::validateTransaction($object, $type, $xactions);
93 case PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
:
94 foreach ($xactions as $xaction) {
95 $email = $xaction->getNewValue();
96 if (!strlen($email)) {
97 // We'll deal with this below.
101 if (!PhabricatorUserEmail
::isValidAddress($email)) {
102 $errors[] = new PhabricatorApplicationTransactionValidationError(
105 pht('Email address is not formatted properly.'));
109 $address = new PhutilEmailAddress($email);
110 if (PhabricatorMailUtil
::isReservedAddress($address)) {
111 $errors[] = new PhabricatorApplicationTransactionValidationError(
115 'This email address is reserved. Choose a different '.
120 // See T13234. Prevent use of user email addresses as application
122 if (PhabricatorMailUtil
::isUserAddress($address)) {
123 $errors[] = new PhabricatorApplicationTransactionValidationError(
127 'This email address is already in use by a user. Choose '.
128 'a different address.'));
133 $missing = $this->validateIsEmptyTextField(
134 $object->getAddress(),
138 $error = new PhabricatorApplicationTransactionValidationError(
141 pht('You must provide an email address.'),
142 nonempty(last($xactions), null));
144 $error->setIsMissingFieldError(true);
153 protected function didCatchDuplicateKeyException(
154 PhabricatorLiskDAO
$object,
159 $errors[] = new PhabricatorApplicationTransactionValidationError(
160 PhabricatorMetaMTAApplicationEmailTransaction
::TYPE_ADDRESS
,
162 pht('This email address is already in use.'),
165 throw new PhabricatorApplicationTransactionValidationException($errors);