vim: refactor open_reply()

In preparation for composing new messages.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
This commit is contained in:
Felipe Contreras 2013-10-14 01:57:28 -05:00
parent 2ec69fd39e
commit de74431cfe

View file

@ -504,12 +504,37 @@ ruby << EOF
return "<#{random_tag}@#{Socket.gethostname}.notmuch>"
end
def open_reply(orig)
def open_compose_helper(lines, cur)
help_lines = [
'Notmuch-Help: Type in your message here; to help you use these bindings:',
'Notmuch-Help: ,s - send the message (Notmuch-Help lines will be removed)',
'Notmuch-Help: ,q - abort the message',
]
dir = File.expand_path('~/.notmuch/compose')
FileUtils.mkdir_p(dir)
Tempfile.open(['nm-', '.mail'], dir) do |f|
f.puts(help_lines)
f.puts
f.puts(lines)
sig_file = File.expand_path('~/.signature')
if File.exists?(sig_file)
f.puts("-- ")
f.write(File.read(sig_file))
end
f.flush
cur += help_lines.size + 1
VIM::command("let s:reply_from='%s'" % $email_address)
VIM::command("call s:new_file_buffer('compose', '#{f.path}')")
VIM::command("call cursor(#{cur}, 0)")
end
end
def open_reply(orig)
reply = orig.reply do |m|
# fix headers
if not m[:reply_to]
@ -522,54 +547,35 @@ ruby << EOF
m.content_transfer_encoding = '7bit'
end
dir = File.expand_path('~/.notmuch/compose')
FileUtils.mkdir_p(dir)
Tempfile.open(['nm-', '.mail'], dir) do |f|
lines = []
lines = []
lines += help_lines
lines << ''
body_lines = []
if $mail_installed
addr = Mail::Address.new(orig[:from].value)
name = addr.name
name = addr.local + "@" if name.nil? && !addr.local.nil?
else
name = orig[:from]
end
name = "somebody" if name.nil?
body_lines << "%s wrote:" % name
part = orig.find_first_text
part.convert.each_line do |l|
body_lines << "> %s" % l.chomp
end
body_lines << ""
body_lines << ""
body_lines << ""
reply.body = body_lines.join("\n")
lines += reply.to_s.lines.map { |e| e.chomp }
lines << ""
old_count = lines.count - 1
f.puts(lines)
sig_file = File.expand_path('~/.signature')
if File.exists?(sig_file)
f.puts("-- ")
f.write(File.read(sig_file))
end
f.flush
VIM::command("let s:reply_from='%s'" % $email_address)
VIM::command("call s:new_file_buffer('compose', '#{f.path}')")
VIM::command("call cursor(#{old_count}, 0)")
body_lines = []
if $mail_installed
addr = Mail::Address.new(orig[:from].value)
name = addr.name
name = addr.local + "@" if name.nil? && !addr.local.nil?
else
name = orig[:from]
end
name = "somebody" if name.nil?
body_lines << "%s wrote:" % name
part = orig.find_first_text
part.convert.each_line do |l|
body_lines << "> %s" % l.chomp
end
body_lines << ""
body_lines << ""
body_lines << ""
reply.body = body_lines.join("\n")
lines += reply.to_s.lines.map { |e| e.chomp }
lines << ""
cur = lines.count - 1
open_compose_helper(lines, cur)
end
def folders_render()