Extract multiple attachments from eml via Hazel & shell script?

Hi all,

I am recently exploring the option to switch from Apple Mail to MailMate. Getting used to it is a little bit of a challenge, but I’m getting there and really like it. I do have a little problem, though. Here’s the story:

I am trying to accomplish the automated saving of attached pdfs (kind of an evergreen topic). Initially I saw the “Export to folder” command and thought:“Nice, this is much easier than in Mail”. However, it doesn’t save the attachments itself but rather the whole message as EML. Makes kind of sense if you think about it.

After exploring mailmate, it’s integrated bundles and all of the available bundles on Github and running some searches on the mailing list, I tried extracting the attachments with Hazel. After some more searching and digging stackoverflow brought me this:

perl -MMIME::Base64 -ne 'print decode_base64($_)' < file.eml > out.pdf

It works (Yay :)) but it only extracts the first PDF within an EML file. Since writing my own Bundle is above my current capabilities I think I’d like to go with the Hazel route but fail to implement the above command with some sort of “please, for each attachement in EML file run the magic command” rule.

Can anyone help me, or nudge me in the right direction?

Thanks in advance and all the best,
Patrick