FileDocCategorySizeDatePackage
EmailChecker.javaAPI DocExample1982Mon Jan 09 11:02:00 GMT 2006None

EmailChecker

public class EmailChecker extends Object implements Runnable

Fields Summary
private JLabel
label
Constructors Summary
public EmailChecker(JLabel label)

        this.label = label;
    
Methods Summary
public synchronized voidcheckEmail()

        String username = "joshy@code.joshy.org";
        String password = "satans";
        String hostname = "code.joshy.org";
        int port = 143;
        
        Properties props = System.getProperties();
        Session sess = Session.getDefaultInstance(props);
        sess.setDebug(true);
        Store store = sess.getStore("imap");
        store.connect(hostname, port, username, password);
        Folder inbox = store.getFolder("INBOX");
        final int new_count = inbox.getUnreadMessageCount();
        
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                //label.setText("You have " + new_count + " unread messages.");
                if(new_count > 4) {
                    label.setFont(new Font("WebDings",Font.PLAIN,40));//label.getFont().getSize()));
                    label.setText(""+(char)0xf099);
                } else {
                    label.setFont(new Font("WingDings",Font.PLAIN,40));//label.getFont().getSize()));
                    label.setText(""+(char)0xf02a);
                }
                System.out.println("unread messages = " + new_count);
            }
        });
    
public static voidp(java.lang.String str)

        System.out.println(str);
    
public voidrun()

        while(true) {
            try {
                checkEmail();
                Thread.currentThread().sleep(1000*60); // sleep 1 min
            } catch (Exception ex) {
                System.out.println("exception: " + ex);
                ex.printStackTrace();
            }
        }