1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
buf2 = null;
FetchProfile fp = new FetchProfile();
jTextArea1.setText("");
user = "user";
pass = "pass";
pop = "pop";
props = new Properties();
session = Session.getDefaultInstance(props, null);
store = session.getStore("pop3");
store.connect(pop, user, pass);
folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
Message messages[] = folder.getMessages();
for (int i = 0, n = messages.length; i < n; i++) {
jTextArea1.append(i + ": " + messages[i].getFrom()[0] + "\t" + messages[i].getSubject() + "\n");
statusMessageLabel.setText(i + 1 + " messages pour : " + user);
}
fp.add(UIDFolder.FetchProfileItem.UID);
folder.fetch(folder.getMessages(), fp);
String cle2 = fp.getItems().toString();
cle2 = cle2.substring(cle2.lastIndexOf("@")+1);
buf2.append(cle2);
if(!buf2.equals(buf1)) {
JOptionPane.showMessageDialog(null, " Vous avez un nouveau message ;-) ", "Information", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("mail.png"));
}
else
statusMessageLabel.setText("Pas de nouveaux messages");
buf2 = buf1;
folder.close(false);
store.close(); |