LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-01-2005, 08:35 PM   #1
rignes
Member
 
Registered: Mar 2003
Location: USA
Distribution: Slackware-current
Posts: 155

Rep: Reputation: 30
Firefox, mutt, and mailto links


I just set this up after much searching and it works for me. I put the info on my blog at http://rignesnet.tzo.com but here is the text for my entry incase someone here might find it useful.

Quote:
I love Firefox but one thing that has been bugging me is getting it to handle mailto URL's in Linux. For some reason there is no actual way to configure this easy in the preferences. So, I Googled about figuring someone has to have done it already but I could only find references to getting Thunderbird and Firefox working together. I like mutt, so I decided to try my hand for the first time ever at actually writing up something that was kind of useful. Well, useful for me anyway.

Inspired by the example helper scripts I saw for Thunderbird I came up with this:


#!/bin/bash
MAILTO_URL="$1"

#Strip off the protocol
MAIL_DATA=$(echo "$MAILTO_URL" | /bin/sed -s 's/^mailto://')

#Get Recipient and strip it off
RECIPIENT=$(echo "$MAIL_DATA" | cut -d? -f1 -)
MAIL_DATA=$(echo "$MAIL_DATA" | /bin/sed -s s/^$RECIPIENT//)

#Get Subject,BCC, and CC
SUBJECT=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?subject=//' \
| /bin/sed -s 's/?.*//')
BCC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?bcc=//' | /bin/sed -s 's/?.*//')
CC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?cc=//' | /bin/sed -s 's/?.*//')

# Call mutt in an aterm
aterm -fg white -bg black -geometry 80x50 -fn 9x15 \
-e mutt "$RECIPIENT" -b "$BCC" -c "$CC" -s "$SUBJECT"

I named this script mailto_helper, made it executable, and stuck it in a logical place for me. Then I opened the URL "about:config" in Firefox. In there I right clicked and created a new string called "network.protocol-handler.app.mailto" with a value of the path to where I put mailto_helper and to my surprise it worked. I'm sure a real programmer/scripter could do something better but I don't think it's all to bad for a novice like me.
 
Old 01-02-2005, 12:08 AM   #2
rignes
Member
 
Registered: Mar 2003
Location: USA
Distribution: Slackware-current
Posts: 155

Original Poster
Rep: Reputation: 30
I just realized that the URL needs to be all lowercase for it to work, so I changed it to work with upper and lowercase URL's.

Code:
#!/bin/bash
MAILTO_URL="$1" 

#Strip off the protocol
MAIL_DATA=$(echo "$MAILTO_URL" | /bin/sed -s 's/^[Mm][Aa][Ii][Ll][Tt][Oo]://') 

#Get Recipient and strip it off
RECIPIENT=$(echo "$MAIL_DATA" | cut -d? -f1 -)
MAIL_DATA=$(echo "$MAIL_DATA" | /bin/sed -s s/^$RECIPIENT//) 

#Get Subject,BCC, and CC
SUBJECT=$(echo "$MAIL_DATA" | \
/bin/sed -s 's/.*?[Ss][Uu][Bb][Jj][Ee][Cc][Tt]=//' | /bin/sed -s 's/?.*//')
BCC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?[Bb][Cc][Cc]=//' | \
/bin/sed -s 's/?.*//')
CC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?[Cc][Cc]=//' | \
/bin/sed -s 's/?.*//') 

#Call mutt in an aterm
aterm -fg white -bg black -geometry 80x50 -fn 9x15 -e \
mutt "$RECIPIENT" -b "$BCC" -c "$CC" -s "$SUBJECT"
 
Old 02-18-2005, 11:23 AM   #3
royer
LQ Newbie
 
Registered: Feb 2005
Distribution: slackware
Posts: 1

Rep: Reputation: 0
firefox & mutt

I was happy to find your hint
Is there some reason to write a long script?
For me this mailto_helper do the job (and it
send links) :

#!/bin/bash
xterm -e /usr/bin/mutt "$1"

In fact my firefox-1.0 behaves similarly
by default,
but it calls gnome-terminal, and this is
not easy on my slow machine
( I am not using gnome but it is installed)
 
Old 02-18-2005, 02:44 PM   #4
rignes
Member
 
Registered: Mar 2003
Location: USA
Distribution: Slackware-current
Posts: 155

Original Poster
Rep: Reputation: 30
http://rignesnet.tzo.com/articles/mailto_helper.html

