Skip to content

Instantly share code, notes, and snippets.

@guyzmo
Created April 27, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyzmo/1b3cd9fd324c6a16b89546212141c0d6 to your computer and use it in GitHub Desktop.
Save guyzmo/1b3cd9fd324c6a16b89546212141c0d6 to your computer and use it in GitHub Desktop.
Afew Filter: Auto-tag thread filter
#!/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