I use the IMAP command PEEK with a list of uids to get the sizes.  That requires a list of message-ids to start with.  So, I grab all the message-ids and then peek at them to figure out if any of them are too big.