mutt: Add ciscoclean
authorStefan Huber <shuber@sthu.org>
Fri, 6 Mar 2020 11:04:50 +0000 (12:04 +0100)
committerStefan Huber <shuber@sthu.org>
Fri, 6 Mar 2020 11:11:05 +0000 (12:11 +0100)
dotfiles/mutt/scripts/ciscoclean [new file with mode: 0755]

diff --git a/dotfiles/mutt/scripts/ciscoclean b/dotfiles/mutt/scripts/ciscoclean
new file mode 100755 (executable)
index 0000000..a94c4d5
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+set -e
+
+PROG="$0"
+
+ciscowipe() {
+    # Remove secure-web.cisco.com prefix
+      sed -E "s!https?://secure-web.cisco.com/[^/ ]*/!!g" |
+    # URL decode
+     # Decodes all URL escape sequences
+     #sed -e 's!+! !g;s!%\([0-9A-Fa-f]\{2\}\)!\\x\1!g' | xargs -0 printf "%b"
+     # Decodes only some escape sequences, but leaves others, like spacs,
+     # as is.
+     sed 's!%3A!:!g;s!%2F!/!g;s!%3F!?!g;s!%3D!=!g;s!%26!\&!g'
+}
+
+usage() {
+    cat<<EOF
+Mr. Clean for Cisco's mail snakeoil. It restores the original URL from the URL
+generated by Cisco's mail security software.
+
+Usage:
+    $PROG -h
+    $PROG [FILE]...
+
+If no filename is given then stdin is processed. Otherwise all files passed are
+processed.
+EOF
+}
+
+if [ "$#" -eq 0 ]; then
+    ciscowipe
+else
+    for f in "$@"; do
+        if [ "$f" = "-h" ]; then
+            usage
+            exit
+        fi
+        cat "$f" | ciscowipe
+    done
+fi