Skip to content

Instantly share code, notes, and snippets.

@segilbert
Last active December 19, 2015 14:19
Show Gist options
  • Save segilbert/5968297 to your computer and use it in GitHub Desktop.
Save segilbert/5968297 to your computer and use it in GitHub Desktop.
Confluence mailto macro from James Mortimer. Tweaked to remove <br/> from the body before sending to mailto body section to display properly. [Confluence Mailto Macro](https://confluence.atlassian.com/display/DISC/Mailto+User+Macro)
## Check parameters
#if($paramemail && $paramemail.length()>0)
#set($email=$paramemail)
#else
#if($param0 && $param0.length()>0)
#set($email=$param0)
#else
#set($email="[email protected]")
#end
#end
##
#if($paramsubject && $paramsubject.length()>0)
#set($subject=$paramsubject)
#else
#if($param1 && $param1.length()>0)
#set($subject=$param1)
#else
#set($subject="WIKI")
#end
#end
##
#if($paramalias && $paramalias.length()>0)
#set($alias=$paramalias)
#else
#if($param2 && $param2.length()>0)
#set($alias=$param2)
#else
#set($alias="Send $subject email to $email.")
#end
#end
#if($paramlinedatabefore && $paramlinedatabefore.length()>0)
#set($linedatabefore=$paramlinedatabefore)
#else
#if($param2 && $param2.length()>0)
#set($linedatabefore=$param2)
#else
#set($linedatabefore="")
#end
#end
#if($paramlinedataafter && $paramlinedataafter.length()>0)
#set($linedataafter=$paramlinedataafter)
#else
#if($param2 && $param2.length()>0)
#set($linedataafter=$param2)
#else
#set($linedataafter="")
#end
#end
#if(!$paramshowIcon || $paramshowIcon=="true")
#set($emailIcon=' <sup><img class="rendericon" src="/images/icons/mail_small.gif" height="12" width="13" align="absmiddle" alt="" border="0"/></sup>')
#else
#set($emailIcon="")
#end
##
#set($showBody="true")
#if($paramshowBody)#set($showBody=$paramshowBody)#end
##
## Get a newline character
#set($newline="")
#set($newline=$newline.format('%n',null))
##
## Remove leading and training newlines and returns
#set($body=$body.replaceAll("^(${newline}|\r)*",""))
#set($body=$body.replaceAll("(${newline}|\r)*$",""))
##
## Append a link to the current page to email body (just in the message, not the display)
#if(!$paramappendLink || $paramappendLink=="true")
#set($bodymsg="${body}${newline}$action.getGlobalSettings().getBaseUrl()$content.getUrlPath()")
#else
#set($bodymsg=$body)
#end
##
## URL Encode parameters
#set($emailEnc=$webwork.urlEncode($email))
#set($subjectEnc=$webwork.urlEncode($subject))
#set($bodyEnc=$bodymsg)
#set($bodyEnc=$bodyEnc.replaceAll("<br/>"," "))
#set($bodyEnc=$webwork.urlEncode($bodyEnc))
##
## pluses are not used for spaces in mailto: encoding
#set($subjectEnc=$subjectEnc.replaceAll("[+]","%20"))
#set($bodyEnc=$bodyEnc.replaceAll("[+]","%20"))
##
##
#set($url="mailto:$emailEnc?Subject=$subjectEnc&Body=$bodyEnc")
##
## Output
##
<p>$linedatabefore <span class="nobr"><a href="$url">${alias}${emailIcon}</a></span> $linedataafter</p>
#if($showBody=="true")
## insert newlines into html versions
#set($body=$body.replaceAll(${newline},"</br>"))
<div class="panel">
<div class="panelContent">
<b>$subject</b></br>
$body
</div>
</div>
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment