LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Firefox, mutt, and mailto links (https://www.linuxquestions.org/questions/linux-software-2/firefox-mutt-and-mailto-links-272743/)

rignes 01-01-2005 08:35 PM

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.

rignes 01-02-2005 12:08 AM

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"


royer 02-18-2005 11:23 AM

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)

rignes 02-18-2005 02:44 PM

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

tonytraductor 06-06-2009 06:46 PM

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

rignes 06-08-2009 02:51 PM

You're Welcome.

I'm glad you found it useful! ;)

Brian

peterlscott 06-29-2011 03:35 PM

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.

mimosinnet 09-05-2011 10:59 AM

Quote:

Originally Posted by peterlscott (Post 4399517)
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!

tonytraductor 09-26-2011 01:57 AM

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.

peterlscott 12-05-2011 02:38 PM

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 "$_"`
###########################################################

peterlscott 06-23-2022 03:59 PM

a much simpler mailto handler using mutt with firefox
 
Try this one-line bash script:
#!bin/bash
gnome-terminal -- /usr/bin/mutt $1

I called it "mailto_handler", made it executable, and put it
here:

~/bin/mailto_handler

and in firefox, click the hamburger, go to settings -->
applications --> mailto, and put "use mailto_handler".
Then to test this, I put an anchor tag in a web page:
<a href="mailto:my name <myself@xyz.edu>">clickme</a>

and when I click the "clickme", a gnome-terminal pops up, asks
for a subject, and I can add any content, exit, push "y" to
send the message, which is to myself. It all works.

I could not figure out how to do a similar strategy with a
google-chrome browser, which I never use anyway. The google-chrome help stuff is too confusing and not helpful.


All times are GMT -5. The time now is 01:08 PM.