Check the recipient list again before writing the file

Detect a recipient that has been removed between GPGEditRecipients() and GPGEncrypt()
This commit is contained in:
Markus Braun
2008-07-30 14:15:02 +00:00
parent 594ac054a8
commit 71645fcb3a

View File

@@ -361,32 +361,51 @@ function s:GPGEncrypt()
let options=options . " --" . option . " " let options=options . " --" . option . " "
endfor endfor
" check recipientslist for unknown recipients again " check here again if all recipients are available in the keyring
for recipient in b:GPGUnknownRecipients let recipients = []
echohl GPGWarning if (exists("b:GPGRecipients") && type(b:GPGRecipients) == type([]))
echom "The recipient \"" . recipient . "\" is not in your public keyring!" let recipients += b:GPGRecipients
echohl None else
unlet b:GPGRecipients
endif
if (exists("b:GPGUnknownRecipients") && type(b:GPGUnknownRecipients) == type([]))
let recipients += b:GPGUnknownRecipients
else
unlet b:GPGUnknownRecipients
endif
let b:GPGRecipients = []
let b:GPGUnknownRecipients = []
for recipient in recipients
let gpgid=s:GPGNameToID(recipient)
if (strlen(gpgid) > 0)
if (match(b:GPGRecipients, gpgid) < 0)
let b:GPGRecipients+=[gpgid]
endif
else
if (match(b:GPGUnknownRecipients, recipient) < 0)
let b:GPGUnknownRecipients+=[recipient]
echohl GPGWarning
echom "The recipient \"" . recipient . "\" is not in your public keyring!"
echohl None
endif
end
endfor endfor
" check if there are unknown recipients and warn " check if there are unknown recipients and warn
if(len(b:GPGUnknownRecipients) > 0) if(exists("b:GPGUnknownRecipients") && len(b:GPGUnknownRecipients) > 0)
echohl GPGWarning echohl GPGWarning
echom "There are unknown recipients!!"
echom "Please use GPGEditRecipients to correct!!" echom "Please use GPGEditRecipients to correct!!"
echo echo
echohl None echohl None
call s:GPGDebug(1, "unknown recipients are: " . join(b:GPGUnknownRecipients, " "))
" Let user know whats happend and copy known_recipients back to buffer " Let user know whats happend and copy known_recipients back to buffer
let dummy=input("Press ENTER to quit") let dummy=input("Press ENTER to quit")
endif endif
" built list of recipients " built list of recipients
let recipients=""
if (exists("b:GPGRecipients") && len(b:GPGRecipients) > 0) if (exists("b:GPGRecipients") && len(b:GPGRecipients) > 0)
call s:GPGDebug(1, "recipients are: " . join(b:GPGRecipients, " "))
for gpgid in b:GPGRecipients for gpgid in b:GPGRecipients
let recipients=recipients . " -r " . gpgid let options=options . " -r " . gpgid
endfor endfor
else else
if (match(b:GPGOptions, "encrypt") >= 0) if (match(b:GPGOptions, "encrypt") >= 0)
@@ -401,10 +420,10 @@ function s:GPGEncrypt()
" encrypt the buffer " encrypt the buffer
let &shellredir=s:shellredir let &shellredir=s:shellredir
let &shell=s:shell let &shell=s:shell
silent exec "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . recipients . " " . s:stderrredirnull silent exec "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull
let &shellredir=s:shellredirsave let &shellredir=s:shellredirsave
let &shell=s:shellsave let &shell=s:shellsave
call s:GPGDebug(1, "called gpg command is: " . "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . recipients . " " . s:stderrredirnull) call s:GPGDebug(1, "called gpg command is: " . "'[,']!" . s:GPGCommand . " --quiet --no-encrypt-to " . options . " " . s:stderrredirnull)
if (v:shell_error) " message could not be encrypted if (v:shell_error) " message could not be encrypted
silent u silent u
echohl GPGError echohl GPGError