8000 Support PGP sign and encryption. · shugo/mournmail@1f79a42 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit

Permalink
Support PGP sign and encryption.
Browse files Browse the repository at this point in the history
  • Loading branch information
shugo committed Dec 20, 2017
1 parent 98134ce commit 1f79a42
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions
60A8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class DraftMode < Textbringer::Mode
MAIL_MODE_MAP.define_key("\C-c\C-k", :draft_kill_command)
MAIL_MODE_MAP.define_key("\C-c\C-x\C-i", :draft_attach_file_command)
MAIL_MODE_MAP.define_key("\t", :draft_complete_or_insert_tab_command)
MAIL_MODE_MAP.define_key("\C-c\C-xv", :draft_pgp_sign_command)
MAIL_MODE_MAP.define_key("\C-c\C-xe", :draft_pgp_encrypt_command)

define_syntax :field_name, /^[A-Za-z\-]+: /
define_syntax :quotation, /^>.*/
Expand Down Expand Up @@ -34,12 +36,18 @@ def initialize(buffer)
header, body = s.split(/^--text follows this line--\n/, 2)
attached_files = []
attached_messages = []
pgp_sign = false
pgp_encrypt = false
header.scan(/^([!-9;-~]+):[ \t]*(.*(?:\n[ \t].*)*)\n/) do |name, val|
case name
when "Attached-File"
attached_files.push(val.strip)
when "Attached-Message"
attached_messages.push(val.strip)
when "PGP-Sign"
pgp_sign = val.strip == "yes"
when "PGP-Encrypt"
pgp_encrypt = val.strip == "yes"
else
m[name] = val
end
Expand Down Expand Up @@ -71,7 +79,10 @@ def initialize(buffer)
m.body << part
end
end
m.deliver!
if pgp_sign || pgp_encrypt
m.gpg(sign: pgp_sign, encrypt: pgp_encrypt)
end
m.deliver
next_tick do
message("Mail sent.")
end
Expand Down Expand Up @@ -104,9 +115,7 @@ def initialize(buffer)
define_local_command(:draft_attach_file, doc: "Attach a file.") do
|file_name = read_file_name("Attach file: ")|
@buffer.save_excursion do
@buffer.beginning_of_buffer
@buffer.re_search_forward(/^--text follows this line--$/)
@buffer.beginning_of_line
end_of_header
@buffer.insert("Attached-File: #{file_name}\n")
end
end
Expand Down Expand Up @@ -138,5 +147,27 @@ def initialize(buffer)
@buffer.insert("\t")
end
end

define_local_command(:draft_pgp_sign, doc: "PGP sign.") do
@buffer.save_excursion do
end_of_header
@buffer.insert("PGP-Sign: yes\n")
end
end

define_local_command(:draft_pgp_encrypt, doc: "PGP encrypt.") do
@buffer.save_excursion do
end_of_header
@buffer.insert("PGP-Encrypt: yes\n")
end
end

private

def end_of_header
@buffer.beginning_of_buffer
@buffer.re_search_forward(/^--text follows this line--$/)
@buffer.beginning_of_line
end
end
end

0 comments on commit 1f79a42

Please sign in to comment.
0