You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2016/09/13 08:26:49 UTC
[2/5] incubator-ponymail git commit: support old shortlink format,
add comments
support old shortlink format, add comments
Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/c80da618
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/c80da618
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/c80da618
Branch: refs/heads/coffee-and-cake
Commit: c80da6189209b557b0a791f7cc6fcee69eaa8694
Parents: db4eed8
Author: Daniel Gruno <hu...@apache.org>
Authored: Tue Sep 13 10:24:09 2016 +0200
Committer: Daniel Gruno <hu...@apache.org>
Committed: Tue Sep 13 10:24:09 2016 +0200
----------------------------------------------------------------------
site/js/coffee/misc.coffee | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/c80da618/site/js/coffee/misc.coffee
----------------------------------------------------------------------
diff --git a/site/js/coffee/misc.coffee b/site/js/coffee/misc.coffee
index 92091ec..c4c387e 100644
--- a/site/js/coffee/misc.coffee
+++ b/site/js/coffee/misc.coffee
@@ -94,16 +94,25 @@ 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 = (mid) ->
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 and (pm_config and pm_config.shortLinks)
out = ""
+ ### For each bit in $howlongdowewantthis ... ###
for i in [0..shortBits-1]
+ ### 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
out += res
@@ -112,15 +121,30 @@ shortenURL = (mid) ->
return mid
unshortenURL = (mid) ->
+ ### If new format ... ###
if mid.substr(0,2) == 'PZ'
out = ""
+ ### For each 7-char bit, convert from base36 to base16, remove padding ###
for i in [0..shortBits-1]
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
+ ### Old format from 0.9 and before ###
+ else if mid[0] == 'Z' or mid[0] == 'B'
+ out = ""
+ ### For each 7-char bit, convert from base36 to base16, remove padding ###
+ for i in [0..1]
+ 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