Yes, I need Sieve for this, because actually I don't know sender or recipient. Sieve script activate on some user in some time.
In fact, I did not read the specification *spec-bosch-sieve-extprograms.txt* on github (I use dovecot wiki old revisions) and generally was not attentive enough.
I wrote python script and this is works like a charm for month.
|require [ "vnd.dovecot.pipe", "variables" ]; if address :is :all "from" "k0ste@k0ste.ru" { pipe "sieve_to_owncloud"; } |
Incoming messages goes to script stdin, if script failed - messages delivered to mailbox, otherwise (script is ok) - message discarded. On 02/16/2017 04:19 PM, Konstantin Khomoutov wrote:
On Wed, 15 Feb 2017 17:13:31 +0700 Konstantin Shalygin k0ste@k0ste.ru wrote:
Read all about Extprograms, but have a question. Use case: Every day we have couple messages with attachment (from one sender, this is one-way communication). This attachment is uploads to ownCloud. By hand... need some automation. As I see, pipe cat execute scripts with text data USER/FROM/SUBJECT - and I think with variables it can be any text data, how about attachment?
How I see this: script executes and as arg receives from sieve attachment file, or message file and we can parse it for attachment. When we have attachment - upload to ownCloud via RESTapi and purge message.
Found some realization for encrypt messages https://github.com/EtiennePerot/gpgit/blob/master/encmaildir.sh but for me more easy just connect to IMAP and do what I want (but I love sieve). Do you really need Sieve for this?
IMO such things are best handled in the SMTP server:
Set up an alias for the mail address receiving these mails.
Make that alias expand both to its real final destination (an address, mails to which would be delivered to the IMAP folder as before) and to a special "program" entry which looks like "| /path/to/the/external/program".
See
man aliases
[4] for more info.The program is supposed to receive the mail message to its standard input stream and do whatever it wishes with them. For instance, this could be a shell script calling something like
ripmime
[1] on the input, saving the attachments and then calling into whatever would upload them.Note that if the program completed its task OK, it should return with the zero result code. Otherwise it's advised to use one of result codes defined by Sendmail, which are described in [2] and whose exact numeric values could be googled (for instance, see [3]). If your program return a "known" exit code on error, you'll get better diagnostics reported for that failure by your SMTP server.
-- Best regards, Konstantin Shalygin