mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
de-duplicate emails received by phabricator multiple times
Summary: this can happen if you have Phabricator and email lists co-mingling such that Phabricator receives an email multiple times. we can prevent this from then spamming everyone or otherwise taking the action multiple times by storing a message id hash and dropping the message if we have more than one message that matches. Test Plan: simulated sending the same email multiple times on the command line. noted only the first one made it through. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1726 Differential Revision: https://secure.phabricator.com/D4328
This commit is contained in:
parent
f12af03836
commit
3448781c40
4 changed files with 33 additions and 0 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE `{$NAMESPACE}_metamta`.`metamta_receivedmail`
|
||||||
|
ADD `messageIDHash` CHAR(12) BINARY NOT NULL,
|
||||||
|
ADD KEY `key_messageIDHash` (`messageIDHash`);
|
|
@ -34,6 +34,9 @@ $received->setBodies(array(
|
||||||
'text' => $text_body,
|
'text' => $text_body,
|
||||||
'html' => $parser->getMessageBody('html'),
|
'html' => $parser->getMessageBody('html'),
|
||||||
));
|
));
|
||||||
|
$received->setMessageIDHash(
|
||||||
|
PhabricatorHash::digestForIndex($received->getMessageID())
|
||||||
|
);
|
||||||
|
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
foreach ($parser->getAttachments() as $attachment) {
|
foreach ($parser->getAttachments() as $attachment) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO {
|
||||||
protected $relatedPHID;
|
protected $relatedPHID;
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $message;
|
protected $message;
|
||||||
|
protected $messageIDHash;
|
||||||
|
|
||||||
public function getConfiguration() {
|
public function getConfiguration() {
|
||||||
return array(
|
return array(
|
||||||
|
@ -145,6 +146,27 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO {
|
||||||
return $this->setMessage($message)->save();
|
return $this->setMessage($message)->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$message_id_hash = $this->getMessageIDHash();
|
||||||
|
if ($message_id_hash) {
|
||||||
|
$messages = $this->loadAllWhere(
|
||||||
|
'messageIDHash = %s',
|
||||||
|
$message_id_hash
|
||||||
|
);
|
||||||
|
$messages_count = count($messages);
|
||||||
|
if ($messages_count > 1) {
|
||||||
|
$first_message = reset($messages);
|
||||||
|
if ($first_message->getID() != $this->getID()) {
|
||||||
|
$message = sprintf(
|
||||||
|
'Ignoring email with message id hash "%s" that has been seen %d '.
|
||||||
|
'times, including this message.',
|
||||||
|
$message_id_hash,
|
||||||
|
$messages_count
|
||||||
|
);
|
||||||
|
return $this->setMessage($message)->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
list($to,
|
list($to,
|
||||||
$receiver_name,
|
$receiver_name,
|
||||||
$user_id,
|
$user_id,
|
||||||
|
|
|
@ -1076,6 +1076,11 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('20130101.confxaction.sql'),
|
'name' => $this->getPatchPath('20130101.confxaction.sql'),
|
||||||
),
|
),
|
||||||
|
'20130102.metamtareceivedmailmessageidhash.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' =>
|
||||||
|
$this->getPatchPath('20130102.metamtareceivedmailmessageidhash.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue