0

What I'm trying to do is to forward all the emails that are stored (moved) into a specific user folder to a predefined email address

e.g.

Any new email stored in /home/mycooluser/mail/spam-mail to be forwarded spamreport@mycooldomain.com.

I'm trying to achieve this with some procmail config the issue is that messages needs to be zipped up and sent as an attachment.

Can anybody shed some light on how I could achieve this?

user3018558
  • 105
  • 1
  • 9

1 Answers1

0

The context in which Procmail runs is when you are in the middle of receiving a new message. Inside your .procmailrc you typically don't know yet where the message you are delivering will be stored, because deciding that is now the job of Procmail. Once it has made the decision, it can be made to perform additional actions; but your requirement to zip a folder seems out of place for this kind of logic. I imagine you don't want to zip and send the whole folder every time one new message is added to it...?

A more natural implementation would be a periodic cron job. Decide how often it needs to run (hourly? nightly?) and have it erase the messages it successfully zips and sends. If there are no messages in the folder since the previous run, obviously don't zip or send anything.

If indeed you do want to use Procmail for this after all, the logic looks something like

:0c
!otheraddress@example.net
:0:
Foldername

If Foldername is a maildir folder, lose the colon after the :0 and adjust the folder name to the correct syntax (maildir folders don't require locking).

! simply forwards without zipping. It's not hard to look up how to also zip but I won't develop this further as I imagine this isn't really what you want or need, as explained above.

tripleee
  • 1,324
  • 3
  • 14
  • 24
  • I think the idea about cronjob is very good! I have edited the OP to remove references to procmail as there are of course multiple way to have this done. As mentioned the real requirement is to pick up messages from the spam-mail folder (one by one) and forward to spamreport. The original message needs to be zipped up so I do agree with you procmail "might" not be the right tool here. – user3018558 Jan 23 '18 at 11:46
  • But then what is your question? Zipping to stdout so you can pipe to `mutt` is covered e.g. here https://stackoverflow.com/questions/18933975/zip-file-and-print-to-stdout – tripleee Jan 23 '18 at 12:37
  • Many thanks for the help! So the requirement would be to zip one by one the messages found in spam-mail (not sure how), forward in attachment (ok with this) and remove both zip (ok) and email (not sure how) once the operation is successful. Thanks! P.s. using mbox. – user3018558 Jan 24 '18 at 11:20
  • I already linked to a resource showing you how to zip and hinted at how to send the resulting archive by email. If you have a *specific* coding problem, maybe ask on [so] with a [MCVE](https://stackoverflow.com/help/mcve) showing how you are stuck. Briefly, `zip mbox | mutt recipient@example.net` probably with some options and then if that was successful, delete the file. If this is a crucial service, take some steps to make sure you never delete anything until the zip is actually delivered to its destination (maybe rename the mbox and expire it only after its a month old, or something?) – tripleee Jan 24 '18 at 11:25
  • See also also https://superuser.com/questions/605090/send-mail-with-an-zip-attached-from-mutt-without-prompt-options – tripleee Jan 24 '18 at 11:29
  • Further googling gets me this: https://serverfault.com/questions/40284/create-virtual-file-from-bash-command-output – tripleee Jan 24 '18 at 11:31