imapfilter icon indicating copy to clipboard operation
imapfilter copied to clipboard

saving messages to a local maildir (AKA one way fetch)

Open rdslw opened this issue 3 years ago • 3 comments

I'd love to have ability to save messages (after usual filtering/selection) to a localdirectory (preferabbly Maildir format).

That would allow usage of imapfilter without offlineimap/mbsync/fetchmail other external tools. Many people simple need to oneway fetch, after imapfilter(ing), so such feature would be nice addition.

Full blown solution would be ability to define account (in addition to account1 = IMAP = {}) as a account2 = MAILDIR = { localdir = /some/path } and then ability to use account2 as a normal account, BUT I think it's too far fetch goal.

Nice small approach would be a simple ability to save messages to a maildir (important: in append mode, as there might be some messages already).

Any thought on it?

rdslw avatar Nov 28 '21 22:11 rdslw

Imapfilter doesn't have any inline support for storing messages to a local format, as it's out of its scope. But thanks to Lua, it can be easily extended to do a lot more things, such as storing messages to whatever mail storage format one desires.

So in theory you could easily implement this with a Lua library such as: https://git.osuv.de/m/lua-maildir

As you mentioned imapfilter can fetch whole messages, so the idea would be to create a few helper functions, that use this library, in order to store the messages locally.

What do you think?

lefcha avatar Dec 11 '21 18:12 lefcha

I am facing a similar problem: each day I need to download one messages that contains a certain attachment from an IMAP server. This is what I found to be useful so far:

results = myimapserver.mymaildir:is_unseen()
for _, message in ipairs(results) do
    mailbox, uid = table.unpack(message)
    attachment = mailbox[uid]:fetch_part('2')
    print (attachment)
end

My idea was that the print command would produce an output to the surrounding shell that could be piped into "munpack" to recreate the original attachment. But, sadly, that does not work like I thought:

munpack: reading from standard input
Did not find anything to unpack from standard input

I know that there are other programs out there, that do exactly what I want to do, but still, I hope that it is possible to do this using imapfilter, because imapfilter is already doing a lot of sorting and moving to my messages, so I wouldn't like having to involve a second program.

wehkah avatar Apr 09 '22 11:04 wehkah

I finally found a solution to this problem, which does not include imapfilter: getmail.

Getmail retrieves mail from an IMAP account and stores it in local files. From there you can use munpack to extract the attachment(s).

wehkah avatar Jun 30 '22 15:06 wehkah

Maybe one day ill find some time do write a PR for it :)

rdslw avatar Jan 09 '23 14:01 rdslw