Example usage for org.apache.commons.net.pop3 POP3SClient login

List of usage examples for org.apache.commons.net.pop3 POP3SClient login

Introduction

In this page you can find the example usage for org.apache.commons.net.pop3 POP3SClient login.

Prototype

public boolean login(String username, String password) throws IOException 

Source Link

Document

Login to the POP3 server with the given username and password.

Usage

From source file:ob.PO.TaskPO.java

@Override
public void run() {
    setTaskLog("");
    if (thistype == 0) {//
        Date tasktime;/*from  ww w.  j a  v  a2 s .  c  o m*/
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); //????
        try {
            tasktime = sdf.parse(thisstr1 + thisstr2);
            //if(cl.)
        } catch (ParseException ex) {
            setTaskLog("");
            return;
        }
        Date nowtime = new Date();
        if (nowtime.after(tasktime)) {
            setTaskLog("??");
            return;
        }
        while (nowtime.before(tasktime)) {
            long deltaminute = (tasktime.getTime() - nowtime.getTime()) / (1000 * 60); //
            long day = deltaminute / (24 * 60);
            long hour = (deltaminute / 60) % 24;
            long minute = deltaminute % 60;
            setTaskLog("\n" + day + "" + hour + "" + minute
                    + "");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
                setTaskLog("");
                return;
            }
            nowtime = new Date();
        }
        if (nowtime.getTime() - tasktime.getTime() > 60 * 1000) {//?
            setTaskLog("?");
            return;
        }
        setTaskLog("");
    } else if (thistype == 1) {//
        int lastmessage_num = -1;
        POP3SClient pop3 = new POP3SClient(true);
        POP3MessageInfo[] messages;
        pop3.setDefaultTimeout(600000);
        while (true) {
            try {
                pop3.connect("pop." + thisstr1.split("@")[1]);//pop. + domain
                if (!pop3.login(thisstr1, AESUtil.Decryptor(thisstr2))) {
                    pop3.disconnect();
                    setTaskLog("?.");
                    return;
                }
                messages = pop3.listMessages();
                if (lastmessage_num < 0) {//?
                    lastmessage_num = messages.length;//?
                    setTaskLog("?" + lastmessage_num);
                } else if (lastmessage_num < messages.length) {//
                    break;
                }
                setTaskLog("?" + messages.length);
                Thread.sleep(10000);
            } catch (Exception ex) {
                setTaskLog("");
                return;
            }
        }
        setTaskLog("");
    } else if (thistype == 2) {//?
        setTaskLog("??");
        while (true) {
            try {
                String Access_token;
                if ((Access_token = Sina.getToken(thisstr1, AESUtil.Decryptor(thisstr2))
                        .getAccessToken()) == null) {
                    setTaskLog("???");
                    return;
                }
                String lasttimeline = GetUserTimeline.getTimeline(Access_token);
                if (lasttimeline == null) {
                } else {
                    if (lasttimeline.contains(thistext)) {//?
                        break;
                    }
                }
                setTaskLog("??");
                Thread.sleep(10000);
            } catch (Exception ex) {
                ex.printStackTrace();
                setTaskLog("??");
                return;
            }
        }
        setTaskLog("???");
    }
    if (thattype == 1) {//?
        setTaskLog("??");
        SimpleEmail email = new SimpleEmail();
        Properties props = new Properties();
        String user, pass;
        try {
            props.load(
                    Thread.currentThread().getContextClassLoader().getResourceAsStream("adminmail.properties"));
            if ((user = (String) props.get("user")) == null || (pass = (String) props.get("pass")) == null) {
                setTaskLog("?");
                return;
            }
            email.setHostName("smtp." + user.split("@")[1]);//?  smtp. + domain
            email.setAuthentication(user, pass);//smtp????  
            email.setSSLOnConnect(true);
            email.addTo(thatusername, "JAVA IFTTT RECEIVER");//  
            email.setFrom(user, "JAVA IFTTT SENDER");//?  
            email.setSubject("JAVA IFTTT SEND EMAIL");//  
            email.setCharset("UTF-8");//??  
            email.setMsg(thattext);//  
            email.send();//??  
        } catch (Exception ex) {
            setTaskLog("??");
            return;
        }
        setTaskLog("????");
    } else if (thattype == 0) {//??
        setTaskLog("???");
        try {
            String Access_token;
            if ((Access_token = Sina.getToken(thatusername, AESUtil.Decryptor(thatpassword))
                    .getAccessToken()) == null) {
                setTaskLog("???");
                return;
            }
            UpdateStatus.Update(Access_token, thattext);
        } catch (Exception ex) {
            ex.printStackTrace();
            setTaskLog("???");
            return;
        }
        setTaskLog("?????");
    }
}