sendmail.dcgi - postreich - Unnamed repository; edit this file 'description' to name the repository. DIR Log DIR Files DIR Refs DIR README --- sendmail.dcgi (1930B) --- 1 #!/bin/sh 2 . ./api/common 3 4 path="$2" 5 gopher_search="$1" 6 7 handle=$( find_value_in_args "handle" "$path" ) 8 template=$( find_value_in_args "template" "$path" ) 9 skip_review=$( find_value_in_args "skip_review" "$path" ) 10 query=$( find_value_in_args "query" "$path" ) 11 12 choose_mailbox() { 13 ls -x1 "api/$MAILBOXES" \ 14 | awk -v t="$template" -v base_dir="$BASE_DIR" \ 15 '{ printf "[1|%s|/%ssendmail.dcgi?handle=%s?template=%s|localhost|70]\n", $1, base_dir, $1, t }' 16 } 17 18 choose_template() { 19 ls -x1 "api/$TEMPLATES" \ 20 | xargs -d '\n' -I x cat "api/$TEMPLATES/"x"/info" \ 21 | awk -F '\t' -v h="$handle" -v base_dir="$BASE_DIR" \ 22 '{ printf "[1|%s|/%ssendmail.dcgi?template=%s?handle=%s|localhost|70]\n", $2, base_dir, $1, h }' 23 } 24 25 show_footer() { 26 printf "\n\n[1|Start over|$BASE_DIR/sendmail.dcgi|localhost|70]" 27 } 28 29 if [ -z "$handle" ]; then 30 printf "Pick recipient:\n" 31 choose_mailbox 32 show_footer 33 return 0 34 fi 35 36 if [ -z "$template" ]; then 37 printf "Pick template:\n" 38 choose_template 39 show_footer 40 return 0 41 fi 42 43 if [ -z "$query" ]; then 44 query="$gopher_search" 45 fi 46 47 result=$( api/$TEMPLATES/$template/main "$path" "$query" ) 48 if [ ! $? -eq 0 ]; then 49 printf "%s" "$result" 50 return 0 51 fi 52 53 if [ -z "$skip_review" ]; then 54 printf "Review your mail before sending:\n\n" 55 printf "%s\n\n" "$result" 56 printf "[1|Send it|%s|localhost|70]\n" "$SELECTOR?skip_review=1?query=$query" 57 show_footer 58 return 0 59 fi 60 61 cd api 62 pubkey=$( ./get-mailbox -k "$handle" ) 63 mailbox=$( ./get-mailbox "$handle" ) 64 result=$( printf "%s" "$result" \ 65 | encrypt_with_key_and_encode "$pubkey" ) 66 timestamp=$( date ) 67 printf "%s,%s\n" "$timestamp" "$result" >> "$mailbox" 68 cd .. 69 70 printf "Mail sent!\n" 71 printf "[1|Return to main office|/|localhost|70]" 72 73 # todo: prevent resubmission of mail, maybe with a session token tied 74 # to the `skip_review` arg. the token could be stored and checked in a 75 # file somewhere. 76