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
This commit is contained in:
Pedro Alvarez 2016-06-24 16:59:34 +01:00 committed by Pedro Alvarez
parent 72d4a86179
commit c5b66fb43d

View File

@ -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 = "<storyboard.story.%s.%s@%s>" % (
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)