#4940 Don't reject unrelated email messages.
Merged 3 years ago by pingou. Opened 3 years ago by rombobeorn.
rombobeorn/pagure master  into  master

@@ -136,29 +136,35 @@ 

          else:

              msg = email.message_from_file(self.fp)

  

-         msg_id = msg.get("In-Reply-To", None)

-         if msg_id is None:

-             self.log("No In-Reply-To, keep going")

-             return Milter.REJECT

- 

-         # Ensure we don't get extra lines in the message-id

-         msg_id = msg_id.split("\n")[0].strip()

- 

-         self.log("msg-ig %s" % msg_id)

          self.log("To %s" % msg["to"])

          self.log("Cc %s" % msg.get("cc"))

          self.log("From %s" % msg["From"])

  

-         # Check the email was sent to the right address

+         # First check whether the message is addressed to this milter.

          email_address = msg["to"]

          if "reply+" in msg.get("cc", ""):

              email_address = msg["cc"]

          if "reply+" not in email_address:

+             # The message is not addressed to this milter so don't touch it.

              self.log(

                  "No valid recipient email found in To/Cc: %s" % email_address

              )

              return Milter.CONTINUE

  

+         if msg["From"] and msg["From"] == _config.get("FROM_EMAIL"):

+             self.log("Let's not process the email we send")

+             return Milter.ACCEPT

+ 

+         msg_id = msg.get("In-Reply-To", None)

+         if msg_id is None:

+             self.log("No In-Reply-To, can't process this message.")

+             return Milter.REJECT

+ 

+         # Ensure we don't get extra lines in the message-id

+         msg_id = msg_id.split("\n")[0].strip()

+ 

+         self.log("msg-id %s" % msg_id)

+ 

          # Ensure the user replied to his/her own notification, not that

          # they are trying to forge their ID into someone else's

          salt = _config.get("SALT_EMAIL")
@@ -199,11 +205,6 @@ 

              session.remove()

              return Milter.REJECT

  

-         if msg["From"] and msg["From"] == _config.get("FROM_EMAIL"):

-             self.log("Let's not process the email we send")

-             session.remove()

-             return Milter.REJECT

- 

          msg_id = clean_item(msg_id)

  

          if msg_id and "-ticket-" in msg_id:

Tests that select those messages that Pagure is supposed to process must be performed before the milter starts rejecting messages for not following Pagure's rules. With these changes the milter will do things in a valid order.

Error messages are still missing but that will have to wait a while.

Pull-Request has been merged by pingou

3 years ago