JavaMail: MailBox always lowers the same email

3

I'm downloading emails from Gmail , and saving the ones that are important to my client's system in the database.

The problem is when I use the code below, it always returns me the same emails, getting duplicitous.

Has anyone ever gone through this?

Code:

try {
    System.out.println("asdasdasd");
    // create properties field
    Properties properties = new Properties();

    properties.put("mail.pop3.host", host);
    properties.put("mail.pop3.port", "995");
    properties.put("mail.pop3.starttls.enable", "true");
    Session emailSession = Session.getDefaultInstance(properties);

    // create the POP3 store object and connect with the pop server
    Store store = emailSession.getStore("pop3s");

    store.connect(host, user, password);

    // create the folder object and open it
    Folder emailFolder = store.getFolder("INBOX");
    emailFolder.open(Folder.READ_ONLY);

    Message[] messages = emailFolder.getMessages();
    System.out.println("messages.length---" + messages.length);

    for (int i = 0, n = messages.length; i < n; i++) {
        Message message = messages[i];
        System.out.println("---------------------------------");
        System.out.println("Email Number " + (i + 1));
        System.out.println("Subject: " + message.getSubject());
        System.out.println("From: " + message.getFrom()[0]);
        System.out.println("Text: " + message.getContent().toString());
        System.out.println(message.getLineCount());

    }

    // close the store and folder objects
    emailFolder.close(false);
    store.close();

} catch (NoSuchProviderException e) {
    e.printStackTrace();
} catch (MessagingException e) {
    e.printStackTrace();
} catch (Exception e) {
    e.printStackTrace();
}
    
asked by anonymous 19.08.2015 / 20:44

0 answers