[MlMt] Creating a bundle template for message data, including attachments
leo
mailmate at halloleo.hailmail.net
Sat Oct 9 21:24:05 EDT 2021
Hey Phillip
Just came by accident across your post.
Super cool that you do a lot with bundles - I want to do more with
bundles too:
* I am looking for a bundle/command which saves a message to a
predefined folder without all the folder hierarchy the “Export - Copy
to Folder” command creates.
* Also I would like to have a bundle to to save attachments to an
additional fixed/preset location.
One day…
Happy emailing,
Leo
On 2 Oct 2021, at 2:13, P wrote:
> Hello everyone,
>
> I've been exploring the world of MailMate bundles recently. They are a
> great format for anything to be shared, or for relatively simple
> scripts. However, as some of my scripts have become more and more
> complicated, I've started to find my proliferating .mmcommand and
> executable files a bit unmanageable. Debugging can be particularly
> tricky.
>
> Given that the vast majority of my bundle commands would be of no use
> to anyone besides myself, I'm trying a different strategy: creating a
> simple script to pull out message information and send it to Keyboard
> Maestro in JSON format. Once in KM, it's easy to pass it to whatever
> script or app is needed. I also find it easier to keep everything
> organised this way.
>
> Here's what the .mmcommand file looks like:
>
> ```
> {
> name = 'template';
> input = 'canonical';
> environment =
> 'macro=E61C4928-CE11-460D-ADD9-2B379C1BBB5D\nmsgID=${message-id.split}\nsubjectPrefix=${subject.prefix}\nsubjectBody=${subject.body}\nfromName=${from.name}\nfromAddress=${from.address}\ntoName=${to.name}\ntoAddress=${to.address}\ncontentType=${content-type.type}';
> command = '#!/bin/bash\n"${MM_BUNDLE_SUPPORT}/bin/template"';
> keyEquivalent = '^[';
> uuid = '47d6808e-e6a7-41d9-9d92-d2948423be26';
> }
> ```
>
> And here's the executable:
>
> ```
> #!/bin/bash
>
> tmpFile="$TMPDIR/8D444CFE-C1F9-4F82-AD8B-4EA7EC7A77C2.eml"
> cat > "${tmpFile}"
>
> osascript <<END
>
> tell application "Keyboard Maestro Engine"
> do script "${macro}" with parameter
> "{\"tmpFile\":\"${tmpFile}\",\"msgID\":\"${msgID}\",\"subjectPrefix\":\"${subjectPrefix}\",\"subjectBody\":\"${subjectBody}\",\"fromName\":\"${fromName}\",\"fromAddress\":\"${fromAddress}\",\"toName\":\"${toName}\",\"toAddress\":\"${toAddress}\"}"
> end tell
>
> END
>
> unlink "${tmpfile}"
> ```
>
> As you can see, I put the KM macro ID into the environment variables,
> which allows a single executable file to send the JSONified data to
> any number of macros. I just have to create a new .mmcommand file each
> time.
>
> The variables passed:
>
> tmpFile (full-text of the message)
> msgID
> subjectPrefix
> subjectBody
> fromName
> fromAddress
> toName
> toAddress
>
> It takes a bit of detective work to figure out what the available
> environment variables are but I think I've gotten most of them. The
> one major thing that I've failed to figure out is how to get
> attachments.
>
> In the [bundle
> documentation](https://github.com/mailmate/mailmate_manual/wiki/Bundles#inputfilespattern),
> under "inputFilesPattern," it's mentioned that attachments are
> accessible via the `MM_FILES` environment variable. However, I've
> found only one example of this in use ([by David
> Slochower](https://github.com/slochower/bundles/tree/master/My%20Save.mmbundle)).
> It's written in Python—a language that, unfortunately, I don't know
> very well. Consequently, I'm struggling to see how it works or how it
> could be adapted.
>
> So, long story short, I am wondering if anyone has any other examples
> of getting attachment info from `MM_FILES`, or some advice on how I
> could integrate it into my above-mentioned template.
>
> I know that `MM_FILES` itself provides data in JSON format, which can
> be tricky to parse in AppleScript, but there are several ways around
> that. I just can't seem to get anything from that environment
> variable, which makes me think that I must be missing something.
>
> Many thanks,
>
> Philip._______________________________________________
> mailmate mailing list
> mailmate at lists.freron.com
> https://lists.freron.com/listinfo/mailmate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20211010/dafbb3de/attachment.htm>
More information about the mailmate
mailing list