Hi Thomas,
This looks like a bug. We will file an issue to fix this. In the meantime, you could work around the problem by adding a function that will catch the exception an return an empty string for the url -- something like this:
<#function getMessgeUrl message>
<#local msgUrl = "" />
<#attempt>
<#local msgUrl = message.webUi.url />
<#recover>
</#attempt>
<#return msgUrl />
</#function>
Then call that function in your code
<#if page.context.message??>
<#assign shareTitle= page.context.message.subject />
<#assign href= getMessageUrl(page.context.message) />
<#assign id= page.context.message.id />
<#else>
<#assign shareTitle= env.context.message.subject />
<#assign href= getMessageUrl(env.context.message) />
<#assign id= env.context.message.id />
</#if>
-Doug