Smarter eMailMacro

4 views
Skip to first unread message

BenJam

unread,
Dec 27, 2007, 10:45:51 AM12/27/07
to TiddlyWiki
Guys

I'm looking for something a little different to the eMail macro from
FND over at http://devpad.tiddlyspot.com/#eMailMacro.

Was wondering if there's anything in existence that will enable to me
mail a linked tiddler i.e. not the tiddler currently containing the
email link (i put it in as a good old <<button>> instead of in the
global viewTemplate. At the moment I'm sending email links with the
<<email [to: blah]>> content included, and it looks a bit
embarrassing!

Apologies if this is an RTFM case as I'm on the new side to JS and TW.

Eric Shulman

unread,
Dec 27, 2007, 11:43:50 AM12/27/07
to TiddlyWiki
> I'm looking for something a little different to the eMail macro from
> FND over athttp://devpad.tiddlyspot.com/#eMailMacro.
>
> Was wondering if there's anything in existence that will enable to me
> mail a linked tiddler i.e. not the tiddler currently containing the
> email link (i put it in as a good old <<button>> instead of in the
> global viewTemplate. At the moment I'm sending email links with the
> <<email [to: blah]>> content included, and it looks a bit
> embarrassing!

If you use the [[ViewTemplate]] technique (as suggested in Fred's
documentation), you can make 'email' a toolbar command for every
tiddler. That would eliminate the need to embed the <<email>> macro
directly into any specific tiddler source, so that source could be
sent without the also containing the macro itself.

Then again, if you really only want the ability to email a specific
tiddlers, you *must* embed the <<email>> macro in the tiddler
content... which means the macro gets sent as part of the email
message... which is where you find yourself now.

So... what to do?

The only thing that comes to mind is to tweak the plugin code so that
the stored tiddler source can be filtered before constructing the
"mailto:" URI output to remove any embedded occurences of the
<<email>> macro.

something like this:
msgBody = msgBody.replace(/\<\<email(.*|\n)?\>\>/gi,"");

If Fred concurs, then perhaps he will add this line to his plugin...
if not... I suggest using the [[ViewTemplate]] method that he has
already provided, rather than creating a variant plugin. However, if
you DO choose to modify the plugin yourself, please make sure to give
your variant plugin a different tiddler name, so that it doesn't get
confused with Fred's original version when you share your document
with others.

HTH,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

FND

unread,
Dec 27, 2007, 12:16:06 PM12/27/07
to Tiddl...@googlegroups.com
> Was wondering if there's anything in existence that will enable to me
> mail a linked tiddler

The eMailMacro could be extended with an optional parameter for
specifying a target tiddler (instead of using the originating tiddler).
However, to be quite frank, I don't really feel like looking into that
right now - especially because there's a workaround (see below).

> At the moment I'm sending email links with the <<email [to: blah]>>
> content included, and it looks a bit embarrassing!

Oddly enough, on my machine here (using Firefox and Thunderbid on
Windows XP), such macro calls show up only as "< >" in the output.
I'm not entirely sure why that happens (and not sure I care... ).

> tweak the plugin code so that the stored tiddler source can be
> filtered before constructing the "mailto:" URI output to remove any
> embedded occurences of the <<email>> macro.

That's a nice idea, Eric - done (updating the macro to v0.95):
http://devpad.tiddlyspot.com/#eMailMacro

Please let me know whether that works for you, Ben.


-- F.

FND

unread,
Dec 27, 2007, 12:50:49 PM12/27/07
to Tiddl...@googlegroups.com
Two more changes (keeping the version number at 0.95 though):

First, I've renamed the new parameter from "hideMacro" to "filterMacro"
(I guess that's more appropriate).

Second:

> Oddly enough, on my machine here (using Firefox and Thunderbid on
> Windows XP), such macro calls show up only as "< >" in the output.
> I'm not entirely sure why that happens (and not sure I care... ).

Okay, so I did care - at least a bit. A quick Google search led me to
this blog posting:
http://tinyurl.com/2w8j4s
(http://lunarmedia.com/blogs/lunarmedia_blog/archive/2006/10/23/120405.aspx)

I've updated the macro to use that function - now the output contains
the macro calls on my setup as well (provided I don't specify the
filterMacro parameter, of course).
Let's hope this didn't ruin anything in the process (the whole escaping
business is not exactly my specialty)...


-- F.

klinuxer

unread,
Dec 27, 2007, 7:09:56 PM12/27/07
to Tiddl...@googlegroups.com
to send the contends of another tiddler you could extend FND's tiddler this way:

var label = getParam(prms, "label") || "e-mail";
var tooltip = getParam(prms, "tooltip") || "e-mail this tiddler";
var btnClass = getParam(prms, "class") || "button";
//get the title of the tiddler with the text or take title of currently tiddler
var tiddlerTitle = getParam(prms, "tiddler") || tiddler.title;
//get the text of the tiddler
var tiddlerText = store.getTiddler(tiddlerTitle).text;
var msgTo = getParam(prms, "to");
var msgCC = getParam(prms, "cc");
var msgBCC = getParam(prms, "bcc");
var msgSubject = getParam(prms, "subject");
var filterMacro = getParam(prms, "filterMacro");
// retrieve tiddler contents
if(!msgSubject) {
msgSubject = entitify(escape(tiddler.title));
}
var msgBody = (filterMacro == "true") ?
tiddlerText.replace(/\<\<email(.*|\n)?\>\>/gi, "") : tiddlerText;

Eric Shulman

unread,
Dec 27, 2007, 9:24:07 PM12/27/07
to TiddlyWiki
> var tiddlerText = store.getTiddler(tiddlerTitle).text;

If the specified tiddler does not exist, getTiddler() returns NULL,
and the above line of code will cause an error (e.g., "object has no
properties").

Instead, you should use the core function:

var tiddlerText = store.getTiddlerText(tiddlerTitle,"default text");

which incorporates a check to make sure the tiddler exists. Then, if
the tiddler doesn't exist, getTiddlerText() tries to retrieve fallback
content from a *shadow* definition (hard-coded into the core or
defined by a plugin). If there is no shadow definition either, then
the 2nd param (i.e., "default text") is returned as a final fallback
result.

BenJam

unread,
Dec 28, 2007, 5:37:30 AM12/28/07
to TiddlyWiki
Wow, thanks guys, there's plenty there to be getting on with. Right
now I'm trying to mess about with some styling but I'll check back on
it first week of new year.

Thanks again

FND

unread,
Dec 28, 2007, 6:06:19 AM12/28/07
to Tiddl...@googlegroups.com
Okay, so I've updated the macro with a parameter for a target tiddler.

I have also added a default limit (500) for the number of characters
returned from the tiddler body, as well as a parameter to override that
limit.
This is required because there are limits to how long a mailto link may
be. The exact number probably depends on the combination of browser and
e-mail client - so if anyone has some insight on that issue, please let
me know so I can adjust the default limit.

Get v0.96 here:
http://devpad.tiddlyspot.com/#eMailMacro


-- F.

klinuxer

unread,
Dec 28, 2007, 7:43:34 AM12/28/07
to Tiddl...@googlegroups.com
FND,

I think if the URL length is limited so[1], you can add some more characters.

[1]:http://www.boutell.com/newfaq/misc/urllength.html

FND

unread,
Dec 28, 2007, 8:10:30 AM12/28/07
to Tiddl...@googlegroups.com
> I think if the URL length is limited so[1], you can add some more characters.

Thanks; I've raised the limit for to 2000 - and that limit now pertains
to the entire message string (including subject and recipients, though
not the "mailto:" part).

Thanks for the info!


-- F.

BenJam

unread,
Dec 28, 2007, 11:31:25 AM12/28/07
to TiddlyWiki
Thanks F! Will give it a blast monday.

Benjamin...@googlemail.com

unread,
Jan 13, 2008, 4:09:12 PM1/13/08
to TiddlyWiki


On Dec 28 2007, 4:31 pm, BenJam <iphone.ben...@googlemail.com> wrote:
> On Dec 28, 11:06 am, FND <Ace_No...@gmx.net> wrote:
>
> > Okay, so I've updated themacrowith a parameter for a target tiddler.
>
> > I have also added a default limit (500) for the number of characters
> > returned from the tiddler body, as well as a parameter to override that
> > limit.
> > This is required because there are limits to how long a mailto link may
> > be. The exact number probably depends on the combination of browser and
> > e-mail client - so if anyone has some insight on that issue, please let
> > me know so I can adjust the default limit.
>
> > Get v0.96 here:
> >    http://devpad.tiddlyspot.com/#eMailMacro
>
> > -- F.
>
> Thanks F! Will give it a blast monday.

F... for some reason I only get the current tiddler... drat and double
drat! Cant fathom why!?

FND

unread,
Jan 13, 2008, 7:11:43 PM1/13/08
to Tiddl...@googlegroups.com
> for some reason I only get the current tiddler... drat and double
> drat! Cant fathom why!?

I know we've solved this issue via Twitter already - so let's recap:
The problem was my confusing documentation of the macro's parameters,
which led Ben to believe that parameters should to be enclosed in
[single brackets].

Generally, there are four ways to use macro parameters:
* no enclosing: <<foo bar baz>>
* single quotes: <<foo 'bar' 'baz'>>
* double quotes: <<foo "bar" "baz">>
* double brackets: <<foo [[bar]] [[baz]]>>

There's also fifth way, using {{curly brackets}} - those contents are
evaluated though, so they're only used if the parameter value has to be
calculated in some way.

I've updated the wiki with this information:
http://www.tiddlywiki.org/wiki/Macros#Parameters
Feel free to polish these descriptions...


-- F.

Reply all
Reply to author
Forward
0 new messages