ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject incubator-ponymail git commit: broken thread; attempted recovery causes unhandled error
Date Fri, 25 Nov 2016 19:56:59 GMT
Repository: incubator-ponymail
Updated Branches:
  refs/heads/master f5d78a0d4 -> 0d8446b6b


broken thread; attempted recovery causes unhandled error

This fixes #124

Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/0d8446b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/0d8446b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/0d8446b6

Branch: refs/heads/master
Commit: 0d8446b6bcc987c9ad1bba0e3573757475cda711
Parents: f5d78a0
Author: Sebb <sebb@apache.org>
Authored: Fri Nov 25 19:56:35 2016 +0000
Committer: Sebb <sebb@apache.org>
Committed: Fri Nov 25 19:56:35 2016 +0000

----------------------------------------------------------------------
 site/api/atom.lua      | 21 +++----------------
 site/api/lib/utils.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++
 site/api/thread.lua    | 23 +++------------------
 3 files changed, 56 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0d8446b6/site/api/atom.lua
----------------------------------------------------------------------
diff --git a/site/api/atom.lua b/site/api/atom.lua
index 012e781..bcba51b 100644
--- a/site/api/atom.lua
+++ b/site/api/atom.lua
@@ -23,6 +23,8 @@ local user = require 'lib/user'
 local aaa = require 'lib/aaa'
 local cross = require 'lib/cross'
 
+require 'lib/utils'
+
 local emls_thrd
 
 -- func for fetching all child emails of a parent topic
@@ -46,23 +48,6 @@ function fetchChildren(r, pdoc, c, biglist)
     return children
 end
 
--- func for finding the original email in a thread, if need be
-function findParent(r, doc)
-    local step = 0
-    while step < 50 do
-        step = step + 1
-        if not doc['in-reply-to'] then
-            break
-        end
-        local docs = elastic.find('message-id:"' .. r:escape(doc['in-reply-to'])..'"', 1,
"mbox")
-        if #docs == 0 then
-            break
-        end
-        doc = docs[1]
-    end
-    return doc
-end
-
 function handle(r)
     cross.contentType(r, "application/xhtml+xml")
     local t = {}
@@ -174,7 +159,7 @@ function handle(r)
         local doc = elastic.get("mbox", get.mid)
         if doc then
             -- make sure we have the real parent
-            local parent = findParent(r, doc)
+            local parent = findParent(r, doc, elastic)
             
             -- we got the original email, now let's find and process all kids
             if parent then

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0d8446b6/site/api/lib/utils.lua
----------------------------------------------------------------------
diff --git a/site/api/lib/utils.lua b/site/api/lib/utils.lua
new file mode 100644
index 0000000..693bff8
--- /dev/null
+++ b/site/api/lib/utils.lua
@@ -0,0 +1,50 @@
+--[[
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+]]--
+
+-- This is lib/utils.lua - utility methods
+
+--[[
+This module is intended to be directly required by the caller
+and so should not have any global state.
+For this reason it cannot include other lib files such as elastic
+]]--
+
+-- find the original topic starter
+function findParent(r, doc, elastic)
+    local step = 0
+    -- max 50 steps up in the hierarchy
+    while step < 50 do
+        step = step + 1
+        local irt = doc['in-reply-to']
+        if not irt then
+            break -- won't happen because irt is always present currently
+        end
+        -- Extract the reference, if any
+        irt = irt:match("(<[^>]+>)")
+        if not irt then
+            break
+        end
+        local docs = elastic.find('message-id:"' .. r:escape(irt)..'"', 1, "mbox")
+        if #docs == 0 then
+            break
+        end
+        doc = docs[1]
+    end
+    return doc
+end
+
+

http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/0d8446b6/site/api/thread.lua
----------------------------------------------------------------------
diff --git a/site/api/thread.lua b/site/api/thread.lua
index aaaa9da..dcbb363 100644
--- a/site/api/thread.lua
+++ b/site/api/thread.lua
@@ -27,6 +27,8 @@ local config = require 'lib/config'
 
 local emls_thrd
 
+require 'lib/utils'
+
 -- anonymizer func
 function anonymize(doc)
     if doc.from and doc.from ~= JSON.null and #doc.from > 0 then
@@ -94,25 +96,6 @@ function fetchChildren(r, pdoc, c, biglist, rights, account)
     return children
 end
 
--- find the original topic starter
-function findParent(r, doc)
-    local step = 0
-    -- max 50 steps up in the hierarchy
-    while step < 50 do
-        step = step + 1
-        if not doc['in-reply-to'] then
-            break
-        end
-        local docs = elastic.find('message-id:"' .. r:escape(doc['in-reply-to'])..'"', 1,
"mbox")
-        if #docs == 0 then
-            break
-        end
-        doc = docs[1]
-    end
-    return doc
-end
-
-
 function handle(r)
     r.content_type = "application/json"
     local now = r:clock()
@@ -134,7 +117,7 @@ function handle(r)
         end
     end
     if get.timetravel then
-        doc = findParent(r, doc)
+        doc = findParent(r, doc, elastic)
     end
     local doclist = {}
     


Mime
View raw message