Tuesday, February 17, 2009

Open mailto links in gmail using chrome



Ok, so I like Chrome and I like Windows 7, but it's not happy with mailto links.  Google talk doesn't work right, it sends the subject but not the target! Bad Google!

I found an article at Brendan Nee's blog about doing this in WinXP and I found out how to make file associations in the registry (Windows 7 won't let you make new protocol associations through the GUI, or at least I haven't found out how yet).  After some tinkering I found that gmail doesn't like the standard mailto syntax!  C'mon Google, get on the standardization train.  Basically, it will go into gmail composer with the right email address, but no subject!  Craigslist doesn't like that.

Anyway, so I hacked out a little vbs that converts the standard mailto syntax into what gmail wants in the http request and put it in c:\windows\system32.  I'm sure someone else could to it better blah blah blah, but this works.  It's missing support for the remaining mailto syntax options (cc, bcc, etc), but all I really wanted was for this to work with craigslist.  I wonder how it'd handle cc's...  Here's my results, I tried to make them as user-inspecific as possible:


mailto.vbs
Set wshShell = WScript.CreateObject ("WScript.shell")
Dim ArgObj, var1, var2, var3, whoto, subject, urltofollow
Dim firstarray, secondarray, thirdarray
Set ArgObj = WScript.Arguments 

'Collect arguments into an array
var1 = ArgObj(0)

'Split the array using ? as the delimiter
firstarray = split(var1 , "?")

'Put the first half in var2, then split that up at the :
' and put the second half of THAT (the email addy) into the
' "whoto" variable.

var2 = firstarray(0)
secondarray = split(var2 , ":")
whoto = secondarray(1)


'Dump the second half of Var1 (the subject half) into var3, 
'then split that up at the =, leaving the actual subject 
'in the second half.  Dump that into the "subject" variable

var3 = firstarray(1)
thirdarray = split(var3 , "=")
subject = thirdarray(1)

'Rather than mess with wshell.run's syntax, generate the actual link and dump it into urltofollow.
urltofollow = "https://mail.google.com/mail/?view=cm&fs=1&tf=1&source=mailto&to=" + whoto + "&su=" + subject

'Run it!
'Use this for Windows 7
wshshell.run """%localappdata%\google\chrome\application\chrome.exe""" + urltofollow, 6, True
'Use this for Windows XP
'wshshell.run """%homepath%\local settings\application data\google\chrome\application\chrome.exe""" + urltofollow, 6, True
set wshshell = nothing



chrome.reg


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\mailto]
@="URL: mailto"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\mailto\DefaultIcon]
@=""

[HKEY_CLASSES_ROOT\mailto\shell]

[HKEY_CLASSES_ROOT\mailto\shell\open]

[HKEY_CLASSES_ROOT\mailto\shell\open\command]
@="cscript //b \"C:\\windows\\system32\\mailto.vbs\" \"%1\""