Fine print:
This article assumes that you do have a known-good backup before attempting any of this, and that you are already well-acquainted with working in the "command-line"/Terminal,and that you already know what you're doing in that environment. Proceed at your own risk.
While these instructions are specific to Cyrus
in Mac OS X Server, they should apply (with necessary modifications) to any other OS where Cyrus is the MDA.
If you're considering hosting your own email service(s), or would like support for doing so - please feel free to contact us. There's quite a large number of considerations involved, and while with OS X Server Apple does make it "easy," in many respects, running a server is not like owning a piano: You can't just have it worked a few times a year and forget about its upkeep the rest of the time.
With Cyrus IMAP, you can manually specify the purging of messages in user mailboxes, via ipurge (in the Terminal) - man ipurge for more. You'll find that to be a rather terse manpage, however.
If you wish to purge a specific folder within a user account, you would use - for example (as root in this example) on Mac OS X Server 10.4 (On 10.5 serversubstitute _cyrus for cyrusimap ):
sudo -u cyrusimap /usr/bin/cyrus/bin/ipurge -d 7 -f "user/username/Junk E-mail"
However, you might find that using the above, won't actually purge a number of Junk emails. By default, ipurge will respect the mail header information in those spam messages. If you examine the messages, you'll find that many have a wildly incorrect date - either far in the past or sometime in the future. Possibly intentional, but let's not waste time trying to understand the mind of a spammer.
One way that you can resolve this, is to purge messages instead by working with the date your server received them:
sudo -u cyrusimap /usr/bin/cyrus/bin/ipurge -X -d 7 -f "user/username/Junk E-mail"
That's an upper-case "X" in the above example. Per the ipurge manpage:
" -X Use delivery time instead of Date: header for date matches"
Automating such a process is beyond the scope of this tip, but should be evident to anyone familiar with the items discussed.