Now it also works when receiving messages over SMTP. Still need to eliminate dupes.