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 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 |
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) |
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 |
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 |
You're Welcome.
I'm glad you found it useful! ;) Brian |
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. |
Quote:
|
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. |
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 "$_"` ########################################################### |
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. |