I have a Perl script that uses NET::IMAPClient and MIME::Parser which simply reads new emails from an IMAP server and saves any attachments to disk. My question is: what is the best way to run this script as soon as there's new email? I can use cron to periodically run the script, I could check every few seconds even, but I suspect there is a better way. Ideally I would act upon the receiving of an email immediately, like a system event. What are common software and techniques to achieve this? I'm using a Debian system.
Receiving emails over IMAP and parsing with a script with minimal delay
email;perl;imap
In general you keep checking for e-mail unless, as mentioned by @JoelDavis, the server can be extended with some push command.Further if your e-mail server supports it one can make use of the IDLE extension for IMAP4:http://tools.ietf.org/html/rfc2177http://en.wikipedia.org/wiki/IMAP_IDLEThe IMAPClient has native support for IDLE:http://search.cpan.org/~djkernen/Mail-IMAPClient-2.2.9/IMAPClient.pod#idle