I would like to be able to read incoming mail from a Postfix MTA using a shell script. The shell script should be able to retrieve the mail headers, subject, body, attachments, etc., then mark the mail as read. The messages are stored in the Maildir/ format. When a mail is read in Postfix, it's moved from the Maildir/new folder to the Maildir/cur folder which is helpful to retain as a backup in case a message needs to be reprocessed.
I have googled this extensively but haven't found anything helpful, plenty of examples of how to send mail, but nothing useful to read mail through a script. The mail/mailx command only seems to allow interactive access, there doesn't appear to be an option to use it through a shell script. This only needs to work for one user, since I am using a catchall configuration to catch all incoming mail into a single mailbox, for subsequent processing by the script.
There's always the option of polling the Maildir/new folder for incoming messages using a cronjob or incron but I it would be nice to use Postfix's mail management capabilities as opposed to manually managing the msg files. My script will be local to the Postfix server.
Any suggestions/ideas? thanks.
Edit: Maybe I should mention that I'm not looking for help with the script. I'm looking for some command line tool that can access Postfix Maildir/ msg store and read/do stuff with the msgs and can be invoked in a non-interative manner. In other words basic functionality of the mail tool, but non-interactive.