01: package org.claros.intouch.webmail.adapters;
02:
03: import java.io.PrintWriter;
04: import java.util.List;
05:
06: import javax.mail.Message;
07:
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10: import org.claros.intouch.webmail.services.ImapIdleCheckService;
11:
12: /**
13: *
14: * @author umut
15: *
16: */
17: public class IdleOutputThread extends Thread {
18: private static Log log = LogFactory.getLog(IdleOutputThread.class);
19:
20: private PrintWriter out;
21: private String username;
22:
23: public IdleOutputThread() {
24: super ();
25: }
26:
27: public IdleOutputThread(PrintWriter out, String username) {
28: super ();
29: this .out = out;
30: this .username = username;
31: }
32:
33: public void run() {
34: while (true) {
35: try {
36: List notices = IdleMessageCountAdapter
37: .getNotices(username);
38: if (notices != null) {
39: Message tmp = null;
40: for (int i = 0; i < notices.size(); i++) {
41: tmp = (Message) notices.get(i);
42: if (out == null) {
43: ImapIdleCheckService.removeListener(
44: username, "INBOX");
45: break;
46: }
47: out.print("alert('" + tmp.getMessageNumber()
48: + ":" + tmp.getSubject() + "');");
49: out.flush();
50: }
51: IdleMessageCountAdapter.resetUserNotices(username);
52: }
53: out.print(";");
54: out.flush();
55: Thread.sleep(4000);
56: } catch (Throwable t) {
57: log.warn(t);
58: }
59: }
60: }
61:
62: }
|