Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GPG encrypting and signing #27

Open
ghost opened this issue Mar 29, 2017 · 1 comment
Open

Support GPG encrypting and signing #27

ghost opened this issue Mar 29, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 29, 2017

Feature request: extend the GPG support to include signing and encrypting, as well as the current decrypting/verification.

This would be a convenience function that structures the email correctly per convention, and encrypts / signs the body and attachments (and not the header).

@ghost
Copy link
Author

ghost commented Mar 31, 2017

Hi,

Here's a horrible, horrible hack -- when I started this, I didn't know how to declare functions in vim, so this will probably break your computer. It does not encrypt attachments; it does not handle multiple To: recipients; it does not handle CC: or BCC: recipients. If you even put more than one person in the To: it'll probably croak. If you have a really unique email address, it'll fail. In fact, there are probably more fail cases than there are success cases, and you should probably stop reading and go have a soda and read some Calvin and Hobbes. It could do all of these things, but as I said, it's a hack, suitable only for desperate people.

What it does do (when it works) is grab the To: and From: addresses, and encrypt everything after the Attach: line with those two keys. It then replaces the body with the ASCII armored result. It also signs, because why not. The snippet below binds the function to e.

I have this at the end of my .config/nvim/init.vim file; you could have it in your .vimrc. I tried sticking it in notmuch.vim and lost interest when I hit my first error. As I said, desperate ugly solution for desperate (but beautiful) people.

" Encryption for NotMuch
function! ComposeEncrypt()
        let l:email = '[A-Za-z0-9._%+-]\+@[A-Za-z0-9.-]\+\.[A-Za-z]\+'
        norm 1G
        norm /^From:/
        let l:from = matchstr(getline('.'), l:email)
        norm /^To:/
        let l:to = matchstr(getline('.'), l:email)
        let l:command = "gpg -ase --recipient " . l:from . " --recipient " . l:to . " --trust-model always"
        norm /^Attach:/
        norm j
        norm ma
        exec '.,$yank a'
        let @x = system(l:command, @a)
        norm 'a
        normal VGd
        normal "xp
        normal :g/^gpg: /d
endfunction
map <Leader>e :call ComposeEncrypt()<CR>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants