summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSlatian <baschdel@disroot.org>2023-11-17 18:10:47 +0100
committerSimon Lees <simon@simotek.net>2023-11-27 00:09:09 +0000
commitcf194f0133b0c3585da5e830e19e27861b8baaf4 (patch)
tree49bdd7c20300d2f270901b500476274dd7b94c37
parent52484b7a9457ee98f989fdfd680cb240df04b67d (diff)
Shellchecked xdg-email:
* Replace backticks with `"$(` * Quote variables and replacements (non un-quotes seemed intentional) * Moved `local` variable definitions to their own lines so they don't clash with value assignment * fixed formattting in `open_envvar` Not fixed: * SC3037 (warning): In POSIX sh, echo flags are undefined. (Fixing those is a bit more involved)
-rw-r--r--scripts/xdg-email.in88
1 files changed, 45 insertions, 43 deletions
diff --git a/scripts/xdg-email.in b/scripts/xdg-email.in
index b23231a..fc24886 100644
--- a/scripts/xdg-email.in
+++ b/scripts/xdg-email.in
@@ -34,21 +34,21 @@ run_thunderbird()
{
local THUNDERBIRD MAILTO NEWMAILTO TO CC BCC SUBJECT BODY ATTACH
THUNDERBIRD="$1"
- MAILTO=$(echo "$2" | sed 's/^mailto://')
+ MAILTO="$(echo "$2" | sed 's/^mailto://')"
echo "$MAILTO" | grep -qs "^?"
if [ "$?" = "0" ] ; then
- MAILTO=$(echo "$MAILTO" | sed 's/^?//')
+ MAILTO="$(echo "$MAILTO" | sed 's/^?//')"
else
- MAILTO=$(echo "$MAILTO" | sed 's/^/to=/' | sed 's/?/\&/')
+ MAILTO="$(echo "$MAILTO" | sed 's/^/to=/' | sed 's/?/\&/')"
fi
- MAILTO=$(echo "$MAILTO" | sed 's/&/\n/g')
- TO=$(/bin/echo -e $(echo "$MAILTO" | grep '^to=' | sed 's/^to=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
- CC=$(/bin/echo -e $(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
- BCC=$(/bin/echo -e $(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
- SUBJECT=$(echo "$MAILTO" | grep '^subject=' | tail -n 1)
- BODY=$(echo "$MAILTO" | grep '^body=' | tail -n 1)
- ATTACH=$(/bin/echo -e $(echo "$MAILTO" | grep '^attach=' | sed 's/^attach=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }' | sed 's/,$//'))
+ MAILTO="$(echo "$MAILTO" | sed 's/&/\n/g')"
+ TO="$(/bin/echo -e "$(echo "$MAILTO" | grep '^to=' | sed 's/^to=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }')")"
+ CC="$(/bin/echo -e "$(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }')")"
+ BCC="$(/bin/echo -e "$(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }')")"
+ SUBJECT="$(echo "$MAILTO" | grep '^subject=' | tail -n 1)"
+ BODY="$(echo "$MAILTO" | grep '^body=' | tail -n 1)"
+ ATTACH="$(/bin/echo -e "$(echo "$MAILTO" | grep '^attach=' | sed 's/^attach=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }' | sed 's/,$//')")"
if [ -z "$TO" ] ; then
NEWMAILTO=
@@ -84,22 +84,23 @@ run_thunderbird()
open_kde()
{
+ local kreadconfig profile client
if [ -n "$KDE_SESSION_VERSION" ] && [ "$KDE_SESSION_VERSION" -ge 5 ]; then
- local kreadconfig=kreadconfig$KDE_SESSION_VERSION
+ kreadconfig=kreadconfig$KDE_SESSION_VERSION
else
- local kreadconfig=kreadconfig
+ kreadconfig=kreadconfig
fi
- if command -v $kreadconfig >/dev/null; then
- local profile=$($kreadconfig --file emaildefaults \
- --group Defaults --key Profile)
+ if command -v "$kreadconfig" >/dev/null; then
+ profile="$("$kreadconfig" --file emaildefaults \
+ --group Defaults --key Profile)"
if [ -n "$profile" ]; then
- local client=$($kreadconfig --file emaildefaults \
+ client="$("$kreadconfig" --file emaildefaults \
--group "PROFILE_$profile" \
--key EmailClient \
- | cut -d ' ' -f 1)
+ | cut -d ' ' -f 1)"
if [ -z "${client%%*.desktop}" ] && ! command -v "$client" >/dev/null 2>&1; then
- client=`desktop_file_to_binary "$client"`
+ client="$(desktop_file_to_binary "$client")"
fi
if echo "$client" | grep -Eq 'thunderbird|icedove'; then
@@ -115,14 +116,14 @@ open_kde()
*) command=kde-open$KDE_SESSION_VERSION ;;
esac
- if command -v $command >/dev/null; then
+ if command -v "$command" >/dev/null; then
DEBUG 1 "Running $command \"$1\""
if [ "$KDE_SESSION_VERSION" = 3 ]; then
# KDE3 uses locale's encoding when decoding the URI,
# so set it to UTF-8
- LC_ALL=C.UTF-8 $command "$1"
+ LC_ALL=C.UTF-8 "$command" "$1"
else
- $command "$1"
+ "$command" "$1"
fi
else
DEBUG 1 "$command missing; trying generic mode instead."
@@ -140,9 +141,9 @@ open_gnome3()
{
local client
local desktop
- desktop=`xdg-mime query default "x-scheme-handler/mailto"`
- client=`desktop_file_to_binary "$desktop"`
- case $client in *thunderbird*|*icedove*)
+ desktop="$(xdg-mime query default "x-scheme-handler/mailto")"
+ client="$(desktop_file_to_binary "$desktop")"
+ case "$client" in *thunderbird*|*icedove*)
run_thunderbird "$client" "$1"
esac
@@ -167,8 +168,8 @@ open_gnome3()
open_gnome()
{
local client
- client=`gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -d ' ' -f 1`
- case $client in *thunderbird*|*icedove*)
+ client="$(gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -d ' ' -f 1)"
+ case "$client" in *thunderbird*|*icedove*)
run_thunderbird "$client" "$1"
esac
@@ -195,9 +196,9 @@ open_lxqt()
{
local client
local desktop
- desktop=`qtxdg-mat def-email-client 2>/dev/null`
- client=`desktop_file_to_binary "$desktop"`
- echo $client | grep -E 'thunderbird|icedove' > /dev/null 2>&1
+ desktop="$(qtxdg-mat def-email-client 2>/dev/null)"
+ client="$(desktop_file_to_binary "$desktop")"
+ echo "$client" | grep -E 'thunderbird|icedove' > /dev/null 2>&1
if [ $? -eq 0 ] ; then
run_thunderbird "$client" "$1"
fi
@@ -230,16 +231,16 @@ open_xfce()
open_envvar()
{
- local OLDIFS="$IFS"
+ old_ifs="$IFS"
IFS=:
for i in $MAILER; do
- IFS="$OLDIFS"
+ IFS="$old_ifs"
- eval "$i" '"$1"'
+ eval "$i" '"$1"'
- if [ $? -eq 0 ]; then
- exit_success
- fi
+ if [ $? -eq 0 ]; then
+ exit_success
+ fi
done
exit_failure_operation_failed
@@ -264,9 +265,9 @@ open_generic()
{
local client
local desktop
- desktop=`xdg-mime query default "x-scheme-handler/mailto"`
- client=`desktop_file_to_binary "$desktop"`
- case $client in *thunderbird*|*icedove*)
+ desktop="$(xdg-mime query default "x-scheme-handler/mailto")"
+ client="$(desktop_file_to_binary "$desktop")"
+ case "$client" in *thunderbird*|*icedove*)
run_thunderbird "$client" "$1"
esac
@@ -279,9 +280,10 @@ url_encode()
# The shell needs the default internal field separator
# otherwise it would search for $utf8 as a command in whole.
IFS=" "
-str=$(echo "$1" | $utf8)
-local ORIG_LANG="$LANG"
-local ORIG_LC_ALL="$LC_ALL"
+str="$(echo "$1" | $utf8)"
+local ORIG_LANG ORIG_LC_ALL
+ORIG_LANG="$LANG"
+ORIG_LC_ALL="$LC_ALL"
LANG=C
LC_ALL=C
result=$(echo "$str" | awk '
@@ -375,7 +377,7 @@ while [ $# -gt 0 ] ; do
exit_failure_syntax "file argument missing for --attach option"
fi
check_input_file "$1"
- file=`readlink -f "$1"` # Normalize path
+ file="$(readlink -f "$1")" # Normalize path
if [ -z "$file" ] || [ ! -f "$file" ] ; then
exit_failure_file_missing "file '$1' does not exist"
fi
@@ -428,7 +430,7 @@ case $mailto in
esac
# Strip trailing ? and &
-mailto=`echo "${mailto}"| sed 's/[?&]$//'`
+mailto="$(echo "${mailto}"| sed 's/[?&]$//')"
# Shouldn't happen
[ x"${mailto}" != x"" ] || exit_failure_syntax