0

I use fetchmail with imap protocol to upload emails from a mail server, and pipe them in procmail. I do this with the following command:

fetchmail -f /home/$USER/.fetchmailrc --ssl -t 100 -d 240 -s -m "/usr/bin/procmail /home/$USER/.procmailrc " 

The .fetchmailrc is as follows:

poll imap.my_email_server.com protocol IMAP
user "user@email_server.com" with password "myPassword" is "user@email_server.com" here keep

The .procmailrc is the following :

:0: 
* ^Subject: someSubject
{
  :0 c
  |  $BIN/parse_email
  :0 c
  $HOME/posnav
  :0 
  /dev/null
}

Everything works fine but how can i make the last command (here I push the email to /dev/null just to show the purpose) delete the email on the server from where I have fetched the emails ?

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    Procmail is designed to process local mail. That's also why you need fetchmail in the 1st place. Even an external helper would likely cause issues b/c IMAP expects to operate uninterrupted. Look at other tools. I never used them but maybe [imapfilter](https://github.com/lefcha/imapfilter) & similar? – xebeche Jun 24 '19 at 16:39
  • There is a simple and basically unmaintained tool [`procimap`](https://github.com/tripleee/procimap) which I used for many years, but it inherits some pesky design warts from the code it's forked from, and adds some of its own. Needless to say (because it's already explained in the previous comment) Procmail itself has no capabilities to talk to an IMAP server. – tripleee Jun 25 '19 at 08:26
  • As an aside, saving with `:0c` to one folder only to then deliver to `/dev/null` is rather roundabout. Simply lose the `c` flag on the first delivering recipe instead. – tripleee Jun 25 '19 at 11:16
  • The lock on the braces is also incorrect, and the `c` on the pipe looks highly dubious, though it is of course possible that it is correct if the `parse_email` action is performed for side effects, and cannot be made to also save the messate somewhere. – tripleee Jun 25 '19 at 11:18
  • AFAIK, this is beyond the capabilities of both procmail and fetchmail. What I would do it finding or developping another tool that will receive a list of messages and will connect to the IMAP server (using the .fetcmailrc file to avoid key duplication) and ask for deletion of the messages. – Serge Ballesta Jun 25 '19 at 11:33

1 Answers1

1

If you want to delete the mail on the server, you have to tell fetchmail to do that.

But, you explicitly told fetchmail to keep the message on the server by including the keyword "keep" in the run control file.

Change it to "no keep":

poll imap.my_email_server.com protocol IMAP
user "user@email_server.com" with password "myPassword" is "user@email_server.com" here no keep
Peter
  • 971
  • 8
  • 15