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