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 95AC4431FC7 for ; Thu, 1 May 2014 16:09:06 -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 Zq3qBGSF5S94 for ; Thu, 1 May 2014 16:08:59 -0700 (PDT) Received: from mail-oa0-f46.google.com (mail-oa0-f46.google.com [209.85.219.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 58382431FCF for ; Thu, 1 May 2014 16:08:46 -0700 (PDT) Received: by mail-oa0-f46.google.com with SMTP id i4so3635589oah.33 for ; Thu, 01 May 2014 16:08:45 -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=nPvjm+fSKBytOKLMOx75NLA3uuT451ifQo99d8PTe/c=; b=PUD0I7+ruz/vuNKhKwAivuyjptWvG9tUmQoU6Umz3fCcD73aoC/3X+vUilSzDtEKqz l2xHmCp8DIeUwGJNzCdbVUj6o0NfGyKsuiavN7ofz56EaWy5Ib8LXXrgDGpkx6XT5/IG esItSM7ibfcSOXKswV9IUailo1mplXZIHfjLxSDRpKfLAtUvMtL2qx14HFFvpGcaz7/v OrcDtG3OydRtRuaPw+Vky5XjCCSGE4vdIv0rw5wfRRGbOtBZi46ieewHrUUrKd86L/zJ NgZ62rcH69h8/Y6skFxJibInud06//0rxn2qFCj2Ao1FU5EswxcKWRG+Or3kTPiy5NRh GPQQ== X-Received: by 10.60.51.136 with SMTP id k8mr13555298oeo.33.1398985725880; Thu, 01 May 2014 16:08:45 -0700 (PDT) Received: from localhost (189-211-224-40.static.axtel.net. [189.211.224.40]) by mx.google.com with ESMTPSA id cq1sm122272455oeb.4.2014.05.01.16.08.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 May 2014 16:08:44 -0700 (PDT) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: [PATCH v2 3/3] vim: improve the way messages are sent Date: Thu, 1 May 2014 17:57:54 -0500 Message-Id: <1398985074-17646-4-git-send-email-felipe.contreras@gmail.com> X-Mailer: git-send-email 1.9.2+fc1.19.g85b6256 In-Reply-To: <1398985074-17646-1-git-send-email-felipe.contreras@gmail.com> References: <1398985074-17646-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: Thu, 01 May 2014 23:09:06 -0000 We want the proper encoding and content-type to be set when sending the mail, but human-readable plain-text for composing. So split the code in two parts: the presentation and the transport conversion. This fixes an issue while sending non-ascii mails to strict servers; the mail needs to be encoded. Signed-off-by: Felipe Contreras --- vim/notmuch.vim | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/vim/notmuch.vim b/vim/notmuch.vim index 0cb94f6..331e930 100644 --- a/vim/notmuch.vim +++ b/vim/notmuch.vim @@ -86,17 +86,22 @@ endfunction function! s:compose_send() let b:compose_done = 1 let fname = expand('%') + let lines = getline(5, '$') - " remove headers - 0,4d - write +ruby << EOF + # Generate proper mail to send + text = VIM::evaluate('lines').join("\n") + fname = VIM::evaluate('fname') + transport = Mail.new(text) + transport.message_id = generate_message_id + transport.charset = 'utf-8' + File.write(fname, transport.to_s) +EOF let cmdtxt = g:notmuch_sendmail . ' -t -f ' . s:reply_from . ' < ' . fname let out = system(cmdtxt) let err = v:shell_error if err - undo - write echohl Error echo 'Eeek! unable to send mail' echo out @@ -572,9 +577,7 @@ ruby << EOF end m.cc = orig[:cc] m.from = $email - m.message_id = generate_message_id m.charset = 'utf-8' - m.content_transfer_encoding = '7bit' end lines = [] @@ -600,7 +603,7 @@ ruby << EOF reply.body = body_lines.join("\n") - lines += reply.to_s.lines.map { |e| e.chomp } + lines += reply.present.lines.map { |e| e.chomp } lines << "" cur = lines.count - 1 @@ -611,18 +614,13 @@ ruby << EOF def open_compose() lines = [] - lines << "Date: #{Time.now().strftime('%a, %-d %b %Y %T %z')}" lines << "From: #{$email}" lines << "To: " cur = lines.count lines << "Cc: " lines << "Bcc: " - lines << "Message-Id: #{generate_message_id}" lines << "Subject: " - lines << "Mime-Version: 1.0" - lines << "Content-Type: text/plain; charset=utf-8" - lines << "Content-Transfer-Encoding: 7bit" lines << "" lines << "" lines << "" @@ -928,6 +926,16 @@ ruby << EOF end text end + + def present + buffer = '' + header.fields.each do |f| + buffer << "%s: %s\r\n" % [f.name, f.to_s] + end + buffer << "\r\n" + buffer << body.to_s + buffer + end end end -- 1.9.2+fc1.19.g85b6256