From c1942eae72f03e9077cd20495143690118bfb15f Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Tue, 1 Apr 2014 21:36:42 -0400 Subject: [PATCH 1/3] added Linux email support --- plyer/platforms/linux/email.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 plyer/platforms/linux/email.py diff --git a/plyer/platforms/linux/email.py b/plyer/platforms/linux/email.py new file mode 100644 index 000000000..4036764ef --- /dev/null +++ b/plyer/platforms/linux/email.py @@ -0,0 +1,28 @@ +import subprocess +from urllib import quote +from plyer.facades import Email + +class LinuxEmail(Email): + def _send(self, **kwargs): + recipient = kwargs.get('recipient') + subject = kwargs.get('subject') + text = kwargs.get('text') + create_chooser = kwargs.get('create_chooser') + + uri = "mailto:" + if recipient: + uri += str(recipient) + if subject: + uri += "?" if not "?" in uri else "&" + uri += "subject=" + uri += quote(str(subject)) + if text: + uri += "?" if not "?" in uri else "&" + uri += "body=" + uri += quote(str(text)) + + subprocess.Popen(["xdg-open", uri]) + + +def instance(): + return LinuxEmail() From 0d68fbaef300c53db407f6296c00e493e4b040bf Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Thu, 3 Apr 2014 16:35:50 -0400 Subject: [PATCH 2/3] use xdg-email by default, fallback to xdg-open + mailto uri --- plyer/platforms/linux/email.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plyer/platforms/linux/email.py b/plyer/platforms/linux/email.py index 4036764ef..704a44069 100644 --- a/plyer/platforms/linux/email.py +++ b/plyer/platforms/linux/email.py @@ -10,18 +10,28 @@ def _send(self, **kwargs): create_chooser = kwargs.get('create_chooser') uri = "mailto:" + args = ["xdg-email"] if recipient: uri += str(recipient) + args += [str(recipient)] if subject: uri += "?" if not "?" in uri else "&" uri += "subject=" uri += quote(str(subject)) + args += ["--subject", str(subject)] if text: uri += "?" if not "?" in uri else "&" uri += "body=" uri += quote(str(text)) + args += ["--body", str(text)] - subprocess.Popen(["xdg-open", uri]) + try: + subprocess.Popen(args) + except OSError: + try: + subprocess.Popen(["xdg-open", uri]) + except OSError: + print "Warning: unable to start an email client. Make sure xdg-open is installed." def instance(): From 4b2954ecc721b61f7f081fd1fcb82ceed01874cd Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Thu, 3 Apr 2014 16:44:47 -0400 Subject: [PATCH 3/3] revert previous commit, use xdg-open to open email client --- plyer/platforms/linux/email.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/plyer/platforms/linux/email.py b/plyer/platforms/linux/email.py index 704a44069..4036764ef 100644 --- a/plyer/platforms/linux/email.py +++ b/plyer/platforms/linux/email.py @@ -10,28 +10,18 @@ def _send(self, **kwargs): create_chooser = kwargs.get('create_chooser') uri = "mailto:" - args = ["xdg-email"] if recipient: uri += str(recipient) - args += [str(recipient)] if subject: uri += "?" if not "?" in uri else "&" uri += "subject=" uri += quote(str(subject)) - args += ["--subject", str(subject)] if text: uri += "?" if not "?" in uri else "&" uri += "body=" uri += quote(str(text)) - args += ["--body", str(text)] - try: - subprocess.Popen(args) - except OSError: - try: - subprocess.Popen(["xdg-open", uri]) - except OSError: - print "Warning: unable to start an email client. Make sure xdg-open is installed." + subprocess.Popen(["xdg-open", uri]) def instance():