Implement "scan"

This isn't perfect yet: for example, it doesn't look up names in the
address book, and it doesn't allow the folder to be picked, but I
think aside from that it more or less works.

"scan" is the only program that looks at the SQL cache of
subject/from/date sort of things, so I figured it would be a decent
test...