On Sat, Aug 11, 2012 at 3:41 AM, Bob Mancarella wrote:
Hi Dhanji,
I have been looking at the sitebricks code and wondered if you could help me out. It doesn't look like the google group is getting much traffic so I thought i would try you directly. I am just interested in the mail code which I know is your pride and joy. Looking at the code I can say that it looks extremely well done.
Thanks for the nice words--the list is still active.
Yea, we mostly built sitebricks-mail to power Fluent.io when it was going (still being used). Unfortunately we didn't have time to doc it well.
Since I didn't find any documentation for the mail code I was just wondering how to setup a generic IMAP client. I tried this just to start.
Mail mail = new SitebricksMail();
try
{
client.connect();
}
catch (Exception e)
{
e.printStackTrace();
}
ListenableFuture<Folder> future = client.open("Inbox", true);
FolderObserver fo = new FolderObserver()
{
public void changed(SortedSet<Integer> added, SortedSet<Integer> removed)
{
System.out.println("changed!");
}
};
client.watch(future.get(), fo);
boolean idling = client.isIdling();
Login and connect work great. fo is created and watch is called without error. idling is always false and when I send an email to the account it never calls the FolderObserver.
I am sure I am just doing something fundamentally wrong and would appreciate it if you could set me on the right path.
You have to wait for IDLE to be acknowledged by the server (nearly everything in sitebricks-mail is asynchronous/non-blocking; like node.js or EventMachine). You can crank up the logging levels to see what's happening in the background--maybe the folder is not being opened properly?
Try registering a DisconnectListener on connect() and listen for the idleStart() event. Once this is fired you know it is idling.
Thanks,
Bob