URI: 
       Don't sanitize handle within get/send mail - postreich - Unnamed repository; edit this file 'description' to name the repository.
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit cacd7ba6b69159c5970baaf1eef3f759f23e9be4
   DIR parent dff1a971ef77a24ce8bcefa9f48427c84ba908c3
  HTML Author: Scarlett McAllister <no+reply@roygbyte.com>
       Date:   Sat, 20 Jan 2024 18:35:05 -0400
       
       Don't sanitize handle within get/send mail
       
       Handle is only used for matching. Otherwise, the results are
       confusing: the commands might produce an output that does not exactly
       accord with the input. Like, might input a string like "hello?>!.,*",
       and that gets sanitized to "hello", for which there is a mailbox. But,
       of course that doesn't match the input, so kinda weird! No good.
       
       Diffstat:
         M geomyidae/postoffice/get-mailbox    |      62 +++++++++++++++++++------------
         M geomyidae/postoffice/send-mail      |      39 ++++++++++++++++++++++---------
       
       2 files changed, 66 insertions(+), 35 deletions(-)
       ---
   DIR diff --git a/geomyidae/postoffice/get-mailbox b/geomyidae/postoffice/get-mailbox
       @@ -1,44 +1,58 @@
        #!/bin/sh
        # Args:
        #        $1 handle
       +#
       +# Result:
       +#        filename
       +#
       +# Usage:
       +#        Retrieve the filename of the pubkey
       +#        $ get-mailbox -k roygbyte
       +#        Dump the contents of the pubkey
       +#        $ get-mailbox -k -c roygbyte
        
        . ./common
        
       -if [ ! -r $MAILBOXES ]; then
       -    printf "Can't find or read mailbox file.\n"
       +attr_dir="$MAILBOXES"
       +attr_label="Mailbox"
       +contents=1
       +
       +while getopts "kc" f
       +do
       +    case $f in
       +        k)
       +            attr_dir="$PUBKEYS"
       +            attr_label="Pubkey"
       +            ;;
       +        c)
       +            contents=0
       +            ;;
       +    esac
       +done
       +shift `expr $OPTIND - 1` # Move pos args to front
       + 
       +if [ ! -d "$attr_dir" ]; then
       +    printf "$attr_label directory does not exist.\n"
            return 1
        fi
        
       -handle=$( sanitize_handle "$1" )
       +handle="$1"
        if [ ! -n "$handle" ]; then
            printf "Specify a handle.\n"
            return 1
        fi
        
       -result=$( awk -v handle="$handle" '
       -BEGIN {
       -      FS = "\t"
       -}
       -{
       -        if ( handle == $1 ) {
       -           print $2 # return public key
       -           exit 0
       -        }
       -}
       -' "$MAILBOXES" )
       -
       -if [ ! -n "$result" ]; then
       -    printf "Mailbox not found.\n"
       +result=$( ls -x1 "$attr_dir" \
       +              | grep -xic "$handle" )
       +if [ $result -eq 0 ]; then
       +    printf "$attr_label not found.\n"
            return 2
        fi
        
       -result=$( decode_and_verify_pubkey "$result" )
       -if [ ! $? ]; then
       -    printf "$result"
       -    return 1
       +if [ $contents -eq 0 ]; then
       +    cat "$attr_dir/$handle"
       +else    
       +    printf "%s\n" "$attr_dir/$handle"
        fi
       -public_key="$result"
       -
       -printf "%s\n" "$result"
        return 0
        
   DIR diff --git a/geomyidae/postoffice/send-mail b/geomyidae/postoffice/send-mail
       @@ -7,24 +7,41 @@
        
        # 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=$?
       -if [ ! $exit_code ]; then
       +message=$( sanitize_message "$2")
       +handle="$1"
       +result=$( ./get-mailbox -k "$handle" )
       +if [ ! $? -eq 0 ]; then
            printf "$result"
            return 1
        fi
       +pubkey="$result"
        
       +result=$( ./get-mailbox "$handle" )
       +if [ ! $? -eq 0 ]; then
       +    printf "$result"
       +    return 1
       +fi
       +mailbox="$result"
        
       +result=$( printf "%s" "$message" \
       +              | encrypt_with_key_and_encode "$pubkey" )
       +if [ ! $? ]; then
       +    printf "Encryption or encoding failed.\n"
       +    return 1
       +fi
        
       -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>
       -#                                        or should it be handle\tmessage
       +timestamp=$( date )
       +printf "%s,%s\n" "$timestamp" "$result" >> "$mailbox"
        
        # need to verify the message is below a certain length
       -# need to verify the chosen border exists
       +
       +# need to verify the chosen border exists, ideally using some
       +#    smart way...
       +# what if... there is a `type` of mail option. and the first `type` to
       +#   implement will be the `vday card`. there could also be like..
       +# `snail mail` or `hate mail` or... `love letters` or...
       +# `fan mail`
       +
       +