Created
April 27, 2017 19:42
-
-
Save guyzmo/1b3cd9fd324c6a16b89546212141c0d6 to your computer and use it in GitHub Desktop.
Afew Filter: Auto-tag thread filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
from __future__ import print_function, absolute_import, unicode_literals | |
from afew.filters.BaseFilter import Filter | |
from afew.FilterRegistry import register_filter | |
@register_filter | |
class AutoTagThreadFilter(Filter): | |
message = 'Auto tag mails based on thread' | |
query = '' | |
def handle_message(self, message): | |
try: | |
tags = set() | |
if message.get_thread_id(): | |
for message in self.database.get_thread(message.get_thread_id()): | |
tags.update(message.get_tags()) | |
if len(tags) != 0: | |
self.add_tags(message, *tags) | |
except Exception as err: | |
self.log.exception("Skipping message with m-id: `{}`".format(message.get_header('Message-ID').encode('utf-8'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment