You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2024/12/05 14:49:28 UTC

(incubator-ponymail-foal) 01/03: Allow search by Message-Id

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit 8f2da3896e2e44f65747c9a026b66f62961c249c
Author: Sebb <se...@apache.org>
AuthorDate: Thu Dec 5 14:48:01 2024 +0000

    Allow search by Message-Id
---
 server/openapi.yaml        | 4 ++++
 server/plugins/defuzzer.py | 6 +++++-
 webui/js/source/search.js  | 9 +++++++++
 webui/list.html            | 1 +
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/server/openapi.yaml b/server/openapi.yaml
index 4c22c81..23e2ef4 100644
--- a/server/openapi.yaml
+++ b/server/openapi.yaml
@@ -83,6 +83,10 @@ components:
           description: "Optional To: header search for narrowing down results"
           type: string
           example: janedoe@example.org
+        header_messageid:
+          description: "Optional Message-Id: header search for narrowing down results"
+          type: string
+          example: "<52...@unhygienix.ics.uci.edu>"
       required:
       - list
       - domain
diff --git a/server/plugins/defuzzer.py b/server/plugins/defuzzer.py
index 65dd0a5..42e2592 100644
--- a/server/plugins/defuzzer.py
+++ b/server/plugins/defuzzer.py
@@ -211,10 +211,13 @@ def defuzz(formdata: dict, nodate: bool = False, list_override: typing.Optional[
             )
 
     # Header parameters
-    for header in ["from", "subject", "body", "to"]:
+    for header in ["from", "subject", "body", "to", "messageid"]:
         hname = "header_%s" % header
         if hname in formdata:
             hvalue = formdata[hname]
+            # '-' not allowed in variable names, so we convert here
+            if header == 'messageid':
+                header = 'message-id'
             must.append({"match_phrase": {header: hvalue}})
 
     query_as_bool = {"must": must}
@@ -222,4 +225,5 @@ def defuzz(formdata: dict, nodate: bool = False, list_override: typing.Optional[
     if must_not:
         query_as_bool["must_not"] = must_not
 
+    print(query_as_bool)
     return query_as_bool
diff --git a/webui/js/source/search.js b/webui/js/source/search.js
index 79047d9..8f69425 100644
--- a/webui/js/source/search.js
+++ b/webui/js/source/search.js
@@ -37,6 +37,7 @@ function search(query, date) {
     let header_subject = document.getElementById('header_subject');
     let header_to = document.getElementById('header_to');
     let header_body = document.getElementById('header_body');
+    let header_messageid = document.getElementById('header_messageid');
     let qparts = query.split('&'); // look for additional query options
     if (qparts.length > 0) { // i.e. query + header bits
         query = qparts.shift(); // Keep only the query
@@ -55,6 +56,9 @@ function search(query, date) {
             if (hv[0] == 'header_body') {
                 header_body.value = hv[1];
             }
+            if (hv[0] == 'header_messageid') {
+                header_messageid.value = hv[1];
+            }
             // N.B. other options are currently ignored
         }
     }
@@ -82,6 +86,11 @@ function search(query, date) {
         newhref += "&header_body=%s".format(header_body.value);
         header_body.value = "";
     }
+    if (header_messageid.value.length > 0) {
+        sURL += "&header_messageid=%s".format(encodeURIComponent(header_messageid.value));
+        newhref += "&header_messageid=%s".format(header_messageid.value);
+        header_messageid.value = "";
+    }
     GET(sURL, renderListView, {
         search: true,
         global: global
diff --git a/webui/list.html b/webui/list.html
index 7437a0d..2687175 100644
--- a/webui/list.html
+++ b/webui/list.html
@@ -71,6 +71,7 @@ the License. -->
             <div style="display: inline-block; width: 120px;">Subject: </div><span id='hd_subject'><input style="min-width: 200px; margin-right: 10px; background-color: white; font-size: 8pt;" name="header_subject" id='header_subject' value=""/></span><br/>
             <div style="display: inline-block; width: 120px;">To: </div><span id='hd_to'><input title="Name or email address" style="min-width: 200px; margin-right: 10px; background-color: white; font-size: 8pt;" name="header_to" id='header_to' value=""/></span><br/>
             <div style="display: inline-block; width: 120px;">Body: </div><span id='hd_body'><input style="min-width: 200px; margin-right: 10px; background-color: white; font-size: 8pt;" name="header_body" id='header_body' value=""/></span><br/>
+            <div style="display: inline-block; width: 120px;">Message-Id: </div><span id='hd_message_id'><input style="min-width: 200px; margin-right: 10px; background-color: white; font-size: 8pt;" name="header_messageid" id='header_messageid' value=""/></span><br/>
           </li>
         </ul>