Actually, I never thought to try just passing the entire mailto URL to mutt so I just tried it now. It looks like, for me at least, that mutt is able to pull the subject out of a mailto URL but it didn't seem to handle the cc and bcc part well, which is what I wanted to cover. So, while the reason I did the long script is because, well, I didn't know mutt would do it, the side effect is that now I know for sure the subject, cc, and bcc fields will be handles correctly.

But, it seems that my little script isn't 100% needed. It was pointed out to me that Show Old Extensions would let you run mozex which is clearly superior to what I wrote if you want to handle other kinds of links.

Of course, there is nothing wrong with using my script if you want to. I'm just happy that someone else has found it useful.

I made an article on my blog that consolidates the info sprinkled about my blog into one place at http://rignesnet.tzo.com/articles/mailto_helper.html . After my last post I chanced it to be a little shorter.

Thanks for the comment.

Brian
 
Old 06-06-2009, 06:46 PM   #5
tonytraductor
LQ Newbie
 
Registered: Sep 2008
Location: new haven, ct, usa
Distribution: Debian Stable
Posts: 8

Rep: Reputation: 0
Well done, Brian!

I was just googling and trying to find the same thing, how to handle mailto: links with mutt. I found your blog, and this thread.
Your script rocks!

I might have though to do it with perl, since I'm a complete moron with sed, but this is awesome.

thanks,
tony
 
Old 06-08-2009, 02:51 PM   #6
rignes
Member
 
Registered: Mar 2003
Location: USA
Distribution: Slackware-current
Posts: 155

Original Poster
Rep: Reputation: 30
You're Welcome.

I'm glad you found it useful!

Brian
 
Old 06-29-2011, 03:35 PM   #7
peterlscott
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Rep: Reputation: Disabled
A simple perl script to hand mailto urls to mutt

OK, here it is, in case it might be of some use.
I call it "mailto_handler".

#!/usr/bin/perl
$_ = $ARGV[0];
chomp;
s/^mailto://;
`gnome-terminal -e "mutt $_"`

# This script is meant to handle mailto: URLs from Firefox
# and Opera. (I'm using Scientific Linux 6.0 (like RHEL 6.0),
# with Gnome version 2.28.0, and FVWM window manager.)
#
# It first removes the "mailto:" portion of the string it
# receives from the browser, so that $_ becomes merely the
# email address, like "staff@abc.org". Then it should pop
# up a gnome-terminal, within which it executes the mutt
# command, which with this example would be
# "mutt staff@abc.org".
#
# To get it to work properly:
# In System --> Preferences --> Preferred Applications, select
# for the mail reader "Custom", and insert the command
# "mailto_handler %s", and uncheck the "Run in terminal" box.
#
# Also in the gnome-terminal:
# Edit --> Profile Preferences --> Title and Command, choose
# "Exit the terminal" when command exits.
# Then when you click on a mailto URL the gnome-terminal
# window that pops up should say, at the bottom,
# "To: staff@abc.org", and you are set to send your email.
#
# It also works for Opera, but for Opera, go to
# Tools --> Preferences --> Advanced --> Programs, and edit
# the "mailto" Protocol to specify "Open with other application",
# where you should insert the command "mailto_handler" (no %s),
# with nothing in the "Parameter" field, and again leave the
# "Open in terminal" box unchecked.
 
1 members found this post helpful.
Old 09-05-2011, 10:59 AM   #8
mimosinnet
LQ Newbie
 
Registered: Feb 2006
Location: Barcelona, Spain
Distribution: Gentoo
Posts: 21

Rep: Reputation: 0
Quote:
Originally Posted by peterlscott View Post
OK, here it is, in case it might be of some use.
I call it "mailto_handler".
The beauty of simplicity! I have tried and works well. Thanks!
 
Old 09-26-2011, 01:57 AM   #9
tonytraductor
LQ Newbie
 
Registered: Sep 2008
Location: new haven, ct, usa
Distribution: Debian Stable
Posts: 8

Rep: Reputation: 0
choice of muttrc?

I have two muttrc files, for use with two different e-mail addresses.
I'd like to be able to use this, but choose with rc.
I tried to do it with

xterm \
-e read -p "gmail (mutt) or gmx (gmx)? " mailprog
$mailprog "$1"

I get
xterm: Can't execvp read: No such file or directory

So that's not working...how can I give myself the choice when I click these links?

