diff options
| -rwxr-xr-x | grab-url-from-mail-alpha.sh | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/grab-url-from-mail-alpha.sh b/grab-url-from-mail-alpha.sh index 0ebf2d1..ee15c95 100755 --- a/grab-url-from-mail-alpha.sh +++ b/grab-url-from-mail-alpha.sh @@ -1,7 +1,5 @@ #!/bin/bash -GUFM_OWNER_ADDRESS="[email protected]"; -GUFM_SEND_FROM="[email protected]"; GUFM_USER_AGENT="Mozilla/5.0 (X11; Linux x86_64;rv:42.0) Gecko/20100101 Firefox/42.0"; # max mail lines to be saved. GUFM_MAX_MESSAGE_LINES=32; @@ -11,7 +9,12 @@ GUFM_MAX_MESSAGE_LINE_LENGTH=256; GUFM_LOG_FILE="/home/a/ams/hacks/gufm.log"; GUFM_DEBUG=1; -GUFM_ALLOWED_SENDERS_FILE="/home/a/ams/grab-url-from-url-alpha.conf"; +GUFM_CONFIG_FILE="/home/a/ams/grab-url-from-mail-alpha.conf"; +if [ ! -e ${GUFM_CONFIG_FILE} ]; then + echo "${GUFM_CONFIG_FILE}: file not found" + exit 1 +fi +. "${GUFM_CONFIG_FILE}"; MESSAGE_ID=""; # filled later, se below. # misc functions @@ -33,16 +36,7 @@ function gufm_cleanup() { trap gufm_cleanup EXIT SIGHUP SIGQUIT SIGINT SIGTERM SIGKILL; -# lets load the allowed senders email addresses; format: -# declare -A gufm_allowed_senders=( -# [[email protected]]=1 -# [[email protected]]=1 -# ) -# thanks for that idea AMS! -# attention: hash table name `gufm_allowed_senders` hardcoded, -# no easy way to make it configurable. -. "${GUFM_ALLOWED_SENDERS_FILE}"; -for sender in "${!gufm_allowed_senders[@]}"; do +for sender in "${!GUFM_ALLOWED_SENDERS[@]}"; do l "loaded allowed sender: '$sender'."; done @@ -64,7 +58,7 @@ function gufm_is_allowed() { # this repeated check basically checks for malformed From: fields # in case above conditions kicked in and From: contained e.g.: <> [ "${sender}" == "" ] && { l "empty sender"; return 0; } - is_allowed=${gufm_allowed_senders["${sender}"]}; + is_allowed=${GUFM_ALLOWED_SENDERS["${sender}"]}; [ "${is_allowed}" == "1" ] && { l "welcome '${sender}'"; return 0; } l "'${sender}' disallowed."; return 1; @@ -137,7 +131,7 @@ function gufm_validate_url() { local url="${1}"; [ "${url}" != "" ] || return 1; - [[ ${url} =~ ^[a-zA-Z/\.@:\?\=\+\&0-9%]*$ ]] || return 2; + [[ ${url} =~ ^[a-zA-Z/\.@:\?\=\+\&0-9%-]*$ ]] || return 2; return 0; } @@ -174,7 +168,7 @@ gufm_is_allowed "${from}" || { gufm_sender_not_allowed "${from}" "${url}" "${tmp tmpfile=`mktemp`; l "saving into '${tmpfile}'"; -curl -k -L -X GET -H "User-Agent: ${GUFM_USER_AGENT}" -o "${tmpfile}" "${url}" 2>/dev/null; +url_effective=`curl -s -k -L -w '%{url_effective}' -X GET -H "User-Agent: ${GUFM_USER_AGENT}" -o "${tmpfile}" "${url}"`; l "curl rc=$?"; file="foo"; @@ -192,6 +186,15 @@ else decode_eof="_EOF_-${file}.html"; fi; +url_message="" +if [ "${url}" != "${url_effective}" ]; then + url_message="The URL + ${url} +was redirected to + ${url_effective} +" +fi + cat <<EOM | /usr/lib/sendmail -f ${GUFM_SEND_FROM} -oi -t 2>/dev/null To: ${from} From: ${GUFM_SEND_FROM} @@ -199,7 +202,7 @@ Reply-To: ${from} Content-Type: text/plain; charset=us-ascii Subject: wget: 1 files retrieved with wget $url -${url} +${url_message} Please report bugs to ${GUFM_OWNER_ADDRESS}. |
