Here’s an AppleScript that flushes read e-mails and unflagged e-mail from my RSS inbox. It took me quite a while to figure out that AppleScript would also obtain IDs for deleted messages (i.e., non-expunged IMAP ones) and turn what was supposed to be a simple operation into a massive churning of my disk drive as the blubbering idiocy that is Mail.app tried to delete things it had already deleted and fell all over itself.
So I just added the rather nonsensical…
and deleted status = false, and lo, it was massively faster.
Since this doesn’t care about specific messages, it is designed to be activated from the Finder (or via Mail Act-On):
tell application “Mail“ set theMessages to (every message in mailbox “