Macro to URI-Encode/Decode String Input?

167 views
Skip to first unread message

Scott Simmons (Secret-HQ)

unread,
Sep 26, 2018, 9:31:17 PM9/26/18
to TiddlyWiki
Hi, all --

What's the TiddlyWay to URI-encode and URI-decode strings for use in macros? I know there's a filter now that do some of that, but what I'd like is the ability to pass in a string via a macro and get back the URI-encoded version, which I could use to set variables to use in building a "mailto:" string.

For example, I have different tiddlers with different (short!) e-mail form-letter skeletons. I want my macro to be able to grab the body of one, URI-encode it, and assemble a URL like:

mailto:jd...@coolexample.com?subject=One%20of%20Several%20Possible%20Subject%20Lines&body=That%20whole%20tiddler%body%from%the%20other%20tiddler%2E

Will I have to venture into the land of JavaScript modules for that?

Mark S.

unread,
Sep 26, 2018, 11:05:32 PM9/26/18
to TiddlyWiki
Since you seem to want to use a template, maybe rather than doing it piece by piece you could do it in once. For instance, if you had a template tiddler:

title: template

Subject: {{!!subject}}
mailto: {{!!to}}
message: When in the course of human events,
it becomes necessary for one people to dissolve


And a tiddler with this code and field contents

subject: Self evident truths 
title: encode example
to: dtrump@whitehouse.gov

<$wikify  name="missive" text="{{||template}}" >
<$list filter="[<missive>] +[encodeuri[]]">
<<currentTiddler>>
</$list>
<$wikify>

Then the output looks like:

TonyM

unread,
Sep 27, 2018, 10:04:38 AM9/27/18
to TiddlyWiki
Mark

Have you taken this all the way to a mailto: link and can you populate the body of the email. I keep hitting buggy walls when I try.

Further I wonder if it could be possible to add an attachment like a tiddler or json file.

I see this as a way for people to contribute content from a modified read only or noteself wiki.

Grasping for straws to make this work.

Regards
Tony

Mark S.

unread,
Sep 27, 2018, 10:08:37 AM9/27/18
to TiddlyWiki
Populate the body of *what* email? Is there some plugin being used in this context? How does the tiddler get transferred to an email?

Thanks!
-- Mark

@TiddlyTweeter

unread,
Sep 27, 2018, 12:26:26 PM9/27/18
to TiddlyWiki
There needs to be some step to pass it to the browser to invoke email. Encoding is only step 1.

A long time ago Riz & Thomas Elmiger did a bunch of work on this (for me [i'm feeling guilty still  for that effort by them that I could not reciprocate]) that works well. I could maybe give more detail if I know its worth the effort for me to dig the details out.

Josiah

Thomas Elmiger

unread,
Sep 27, 2018, 1:44:05 PM9/27/18
to TiddlyWiki
Well, Josiah, if you format a link like Scott does in the first post, the magic is already there: when the browser receives a click on a mailto-link, it asks the computer for the email program to hand over everything that follows.

Cheers,
Thomas

Mark S.

unread,
Sep 27, 2018, 5:39:28 PM9/27/18
to TiddlyWiki

Following TiddlyTweeters comments, I think I see what you're doing. The attached should build a link (tiddler encode-example), that when clicked will bring up your email client with the fields filled. The subject and to fields come from fields in the encode-example, and the body comes from tiddler "body" (it needs it's own tiddler because of the multiple lines).

-- Mark

On Wednesday, September 26, 2018 at 6:31:17 PM UTC-7, Scott Simmons (Secret-HQ) wrote:
mail-link.json

Scott Simmons (Secret-HQ)

unread,
Oct 1, 2018, 11:22:05 PM10/1/18
to TiddlyWiki
That's exactly it, Mark!  Thank you SO much for putting together the example tiddlers.  They demonstrate the idea perfectly, including the concept that was my stumbling block: how to pass my tiddler text through the available filter (uriencode[]) and use the output on the other side to assemble a mailto string.

My original post was made on the run and could have been a little clearer.  Thanks to everyone for digging in and figuring out what I was after.

A little more background for anyone who's curious:  I have a <<mailto>> macro that's pretty generic, but I'm sprucing it up to deploy in a TiddlyWiki where some of the body of the e-mail message will be assembled into a boilerplate message from values found in various fields around the TiddlyWiki but the user will be able to enter a personalized message that appears at the beginning of the body.  The idea is to have an e-mail something like:

Hi, $(recipient)$ —
 
Your package has shipped.

Included:
$(list of items)$
 
$(user's personalized message to the recipient)$

You can track this package online at the $(carrier)$ Web site.  Here's a link:
$(tracking link)$

$(user's signature)$

The computer this will be used on has Microsoft Outlook as its email client, so once I assemble the body, I can uriencode it and pass it the <<mailto>> macro.  Then all the TW user at the computer has to do to send an e-mail is enter the variables into some inputs in the default tiddler and click the mailto link.

Scott Simmons (Secret-HQ)

unread,
Oct 1, 2018, 11:26:57 PM10/1/18
to TiddlyWiki
On Thursday, September 27, 2018 at 12:26:26 PM UTC-4, @TiddlyTweeter wrote:

There needs to be some step to pass it to the browser to invoke email. Encoding is only step 1.

A long time ago Riz & Thomas Elmiger did a bunch of work on this (for me [i'm feeling guilty still  for that effort by them that I could not reciprocate]) that works well. I could maybe give more detail if I know its worth the effort for me to dig the details out.

In my case, the computer where the TiddlyWiki is in use has a standalone e-mail client, which mailto links invoke — so that's easy.

But if you wanted to pass the whole kit & kaboodle to a Web-based e-mail client like Gmail — or directly to an SMTP server — I can imagine that would get to be a pretty big project pretty quickly!

Do you remember what your use case was, Josiah?  (I'm just curious.  Please don't waste a lot of time trying to dig up the old work, as I know you've got other stuff going on.) 

@TiddlyTweeter

unread,
Oct 8, 2018, 1:26:13 PM10/8/18
to TiddlyWiki
Ciao Scott

I have not forgotten this. I'm slow. It may take me some time but I feel there is need to try bring together the various works on this and I will. There has been a lot. Its very fragmented at the moment. I try find time to look at it in the next few weeks and make more of a whole of it so its easier to use and understand.

Best wishes
Josiah

TonyM

unread,
Oct 8, 2018, 6:58:12 PM10/8/18
to TiddlyWiki
Scott,

I am keen to do something familiar but every time I try there are some quirks that cause it to fail. I am trying to build a solution that allows any tiddler or group of tiddlers to be sent as an email using an email address found in a contact tiddler. Marks solution will get me there in the long run. But it can be quite frustrating. In user land they can call this "mail merge" which is an essential extended feature for document and database handling which is something tiddlywiki should excel at. 

Regards
Tony
Reply all
Reply to author
Forward
0 new messages