I use perl Mail::IMAPClient in the manner below in order to get info about emails before they are downloaded.
print "\\tSubject: ".$imap->parse_heade