(gmx is aliased to "mutt -F .guttrc", which accesses gmx.com mail over imap, while "mutt" just calls with the .muttrc for accessing gmail over imap).

In the meantime, I have FF (iceweasel, really) calling thunderbird (icedove, really), which is set up for both, and I can choose, but even having icedove (or any gui-pop-mailer, like sylpheed or whatever) installed, solely for this purpose, seems like overkill, since I generally read my mail in mutt, or, occasionally, on the web interfaces for these services, but never in icedove.

I suppose I could just copy/paste an e-mail address to my terminal (gnome-terminator allows pasting, unlike xterm), but clicking the link and having mutt come up, with a choice of configs, would be much cooler.
 
Old 12-05-2011, 02:38 PM   #10
peterlscott
LQ Newbie
 
Registered: Jun 2011
Posts: 3

Rep: Reputation: Disabled
upgraded perl script for handling mailto URLs with mutt

Here's a slightly longer perl script to handle more complex mailto URLs to mutt. I'm NOT a perl expert, but this works for me:

###########################################################

#!/usr/bin/perl
# updated mailto_handler to include the possible parts of
# "subject", "cc" and "bcc", should they exist in the "mailto"
# URL. ("body" is not included.) The format of a "mailto"
# URL that includes subject, cc and bcc would be this:
#
# "mailto:foo@bar.org,a@bc.org?subject=test one&cc=d@ef.com&bcc=g@hi.edu"
#
# most browsers will replace spaces by the "%20" string, since
# that's the proper way to encode URLs. However one does not want
# a multi-word "subject" (e.g. "test one") to appear as
# "test%20one" in a subject line. So at the end of the script, we
# convert, in the command line, all %20s to spaces before sending
# the command line to mutt. NOTE: do not use "?" or "&" in the
# subject field. This script will fail if you do.
#
# The idea is that if one clicks on a "mailto' link, a
# gnome-terminal should pop up, within which a mutt command
# will be issued. With the above "mailto" example URL, the mutt
# command emitted would be
#
# "mutt foo@bar.org,a@bc.org -s 'test one' -c 'd@ef.com' -b 'g@hi.edu'"
#
# Of course, the usual "mailto:foo@bar.org" as a URL will work
# just fine.
#
# To get it to work with gnome:
# in System --> Preferences --> Preferred Applications, select
# for the mail reader "Custom", and insert the command
# 'mailto_handler %s', and uncheck the "Run in terminal" box.
#
# Also in a gnome-terminal:
# Edit --> Profile Preferences --> Title and Command, choose
# "Exit the terminal" when command exits.
#
# For Opera: Tools --> Preferences --> Advanced --> Programs,
# and edit the "mailto" Protocol to specify "Open with other
# applicataion", insert the command "mailto_handler" (no %s),
# with nothing in the "Parameter" field, and again leave the
# "Open in terminal" box unchecked.
#
# Updated December 04, 2011
#
$_ = $ARGV[0];
chomp;
s/^mailto://; # strip off the "mailto:"
my @parts = split /\?/, $_;
my $numparts = @parts + 0;
my $email = "$parts[0]"; # there will always be $parts[0]
my $cmd = "mutt $email ";
if ($numparts > 1) { # if there's more, grab the data
if ($numparts != 2) {
die ("too many '?' chars; only one allowed");
}
my @rest = split /&/, $parts[1]; # get subject, cc, bcc
foreach $field (@rest) {
if ($field =~ /^subject=/) {
$subject = substr($field, 8);
$cmd .= "-s '$subject' ";
}
if ($field =~ /^cc=/) {
$cc = substr($field, 3);
$cmd .= "-c '$cc' ";
}
if ($field =~ /^bcc=/) {
$bcc = substr($field, 4);
$cmd .= "-b '$bcc' ";
}
}
}
# replace any "%20" strings inserted by browser by space char.
$_ = $cmd;
s/%20/ /g;
`gnome-terminal -e "$_"`
###########################################################
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox, Mailto and Kmail won't work together Joe Bloggs Linux - Newbie 7 11-22-2005 02:14 PM
Sending links from Firefox mickeyboa Fedora 3 07-02-2005 08:09 AM
FireFox and mailto Liakoni Mandriva 15 11-24-2004 04:35 PM
associate mailto in firefox to a program true_atlantis Linux - Software 1 04-26-2004 02:39 PM
Evolution and mailto: links??? datadriven Linux - Software 0 09-24-2003 09:21 AM


All times are GMT -5. The time now is 07:11 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration