Mailto Links and Zimbra [How to]
by Dan on Jul.20, 2009, under How To, Tech
I’ve been looking throughout the Internet today looking for ways to get mailto: links to work with Firefox and Zimbra. Since I didn’t want to touch the registry and most of the people here use Macs anyway, I had to make a Greasemonkey script to do the job. Sure, there are already scripts to do this, but they point to the standard interface. I wanted the advanced interface.
First, take this code, put it in a text editor, and change “mail.server.com” to your zimbra server (2 instances).
// ==UserScript==
// @name Mailto Compose In Zimbra
// @namespace http://www.dawnbreaker.com
// @description Rewrites "mailto:" links to Zimbra compose links
// @include *
// @exclude https://mail.server.com
// ==/UserScript==
(function() {
var processMailtoLinks = function() {
var xpath = "//a[starts-with(@href,'mailto:')]";
var res = document.evaluate(xpath, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var linkIndex, mailtoLink;
for (linkIndex = 0; linkIndex < res.snapshotLength; linkIndex++) {
mailtoLink = res.snapshotItem(linkIndex);
//alert(mailtoLink.href);
var m = mailtoLink.href;
var matches = m.match(/^mailto:([^\?]+)(\?([^?]*))?/);
var emailTo, params, emailCC, emailSubject, emailBody;
emailTo = matches[1];
//alert("Found to=" + emailTo);
params = matches[3];
if (params) {
var splitQS = params.split('&');
var paramIndex, param;
for (paramIndex = 0; paramIndex < splitQS.length; paramIndex++) {
param = splitQS[paramIndex];
nameValue = param.match(/([^=]+)=(.*)/);
if (nameValue && nameValue.length == 3) {
// depending on name, store value in a pre-defined location
switch(nameValue[1]) {
case "to":
emailTo = emailTo + "%2C%20" + nameValue[2];
break;
case "cc":
emailCC = nameValue[2];
//alert("Found CC=" + emailCC);
break;
case "subject":
emailSubject = nameValue[2];
//alert("Found subject=" + emailSubject);
break;
case "body":
emailBody = nameValue[2];
//alert("Found body=" + emailBody);
break;
}
}
}
}
mailtoLink.href = "https://mail.server.com/zimbra?app=mail&view=compose" +
(emailTo ? ("&to=" + emailTo) : "") +
(emailCC ? ("&cc=" + emailCC) : "") +
(emailSubject ? ("&subject=" + emailSubject) : "") +
(emailBody ? ("&body=" + emailBody) : "");
// mailtoLink.onclick = function() { location.href = newUrl; return false; };
}
}
window.addEventListener("load", processMailtoLinks, false);
})();
Then paste the code into the generator here: http://arantius.com/misc/greasemonkey/script-compiler
Leave the GUID as it is, change the max version to 3.5.* and then add anything else you might want.
Compile the script and then install the .xpi file into firefox.
July 20th, 2009 on 4:50 pm
I should have taken “computer” as my second language instead of French…
July 20th, 2009 on 4:55 pm
Well.. I run into a lot of problems at work with software and such and I always want to record them and post the solutions online. I’ve already passed this link on to a bunch of people and its already being used.
July 20th, 2009 on 10:12 pm
Thank you, this is brilliant and fantastic.
Jane G´s last blog ..Word to Writer – part 3 – Fields (variables)
July 20th, 2009 on 10:55 pm
I’m not even gonna pretend to understand what just happened up there.
Dan Reply:
July 20th, 2009 at 10:57 pm
Its so when you click an email link in Firefox, it opens up Zimbra email.. much similar to Firefox having GMail and yahoo mail built in
Gill Reply:
July 21st, 2009 at 9:38 am
Good, I’m glad I’m not the only one who had no idea what any of that meant!
August 3rd, 2009 on 2:43 pm
Excellent!
Give ‘em an inch and theyt’ll take a mile: Can you expand this so it opens in a new broswer window somehow?
top work – cheers!
August 27th, 2009 on 9:37 am
massive !!
works brilliantly and made me install greasemonkey which is really useful too – thanks
out of interest how might you change the code to point to the ZCS desktop app as distinct from webmail ?
cheers
Dan Reply:
August 27th, 2009 at 9:54 am
@babysnake, I think in that case you can set Zimbra Desktop to be the default mail client and then remove the extension in firefox.
August 27th, 2009 on 1:13 pm
thanks i’ll try !
August 27th, 2009 on 1:43 pm
i can get ZCS desktop to fire up on hitting mailto: but it doesn’t open a new mail with the address !
your script is better !!