Google Talk mail notification

Has anybody worked on adding Google Talk mail notification support to Smack? I gathered the information I need to implement it and I just started coding, but it would be great to save myself the trouble if somebody else has working code.

In any case, I’‘ll share it back with the community once I’'m done.

Here is my implementation. It seems to work fine, but the public documentation for this proprietary extension seems to be pretty scarce.

This is how I poll the mailbox after log-in:

/* Let the Google Talk server know that we want to receive mail notifications. Optional, but if performed, you don’'t need to poll the mailbox again (see below) for the duration of this session; the server will send you a notification whenever there is an update. */

GoogleSetting setting = new GoogleSetting();

setting.setTo(StringUtils.parseBareAddress(connection.getUser()));

setting.setType(IQ.Type.SET);

setting.setMailNotificationsEnabled(true);

connection.sendPacket(setting);

// Send a query packet to received the current status of the mailbox.

GoogleMailExtensions.Query query = new GoogleMailExtensions.Query();

connection.sendPacket(query);

I also attach a packet listener to handle new-mail notifications and mailbox responses:

PacketFilter googleMailFilter =

new OrFilter(new PacketTypeFilter(GoogleMailExtensions.Mailbox.class),

new PacketTypeFilter(GoogleMailExtensions.NewMail.class));

connection.addPacketListener(new PacketListener() {…}, googleMailFilter);

Whenever you receive a NewMail instance, you should send a GoogleMailExtensions.Query packet to actually fetch the changes.

Oh, well, I’‘m adding all that to the Javadoc now, but you won’'t find it in the attached patch.
revision4390.diff (18413 Bytes)