URI: 
       Begin implementing send feature - postreich - Unnamed repository; edit this file 'description' to name the repository.
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit fc8382d31698a17c076eb873c2c25882d360405b
   DIR parent 8330df15a5ef86740b64621ddd57ce8060647f18
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Wed, 17 Jan 2024 20:23:58 -0400
       
       Begin implementing send feature
       
       Diffstat:
         M geomyidae/postoffice/common         |      27 ++++++++++++++++++++++++++-
         M geomyidae/postoffice/create-mailbox |      16 +++-------------
         M geomyidae/postoffice/get-mailbox    |      13 ++++++++++---
         M geomyidae/postoffice/send-mail      |       5 +++--
       
       4 files changed, 42 insertions(+), 19 deletions(-)
       ---
   DIR diff --git a/geomyidae/postoffice/common b/geomyidae/postoffice/common
       @@ -19,6 +19,31 @@ sanitize_handle() {
                | head -c 16
        }
        
       -decode_and_verify_pubkey() {
       +sanitize_message() {
       +    printf "%s" "$1" \
       +        | sed -E 's/[^a-zA-Z0-9\-\\_+=]//g' \
       +        | head -c 16
       +}
        
       +decode_and_verify_pubkey() {
       +    if [ -z "$1" ]; then
       +        printf "No input provided\n"
       +        return 1
       +    fi
       +    decoded_payload=$( printf "$1" "$base64_payload" \
       +                           | base64 -d --ignore-garbage )
       +    # test result of `base64` invocation.
       +    if [ ! $? ]; then
       +        printf "Invalid input given. Payload was not base 64.\n"
       +        return 1
       +    fi
       +    printf "%s" "$decoded_payload" \
       +        | openssl pkey -pubcheck -pubin > /dev/null
       +    # test result of `openssl` invocation. 
       +    if [ ! $? ]; then
       +        printf "Key is not valid.\n"
       +        return 1
       +    fi
       +    printf "%s\n" "$decoded_payload"
       +    return 0
        }
   DIR diff --git a/geomyidae/postoffice/create-mailbox b/geomyidae/postoffice/create-mailbox
       @@ -8,22 +8,12 @@
        
        handle=$( sanitize_handle "$1" )
        base64_payload=$( sanitize_base64 "$2" )
       -decoded_payload=$( printf "%s" "$base64_payload" \
       -                       | base64 -d --ignore-garbage ) # wrap? -w 0
       -# test result of `base64` invocation.
       +result=$( decode_and_verify_pubkey "$base64_payload" )
        if [ ! $? ]; then
       -    printf "Invalid input given. Payload was not base 64.\n"
       +    printf "$result"
            return 1
        fi
       -
       -printf "%s" "$decoded_payload" \
       -    | openssl pkey -pubcheck -pubin > /dev/null
       -# test result of `openssl` invocation. 
       -if [ ! $? ]; then
       -    printf "Key is not valid.\n"
       -    return 1
       -fi
       -public_key="$decoded_payload"
       +public_key="$result"
        
        result=$( ./get-mailbox "$handle" )
        exit_code=$?
   DIR diff --git a/geomyidae/postoffice/get-mailbox b/geomyidae/postoffice/get-mailbox
       @@ -15,7 +15,7 @@ if [ ! -n "$handle" ]; then
            return 1
        fi
        
       -mailbox=$( awk -v handle="$handle" '
       +result=$( awk -v handle="$handle" '
        BEGIN {
              FS = "\t"
        }
       @@ -27,11 +27,18 @@ BEGIN {
        }
        ' "$MAILBOXES" )
        
       -if [ ! -n "$mailbox" ]; then
       +if [ ! -n "$result" ]; then
            printf "Mailbox not found.\n"
            return 2
        fi
        
       -printf "%s\n" "$mailbox"
       +result=$( decode_and_verify_pubkey "$result" )
       +if [ ! $? ]; then
       +    printf "$result"
       +    return 1
       +fi
       +public_key="$result"
       +
       +printf "%s\n" "$result"
        return 0
        
   DIR diff --git a/geomyidae/postoffice/send-mail b/geomyidae/postoffice/send-mail
       @@ -7,6 +7,7 @@
        
        # I am sanitizing inside the ./get-mailbox program, so do I need
        # to do it here for any reason?
       +message=$( sanitize_message "$2" )
        handle=$( sanitize_handle "$1" ) 
        result=$( ./get-mailbox "$handle" )
        exit_code=$?
       @@ -15,9 +16,9 @@ if [ ! $exit_code ]; then
            return 1
        fi
        
       -public_key=$( printf "%s" "$result" \
       -                     | base64 -d --ignore-garbage )
        
       +
       +printf "%s\t%s\n" "$handle" "$message" >> "$MAILROOM"
        # need to decode the mailbox pubkey
        # need to encrypt the message with the pubkey
        # need to add the message to a mailheap/mailroom file, <pubkey>\t<message>