From 23c507d488c720bbb263e5d7f4e0e6934eb71354 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Sun, 3 Nov 2013 07:55:46 +1800 Subject: [PATCH] [PATCH 13/21] vim: refactor open_reply() --- b8/39fa0a0040361a10c79befd5639f1b5b662c00 | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 b8/39fa0a0040361a10c79befd5639f1b5b662c00 diff --git a/b8/39fa0a0040361a10c79befd5639f1b5b662c00 b/b8/39fa0a0040361a10c79befd5639f1b5b662c00 new file mode 100644 index 000000000..46158f0c2 --- /dev/null +++ b/b8/39fa0a0040361a10c79befd5639f1b5b662c00 @@ -0,0 +1,193 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 5556B431FAF + for ; Sat, 2 Nov 2013 07:03:52 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id R7WjF3S+pRCg for ; + Sat, 2 Nov 2013 07:03:47 -0700 (PDT) +Received: from mail-oa0-f47.google.com (mail-oa0-f47.google.com + [209.85.219.47]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id D5947429E2F + for ; Sat, 2 Nov 2013 07:03:09 -0700 (PDT) +Received: by mail-oa0-f47.google.com with SMTP id i1so5600758oag.20 + for ; Sat, 02 Nov 2013 07:03:09 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:in-reply-to:references; + bh=nUfpfnyEzVAgubSTNofFIM/3EdIsp9KtsuFNEDp4SOU=; + b=sAK5o+tEj6oraTSBusDpfG79PUgRF2gy9sKwR3hCq4Wb6vuiUMMrBOtJKzzW19ELFB + 6Y67tvu8nRYuT/AkWUk9uLCejZUQBOtFVKgOc/XNhQYxSjjnUzfYqwm85mCvHZHdmgf6 + Wbq+gOWQgkhBxvJ0eGDcRL3MQICIrEVGNyuyjoX7Vz+Q9TPwqCPa0Hk+mZ86zmgOlzgi + wdADofOfZHPpincZRhsEw49LCCIBd5jvJf+dkE3Jgp9dLu3gpq7fm64tLYemI2vm9Pme + H2OAb6BbkZjK7yJB7mHviC6hrAl7XqB4Sehw6XITONZQJaj+9EVOgd03ZMD+EHNMc1eI + +f2w== +X-Received: by 10.60.116.230 with SMTP id jz6mr6619934oeb.21.1383400989318; + Sat, 02 Nov 2013 07:03:09 -0700 (PDT) +Received: from localhost (187-162-140-241.static.axtel.net. [187.162.140.241]) + by mx.google.com with ESMTPSA id + ru3sm19958939obc.2.2013.11.02.07.03.07 for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 02 Nov 2013 07:03:08 -0700 (PDT) +From: Felipe Contreras +To: notmuch@notmuchmail.org +Subject: [PATCH 13/21] vim: refactor open_reply() +Date: Sat, 2 Nov 2013 07:55:46 -0600 +Message-Id: <1383400554-1832-14-git-send-email-felipe.contreras@gmail.com> +X-Mailer: git-send-email 1.8.4.2+fc1 +In-Reply-To: <1383400554-1832-1-git-send-email-felipe.contreras@gmail.com> +References: <1383400554-1832-1-git-send-email-felipe.contreras@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 02 Nov 2013 14:03:52 -0000 + +In preparation for composing new messages. + +Signed-off-by: Felipe Contreras +--- + vim/notmuch.vim | 92 ++++++++++++++++++++++++++++++--------------------------- + 1 file changed, 49 insertions(+), 43 deletions(-) + +diff --git a/vim/notmuch.vim b/vim/notmuch.vim +index 9a45300..8383fd6 100644 +--- a/vim/notmuch.vim ++++ b/vim/notmuch.vim +@@ -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 += 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 = [] + +- lines += reply.to_s.lines.map { |e| e.chomp } +- 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? + +- old_count = lines.count - 1 ++ 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 << "" + +- f.puts(lines) ++ reply.body = body_lines.join("\n") + +- sig_file = File.expand_path('~/.signature') +- if File.exists?(sig_file) +- f.puts("-- ") +- f.write(File.read(sig_file)) +- end ++ lines += reply.to_s.lines.map { |e| e.chomp } ++ lines << "" + +- f.flush ++ cur = lines.count - 1 + +- 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)") +- end ++ open_compose_helper(lines, cur) + end + + def folders_render() +-- +1.8.4.2+fc1 + -- 2.26.2