We have an external system which happens to fail from time to time. We don't have direct access to the logs of this system, all we get are daily status mails delivered to our Inbox indicating failure or success. Now what we're trying to achieve is counting failure and success messages to somehow measure reliability.
If we would have access to the logs, this would be fairly easy using grep and wc and that kind. But all we have is a bunch of mails.
Now heres the question: Can somebody come up with way to connect to an imap-server, go to a specific folder, get all messages and count a certain string? (preferably bash, python or perl). We don't expect the exact command. Some ideas to get us started would be great.
I'd use Python and imaplib. This imaplib example connects to a mailbox and retrieves all messages. The message body is available in that loop, so you could do whatever pattern-matching you wanted to on it. You could even just (albeit wastefully) just run this script and use your familiar tools on it. (I say "albeit wastefully" because the example scripts reads all messages in the mailbox every time it runs.)