I'm not sure about this approach, therefore I'd like comments.
What I see is troubles (duplicate mails, empty remote ids in DB) which has its root cause in timing of messages between mailfilter_agent and maildir_agent.
What this patch does is doing the mail filtering not at the very first point when a new item is added, but only after
the (maildir) resource sets the RID onto the item.
First tests are very promising. I don't get empty RIDs any longer.
I'm not using IMAP. Would this approach work there as well ?