| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# aerc filter to view HTML emails with w3m. |
| 4 |
# |
| 5 |
# Networking access will be disabled unless the script is named 'html-unsafe'. |
| 6 |
# |
| 7 |
# If stdout is connected to a TTY, the interactive pager of w3m will be enabled. |
| 8 |
|
| 9 |
set -- w3m \ |
| 10 |
-I UTF-8 -O UTF-8 -T text/html \ |
| 11 |
-s -graph \ |
| 12 |
-o fold_textarea=true \ |
| 13 |
-o fold_line=true \ |
| 14 |
-o decode_url=true \ |
| 15 |
-o display_link=true \ |
| 16 |
"$@" |
| 17 |
|
| 18 |
if [ -t 1 ]; then |
| 19 |
# stdout is connected to a terminal, enable interactive mode |
| 20 |
set -- "$@" -o display_borders=true |
| 21 |
|
| 22 |
if w3m --help 2>&1 | head -n1 | grep -q "options.*image"; then |
| 23 |
# display inline images if support is enabled |
| 24 |
set -- "$@" -o display_image=true -o auto_image=true |
| 25 |
fi |
| 26 |
else |
| 27 |
# stdout is connected to a pager, dump output without interaction |
| 28 |
set -- "$@" -cols 100 -dump -o disable_center=true |
| 29 |
fi |
| 30 |
|
| 31 |
if ! [ "$(basename $0)" = "html-unsafe" ]; then |
| 32 |
# attempt network isolation to prevent any phoning home by rendered emails |
| 33 |
set -- "$@" -o no_cache=true -o use_cookie=false |
| 34 |
|
| 35 |
if command -v unshare >/dev/null 2>&1; then |
| 36 |
# run the command in a separate network namespace |
| 37 |
set -- unshare --map-root-user --net "$@" |
| 38 |
elif command -v socksify >/dev/null 2>&1; then |
| 39 |
# if socksify (from dante-utils) is available, use it |
| 40 |
export SOCKS_SERVER="127.0.0.1:1" |
| 41 |
set -- socksify "$@" |
| 42 |
else |
| 43 |
# best effort, use an invalid address as http proxy |
| 44 |
set -- "$@" -o use_proxy=true |
| 45 |
for opt in http_proxy https_proxy gopher_proxy ftp_proxy; do |
| 46 |
if w3m -o | grep -q $opt; then |
| 47 |
set -- "$@" -o $opt='127.0.0.1:1' |
| 48 |
fi |
| 49 |
done |
| 50 |
fi |
| 51 |
fi |
| 52 |
|
| 53 |
exec "$@" |