Greg Cawthorn writes:
When one of our messaging subscribers receives a new message, we want to send them a Message Waiting Indicator (MWI) notification, which appears as an icon on a mobile phone or a stutter tone on a landline. When the message is read or deleted, we want to be able to clear the MWI from the phone. Since we may have several thousand subscribers per deployment we do not want our application to keep mail store connections open for each mailbox to be notified of new messages or changes to message flags. We are looking for a way to build a server-side agent for Courier that will receive triggers for all such message status changes in all mailboxes, from which we can then fire off a trigger to our application via something like a SOAP call.
Multiple folders in a mailbox, each one of which could have an unread message in it, rather complicates this scenario. I think you're better off monitoring only INBOX for unread messages.
After the scope of your situation is thusly reduced, I can think of a couple of ways to implement something like this. There's nothing in Courier that can do this, but it is not impossible to develop something this for your custom application.
Provided, of course, that you get someone who knows what he's doing, to code it. You need to execute a tiny program after delivering each message, and you also need to modify the IMAP server's code to monitor what's going on in INBOX. This presents a number of race conditions that you need to be aware of, and understand. That's why you should give this job only to someone with message background and experience, who knows what he is doing.
Basically, the message delivery agent needs to send a message to a persistent daemon process: "DELIVERED to mailbox X". And the IMAP server needs will be generating "UNREAD messages in INBOX of X is now n" and "CHECKED for new mail in INBOX, and the number of UNREAD messages in INBOX of X is now n". The persistent daemon handles these messages; updates the state of each X's mailbox internally, and generates the message-waiting events.
The reason you need different kinds of messages from the server, is to properly handle race conditions. An IMAP server does not constantly monitor for new messages in a folder, but only when instructed so. Therefore you can have the mail delivery agent report that it delivered a new message to a folder, you then flip on the MWI bit. Then, the IMAP server reports that it thinks there are 0 unread messages; but it doesn't know about the new message, because it hasn't checked for it.
Again, you need someone with messaging and networking experience, who understands mail protocols, to implement this. It's not impossible, but tricky. And I'm presently employed full time :-)
pgpUaUINXw2wB.pgp
Description: PGP signature
