Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the correct way to set incoming mail to quarantine? #18

Open
mkurkela opened this issue Apr 26, 2024 · 3 comments
Open

What is the correct way to set incoming mail to quarantine? #18

mkurkela opened this issue Apr 26, 2024 · 3 comments

Comments

@mkurkela
Copy link

I was trying set some some incoming emails to quarantine

As the Quarantine class did not have encode method, I tried to do my own class derived from Quarantine class that defines the encode method.

class MyQuarantine(ppm.Quarantine):
  def encode(self) -> Payload:
    return Payload(self.response_char)
...
 
...
async def on_end_of_message(cmd: ppm.EndOfMessage) -> ppm.VerdictOrContinue:

  if quarantine.get():
    return MyQuarantine(); 

  return ppm.Continue()

I can successfully reject the message by replacing the return MyQuarantine() line with
return ppm.RejectWithCode(primary_code=(5, 7, 1), text="Blocked address")

@mkurkela
Copy link
Author

After some try & error and sendmail manual reading I managed to put the mail in hold queue

class MailQuarantine(AbstractManipulation):
  response_char: ClassVar[bytes] = b"q"  # SMFIR_QUARANTINE
  reason: str = "Quarantine this"
  def encode(self) -> Payload:
    return Payload(self.response_char + self.reason.encode() + b"\x00")
...
...
async def on_end_of_message(cmd: ppm.EndOfMessage) -> ppm.VerdictOrContinue:

  if quarantee.get():
    return ppm.Continue(manipulations=[MailQuarantine()])

  return ppm.Continue()

@duobradovic
Copy link

duobradovic commented Apr 29, 2024

So it appears MTA (Postfix) is waiting for a Continue after SMFIR_QUARANTINE response.

@buanzo
Copy link

buanzo commented Jun 18, 2024

That is indeed the case. I had tried all combinations, until finally I checked opendmarc's source code and noticed QUARANTINE then ACCEPT or CONTINUE was the appropriate method. For python version reasons, I had to use pymilter instead of purepythonmilter which was my #1 choice so, just in case someone is in a similar situation: sdgathman/pymilter#63 (comment) - Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants