Skip to content

Commit 3448781

Browse files
committedJan 4, 2013
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
1 parent f12af03 commit 3448781

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE `{$NAMESPACE}_metamta`.`metamta_receivedmail`
2+
ADD `messageIDHash` CHAR(12) BINARY NOT NULL,
3+
ADD KEY `key_messageIDHash` (`messageIDHash`);

‎scripts/mail/mail_handler.php

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
'text' => $text_body,
3535
'html' => $parser->getMessageBody('html'),
3636
));
37+
$received->setMessageIDHash(
38+
PhabricatorHash::digestForIndex($received->getMessageID())
39+
);
3740

3841
$attachments = array();
3942
foreach ($parser->getAttachments() as $attachment) {

‎src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php

+22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class PhabricatorMetaMTAReceivedMail extends PhabricatorMetaMTADAO {
99
protected $relatedPHID;
1010
protected $authorPHID;
1111
protected $message;
12+
protected $messageIDHash;
1213

1314
public function getConfiguration() {
1415
return array(
@@ -145,6 +146,27 @@ public function processReceivedMail() {
145146
return $this->setMessage($message)->save();
146147
}
147148

149+
$message_id_hash = $this->getMessageIDHash();
150+
if ($message_id_hash) {
151+
$messages = $this->loadAllWhere(
152+
'messageIDHash = %s',
153+
$message_id_hash
154+
);
155+
$messages_count = count($messages);
156+
if ($messages_count > 1) {
157+
$first_message = reset($messages);
158+
if ($first_message->getID() != $this->getID()) {
159+
$message = sprintf(
160+
'Ignoring email with message id hash "%s" that has been seen %d '.
161+
'times, including this message.',
162+
$message_id_hash,
163+
$messages_count
164+
);
165+
return $this->setMessage($message)->save();
166+
}
167+
}
168+
}
169+
148170
list($to,
149171
$receiver_name,
150172
$user_id,

‎src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php

+5
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,11 @@ public function getPatches() {
10761076
'type' => 'sql',
10771077
'name' => $this->getPatchPath('20130101.confxaction.sql'),
10781078
),
1079+
'20130102.metamtareceivedmailmessageidhash.sql' => array(
1080+
'type' => 'sql',
1081+
'name' =>
1082+
$this->getPatchPath('20130102.metamtareceivedmailmessageidhash.sql'),
1083+
),
10791084
);
10801085
}
10811086

0 commit comments

Comments
 (0)
Failed to load comments.