in reply to how to detect an email ?

Hello

It really depends on your environment.

You can do that:

all this untested (except Net::IMAP::Simple actually that I've been using to pull emails from imap mailboxes once in a while).

good luck and should you need clarifications please be more detailled in youre requirements