mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
7f45824984
Summary: Ref T4107. Two issues: - With strict MySQL settings, we try to insert `null` into the non-nullable `messageCount` field. Add an `initializeNew...` method. - If we don't create a new conpherence (for example, because the message body is empty), we fatal on `getPHID()` right now. Also, make this stuff a little easier to test. Test Plan: Used `mail_handler.php` to receive empty conpherence mail, and new-thread conpherence mail. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4107 Differential Revision: https://secure.phabricator.com/D7760
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
final class ConpherenceCreateThreadMailReceiver
|
|
extends PhabricatorMailReceiver {
|
|
|
|
public function isEnabled() {
|
|
$app_class = 'PhabricatorApplicationConpherence';
|
|
return PhabricatorApplication::isClassInstalled($app_class);
|
|
}
|
|
|
|
public function canAcceptMail(PhabricatorMetaMTAReceivedMail $mail) {
|
|
$usernames = $this->getMailUsernames($mail);
|
|
if (!$usernames) {
|
|
return false;
|
|
}
|
|
|
|
$users = $this->loadMailUsers($mail);
|
|
if (count($users) != count($usernames)) {
|
|
// At least some of the addresses are not users, so don't accept this as
|
|
// a new Conpherence thread.
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private function getMailUsernames(PhabricatorMetaMTAReceivedMail $mail) {
|
|
$usernames = array();
|
|
foreach ($mail->getToAddresses() as $to_address) {
|
|
$address = self::stripMailboxPrefix($to_address);
|
|
$usernames[] = id(new PhutilEmailAddress($address))->getLocalPart();
|
|
}
|
|
|
|
return array_unique($usernames);
|
|
}
|
|
|
|
private function loadMailUsers(PhabricatorMetaMTAReceivedMail $mail) {
|
|
$usernames = $this->getMailUsernames($mail);
|
|
if (!$usernames) {
|
|
return array();
|
|
}
|
|
|
|
return id(new PhabricatorUser())->loadAllWhere(
|
|
'username in (%Ls)',
|
|
$usernames);
|
|
}
|
|
|
|
protected function processReceivedMail(
|
|
PhabricatorMetaMTAReceivedMail $mail,
|
|
PhabricatorUser $sender) {
|
|
|
|
$users = $this->loadMailUsers($mail);
|
|
$phids = mpull($users, 'getPHID');
|
|
|
|
$conpherence = id(new ConpherenceReplyHandler())
|
|
->setMailReceiver(ConpherenceThread::initializeNewThread($sender))
|
|
->setMailAddedParticipantPHIDs($phids)
|
|
->setActor($sender)
|
|
->setExcludeMailRecipientPHIDs($mail->loadExcludeMailRecipientPHIDs())
|
|
->processEmail($mail);
|
|
|
|
if ($conpherence) {
|
|
$mail->setRelatedPHID($conpherence->getPHID());
|
|
}
|
|
}
|
|
|
|
}
|