[MlMt] Rules with variables in them?

Benny Kjær Nielsen mailinglist at freron.com
Mon Oct 31 09:18:37 EDT 2016


On 31 Oct 2016, at 4:10, Patrik Fältström wrote:

> I have one mailbox where I have the name of subfolders in the form of 
> "${#date.month}".
>
> Can I also use that expression in one way or another in the rules?
>
> For example: "Move to folder /x/${#date.year}/${#date.month}"

Not as easily as that (although it would be nice if it were). The 
workaround is to create a bundle command and I've attached an example of 
that. That command can then be used in rules.

> And of course have that folder be created if it does not exist?

That always happens when moving something to a non-existing mailbox.

I should explain the command (since it's undocumented):

~~~
{
	name          = 'Archive to Date';
	environment   = 'MM_FOLDER=${#date.month/-/\\//}\n';
~~~

The `environment` is used to “transfer” a header value to the 
script. In this case a bit of regex is also used to convert `-` to `/`.

~~~
	output        = actions;
	command       = '#!/bin/bash
cat << END
{ actions = ( { type = moveMessage; mailbox = "/Archive/${MM_FOLDER}"; } 
); }
END
';
~~~

The `actions` output type is used when a script needs MailMate to 
perform various actions, e.g., setting tags, moving messages, creating 
new (and possibly send) messages, etc. MailMate expects a property list 
with the wanted actions. The `moveMessage` type requires a `mailbox` 
value. When this value starts with `/` then the mailbox name is 
automatically assumed to be located in the same mailbox as the message 
moved.

~~~
	uuid          = '57A0FF65-7E0B-4853-8355-A4708FD1BC5E';
}
~~~

Note that if you create other commands then the `uuid` *must* be unique. 
You can put such a value on the pasteboard with this snippet for a 
Terminal window:

	uuidgen | tr -d "\n" | pbcopy

Save the attached bundle in this folder:

	~/Library/Application Support/MailMate/Bundles/

Note that it should not be necessary to relaunch MailMate when making 
changes to bundles.

-- 
Benny
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20161031/1d74b690/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Move.mmBundle.zip
Type: application/zip
Size: 2301 bytes
Desc: not available
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20161031/1d74b690/attachment.zip>


More information about the mailmate mailing list