Don't generate mbox links for months where there is no mbox file

This can happen because some emails are in the wrong mbox file based
on their date, so just generating the mbox linked based on which dates
are present in the database can generate extra links.
Support for messageids that contain slashes

Requires changing the order of regexp matching to work, but other than
that it seems safe given the type of URLs we have now.
Add missing import