I'm looking for a way to select a group of messages and have all of their MIME attachments extracted and saved into a specified folder.

I assume that I can mark the messages with the target mark ('*'), and use 'wl-summary-target-mark-set-action' to specify an action to run on each of these marked messages. However, I don't know what action will save all MIME attachments in any given message.

I have searched through the wanderlust docs, but I couldn't find anything. If this info is documented somewhere, could someone point me to it?

I don't think this is possible without writing up custom code. There may be many attachments in each message of all different types. The leading source that everyone seems to copy for the wl-init has (I think) an example for multiple attachments in one message. I have written my own single message which has the attachment regexp that I commonly deal with -- pdf, jpeg, etc. Sometimes people attach signature images, so you'd end up snaring those as well. Some are in-line text, so you'd need to deal with that. I'd say start with one message and then expand your answer to multiple messages.
– lawlistApr 6 '17 at 1:28

Thank you. I'm glad to write my own code and to make use of a regex for selecting the attachments. I don't know what that leading source for wl-init is. Would you be willing to point me to a reference to it?
– HippoManApr 6 '17 at 2:37

2 Answers
2

I briefly Googled, but did not find an example of a multiple file extract function that I thought I had once read somewhere. I only found a multiple attach example. Here is a simplified version of what I use in my own-setup -- I like to check for an existing file with the same name as I extract all files from a single message, and if there is none, then I just keep hitting the return key -- the additional advantage is that I can change the file name if I so choose. I would recommend perfecting a custom solution for single messages, and then expand the answer to include multiple messages:

Yes, I couldn't find anything via googling, either. Thank you for this! It's much more than I expected. Also, I thought of another way to approach this. It's a variation of what I did under mu4e for the same purpose: just write a function to save the text of each marked message in a temporary directory, and then fire off a python script to read the message files to extract the attachments I'm interested in and then delete the temp directory. I actually have a python script already written which does most of that. So now, I have two possible approaches to explore.
– HippoManApr 6 '17 at 2:53

I managed to do this by means of my second proposed method: copying the marked emails to files in a temp directory, and then processing these files via an external python program: "/usr/local/bin/wl-image-process", in this case.

The python program opens each message file and parses it using python's "email" package. It traverses the list of message parts for the multipart message, and if any of the items are of MIME types that I'm interested in (images), it processes them.