Monday, 12 May 2014

Fetchmail IMAP multiple folders and IDLE

 This is more as a reminder for myself than anything the mass public may find useful, but here goes!

I use fetchmail to keep a remote server updated with email from the host system. So I use fetchmail for this, run it in daemon mode and have a config like this:

 

 set daemon 300 set syslog poll myserver.co.uk protocol IMAP username user@myserver.co.uk password mypassword is me@localhost no rewrite keep smtphost localhost 

Pretty simple so far! So I then wanted to pull down the "Junk" folder from the remote server, as I realised mails were getting missed as they got stuck there and I never checked there wasn't something I wanted in there. So I checked and fetchmail has the option to provide multiple folders, in the man pages, web pages, etc, it specified you add 'folder' followed by a comma separated list of the folders you wish to poll. Great, so I tested it, added 'folder inbox' and it identified it was only fetching specific folder 'inbox' I then changed it to 'folder inbox, inbox.junk'

And it failed. It retrieved the first folder, and then stopped. Checking all over I couldn't work it out, man pages appeared correct, in the right section. I tried various different ways of represending it. With quotations, without, spaces, no spaces, multiple lines, etc. And none worked, it always stopped after the first one. I then found a very obsure statement in an online document:

"The ‘idle’ option is intended to be used with IMAP servers..... It also doesn’t work with multiple folders; only the first folder will ever be polled."

Ah, and as I use IDLE the code is obviously just hitting the first folder and stopping (Probably because the code for fetchmail isn't multi-threaded or very smart, it just hits the first thing it finds and sits waiting there on IDLE). So to fix it I set "no idle" in my config, and it works now! (OK, It's a trade-off/performance hit, but I'll have to live with that I guess)

 

No comments:

Post a Comment