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

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


The following commit(s) were added to refs/heads/master by this push:
     new a9db8a3  allow for unshortening of IDs
a9db8a3 is described below

commit a9db8a36d60c2aba2a9f0cf2520892a22c8147d8
Author: Daniel Gruno <[email protected]>
AuthorDate: Thu Oct 14 19:59:56 2021 +0200

    allow for unshortening of IDs
---
 webui/js/ponymail.js      | 21 +++++++++++++++++++++
 webui/js/source/primer.js | 22 ++++++++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/webui/js/ponymail.js b/webui/js/ponymail.js
index bf5247a..1d5bca2 100644
--- a/webui/js/ponymail.js
+++ b/webui/js/ponymail.js
@@ -3360,6 +3360,7 @@ function parse_permalink() {
     if (mid.match(/\?/)) {
         mid = mid.replace(/\?.*$/, '');
     }
+    mid = unshortenID(mid);  // In case of old school shortened links
     init_preferences(); // blank call to load defaults like social rendering
     GET('%sapi/preferences.lua'.format(apiURL), init_preferences, null);
     // Fetch the thread data and pass to build_single_thread
@@ -3412,6 +3413,26 @@ function render_virtual_inbox(state, json) {
 }
 
 
+// hex <- base 36 conversion, reverses short links
+function unshortenID(mid) {
+    // all short links begin with 'Z'. If not, it's not a short link
+    // so let's just pass it through unaltered if so.
+    // Some old shortlinks begin with 'B', so let's be backwards compatible 
for now.
+    if (mid[0] == 'Z' || mid[0] == 'B') {
+        // remove padding
+        var id1 = parseInt(mid.substr(1, 7).replace(/-/g, ""), 36)
+        var id2 = parseInt(mid.substr(8, 7).replace(/-/g, ""), 36)
+        id1 = id1.toString(16)
+        id2 = id2.toString(16)
+
+        // add 0-padding
+        while (id1.length < 9) id1 = '0' + id1
+        while (id2.length < 9) id2 = '0' + id2
+        return id1+id2
+    }
+    return mid
+}
+
 /******************************************
  Fetched from source/render-email.js
 ******************************************/
diff --git a/webui/js/source/primer.js b/webui/js/source/primer.js
index c3f7cc7..1c5f30f 100644
--- a/webui/js/source/primer.js
+++ b/webui/js/source/primer.js
@@ -146,6 +146,7 @@ function parse_permalink() {
     if (mid.match(/\?/)) {
         mid = mid.replace(/\?.*$/, '');
     }
+    mid = unshortenID(mid);  // In case of old school shortened links
     init_preferences(); // blank call to load defaults like social rendering
     GET('%sapi/preferences.lua'.format(apiURL), init_preferences, null);
     // Fetch the thread data and pass to build_single_thread
@@ -196,3 +197,24 @@ function render_virtual_inbox(state, json) {
         delete async_escrow['rendering'];
     }
 }
+
+
+// hex <- base 36 conversion, reverses short links
+function unshortenID(mid) {
+    // all short links begin with 'Z'. If not, it's not a short link
+    // so let's just pass it through unaltered if so.
+    // Some old shortlinks begin with 'B', so let's be backwards compatible 
for now.
+    if (mid[0] == 'Z' || mid[0] == 'B') {
+        // remove padding
+        var id1 = parseInt(mid.substr(1, 7).replace(/-/g, ""), 36)
+        var id2 = parseInt(mid.substr(8, 7).replace(/-/g, ""), 36)
+        id1 = id1.toString(16)
+        id2 = id2.toString(16)
+
+        // add 0-padding
+        while (id1.length < 9) id1 = '0' + id1
+        while (id2.length < 9) id2 = '0' + id2
+        return id1+id2
+    }
+    return mid
+}
\ No newline at end of file

Reply via email to