ponymail-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject [5/5] incubator-ponymail git commit: regen JS
Date Tue, 13 Sep 2016 08:26:52 GMT
regen JS


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

Branch: refs/heads/coffee-and-cake
Commit: d43cc586b094b98b2c2cb13301d4697c9a286326
Parents: 36d40d3
Author: Daniel Gruno <humbedooh@apache.org>
Authored: Tue Sep 13 10:26:29 2016 +0200
Committer: Daniel Gruno <humbedooh@apache.org>
Committed: Tue Sep 13 10:26:29 2016 +0200

----------------------------------------------------------------------
 site/js/ponymail-coffee.js | 42 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/d43cc586/site/js/ponymail-coffee.js
----------------------------------------------------------------------
diff --git a/site/js/ponymail-coffee.js b/site/js/ponymail-coffee.js
index ed44502..6f6a0d5 100644
--- a/site/js/ponymail-coffee.js
+++ b/site/js/ponymail-coffee.js
@@ -2537,17 +2537,34 @@ ponymail_url_regex = new RegExp("(" + "(?:(?:[a-z]+)://)" + "(?:\\S+(?::\\S*)?@)
 
 ponymail_quote_regex = new RegExp("((?:\r?\n)((on .+ wrote:[\r\n]+)|(sent from my .+)|(>+[
\t]*[^\r\n]*\r?\n[^\n]*\n*)+)+)+", "mi");
 
+
+/**
+ * How many bits (of 7 chars each) do we want in our shortLink?
+ * The more bits, the more precise, the fewer bits, the shorter the link.
+ */
+
 shortBits = 3;
 
+
+/* Shortener: cut MID into pieces, convert to base36 to save 3-4 bytes */
+
 shortenURL = function(mid) {
   var a, arr, i, j, num, out, ref, res;
   arr = mid.split("@");
+
+  /* IF arr is 2 bits, it's fine to shorten it (meduim/long generator). if 3, then potentially
not (short generator) */
   if (arr.length === 2 && (pm_config && pm_config.shortLinks)) {
     out = "";
+
+    /* For each bit in $howlongdowewantthis ... */
     for (i = j = 0, ref = shortBits - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <=
ref ? ++j : --j) {
+
+      /* Cut off 8 chars, convert from base16 to base36 */
       a = arr[0].substr(i * 8, 8);
       num = parseInt(a, 16);
       res = num.toString(36);
+
+      /* Padding for small numbers */
       while (res.length < 7) {
         res = '-' + res;
       }
@@ -2559,18 +2576,41 @@ shortenURL = function(mid) {
 };
 
 unshortenURL = function(mid) {
-  var i, j, num, out, ref, res;
+
+  /* If new format ... */
+  var i, j, num, o, out, ref, res;
   if (mid.substr(0, 2) === 'PZ') {
     out = "";
+
+    /* For each 7-char bit, convert from base36 to base16, remove padding */
     for (i = j = 0, ref = shortBits - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <=
ref ? ++j : --j) {
       num = parseInt(mid.substr(2 + (i * 7), 7).replace('-', ''), 36);
       res = num.toString(16);
+
+      /* 0-padding for smaller numbers (<8 chars) */
       while (res.length < 8) {
         res = '0' + res;
       }
       out += res;
     }
     return out;
+  } else if (mid[0] === 'Z' || mid[0] === 'B') {
+
+    /* Old format from 0.9 and before */
+    out = "";
+
+    /* For each 7-char bit, convert from base36 to base16, remove padding */
+    for (i = o = 0; o <= 1; i = ++o) {
+      num = parseInt(mid.substr(1 + (i * 7), 7).replace('-', ''), 36);
+      res = num.toString(16);
+
+      /* 0-padding for smaller numbers (<9 chars) */
+      while (res.length < 9) {
+        res = '0' + res;
+      }
+      out += res;
+    }
+    return out;
   } else {
     return mid;
   }


Mime
View raw message