URI: 
       Add review stage to sendmail - postreich - Unnamed repository; edit this file 'description' to name the repository.
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit e14d389aa68c3e6256f4a431bf5afabeaa3053a4
   DIR parent b3ecc4f176920e2972e1e51515c07eb479482629
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Sun, 28 Jan 2024 21:13:17 -0400
       
       Add review stage to sendmail
       
       Diffstat:
         M src/geomyidae/api/templates/valent… |       6 ++++++
         M src/geomyidae/sendmail.dcgi         |      38 +++++++++++++++++++++++++------
       
       2 files changed, 37 insertions(+), 7 deletions(-)
       ---
   DIR diff --git a/src/geomyidae/api/templates/valentine/main b/src/geomyidae/api/templates/valentine/main
       @@ -43,6 +43,7 @@ if [ -z "$text" ]; then
            text="$query"
        fi
        sweetheart=$( find_value_in_args "sweetheart" "$path" )
       +handle=$( find_value_in_args "handle" "$path" )
        
        choose_sweetheart() {
            cat "$SWEETHEARTS" \
       @@ -81,6 +82,11 @@ if [ ! $? -eq 0 ]; then
                   $MESSAGE_BYTE_LIMIT
            return 1
        fi
       +
       +# Everything is verified. Build and output the message.
       +
       +printf "%s\nTo: %s\n%s\n" "$sweetheart" "$handle" "$text"
       +
        return 0
        
        # valentine's template will expect a single record with two fields.
   DIR diff --git a/src/geomyidae/sendmail.dcgi b/src/geomyidae/sendmail.dcgi
       @@ -2,26 +2,28 @@
        . ./api/common
        
        path="$2"
       -query="$1"
       +gopher_search="$1"
        
        handle=$( find_value_in_args "handle" "$path" )
        template=$( find_value_in_args "template" "$path" )
       +skip_review=$( find_value_in_args "skip_review" "$path" )
       +query=$( find_value_in_args "query" "$path" )
        
        choose_mailbox() {
            ls -x1 "api/$MAILBOXES" \
                | awk -v t="$template" \
       -              '{ printf "[1|%s|sendmail.dcgi?handle=%s?template=%s|localhost|70]\n", $1, $1, t }'
       +              '{ printf "[1|%s|/sendmail.dcgi?handle=%s?template=%s|localhost|70]\n", $1, $1, t }'
        }
        
        choose_template() {
            ls -x1 "api/$TEMPLATES" \
                | xargs -d '\n' -I x cat "api/$TEMPLATES/"x"/info" \
                | awk -F '\t' -v h="$handle" \
       -              '{ printf "[1|%s|sendmail.dcgi?template=%s?handle=%s|localhost|70]\n", $2, $1, h }'
       +              '{ printf "[1|%s|/sendmail.dcgi?template=%s?handle=%s|localhost|70]\n", $2, $1, h }'
        }
        
        show_footer() {
       -    printf "\n\n[1|Start over|sendmail.dcgi|localhost|70]"
       +    printf "\n\n[1|Start over|/sendmail.dcgi|localhost|70]"
        }
        
        if [ -z "$handle" ]; then
       @@ -38,15 +40,37 @@ if [ -z "$template" ]; then
            return 0
        fi
        
       +if [ -z "$query" ]; then
       +    query="$gopher_search"
       +fi
       +
        result=$( api/$TEMPLATES/$template/main "$path" "$query" )
        if [ ! $? -eq 0 ]; then
            printf "%s" "$result"
            return 0
        fi
        
       -echo $result
       +if [ -z "$skip_review" ]; then
       +    printf "Review your mail before sending:\n\n"
       +    printf "%s\n\n" "$result"
       +    printf "[1|Send it|%s|localhost|70]\n" "$SELECTOR?skip_review=1?query=$query"
       +    show_footer
       +    return 0
       +fi
       +
       +cd api
       +pubkey=$( ./get-mailbox -k "$handle" )
       +mailbox=$( ./get-mailbox "$handle" )
       +result=$( printf "%s" "$result" \
       +              | encrypt_with_key_and_encode "$pubkey" )
       +timestamp=$( date )
       +printf "%s,%s\n" "$timestamp" "$result" >> "$mailbox"
       +cd ..
        
       -echo "ready to send"
       +printf "Mail sent!\n"
       +printf "[1|Return to main office|/|localhost|70]"
        
       -show_footer
       +# todo: prevent resubmission of mail, maybe with a session token tied
       +# to the `skip_review` arg. the token could be stored and checked in a
       +# file somewhere.