Skip to content

Instantly share code, notes, and snippets.

@xuhdev
Last active September 21, 2022 07:49
Show Gist options
  • Save xuhdev/d3bedab389b630957a97430ccfc17f96 to your computer and use it in GitHub Desktop.
Save xuhdev/d3bedab389b630957a97430ccfc17f96 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# This file is licensed under CC0 <https://creativecommons.org/publicdomain/zero/1.0/legalcode>
# https://www.topbug.net/blog/2016/12/13/send-git-patches-with-gui-email-clients/
import sys
import webbrowser
try:
from urllib.parse import quote # python 3
except:
from urllib import quote # python 2
SUBJECT_PREFIX = 'Subject:'
if len(sys.argv) >= 2:
to = sys.argv[1]
else:
to = ''
# Determine the subject
for line in sys.stdin:
line = line.strip()
if line.startswith(SUBJECT_PREFIX):
subject = line[len(SUBJECT_PREFIX):].strip()
break
# Determine the body
body = ''
for line in sys.stdin:
body += line
webbrowser.open('mailto:?To={}&Subject={}&Body={}'.format(quote(to), quote(subject), quote(body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment