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