<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">On 18 Oct 2017, at 19:03, Benny Kjær Nielsen wrote:</p>
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px">
<p dir="auto">On 17 Oct 2017, at 23:18, Giovanni Lanzani wrote:</p>
<blockquote style="border-left:2px solid #777; color:#999; margin:0 0 5px; padding-left:5px; border-left-color:#999">
<ul>
<li>the attachment (i.e. the invite);</li>
</ul>
</blockquote>
<p dir="auto">This is where you need me to add something to MailMate. I've kind of postponed providing attachments to bundle commands until it was needed, but this is a “chicken or the egg” type of excuse :)</p>
<p dir="auto">I'm thinking this would be some kind of boolean option for bundle commands which would provide paths to all attachments saved as files (maybe optionally filtered by mime type). I'll need a bit of time to think about this.</p>
<p dir="auto">[...]</p>
<p dir="auto">But MailMate is also lacking the ability to let you add an attachment to a reply. This I would also need to add (and I would want to do this not only for the purpose of this bundle).</p>
<p dir="auto">[...]</p>
<p dir="auto">Maybe I should just let you know when the attachments features described above are available? :)</p>
</blockquote>
<p dir="auto">Ok, I've got something for you now in the latest test release of MailMate.</p>
<p dir="auto">First, a <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">*.mmCommand</code> file now recognizes a new key named <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">filesPattern</code>. This is a regular expression which can be used to tell MailMate which parts of an email to match. When iterating through the so-called MIME parts of a message then it keeps track of the hierarchy of MIME types. For example, a plaint text part might be:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">multipart/mixed multipart/alternative text/plain
</code></pre>
<p dir="auto">A pattern matching this would just be:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">text/plain
</code></pre>
<p dir="auto">If one wanted to only make it match when the message is nothing but a plain text part then it would be:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">^text/plain
</code></pre>
<p dir="auto">In your case you just need to add this to the <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">mmCommand</code>:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">filesPattern = "text/calendar";
</code></pre>
<p dir="auto">This results in any <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">text/calendar</code> parts to be saved in temporary files and the paths are provided using <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">MM_FILES</code> in the environment variables. They are passed with some additional information in a JSON array. Here's an example how one could work with that in ruby:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px; color:black" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><span style="color: #93a1a1; font-style: italic">#!/usr/bin/ruby -w</span>
<span style="color: #268bd2">require</span> <span style="color: #2aa198">'json'</span>
<span style="color: #586e75">input</span><span style="color: #657b83">=</span><span style="color: #b58900">ENV</span><span style="color: #657b83">[</span><span style="color: #2aa198">"MM_FILES"</span><span style="color: #657b83">]</span>
<span style="color: #586e75">files</span> <span style="color: #657b83">=</span> <span style="color: #b58900">JSON</span><span style="color: #657b83">.</span><span style="color: #586e75">parse</span><span style="color: #657b83">(</span><span style="color: #586e75">input</span><span style="color: #657b83">)</span>
<span style="color: #586e75">attachments</span> <span style="color: #657b83">=</span> <span style="color: #657b83">[]</span>
<span style="color: #586e75">files</span><span style="color: #657b83">.</span><span style="color: #586e75">each</span> <span style="color: #657b83">{</span> <span style="color: #657b83">|</span><span style="color: #586e75">file</span><span style="color: #657b83">|</span>
<span style="color: #586e75">attachments</span><span style="color: #657b83">.</span><span style="color: #586e75">push</span><span style="color: #657b83">(</span><span style="color: #586e75">file</span><span style="color: #657b83">[</span><span style="color: #2aa198">"filePath"</span><span style="color: #657b83">]);</span>
<span style="color: #657b83">}</span>
</code></pre>
<p dir="auto">You can then parse the calendar file and do whatever is needed. If a reply needs to be generated then you can return a set of actions. This can also be done using JSON (which is a new feature). Here's an example:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px; color:black" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><span style="color: #586e75">action</span> <span style="color: #657b83">=</span> <span style="color: #657b83">{</span>
<span style="color: #2aa198">:type</span> <span style="color: #657b83">=></span> <span style="color: #2aa198">"replyMessage"</span><span style="color: #657b83">,</span>
<span style="color: #2aa198">:body</span> <span style="color: #657b83">=></span> <span style="color: #2aa198">"This is a reply including an attachment..."</span><span style="color: #657b83">,</span>
<span style="color: #2aa198">:temporaryAttachments</span> <span style="color: #657b83">=></span> <span style="color: #657b83">[</span> <span style="color: #2aa198">"/path/to/another/text/calendar/file.ics"</span> <span style="color: #657b83">],</span>
<span style="color: #2aa198">:resultActions</span> <span style="color: #657b83">=></span> <span style="color: #657b83">[</span> <span style="color: #657b83">{</span> <span style="color: #2aa198">:type</span> <span style="color: #657b83">=></span> <span style="color: #2aa198">"openMessage"</span> <span style="color: #657b83">}</span> <span style="color: #657b83">],</span>
<span style="color: #657b83">}</span>
<span style="color: #586e75">actions</span> <span style="color: #657b83">=</span> <span style="color: #657b83">{</span> <span style="color: #2aa198">:actions</span> <span style="color: #657b83">=></span> <span style="color: #657b83">[</span> <span style="color: #586e75">action</span> <span style="color: #657b83">]</span> <span style="color: #657b83">}</span>
<span style="color: #268bd2">puts</span> <span style="color: #586e75">actions</span><span style="color: #657b83">.</span><span style="color: #586e75">to_json</span>
</code></pre>
<p dir="auto">Note that <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">temporaryAttachments</code> means that MailMate takes responsibility for deleting the files when it's done with them. Using <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">attachments</code> instead means that MailMate won't delete them.</p>
<p dir="auto">A remaining problem here might be that it's not sufficient to attach the calendar file since that'll result in an email with the following structure:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">multipart/mixed
text/plain
text/calendar
</code></pre>
<p dir="auto">It might not work in other email clients if the structure is not:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7">multipart/alternative
text/plain
text/calendar
</code></pre>
<p dir="auto">This is all work-in-progress.</p>
<p dir="auto">By the way, when working with iCalendar files then note that there's a validator available <a href="https://icalendar.org/validator.html" style="color:#3983C4">here</a>.</p>
<p dir="auto">-- <br>
Benny</p>
</div>
</div>
</body>
</html>