Author: pquerna
Date: Mon Aug 24 04:03:24 2009
New Revision: 807067
URL: http://svn.apache.org/viewvc?rev=807067&view=rev
Log:
Start hacking on threading code.
Added:
labs/mboxed/trunk/mboxed/mboxed/lib/threading.py (with props)
Added: labs/mboxed/trunk/mboxed/mboxed/lib/threading.py
URL:
http://svn.apache.org/viewvc/labs/mboxed/trunk/mboxed/mboxed/lib/threading.py?rev=807067&view=auto
==============================================================================
--- labs/mboxed/trunk/mboxed/mboxed/lib/threading.py (added)
+++ labs/mboxed/trunk/mboxed/mboxed/lib/threading.py Mon Aug 24 04:03:24 2009
@@ -0,0 +1,84 @@
+
+
+#
+# Tools for threading of messages.
+# Based upon JWZ's threading document <http://www.jwz.org/doc/threading.html>
+#
+# This is the same as what the original mod_mbox uses too
+#
+
+
+def _get_refs(m):
+ def normalize_refs(input):
+ # see mbox_parse.c, parse_references()
+ r = input.split('>')
+ return [x.strip()+'>' for x in r]
+ refs = []
+ refs.extend(normalize_refs(m.get('References')))
+ refs.extend(normalize_refs(m.get('In-Reply-To')))
+ return refs
+
+
+class Message(object):
+ subject = None
+ id = None
+ refs = None
+
+ # Converts from lib.mbox.Message
+ def from_mbox(msg):
+ m = Message()
+ m.subject = msg.get('Subject')
+ m.id = msg.get('Message-Id')
+ m.refs = msg._get_refs()
+ return m
+
+ # Converts from model.MboxMessage
+ def from_model(msg)
+ m = Message()
+ m.subject = msg.subject
+ m.id = msg.msgid
+ m.refs = msg.refs
+ return m
+
+class Container(object):
+ msg = None
+ parent = None
+ child = None
+ next = None
+
+def thread(messages):
+ id_table = {}
+ for m in messages:
+ # 1a: Lookup by message id
+ id = m.get('Message-Id')
+ my_con = id_table.get(id)
+ if my_con is not None:
+ my_con.id = id
+ my_con.message = m
+ else:
+ my_con = Container()
+ my_con.id = id
+ my_con.message = m
+ id_table[id] = con
+
+ if m.refs if not None:
+ # 1b: Hooking references up
+ for r in m.refs:
+ con = id_table.get(r)
+ if con is None:
+ con = Container()
+ id_table[r] = con
+
+ # no looping
+ if con is my_con
+ continue
+
+ # TODO: child/add remove functions
+ # 1c: Fixup parent references
+ # 2: Find Root set
+ # 3: discard id_table
+ # 4: Prune empty containers.
+ # 5: Group roots by subject
+ # 6: Now you're done threading!
+ # 7: Final sort of siblings by date
+
Propchange: labs/mboxed/trunk/mboxed/mboxed/lib/threading.py
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: labs/mboxed/trunk/mboxed/mboxed/lib/threading.py
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: labs/mboxed/trunk/mboxed/mboxed/lib/threading.py
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]