in reply to Piping input as an option
Why don't you provide an option to read from STDIN and if that option isn't specified read from the IMAP server?
See Getopt::Long