From 3bedcb080705c1b5b2c9fff7015ccb42cc97b0f5 Mon Sep 17 00:00:00 2001 From: Kevin Chollet Date: Fri, 4 May 2018 22:44:01 +0200 Subject: [PATCH] Some cleanup --- imap_recursor.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/imap_recursor.py b/imap_recursor.py index 19acc6a..661934d 100755 --- a/imap_recursor.py +++ b/imap_recursor.py @@ -1,20 +1,22 @@ #!/usr/bin/env python # -# Very basic example of using Python and IMAP to iterate over emails in a -# gmail folder/label. This code is released into the public domain. -# -# http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/ -# +''' + File name: imap_recursor.py + License: GNU LESSER GENERAL PUBLIC LICENSE + Author: Kevin Chollet + Date created: 04/05/2018 + Date last modified: 04/05/2018 + Python Version: 3.2.3 + Sources : sample used : http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/ +''' + import sys import imaplib -import getpass import email -import email.header -import datetime import argparse +import subprocess - -def process_mailbox(M): +def process_mailbox(M, command): """ Do something with emails messages in the folder. For the sake of this example, print some headers. @@ -33,6 +35,10 @@ def process_mailbox(M): print(data[0][1].decode("utf-8")) """msg = email.message_from_bytes(data[0][1])""" + proc = subprocess.Popen(command.split(' '), stdin=subprocess.PIPE) + proc.stdin.write(data[0][1]) + + #Parsing arguments @@ -58,6 +64,10 @@ parser.add_argument('-f', '--folder', action="store", dest="folder", help="Folder to explore", default="INBOX") +parser.add_argument('-e', '--exec', + action="store", dest="execute", +help="Command to execute" ) + options = parser.parse_args() @@ -82,7 +92,7 @@ if result == 'OK': result, data = imap_ressource.select(options.folder) if result == 'OK': print("Processing mailbox...\n") - process_mailbox(imap_ressource) + process_mailbox(imap_ressource,options.execute) imap_ressource.close() else: print("ERROR: Unable to open mailbox ", rv)