Last active
March 14, 2018 22:37
-
-
Save nitrocode/abe3e9c1a37179770e0a793d45849aae to your computer and use it in GitHub Desktop.
Converts mailto links to english instead of opening them in your non cloud based stock mail client that you never configured
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # Sometimes you get a mailto link and it opens up a mail client that you never | |
| # use and on top of that, the mailto url is url encoded so it's full of | |
| # percent characters. Instead of having to decode it manually or put it in a | |
| # website to decode, I decided to write up this solution. | |
| # | |
| # Usage: | |
| # install mailto-english.py /usr/local/bin/mailto-english | |
| # mailto-english "mailto:jobs%40gravitational.com?subject=Application%20for%20DevOps%20Engineer%20at%20Gravitational&body=Hi%21%0A%0AI%27d%20like%20to%20apply%20for%20your%20position%20for%20a%20DevOps%20Engineer%20at%20Gravitational" | |
| import sys | |
| # python2 vs python3 | |
| try: | |
| from urlparse import urlparse, parse_qs | |
| from urllib import unquote | |
| except: | |
| from urllib.parse import urlsplit as urlparse, parse_qs, unquote | |
| # get first arg or provide one | |
| try: | |
| url = sys.argv[1] | |
| except: | |
| url = "mailto:jobs%40gravitational.com?subject=Application&body=Hi%21%20I%20want%20work%20please%21" | |
| query = {} | |
| parsed_url = urlparse(url) | |
| query['email'] = [unquote(parsed_url.path)] | |
| query.update(parse_qs(parsed_url.query)) | |
| # python3 vs python2 | |
| try: | |
| iterate = query.iteritems() | |
| except: | |
| iterate = query.items() | |
| for key, val in iterate: | |
| try: | |
| print("{:>10}: {}".format(key.title(), val[0].replace("\n", " "))) | |
| except: | |
| # skip if first value cannot be retrieved | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment