1
0
mirror of https://github.com/AG7GN/nexus-utilities.git synced 2025-05-20 08:20:11 -07:00

Added ability to send attachments to patmail.sh

This commit is contained in:
Steve Magnuson 2020-04-06 08:50:36 -07:00
parent 70b9dd9828
commit 39e90bfc4b
2 changed files with 46 additions and 9 deletions

View File

@ -1 +1 @@
VERSION="2.1.18" VERSION="2.1.19"

View File

@ -3,8 +3,9 @@
# HEADER # HEADER
#================================================================ #================================================================
#% SYNOPSIS #% SYNOPSIS
#+ ${SCRIPT_NAME} [-hv] TO SUBECT TRANSPORT #+ ${SCRIPT_NAME} [-hv]
#+ ${SCRIPT_NAME} [-l FILE] TO SUBECT TRANSPORT #+ ${SCRIPT_NAME} TO SUBECT TRANSPORT
#+ ${SCRIPT_NAME} [-l FILE] [-f FILE] TO SUBECT TRANSPORT
#% #%
#% DESCRIPTION #% DESCRIPTION
#% This script allows sending Winlink messages via the command line or script. #% This script allows sending Winlink messages via the command line or script.
@ -18,6 +19,9 @@
#% overwritten if it exists. #% overwritten if it exists.
#% To send output to stdout, use /dev/stdout. #% To send output to stdout, use /dev/stdout.
#% Default: /dev/null #% Default: /dev/null
#% -f FILE, --file=FILE Attach file to message where file is full path to
#% file. To attach multiple files, use multiple -f FILE,
#% one per attached file.
#% #%
#% COMMANDS (All 3 COMMANDS are required) #% COMMANDS (All 3 COMMANDS are required)
#% TO One or more recipient email addresses #% TO One or more recipient email addresses
@ -63,7 +67,7 @@
#% #%
#================================================================ #================================================================
#- IMPLEMENTATION #- IMPLEMENTATION
#- version ${SCRIPT_NAME} 2.2.7 #- version ${SCRIPT_NAME} 2.3.4
#- author Steve Magnuson, AG7GN #- author Steve Magnuson, AG7GN
#- license CC-BY-SA Creative Commons License #- license CC-BY-SA Creative Commons License
#- script_id 0 #- script_id 0
@ -153,7 +157,7 @@ VERSION="$(ScriptInfo version | grep version | tr -s ' ' | cut -d' ' -f 4)"
#============================ #============================
#== set short options ==# #== set short options ==#
SCRIPT_OPTS=':l:hv-:' SCRIPT_OPTS=':f:l:hv-:'
#== set long options associated with short one ==# #== set long options associated with short one ==#
typeset -A ARRAY_OPTS typeset -A ARRAY_OPTS
@ -161,8 +165,11 @@ ARRAY_OPTS=(
[help]=h [help]=h
[version]=v [version]=v
[log]=l [log]=l
[file]=f
) )
declare -a ATTACHMENTS=()
LONG_OPTS="^($(echo "${!ARRAY_OPTS[@]}" | tr ' ' '|'))=" LONG_OPTS="^($(echo "${!ARRAY_OPTS[@]}" | tr ' ' '|'))="
# Parse options # Parse options
@ -194,7 +201,8 @@ do
fi fi
# Options followed by another option instead of argument # Options followed by another option instead of argument
if [[ "x${OPTION}" != "x:" ]] && [[ "x${OPTION}" != "x?" ]] && [[ "${OPTARG}" = -* ]]; then if [[ "x${OPTION}" != "x:" ]] && [[ "x${OPTION}" != "x?" ]] && [[ "${OPTARG}" = -* ]]
then
OPTARG="$OPTION" OPTION=":" OPTARG="$OPTION" OPTION=":"
fi fi
@ -211,6 +219,9 @@ do
l) l)
EVENT_LOG="$OPTARG" EVENT_LOG="$OPTARG"
;; ;;
f)
ATTACHMENTS+=("$OPTARG")
;;
:) :)
Die "${SCRIPT_NAME}: -$OPTARG: option requires an argument" Die "${SCRIPT_NAME}: -$OPTARG: option requires an argument"
;; ;;
@ -256,18 +267,44 @@ SUBJECT="$2"
export EDITOR=ed export EDITOR=ed
TFILE="${TMPDIR}/message" TFILE="${TMPDIR}/message"
echo -e "$CALL\n$TO\n\n$SUBJECT" | $PAT compose 2>/dev/null 1> $TFILE HEADER="$CALL\n$TO\n\n$SUBJECT"
echo -e "$HEADER" | $PAT compose 2>/dev/null 1> $TFILE
MSG="$(grep "MID:" $TFILE | tr -d ' \t' | cut -d':' -f3)" MSG="$(grep "MID:" $TFILE | tr -d ' \t' | cut -d':' -f3)"
[[ $MSG == "" ]] && Die "Could not find the MID (Message ID)" [[ $MSG == "" ]] && Die "Could not find the MID (Message ID)"
MSG="$OUTDIR/$MSG.b2f" MSG="$OUTDIR/$MSG.b2f"
sed -i -e 's/<No message body>//' $MSG sed -i -e 's/<No message body>//' $MSG
if (( ${#ATTACHMENTS[@]} ))
then
for F in "${ATTACHMENTS[@]}"
do
if [ -s "$F" ]
then
SIZE=$(stat -L --printf="%s" "$F")
HEADER="File: $SIZE ${F##*/}"
sed -i "/^From: .*/i $HEADER" "$MSG"
else
rm "$MSG"
Die "Attachment \"$F\" empty or not found. Message not sent."
fi
done
fi
$UNIX2DOS -q $MSG $UNIX2DOS -q $MSG
cat - > $TFILE cat - > $TFILE
echo >> $TFILE
$UNIX2DOS -q $TFILE $UNIX2DOS -q $TFILE
COUNT="$(wc -c $TFILE | cut -d' ' -f1)" COUNT="$(wc -c $TFILE | cut -d' ' -f1)"
cat $TFILE >> $MSG cat $TFILE >> $MSG
#rm $TFILE
sed -i -e "s/^Body: .*/Body: $COUNT/" $MSG sed -i -e "s/^Body: .*/Body: $COUNT/" $MSG
if (( ${#ATTACHMENTS[@]} ))
then
for F in "${ATTACHMENTS[@]}"
do
cat "$F" >> "$MSG"
echo -e -n "\r\n" >> "$MSG"
done
fi
#rm $TFILE
echo > "$EVENT_LOG" echo > "$EVENT_LOG"
$PAT --send-only --event-log "$EVENT_LOG" connect $3 >> "$EVENT_LOG" $PAT --send-only --event-log "$EVENT_LOG" connect $3 >> "$EVENT_LOG"
exit $? exit $?