From c5b66fb43ddc2500063ad74207d2e98e0465fae6 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 24 Jun 2016 16:59:34 +0100 Subject: [PATCH] Add support for email threading by story_id Set the 'In-Reply-To' header of the email based on the Story Id, and creation time of the Story. This way, most email clients will put the emails coming from the same Story into the same thread. Change-Id: Ic4041e451f65b2a208f55f77c5f414406159549f --- storyboard/plugin/email/workers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/storyboard/plugin/email/workers.py b/storyboard/plugin/email/workers.py index 1cdfbbea..40ba7a52 100644 --- a/storyboard/plugin/email/workers.py +++ b/storyboard/plugin/email/workers.py @@ -19,9 +19,11 @@ import os import six import smtplib +from email.utils import make_msgid from jinja2.exceptions import TemplateNotFound from oslo_config import cfg from oslo_log import log +from socket import getfqdn import storyboard.db.api.base as db_base from storyboard.db.api.subscriptions import subscription_get_all_subscriber_ids @@ -265,6 +267,32 @@ class SubscriptionEmailWorker(EmailWorkerBase): sub_resource, sub_resource_id) + # Set In-Reply-To message id for 'task' and 'story' resources + if resource == 'task' and method == 'DELETE': + # FIXME(pedroalvarez): Workaround the fact that the task won't be + # in the database anymore if it has been deleted. + # We should archive instead of delete to solve this. + story_id = resource_before['story_id'] + created_at = self.resolve_resource_by_name(session, 'story', + story_id).created_at + elif resource == 'task': + story_id = resource_instance.story.id + created_at = resource_instance.story.created_at + elif resource == 'story': + story_id = resource_instance.id + created_at = resource_instance.created_at + + if story_id and created_at: + thread_id = "" % ( + created_at.strftime("%Y%m%d%H%M"), + story_id, + getfqdn() + ) + else: + thread_id = make_msgid() + + factory.add_header("In-Reply-To", thread_id) + # Figure out the diff between old and new. before, after = self.get_changed_properties(resource_before, resource_after)