1
votes

I'm trying to get new messages starting from the last saved message id of a folder.

Here's my code so far:

self.imap_connection.examine(folder)
imap_query = "UID SEARCH #{last_uid}:*"
messages = self.imap_connection.search(imap_query)

The only response I'm getting from the IMAP server is: Error in IMAP command received by server.

So, does anyone know the correct "syntax" for the ruby imap library to get the uids ??

Regards, Alex

2

2 Answers

2
votes

Getting all the messages after a certain last fetched UID works for me.

imap_connection.uid_search(["UID", "#{last_fetched_uid + 1}:#{MAX_UID}"])

0
votes

The solution is getting all messages of a folder by it's uid and saving it's seqno(it's an imap field):

imap_connection.uid_search("ALL") 

For getting new mails search using the last saved seqno:

imap_connection.uid_search("#{seqno.to_i}:*")

Searching via the last saved uid did not work for me so I used the last saved seqno and voila.