Skip to content


Subversion checkout URL

You can clone with
Download ZIP


How are folders distinguished from mailboxes? #24

vonHabsi opened this Issue · 6 comments

4 participants


I have been trying out imapfilter and tried some code I found on a blog at

The code prints out the mailboxes and the folders.

-- Inbox information

-- Get and print available mailboxes and folders
mailboxes, folders = account1:list_all()

When I run the code top level folders without sub folders are not listed as folders, but they are listed as mailboxes. When I create a new folder it does not appear in the folder listing until I create a sub folder under it, but it it is listed as a mailbox. Is this a feature of IMAP I am unfamiliar with, or does it depend on the type of IMAP server it is connecting to?


This can depend on the server, so it can be different based on how each server implements its folders and mailboxes. So for example one IMAP server might allow folders to have messages but another might not. There are two mailbox/folder attributes to control this, the \NoSelect for folders that can't have messages, and the \Noinferiors for folders/mailboxes that can't have sub-folders.

In addition there is the IMAP CHILDREN extension that introduces the \HasChildren and \HasNoChildren flags to help figure out which folder has sub-folders. All those features are supported by imapfilter in order to produce a list of folders and mailboxes.

In you case you could run imapfilter with the -d option and copy paste the results of the LIST commands here, in order to double check that imapfilter does the right thing. Maybe there's a but in there...


Thanks - I will look it up and get back to you

@lefcha lefcha closed this
mailboxes, folders = account1:list_all()

throws an error for me, namely:

imapfilter: /Users/me/.imapfilter/config.lua:62: attempt to call field 'foreach' (a nil value)
stack traceback:
    [C]: in function 'foreach'
    /Users/me/.imapfilter/config.lua:62: in main chunk

The Lua table module doesn't have a foreach() method, so this is an invalid call. Basically that's what Lua is telling you, that you're trying to call a nil value, ie. a non-existent method.

Try something like this:

mailboxes, folders = account1:list_all()
for _, m in ipairs(mailboxes) print(m) end
for _, f in ipairs(folders) print(f) end

Thanks, that's exactly what I figured, so I was confused how it worked for the OP. Maybe he has some other extensions installed.


@lefcha After compiling/installing a newer version of Lua (that is 5.2.Something), I came across the same problem as the one @LMariachi reported. I switched from foreach to ipairs. It works. However, the code lines mentioned above should be like:

mailboxes, folders = account1:list_all()
for _, m in ipairs(mailboxes) do print(m) end
for _, f in ipairs(folders) do print(f) end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.