Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This tries to import PGP data contained in a mail message
- # Depends on:
- # - GPGKEY having the value of my key
- # - gpglist (part of signing-party package) (perl scripts)
- # -
- #
- # Programs used
- ZN=zenity
- NM=notmuch
- GPG=gpg
- PERL=perl
- # Generic error dialog with zenity
- function error {
- $ZN --error --text="$1"
- }
- # Try to get signatures from a file
- function sigfromfile {
- echo file: $1
- echo "# Trying direct import"
- $GPG --import $1 2>&1
- if [[ $? -ne 0 ]]; then
- echo "# Plain import failed, trying decrypting it first"
- $GPG -d $1 | $GPG --import 2>&1
- fi
- return $?
- }
- # Process cmdline args
- case $# in
- 2)
- # Both thread and message id
- msg_id=$2
- # Fallthrough
- ;&
- 1)
- # Just the thread id
- thr_id=$1
- ;;
- *)
- error "Got $# arguments. ImportSig takes 1 or 2 arguments (thread_id and optional message_id)"
- exit 1
- esac
- if [[ $msg_id ]]; then
- (
- echo "Determining message filename"
- FILE=`$NM search --exclude=false --output=files "id:$msg_id"`
- # Try message file as a whole first
- sigfromfile $FILE
- if [[ $? -ne 0 ]]; then
- echo "# Decrypt message failed, trying attachments explicitly"
- T=`mktemp -d`
- mu extract --target-dir=$T --save-attachments $FILE
- for att in `ls -1 $T`; do
- # extract from each attachment
- sigfromfile $T/$att
- done
- fi
- echo "# Fetching unknown users"
- for KEY in `gpglist $GPGKEY | grep 'User ID not found' | $PERL -nwe '/([0-9A-F]{16})/ && print "$1\n"'`; do
- $GPG --recv-keys $KEY 2>&1
- gpglist $GPGKEY | grep $KEY
- done
- echo "# DONE"
- ) | $ZN --text-info --width 1000 --height 300 --auto-scroll \
- --title="Trying to import PGP data from message..." \
- --font=Monospace
- fi
Add Comment
Please, Sign In to add comment