Guest User

Untitled

a guest
Feb 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This tries to import PGP data contained in a mail message
  4. # Depends on:
  5. # - GPGKEY having the value of my key
  6. # - gpglist (part of signing-party package) (perl scripts)
  7. # -
  8. #
  9. # Programs used
  10. ZN=zenity
  11. NM=notmuch
  12. GPG=gpg
  13. PERL=perl
  14.  
  15. # Generic error dialog with zenity
  16. function error {
  17. $ZN --error --text="$1"
  18. }
  19.  
  20. # Try to get signatures from a file
  21. function sigfromfile {
  22. echo file: $1
  23.  
  24. echo "# Trying direct import"
  25. $GPG --import $1 2>&1
  26.  
  27. if [[ $? -ne 0 ]]; then
  28. echo "# Plain import failed, trying decrypting it first"
  29. $GPG -d $1 | $GPG --import 2>&1
  30. fi
  31. return $?
  32. }
  33.  
  34. # Process cmdline args
  35. case $# in
  36. 2)
  37. # Both thread and message id
  38. msg_id=$2
  39. # Fallthrough
  40. ;&
  41. 1)
  42. # Just the thread id
  43. thr_id=$1
  44. ;;
  45. *)
  46. error "Got $# arguments. ImportSig takes 1 or 2 arguments (thread_id and optional message_id)"
  47. exit 1
  48. esac
  49.  
  50.  
  51. if [[ $msg_id ]]; then
  52. (
  53. echo "Determining message filename"
  54. FILE=`$NM search --exclude=false --output=files "id:$msg_id"`
  55. # Try message file as a whole first
  56. sigfromfile $FILE
  57.  
  58. if [[ $? -ne 0 ]]; then
  59. echo "# Decrypt message failed, trying attachments explicitly"
  60. T=`mktemp -d`
  61. mu extract --target-dir=$T --save-attachments $FILE
  62. for att in `ls -1 $T`; do
  63. # extract from each attachment
  64. sigfromfile $T/$att
  65. done
  66. fi
  67.  
  68. echo "# Fetching unknown users"
  69. for KEY in `gpglist $GPGKEY | grep 'User ID not found' | $PERL -nwe '/([0-9A-F]{16})/ && print "$1\n"'`; do
  70. $GPG --recv-keys $KEY 2>&1
  71. gpglist $GPGKEY | grep $KEY
  72. done
  73.  
  74. echo "# DONE"
  75. ) | $ZN --text-info --width 1000 --height 300 --auto-scroll \
  76. --title="Trying to import PGP data from message..." \
  77. --font=Monospace
  78. fi
Add Comment
Please, Sign In to add comment