Leer correos electrónicos con groovy (Java Mail)

I am using groovy in order to access gmail and read the Inbox. It is regular JavaMail and will not describe it here.

So for simplicity, after I connect to the store, I use this:


 folder.messages.each { msg ->
    doSomething with msg

esto está funcionando bien.

However I have a performance issue. Sometimes messages[] could be big. Some folders contain more than 1000 messages, and checking them all takes time.

I am looking for a quicker way to get only those emails that are the most recent (for example messages from the last 5 days or something like that)

of course I have the date information in each msg and I could do my comparison, but this is not efficient since it will loop through the entire collection.

Is there a better way to get those messages?

preguntado el 09 de enero de 11 a las 04:01

1 Respuestas

If you have JavaMail issue a SEARCH command with the criterion SINCE 04-JAN-2011, you'll get back the set messages in the currently-selected folder delivered since January 4th. (SENTSINCE 04-JAN-2011 will do the same thing, only based on the "Date" message header.)

Algo parecido a esto:

folder.search(new ReceivedDateTerm(ComparisonTerm.GE, sinceDate));

Respondido el 09 de enero de 11 a las 20:01

it worked, thanks a lot, I didn't know this function. There is a noticeable increase in speed, even though I didn't measure it, but it is obvious. Thanks again :-) - albert green

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.