package ushi.util; import java.util.*; import java.text.*; import javax.mail.*; import javax.mail.internet.*; public class MailPopper { public static final int RECEIVE_OK = 0; public static final int RECEIVE_ERROR_MESSAGING = 1; public static final int RECEIVE_ERROR_PROVIDER = 2; public static final int RECEIVE_ERROR_MISSING_HOST = 11; public static final int RECEIVE_ERROR_MISSING_ACCOUNT = 12; public static final int RECEIVE_ERROR_MISSING_PASSWORD = 13; protected String hostName = null; protected String account = null; protected String password = null; protected MailEntry[] entries = null; public MailPopper(){ } public MailPopper(String hostName, String account, String password){ setHostName(hostName); setAccount(account); setPassword(password); } public void setHostName(String v){ hostName = v; } public void setAccount(String v){ account = v; } public void setPassword(String v){ password = v; } public int receive(){ // 初期設定 Properties props = new Properties(); Session sess = Session.getDefaultInstance(props, null); // 接続 Store store; try { store = sess.getStore("pop3"); } catch(NoSuchProviderException e){ e.printStackTrace(); return RECEIVE_ERROR_PROVIDER; } try { store.connect(hostName, 110, account, password); Folder rootFolder = store.getDefaultFolder(); Folder inbox = rootFolder.getFolder("INBOX"); // これのみ inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages(); // 全部取得 entries = new MailEntry[messages.length]; for(int i=0; i