Question

I'm writing a small script to open mailto links from webpages in google chrome small app window:

so far I have this:

#!/bin/sh

notify-send "Opening Gmail" "`echo $1`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"

which works nice - however I'd like to add the email recipient to the notification - something like this - but I need a regex to get the email from the mailto link - which might contain subjects and such..

#!/bin/sh

$str = preg_replace('#<a.+?href="mailto:(.*?)".+?</a>#', "$1", $str);
notify-send "Opening Gmail" "`echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"

this does not work..

any ideas?

UPDATE: here's the working code:

#!/bin/sh

str=$(echo $1|sed 's/.*mailto:\([^?]*\)?.*/\1/')
notify-send "Opening Gmail" "to: `echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
google-chrome -app="https://mail.google.com/mail/?extsrc=mailto&url=`echo $1`"
Was it helpful?

Solution

If you write it like this, it's not shell:)

Can you provide the sample string to use regex unto? Basically it will be sed invocation, that shall cut everything but the address. Although the mail address according to the RFC can be quite complicated, so the simple approach will work in most of the cases, but not every time.

Try to start from something like

sed 's/.*mailto:\([^?]*\)?.*/\1/'

So you might want to use it like this:

str=$(echo $1|sed 's/.*mailto:\([^?]*\)?.*/\1/')

OTHER TIPS

Great! I got your script and made some change to work better, look:

#!/bin/sh

str=$(echo $1|sed 's/.*mailto:\([^?]*\)?.*/\1/')
notify-send "Abrindo Gmail" "to: `echo $str`" -i /usr/local/share/icons/hicolor/48x48/apps/google-chrome.png -t 5000
chromium-browser "https://mail.google.com/mail/?view=cm&fs=1&tf=1&source=mailto&to=$1"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top