From 7b5ec7f5431cd71144c4d2e62a3e7d4045271527 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 20 Jun 2006 08:24:59 +0000
Subject: [PATCH] add message-id and in-reply-to headers for threading

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8076 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../bug_workflow/scripts/sendNotification.xml | 24 +++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/bt5/erp5_forge/WorkflowTemplateItem/portal_workflow/bug_workflow/scripts/sendNotification.xml b/bt5/erp5_forge/WorkflowTemplateItem/portal_workflow/bug_workflow/scripts/sendNotification.xml
index ca2718e536..36e46aefe2 100644
--- a/bt5/erp5_forge/WorkflowTemplateItem/portal_workflow/bug_workflow/scripts/sendNotification.xml
+++ b/bt5/erp5_forge/WorkflowTemplateItem/portal_workflow/bug_workflow/scripts/sendNotification.xml
@@ -79,9 +79,22 @@ to_address = portal.getProperty(\'email_to_address\', \'yo@nexedi.com\')\n
 if not to_address:\n
   return\n
 \n
+# compute Message-ID and In-Reply-To header, for threading on MUAs\n
+history = portal.portal_workflow.getInfoFor(ob=bug,\n
+                                            name=\'history\',\n
+                                            wf_id=\'bug_workflow\',\n
+                                            default=())\n
+comment_count = len([item for item in history\n
+                     if str(item[\'action\']).endswith(\'_action\')])\n
+message_id = "<%s-%s.%s>" % (bug.getId(), comment_count+1, from_address)\n
+in_reply_to = "<%s-%s.%s>" % (bug.getId(), comment_count, from_address)\n
+\n
+\n
 text="""From: "%s" <%s>\n
 To: %s\n
 Subject: [Bug #%s] %s\n
+Message-Id: %s\n
+In-Reply-To: %s\n
 MIME-Version: 1.0\n
 Content-Type: text/plain;\n
   charset="utf-8"\n
@@ -99,8 +112,8 @@ Path: %s\n
 Follow-ups:\n
 \n
 %s\n
-""" % (from_name, from_address, to_address, bug.getId(), bug.getTitle(), \n
-       bug.getTitle(), bug.getSourceTitle(), bug.getDestinationTitle(),\n
+""" % (from_name, from_address, to_address, bug.getId(), bug.getTitle(), message_id, in_reply_to,\n
+       bug.getTitle(), bug.getSourceTitle() or \'\', bug.getDestinationTitle() or \'\',\n
        bug.getValidationStateTitle(), bug.getPath(),\n
        \'\\n\'.join([\'  \' + x for x in bug.getDescription().split(\'\\n\')]),\n
        \'\\n\'.join([\'  \' + x for x in bug.Bug_getFollowUpListAsText().split(\'\\n\')]),\n
@@ -163,9 +176,16 @@ portal.MailHost.send(text)\n
                             <string>from_name</string>
                             <string>from_address</string>
                             <string>to_address</string>
+                            <string>history</string>
+                            <string>len</string>
                             <string>append</string>
                             <string>$append0</string>
                             <string>_getiter_</string>
+                            <string>item</string>
+                            <string>str</string>
+                            <string>comment_count</string>
+                            <string>message_id</string>
+                            <string>in_reply_to</string>
                             <string>x</string>
                             <string>text</string>
                           </tuple>
-- 
2.30.9