<commit_before>--[[
 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 source.lua - a script for displaying the source of an email

local elastic = require 'lib/elastic'
local aaa = require 'lib/aaa'
local user = require 'lib/user'
local cross = require 'lib/cross'

function handle(r)
    r.content_type = "text/plain"
    local get = r:parseargs()
    local eid = (get.id or r.path_info):gsub("\"", ""):gsub("/", "")
    local doc = elastic.get("mbox_source", eid or "hmm")
    
    -- Try searching by mid if not found, for backward compat
    if not doc or not doc.subject then
        local docs = elastic.find("message-id:\"" .. r:escape(eid) .. "\"", 1, "mbox_source")
        if #docs == 1 then
            doc = docs[1]
        end
    end
    if doc and doc.source then
        local canAccess = false
        if doc.private then
            local account = user.get(r)
            if account then
                local lid = doc.list_raw:match("<[^.]+%.(.-)>")
                for k, v in pairs(aaa.rights(r, account)) do
                    if v == "*" or v == lid then
                        canAccess = true
                        break
                    end
                end
            else
                r:puts("You must be logged in to view this email")
                return cross.OK
            end
        else
            canAccess = true
        end
        if canAccess then
            doc.tid = doc.request_id
            r:puts(doc.source)
        else
            r:puts("You do not have access to view this email, sorry.")
        end
    else
        r:puts[[No such email, sorry!]]
    end
    return cross.OK
end

cross.start(handle)<commit_msg>Use the right document type for asssessment<commit_after>--[[
 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 source.lua - a script for displaying the source of an email

local elastic = require 'lib/elastic'
local aaa = require 'lib/aaa'
local user = require 'lib/user'
local cross = require 'lib/cross'

function handle(r)
    r.content_type = "text/plain"
    local get = r:parseargs()
    local eid = (get.id or r.path_info):gsub("\"", ""):gsub("/", "")
    local doc = elastic.get("mbox", eid or "hmm")
    
    -- Try searching by mid if not found, for backward compat
    if not doc or not doc.subject then
        local docs = elastic.find("message-id:\"" .. r:escape(eid) .. "\"", 1, "mbox")
        if #docs == 1 then
            doc = docs[1]
        end
    end
    if doc then
        local canAccess = false
        if doc.private then
            local account = user.get(r)
            if account then
                local lid = doc.list_raw:match("<[^.]+%.(.-)>")
                for k, v in pairs(aaa.rights(r, account)) do
                    if v == "*" or v == lid then
                        canAccess = true
                        break
                    end
                end
            else
                r:puts("You must be logged in to view this email")
                return cross.OK
            end
        else
            canAccess = true
        end
        if canAccess then
            doc.tid = doc.request_id
            local doc_raw = elastic.get('mbox_source', doc.request_id)
            if doc_raw then
                r:puts(doc_raw.source)
            else
                r:puts("No such email")
            end
        else
            r:puts("You do not have access to view this email, sorry.")
        end
    else
        r:puts[[No such email, sorry!]]
    end
    return cross.OK
end

cross.start(handle)
{'fraction_non_alphanumeric': 0.08683529177454691, 'fraction_numerical': 0.0027882891854212307, 'mean_word_length': 1.9839572192513368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5244594', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1304, 'n_words': 563}