in reply to Piping input as an option

Unless you're explicitly closing STDIN before executing the script you'll always have a readable STDIN.

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