About my problem with "dovecot crashes on certain spam messages", I have found that deleting the mail it is working on when it crashes just makes it crash on some other message, but deleting .imap.index.* from the directory of the folder in question makes everything good again.