From 2f8a1d711b405b9e62a11049b04d11d582ccad20 Mon Sep 17 00:00:00 2001
From: Jean-Paul Smets <jp@nexedi.com>
Date: Sun, 14 Oct 2007 14:07:10 +0000
Subject: [PATCH] Initial version of metadata discovery for ingestion of email
 events in CRM.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16993 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../Event_getPropertyDictFromContent.xml      | 217 ++++++++++++++++++
 1 file changed, 217 insertions(+)
 create mode 100644 bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Event_getPropertyDictFromContent.xml

diff --git a/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Event_getPropertyDictFromContent.xml b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Event_getPropertyDictFromContent.xml
new file mode 100644
index 0000000000..34f253fcbe
--- /dev/null
+++ b/bt5/erp5_crm/SkinTemplateItem/portal_skins/erp5_crm/Event_getPropertyDictFromContent.xml
@@ -0,0 +1,217 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Python_magic</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>__ac_local_roles__</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+"""\n
+  This script is called during the metadata discovery process\n
+  for each event which has been ingested through the email interface\n
+  by portal contributions. It tries to analyse the text content \n
+  to define the different event parameters.\n
+\n
+  This version provides only early support.\n
+\n
+  TODO:\n
+  - support forwarded messages\n
+  - support incoming / outgoing messages (in releation with \n
+    Event_finishIngestion)\n
+"""\n
+\n
+def getPersonList(information_text):\n
+  result = []\n
+  for recipient in information_text.split(\',\'):\n
+    if "<" in recipient:\n
+      recipient = recipient[recipient.find(\'<\') + 1:]\n
+      recipient = recipient[:recipient.find(\'>\')]\n
+    if recipient:\n
+      email = context.portal_catalog.getResultValue(url_string=recipient, portal_type="Email")\n
+      if email is not None:\n
+        result.append(email.getParentValue().getRelativeUrl())\n
+  return result\n
+\n
+content_information = context.getContentInformation()\n
+sender_list = getPersonList(content_information.get(\'From\', \'\'))\n
+to_list = getPersonList(content_information.get(\'To\', \'\'))\n
+cc_list = getPersonList(content_information.get(\'CC\', \'\'))\n
+\n
+# Build references\n
+reference_search_list = []\n
+text_search_list = []\n
+for text, prop_dict in context.getSearchableReferenceList():\n
+  if text: text_search_list.append(text)\n
+  if prop_dict.has_key(\'reference\'): reference_search_list.append(prop_dict[\'reference\'])\n
+\n
+# Search reference ticket or project\n
+follow_up_type_list = context.getPortalProjectTypeList() + context.getPortalTicketTypeList()\n
+print follow_up_type_list\n
+follow_up = context.portal_catalog.getResultValue(reference=reference_search_list, portal_type=follow_up_type_list)\n
+if follow_up is None:\n
+  follow_up = context.portal_catalog.getResultValue(reference=text_search_list, portal_type=follow_up_type_list)\n
+\n
+# Build dict.\n
+result = {}\n
+if sender_list: result[\'source_list\'] = sender_list\n
+if to_list or cc_list: result[\'destination_list\'] = to_list + cc_list\n
+if follow_up is not None: result[\'follow_up\'] = follow_up.getRelativeUrl()\n
+\n
+return result\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_code</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_filepath</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>_owner</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>errors</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_code</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>co_argcount</string> </key>
+                        <value> <int>0</int> </value>
+                    </item>
+                    <item>
+                        <key> <string>co_varnames</string> </key>
+                        <value>
+                          <tuple>
+                            <string>_print_</string>
+                            <string>_print</string>
+                            <string>getPersonList</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>content_information</string>
+                            <string>sender_list</string>
+                            <string>to_list</string>
+                            <string>cc_list</string>
+                            <string>reference_search_list</string>
+                            <string>text_search_list</string>
+                            <string>_getiter_</string>
+                            <string>text</string>
+                            <string>prop_dict</string>
+                            <string>_getitem_</string>
+                            <string>follow_up_type_list</string>
+                            <string>follow_up</string>
+                            <string>None</string>
+                            <string>result</string>
+                            <string>_write_</string>
+                          </tuple>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>func_defaults</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Event_getPropertyDictFromContent</string> </value>
+        </item>
+        <item>
+            <key> <string>warnings</string> </key>
+            <value>
+              <tuple>
+                <string>Prints, but never reads \'printed\' variable.</string>
+              </tuple>
+            </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
-- 
2.30.9