diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-30 13:13:54 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-30 13:13:54 +0100 |
commit | d4c67504b31d8a4c6a89f02425f50c28970fcd43 (patch) | |
tree | 84c96c9acf79ede5ba80aa5c95096a9c4806710d /alot/helper.py | |
parent | b65d427c2af72d1894bb1d465cb61325e28c732c (diff) |
unifies pipe to cmd in send_mail and print.
issue #39
Diffstat (limited to 'alot/helper.py')
-rw-r--r-- | alot/helper.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/alot/helper.py b/alot/helper.py index 72c9cb63..3516d77e 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -61,6 +61,22 @@ def cmd_output(command_line): return output +def pipe_to_command(cmd, stdin): + # no unicode in shlex on 2.x + args = shlex.split(cmd.encode('ascii')) + try: + proc = subprocess.Popen(args, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = proc.communicate(stdin) + except OSError, e: + return '', str(e) + if proc.poll(): # returncode is not 0 + return '', err.strip() + else: + return out, err + + def attach(path, mail, filename=None): ctype, encoding = mimetypes.guess_type(path) if ctype is None or encoding is not None: |