Zomgee
mailto-links-and-zimbra-how-to

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.

  • Share/Bookmark
:, , , ,
11 comments for this entry:
  1. Gill

    I should have taken “computer” as my second language instead of French…

  2. Dan

    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.

  3. Jane G

    Thank you, this is brilliant and fantastic. :-)
    Jane G´s last blog ..Word to Writer – part 3 – Fields (variables)

  4. Kathy

    I’m not even gonna pretend to understand what just happened up there.

    Dan Reply:

    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:

    Good, I’m glad I’m not the only one who had no idea what any of that meant!

  5. cybotic

    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!

  6. babysnake

    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:

    @babysnake, I think in that case you can set Zimbra Desktop to be the default mail client and then remove the extension in firefox.

  7. babysnake

    thanks i’ll try !

  8. babysnake

    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 !!

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...