Debian Codegraph @

plyer/platforms/linux/email.py

raw symbols SCIP
1 '''
2 Module of Linux API for plyer.email.
3 '''
4
5 import subprocess
6 try:
7 from urllib.parse import quote
8 except ImportError:
9 from urllib import quote
10 from plyer.facades import Email
11 from plyer.utils import whereis_exe
12
13
14 class LinuxEmail(Email):
15 '''
16 Implementation of Linux email API.
17 '''
18
19 def _send(self, **kwargs):
20 recipient = kwargs.get('recipient')
21 subject = kwargs.get('subject')
22 text = kwargs.get('text')
23
24 uri = "mailto:"
25 if recipient:
26 uri += str(recipient)
27 if subject:
28 uri += "?" if "?" not in uri else "&"
29 uri += "subject="
30 uri += quote(str(subject))
31 if text:
32 uri += "?" if "?" not in uri else "&"
33 uri += "body="
34 uri += quote(str(text))
35
36 subprocess.Popen(["xdg-open", uri])
37
38
39 def instance():
40 '''
41 Instance for facade proxy.
42 '''
43 import sys
44 if whereis_exe('xdg-open'):
45 return LinuxEmail()
46 sys.stderr.write("xdg-open not found.")
47 return Email()