You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/07/10 11:09:19 UTC

[3/7] incubator-ponymail git commit: add a filter for only parsing email from a specific sender

add a filter for only parsing email from a specific sender

Sometimes we'll need to import only email from a specific
(broken?) sender, so let's add a quick filter for this.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/0e86b6df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/0e86b6df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/0e86b6df

Branch: refs/heads/master
Commit: 0e86b6dfb7ee06cd707426e00c69e7b97d78c219
Parents: f6f453e
Author: humbedooh <hu...@apache.org>
Authored: Mon Jun 13 11:37:48 2016 +0200
Committer: humbedooh <hu...@apache.org>
Committed: Mon Jun 13 11:37:48 2016 +0200

----------------------------------------------------------------------
 tools/import-mbox.py | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0e86b6df/tools/import-mbox.py
----------------------------------------------------------------------
diff --git a/tools/import-mbox.py b/tools/import-mbox.py
index 0b59d1f..5c62d20 100644
--- a/tools/import-mbox.py
+++ b/tools/import-mbox.py
@@ -73,6 +73,7 @@ parseHTML = False
 iBody = None
 resendTo = None
 timeout = 600
+fromFilter = None
 
 # Fetch config
 config = configparser.RawConfigParser()
@@ -239,6 +240,9 @@ class SlurpThread(Thread):
             LEY = EY
 
             for message in messages:
+                # If --filter is set, discard any messages not matching by continuing to next email
+                if fromFilter and 'from' in message and message['from'].find(fromFilter) == -1:
+                    continue
                 if resendTo:
                     print("Delivering message %s via MTA" % message['message-id'] if 'message-id' in message else '??')
                     s = SMTP('localhost')
@@ -356,6 +360,8 @@ parser.add_argument('--resend', dest='resend', type=str, nargs=1,
                    help='DANGER ZONE: Resend every read email to this recipient as a new email')
 parser.add_argument('--timeout', dest='timeout', type=int, nargs=1,
                    help='Optional timeout in secs for importing an mbox/maildir file (default is 600 seconds)')
+parser.add_argument('--filter', dest = 'fromfilter', type=str, nargs=1,
+                    help = 'Optional sender filter: Only import emails from this address')
 
 args = parser.parse_args()
 
@@ -388,6 +394,8 @@ if args.html2text:
     parseHTML = True
 if args.ibody:
     archiver.iBody = args.ibody[0]
+if args.fromfilter:
+    fromFilter = args.fromfilter[0]
 if args.resend:
     resendTo = args.resend[0]
     from smtplib import SMTP