最开始的java代码如下 import java.io.UnsupportedEncodingException; import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Folder; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Store; import ce.mail.models.ConnectionProfile; public class ImapProtocolImpl extends Authenticator implements Protocol { private Session session; private PasswordAuthentication authentication; public ImapProtocolImpl(ConnectionProfile profile, String username, String password) { Properties props = new Properties(); props.setProperty("mail.store.protocol", profile.getProtocol()); props.setProperty("mail.imap.host", profile.getFetchServer()); props.setProperty("mail.imap.port", profile.getFetchPort()); authentication = new PasswordAuthentication(username, password); session = Session.getInstance(props, this); } @Override public PasswordAuthentication getPasswordAuthentication() { return this.authentication; } public void connect() { try { Store store = session.getStore(); store.connect(); Folder root = store.getDefaultFolder(); Folder inbox = root.get