Re: sitebricks mail

71 views
Skip to first unread message

Dhanji R. Prasanna

unread,
Aug 10, 2012, 8:06:34 PM8/10/12
to Bob Mancarella, google-s...@googlegroups.com
[+sitebricks-list]


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();
final MailClient client = mail.clientOf("imap.gmail.com", 993).prepare(Mail.Auth.SSL, "mym...@gmail.com", "mypw");
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


Dhanji R. Prasanna

unread,
Aug 10, 2012, 8:07:50 PM8/10/12
to Bob Mancarella, google-s...@googlegroups.com
Try registering a DisconnectListener on connect() and listen for the idleStart() event. Once this is fired you know it is idling.


Oops, this should be "idled()" not "idleStart()"

eriol....@gmail.com

unread,
Feb 25, 2015, 10:57:39 AM2/25/15
to google-s...@googlegroups.com, bob...@gmail.com
On Saturday, August 11, 2012 at 2:07:50 AM UTC+2, dhanji wrote:
> Try registering a DisconnectListener on connect() and listen for the idleStart() event. Once this is fired you know it is idling.
>
>
>
>
>
> Oops, this should be "idled()" not "idleStart()"

I got the same implementation, and it worked, but on disconnect listener, Im getting unidled fired, not sure how to start idle again from there? Or there is some other procedure to start it?

Dhanji R. Prasanna

unread,
Feb 25, 2015, 11:23:05 AM2/25/15
to google-s...@googlegroups.com, bob...@gmail.com
You will need to call watch() for IDLE to start. Remember that the server can disconnect IDLE at any time (usually every 30 minutes). 

And when IDLING you can't do other things. So when your receive notifications during IDLE, you should call unwatch() and perform whatever fetches you need and then call watch() again to resume IDLEing.

Hope this makes sense. 
Dhanji.

--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebricks+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dhanji R. Prasanna

unread,
Feb 25, 2015, 11:25:16 AM2/25/15
to google-s...@googlegroups.com, bob...@gmail.com

Eriol Gjergji

unread,
Feb 25, 2015, 11:30:52 AM2/25/15
to google-s...@googlegroups.com
I understand that, but is there any way to do that procedure from within the disconnect listener, so I dont have to keep a timer or do an infinite loop to check for idle disconnect...

Which is the best practice for doing it?

--
You received this message because you are subscribed to a topic in the Google Groups "Google Sitebricks" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-sitebricks/2QLs8rEA8hs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-sitebri...@googlegroups.com.

Dhanji R. Prasanna

unread,
Feb 25, 2015, 11:35:32 AM2/25/15
to google-s...@googlegroups.com
Since everything is async you need to do some fancy dancing here:

- connect()
- watch()
   - on receiving idled() you know IDLE has started
   - on receiving exists()/expunge()
      - unwatch()
      - open()/fetch()/whatever
      - watch()

I would wire up your client to the disconnect listener so you can signal that new messages have arrived and it can do the unwatch/fetch/watch sequence.

To unsubscribe from this group and all its topics, send an email to google-sitebricks+unsubscribe@googlegroups.com.

Eriol Gjergji

unread,
Feb 25, 2015, 11:36:28 AM2/25/15
to google-s...@googlegroups.com
I see now, makes sense

To unsubscribe from this group and all its topics, send an email to google-sitebri...@googlegroups.com.

Eriol Gjergji

unread,
Feb 26, 2015, 9:10:43 AM2/26/15
to google-s...@googlegroups.com
Is there a method where I can check for oauth2 token if its expired?

Dhanji R. Prasanna

unread,
Feb 26, 2015, 11:19:22 AM2/26/15
to google-s...@googlegroups.com
Not really, login is the only way right now.

To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebri...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages