Re: [PATCH 04/18] insert: copy stdin to Maildir tmp file
authorAli Polatel <polatel@gmail.com>
Mon, 26 Nov 2012 16:21:21 +0000 (18:21 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:02 +0000 (09:51 -0800)
9d/457fbab9ac94f19e94514db1610d5c97fc486b [new file with mode: 0644]

diff --git a/9d/457fbab9ac94f19e94514db1610d5c97fc486b b/9d/457fbab9ac94f19e94514db1610d5c97fc486b
new file mode 100644 (file)
index 0000000..ba1c0e3
--- /dev/null
@@ -0,0 +1,185 @@
+Return-Path: <polatel@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 82284431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 26 Nov 2012 08:21:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id kk3GvowG6cZm for <notmuch@notmuchmail.org>;\r
+       Mon, 26 Nov 2012 08:21:11 -0800 (PST)\r
+Received: from mail-ea0-f181.google.com (mail-ea0-f181.google.com\r
+       [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id CD0B4431FAF\r
+       for <notmuch@notmuchmail.org>; Mon, 26 Nov 2012 08:21:10 -0800 (PST)\r
+Received: by mail-ea0-f181.google.com with SMTP id k14so3537183eaa.26\r
+       for <notmuch@notmuchmail.org>; Mon, 26 Nov 2012 08:21:09 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=date:from:to:cc:subject:message-id:mail-followup-to:references\r
+       :mime-version:content-type:content-disposition:in-reply-to\r
+       :user-agent; bh=y6z/HWJKreT5pNzGGB/oUDN9ZcgrSEZkWxq83FP1QKY=;\r
+       b=ZbjOdsZeioJdO6J2J7LcyMqX3on6HyW0pw+0CH0jBKFF6yMnovlJ+r6yKaukDNuwwS\r
+       BKA43RO8KOxZsPWnq2DRu/vifIsrqcOL/V8mGr5i0p9MJfs79QSQRdFbetsV1+DcRzr1\r
+       kATbEM/Tq6bET2gAxKN/dNmjqhO1tZ+qeu2Gnts5cbOeWEsYXF5YXXPDjbuK49Nm0dTq\r
+       L3qzC8p5Z4BwJufklRcdzQIbZg6jo/SiNyYYNDugQAitUxebHjLlSIaiuGkNZKo5+Rmx\r
+       nrV43cBh/T9NA5h6d3hatXkgP+3XKR0DZFGXcL7bcC4wKglFxmfbKM+hZxBAL/6ywNQE\r
+       rtrw==\r
+Received: by 10.14.223.4 with SMTP id u4mr46738185eep.19.1353946869630;\r
+       Mon, 26 Nov 2012 08:21:09 -0800 (PST)\r
+Received: from localhost ([88.233.27.222])\r
+       by mx.google.com with ESMTPS id y44sm34960557eel.14.2012.11.26.08.21.07\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 26 Nov 2012 08:21:08 -0800 (PST)\r
+Date: Mon, 26 Nov 2012 18:21:21 +0200\r
+From: Ali Polatel <polatel@gmail.com>\r
+To: Peter Wang <novalazy@gmail.com>\r
+Subject: Re: [PATCH 04/18] insert: copy stdin to Maildir tmp file\r
+Message-ID: <20121126162121.GA5669@hayalet>\r
+Mail-Followup-To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+References: <1343223767-9812-1-git-send-email-novalazy@gmail.com>\r
+       <1343223767-9812-4-git-send-email-novalazy@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; micalg=pgp-sha1;\r
+       protocol="application/pgp-signature"; boundary="2oS5YaxWCcQjTEyO"\r
+Content-Disposition: inline\r
+In-Reply-To: <1343223767-9812-4-git-send-email-novalazy@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2011-07-01)\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 26 Nov 2012 16:21:12 -0000\r
+\r
+\r
+--2oS5YaxWCcQjTEyO\r
+Content-Type: text/plain; charset=us-ascii; format=flowed\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Wed, Jul 25, 2012 at 11:42:33PM +1000, Peter Wang wrote:\r
+>Read the new message from standard input into the Maildir tmp file.\r
+>---\r
+> notmuch-insert.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++=\r
+--\r
+> 1 files changed, 49 insertions(+), 2 deletions(-)\r
+>\r
+>diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+>index f01a6f2..340f7e4 100644\r
+>--- a/notmuch-insert.c\r
+>+++ b/notmuch-insert.c\r
+>@@ -75,21 +75,68 @@ maildir_open_tmp (void *ctx, const char *dir, char **t=\r
+mppath, char **newpath)\r
+> }\r
+>\r
+> static notmuch_bool_t\r
+>+copy_fd_data (int fdin, int fdout)\r
+>+{\r
+>+    char buf[4096];\r
+>+    char *p;\r
+>+    ssize_t remain;\r
+>+    ssize_t written;\r
+>+\r
+>+    for (;;) {\r
+>+     remain =3D read (fdin, buf, sizeof(buf));\r
+>+     if (remain =3D=3D 0)\r
+>+         break;\r
+>+     if (remain < 0) {\r
+>+         if (errno =3D=3D EINTR)\r
+>+             continue;\r
+>+         fprintf (stderr, "Error: reading from standard input: %s\n",\r
+>+                  strerror (errno));\r
+>+         return FALSE;\r
+>+     }\r
+>+\r
+>+     p =3D buf;\r
+>+     do {\r
+>+         written =3D write (fdout, p, remain);\r
+>+         if (written =3D=3D 0)\r
+>+             return FALSE;\r
+>+         if (written < 0) {\r
+>+             if (errno =3D=3D EINTR)\r
+>+                 continue;\r
+>+             fprintf (stderr, "Error: writing to temporary file: %s",\r
+>+                      strerror (errno));\r
+>+             return FALSE;\r
+>+         }\r
+>+         p +=3D written;\r
+>+         remain -=3D written;\r
+>+     } while (remain > 0);\r
+>+    }\r
+>+\r
+>+    return TRUE;\r
+>+}\r
+\r
+LGTM. As an optimisation we can also consider using the splice(2) system\r
+call if it is available (as notmuch-deliver does). In case splice()\r
+fails with ENOSYS or EINVAL we can fall back to this method.\r
+\r
+I can write the patch for it once this is accepted.\r
+Thanks for the good work!\r
+\r
+>+static notmuch_bool_t\r
+> insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
+>              const char *dir)\r
+> {\r
+>     char *tmppath;\r
+>     char *newpath;\r
+>     int fdout;\r
+>+    notmuch_bool_t ret;\r
+>\r
+>     fdout =3D maildir_open_tmp (ctx, dir, &tmppath, &newpath);\r
+>     if (fdout < 0) {\r
+>      return FALSE;\r
+>     }\r
+>\r
+>+    ret =3D copy_fd_data (fdin, fdout);\r
+>+\r
+>     close (fdout);\r
+>-    unlink (tmppath);\r
+>-    return FALSE;\r
+>+\r
+>+    if (!ret) {\r
+>+     unlink (tmppath);\r
+>+    }\r
+>+\r
+>+    return ret;\r
+> }\r
+>\r
+> int\r
+>--=20\r
+>1.7.4.4\r
+>\r
+>_______________________________________________\r
+>notmuch mailing list\r
+>notmuch@notmuchmail.org\r
+>http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--2oS5YaxWCcQjTEyO\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v2.0.19 (GNU/Linux)\r
+\r
+iEYEARECAAYFAlCzlwEACgkQQU4yORhF8iCxXQCdH4l/LZZ3WlIPEf6a3FslsISc\r
+OqkAni9Xj57Fn3fqwix5X3BiJJgB4Nni\r
+=YnyS\r
+-----END PGP SIGNATURE-----\r
+\r
+--2oS5YaxWCcQjTEyO--\r