From f599b34bc878bf85d28aff6307cef526a95accea Mon Sep 17 00:00:00 2001 From: Thomi Richards Date: Mon, 22 Jun 2015 15:55:15 +1200 Subject: [PATCH] Add LogMessage action, which allows you to log messages that match a filter. --- gmailfilter/actions.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gmailfilter/actions.py b/gmailfilter/actions.py index a65db8b..4982b2b 100644 --- a/gmailfilter/actions.py +++ b/gmailfilter/actions.py @@ -51,3 +51,20 @@ class DeleteMessage(Action): def process(self, conn, message): conn.delete_messages(message.uid()) logging.info("Deleting message %r" % message) + + +class LogMessage(Action): + + """A Simple action that just logs the message.""" + + def __init__(self, message_template="LOG Message={}"): + """Create a new LogMessage object. + + The message_template string must be a string with a single '{}' in it, + which will be replaced with the message's repr(). + + """ + self.message_template = message_template + + def process(self, conn, message): + logging.info(self.message_template.format(repr(message)))