0

I'm trying to automatically detect emails with attachments and copy them to a specific folder. My Roundcubemail + Sieve setup works and can successfully filter emails and act on them.

However, I can't seem to figure out how to detect the presence of attachments. In an email's source that has attachments, one can usually find this section:

----=_NextPart_...
Content-Disposition: attachment; filename="..." 

So I tried creating a filter for the body that reacts upon the body containing the word attachment as a minimal test case. However, the filter does not fire when I sent an email with an attachment.

The same happens if I create a filter for the header Content-Disposition which should contain the word attachment. My guess is that the Dovecot Managesieve plugin does not filter the entire source of the email, so it never encounters aforementioned section, neither in body, nor in the headers. Alternatively, Roundcubemail is presenting the email source to me in a different way than what Sieve processes and I'm therefore looking for the wrong pattern.

Does anyone know a Sieve script that could detect attachments, or a different way to achieve what I'm trying to do using Roundcubemail?

TimB
  • 970
  • 8
  • 17
  • Many attachements don't have an explicit `Content-Disposition:` header because MIME defaults to that implicitly for many types and so it's redundant. – tripleee Dec 26 '22 at 09:17

1 Answers1

0

Have you tried :mime testing against :anychild ?

require "fileinto";
require "mime";

if header :mime :anychild :param "filename" :matches "Content-Disposition" "*" {
    fileinto "INBOX.Attachments";
}
ernix
  • 3,442
  • 1
  • 17
  • 23
  • How do I remove the attachment ? – Janumar May 26 '23 at 14:32
  • Do you mean to strip attachments from email while filtering? Well, sieve filter is just an organizer. If you want to modify incoming emails while filtering rather than `discard`, you'll have to setup some MIME filter program and sieve extprograms extension. – ernix May 29 '23 at 02:21