Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/receiver/PhabricatorApplicationMailReceiver.php
12256 views
1
<?php
2
3
abstract class PhabricatorApplicationMailReceiver
4
extends PhabricatorMailReceiver {
5
6
private $applicationEmail;
7
private $emailList;
8
private $author;
9
10
abstract protected function newApplication();
11
12
final protected function setApplicationEmail(
13
PhabricatorMetaMTAApplicationEmail $email) {
14
$this->applicationEmail = $email;
15
return $this;
16
}
17
18
final protected function getApplicationEmail() {
19
return $this->applicationEmail;
20
}
21
22
final protected function setAuthor(PhabricatorUser $author) {
23
$this->author = $author;
24
return $this;
25
}
26
27
final protected function getAuthor() {
28
return $this->author;
29
}
30
31
final public function isEnabled() {
32
return $this->newApplication()->isInstalled();
33
}
34
35
final public function canAcceptMail(
36
PhabricatorMetaMTAReceivedMail $mail,
37
PhutilEmailAddress $target) {
38
39
$viewer = $this->getViewer();
40
$sender = $this->getSender();
41
42
foreach ($this->loadApplicationEmailList() as $application_email) {
43
$create_address = $application_email->newAddress();
44
45
if (!PhabricatorMailUtil::matchAddresses($create_address, $target)) {
46
continue;
47
}
48
49
if ($sender) {
50
$author = $sender;
51
} else {
52
$author_phid = $application_email->getDefaultAuthorPHID();
53
54
// If this mail isn't from a recognized sender and the target address
55
// does not have a default author, we can't accept it, and it's an
56
// error because you tried to send it here.
57
58
// You either need to be sending from a real address or be sending to
59
// an address which accepts mail from the public internet.
60
61
if (!$author_phid) {
62
throw new PhabricatorMetaMTAReceivedMailProcessingException(
63
MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER,
64
pht(
65
'You are sending from an unrecognized email address to '.
66
'an address which does not support public email ("%s").',
67
(string)$target));
68
}
69
70
$author = id(new PhabricatorPeopleQuery())
71
->setViewer($viewer)
72
->withPHIDs(array($author_phid))
73
->executeOne();
74
if (!$author) {
75
throw new Exception(
76
pht(
77
'Application email ("%s") has an invalid default author ("%s").',
78
(string)$create_address,
79
$author_phid));
80
}
81
}
82
83
$this
84
->setApplicationEmail($application_email)
85
->setAuthor($author);
86
87
return true;
88
}
89
90
return false;
91
}
92
93
private function loadApplicationEmailList() {
94
if ($this->emailList === null) {
95
$viewer = $this->getViewer();
96
$application = $this->newApplication();
97
98
$this->emailList = id(new PhabricatorMetaMTAApplicationEmailQuery())
99
->setViewer($viewer)
100
->withApplicationPHIDs(array($application->getPHID()))
101
->execute();
102
}
103
104
return $this->emailList;
105
}
106
107
}
108
109