On Sat, Oct 14, 2023 at 03:06:11PM +0200, Sagar Acharya wrote:
> How do I reject all emails with attachments by using an opensmtpd filter?

You need to parse the content of the emails using the data-line filter event.

You'll probably want to check the headers for Mime-Version: and Content-Type:.

If the message is indeed Mime encoded then look in the message body for the
Content-Type: header again, and decide whether to pass it or reject it.

(You might want to pass some attachments such as plain text or text/html, and
 reject all others.)

> At what step do I set the filter? rcpt-to, data, or commit step?

You will need to parse several events, probably at least:

link-connect
link-disconnect
data-line

and maybe others.

> Any tutorials are appreciated.

If you want a general tutorial about writing filters in C, you could look at:

https://research.exoticsilicon.com/articles/mail_filters

Some of the content is applicable to other programming languages too, but the
tutorial is based on programming in C.

Reply via email to