Created
February 8, 2016 04:53
-
-
Save telnoratti/82dda1d5bb23d1492b2f to your computer and use it in GitHub Desktop.
RT ticket filter for afew
This file contains 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
# Copyright (c) 2016, Calvin Winkowski <[email protected]> | |
# | |
# Permission to use, copy, modify, and/or distribute this software for any | |
# purpose with or without fee is hereby granted, provided that the above | |
# copyright notice and this permission notice appear in all copies. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
from afew.filters.BaseFilter import Filter | |
from afew.FilterRegistry import register_filter | |
import re | |
@register_filter | |
class RTFilter(Filter): | |
message = "Create tags for an RT ticket system" | |
rt_header = 'X-RT-Ticket' | |
def __init__(self, database, **kwargs): | |
super(RTFilter, self).__init__(database, **kwargs) | |
self.queue_pattern = re.compile(r'^<([^@]+)@.+$') | |
def handle_message(self, message): | |
if not self._tag_blacklist.intersection(message.get_tags()): | |
if message.get_header(self.rt_header): | |
self.add_tags(message, 'rt') | |
reply_to = message.get_header('Reply-To') | |
self.add_tags(message, 'rt/' + | |
re.match(self.queue_pattern, reply_to).group(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment