Yep, learn a programming language. Track logins to a database by modifying the PHP code of your favorite webmail client, then you can "SELECT MAX(logindate) from LOGINS GROUP BY username ORDER BY logindate DESC;", enumerate the record set, and take appropriate action by either keeping the account and removing all messages, or by signal-even user-delete [username] based on the date criteria you specify. You can also refine your SQL statement to use the datediff() function.
Either way, it's something that's going to require some forethought on your part in addition to some level of programming. Embrace it as a learning experience.
Languages required (as I see it):
SQL
PHP
Bash or Perl
mySQL database administration.
Hope this helped,
Nathan