@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+33
+3
resources/sql/patches/20130102.metamtareceivedmailmessageidhash.sql
··· 1 + ALTER TABLE `{$NAMESPACE}_metamta`.`metamta_receivedmail` 2 + ADD `messageIDHash` CHAR(12) BINARY NOT NULL, 3 + ADD KEY `key_messageIDHash` (`messageIDHash`);
+3
scripts/mail/mail_handler.php
··· 34 34 'text' => $text_body, 35 35 'html' => $parser->getMessageBody('html'), 36 36 )); 37 + $received->setMessageIDHash( 38 + PhabricatorHash::digestForIndex($received->getMessageID()) 39 + ); 37 40 38 41 $attachments = array(); 39 42 foreach ($parser->getAttachments() as $attachment) {
+22
src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php
··· 9 9 protected $relatedPHID; 10 10 protected $authorPHID; 11 11 protected $message; 12 + protected $messageIDHash; 12 13 13 14 public function getConfiguration() { 14 15 return array( ··· 143 144 $message = "Ignoring email with 'X-Phabricator-Sent-This-Message' ". 144 145 "header to avoid loops."; 145 146 return $this->setMessage($message)->save(); 147 + } 148 + 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 + } 146 168 } 147 169 148 170 list($to,
+5
src/infrastructure/storage/patch/PhabricatorBuiltinPatchList.php
··· 1076 1076 'type' => 'sql', 1077 1077 'name' => $this->getPatchPath('20130101.confxaction.sql'), 1078 1078 ), 1079 + '20130102.metamtareceivedmailmessageidhash.sql' => array( 1080 + 'type' => 'sql', 1081 + 'name' => 1082 + $this->getPatchPath('20130102.metamtareceivedmailmessageidhash.sql'), 1083 + ), 1079 1084 ); 1080 1085 } 1081 1086