[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Googleearth mailto: mess .


I am fighting with Googleearth mailto feature which allows the happy user to send a capture or a link of what is looking at to yet another happy user. Problem is the call this mailto function does is to the $BROWSER (equivalent to x-wwwbrowser ?), and then relying on the browser ability to pass the call. Seems that there is no way to know what application is the default handler for such "mailto" calls (as stated in the "readme"). With Iceweasel set as the defaut browser it's working not to bad, just have to set the pref :


to "true" on the user level (about:config) or system wide (/etc/iceweasel/pref/iceweasel.js).

With this settings the mailto: call is passed to evolution as a default, and it works ok with the image attachment being created. The problem is use Icedove, which requires to set Googleearth to use a wrapper perl script to call Thunderbird instead of Evolution. The scripts are stored in Googleearth package (google-earth/linux/mailto-scripts), I had to manually add reference to Icedove because it's only looking for Thunderbird executable in /usr/bin.

I added
pref("network.protocol-handler.app.mailto", "some_path/google-earth/linux/mailto-scripts/mailto-thunderbird.pl");
to /etc/iceweasel/pref/iceweasel.js, then the mailto call went though iceweasel, triggered Icedove launch, and nothing else...

Here is the perl thing (hope it won't trigger all the mighty anti spam weapons ) :

 #!/usr/bin/perl -w

# This script counts on the mailto: having a somewhat reasonable format...
#  it is likely that a sneaky user could do shell injection tricks here,
#  and we don't stop them. Send patches.

# This needs to be in your prefs.js file in firefox:
#user_pref("network.protocol-handler.expose.mailto", true);
#user_pref("network.protocol-handler.app.mailto", "/where/i/copied/mailto-thunderbird.pl");

use warnings;
use strict;

sub find_in_path {
    my $bin = shift;

    # If binary has absolute or relative path, don't search $PATH...
    if ($bin =~ /\//) {
        if (-x $bin) {
            return $bin;
        } else {
            return undef;

    # Search the $PATH...
    my @paths = split /:/,$ENV{'PATH'};
    foreach (@paths) {
        my $full = "$_/$bin";
        return $full if (-x $full);

    return undef;  # not in $PATH.

sub find_installed_name {
    my $product = shift;
    my @names = @_;
    foreach (@names) {
        my $fname = find_in_path($_);
        return $fname if defined $fname;

    print STDERR "Can't find $product in \$PATH. Giving up.\n";
    exit 1

# Mainline ...

die("USAGE: $0 <mailto:url>\n") if (scalar @ARGV != 1);
my $mailexe = find_installed_name('Mozilla Thunderbird', 'mozilla-thunderbird', 'thunderbird', 'icedove'); my $mailto = $ARGV[0]; ^^^ $mailto =~ s/\Amailto\://; I added that

my $to = '';
my $args = '';

if ( $mailto =~ /\A(.*?)\?(.*)\Z/ ) {
    $to = $1;
    $args = $2;
} else {
    # assume whole thing is the To: address.
    $to = $mailto;

my @attachments;
my $cmdline = $mailexe . ' -remote "xfeDoCommand(composeMessage';

$cmdline .= ",to=$to" if ($to ne '');

my @pairs = split /\&/, $args;
foreach my $pair (@pairs) {
   if($pair=~m/([^=]+)=(.*)/) {
      my $field = $1;
      my $value = $2;
      $field =~ tr/A-Z/a-z/;
      if ($field eq 'attach') {
        $value =~ s#\Afile://##;
        push @attachments, $value;
      } else {
        $cmdline .= ",${field}=${value}";

if (@attachments) {
    $cmdline .= ",attachment='";
    my $comma = '';
    foreach my $attach (@attachments) {
        $cmdline .= "${comma}file://${attach}";
        $comma = ',';
    $cmdline .= "'";

$cmdline .= ')"';

#print $cmdline . "\n";

# exec thunderbird if there's no instance running
system("$mailexe -remote 'ping()'");
my $launched = ($? == 0);
system("$mailexe &") if (not $launched);

# Wait for it to respond...
my $maxwait = 15;  # wait 15 seconds, tops.
for (my $i = 0; ((not $launched) and ($i < $maxwait)); $i++) {
    sleep 1;
    system("$mailexe -remote 'ping()'");
    $launched = ($? == 0);

if (not $launched) {
    print STDERR "Failed to launch $mailexe ...";
    exit 1;

# Raise the Thunderbird window.
system("$mailexe -remote 'xfeDoCommand(openInbox)'");

# and maybe send the mailto:

# end of mailto-thunderbird.pl ...
Does any Perl-fluent person could spot what's going wrong, and correct it to send it back to Google as they are begging for (and make them aware of the existence of Icedove at the same time) ? Or is this just plain rubish I shouldn't tinker with ? Or just send it back to it's creator ?

Thanks for any clue/advice.

At the end of the google-earth/linux/README-mailto file one can read :

please encourage your distros and software
vendors to standardize on ways to handle these things, which could remove the
 need for all this explanation some day. Being able to find the user's
favorite apps and manipulate them from another program is not only good for commercial software, but also Free and open source packages, too. After all, stringing together a collection of programs is the Unix Way, isn't it? :)

Good luck,
--ryan, Google.

Maybe they have a point here ?


Reply to: