From: Peter Wang Date: Wed, 25 Jul 2012 13:42:33 +0000 (+1000) Subject: [PATCH 04/18] insert: copy stdin to Maildir tmp file X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=d2f5a9185f80070d520b823c4074d97c6fdd9507;p=notmuch-archives.git [PATCH 04/18] insert: copy stdin to Maildir tmp file --- diff --git a/eb/169a46e1d3a8aa0a0235c33a8d136638f54013 b/eb/169a46e1d3a8aa0a0235c33a8d136638f54013 new file mode 100644 index 000000000..d8dd0586e --- /dev/null +++ b/eb/169a46e1d3a8aa0a0235c33a8d136638f54013 @@ -0,0 +1,145 @@ +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 89D44431FC7 + for ; Wed, 25 Jul 2012 06:43:34 -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 nFaOfaNTjffL for ; + Wed, 25 Jul 2012 06:43:34 -0700 (PDT) +Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com + [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id CE6DC431FC0 + for ; Wed, 25 Jul 2012 06:43:33 -0700 (PDT) +Received: by pbbrr13 with SMTP id rr13so1767731pbb.26 + for ; Wed, 25 Jul 2012 06:43:32 -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:x-mailer:in-reply-to:references; + bh=FDzi2AF74nfQDqwhuBLhWA2JoXw1SZxEaoP74HHfBMM=; + b=EqsEh9z1sLN8NcuTLr2YCY8Z6uOUGf+OorDUMZQAKStvR1JcdRG8MWFKCTPnaFRp8i + oPcqknqoSl4ASVLX73eq3RWFHUE7wdlF/W8Id5V089StT1B7skJzBbNx1wQRh2aFIE8W + 4G6iobs74mcd/wuM/18KCPfd2D9Z5AU+j9ADsn2HeWJyTfr0mqIghLlDCtiU2YdPsohO + Q5T0R9wwnm68fW12YBySbC22UR+vaubtIF5iOA20uqyuuhDbuvqVDmIKXbPi6qL3G9yM + ij6TAeIqwrTLHJofPegRC5zCxdhP3p8hu3e3MQZ7lyBFsqcpjN0a3yR+9Ecfa99pKqql + 7lyg== +Received: by 10.68.223.198 with SMTP id qw6mr53562392pbc.94.1343223812044; + Wed, 25 Jul 2012 06:43:32 -0700 (PDT) +Received: from localhost (215.42.233.220.static.exetel.com.au. + [220.233.42.215]) + by mx.google.com with ESMTPS id nv6sm14410633pbc.42.2012.07.25.06.43.29 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 25 Jul 2012 06:43:31 -0700 (PDT) +From: Peter Wang +To: notmuch@notmuchmail.org +Subject: [PATCH 04/18] insert: copy stdin to Maildir tmp file +Date: Wed, 25 Jul 2012 23:42:33 +1000 +Message-Id: <1343223767-9812-4-git-send-email-novalazy@gmail.com> +X-Mailer: git-send-email 1.7.4.4 +In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com> +References: <1343223767-9812-1-git-send-email-novalazy@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: Wed, 25 Jul 2012 13:43:34 -0000 + +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 **tmppath, 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 = read (fdin, buf, sizeof(buf)); ++ if (remain == 0) ++ break; ++ if (remain < 0) { ++ if (errno == EINTR) ++ continue; ++ fprintf (stderr, "Error: reading from standard input: %s\n", ++ strerror (errno)); ++ return FALSE; ++ } ++ ++ p = buf; ++ do { ++ written = write (fdout, p, remain); ++ if (written == 0) ++ return FALSE; ++ if (written < 0) { ++ if (errno == EINTR) ++ continue; ++ fprintf (stderr, "Error: writing to temporary file: %s", ++ strerror (errno)); ++ return FALSE; ++ } ++ p += written; ++ remain -= written; ++ } while (remain > 0); ++ } ++ ++ return TRUE; ++} ++ ++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 = maildir_open_tmp (ctx, dir, &tmppath, &newpath); + if (fdout < 0) { + return FALSE; + } + ++ ret = copy_fd_data (fdin, fdout); ++ + close (fdout); +- unlink (tmppath); +- return FALSE; ++ ++ if (!ret) { ++ unlink (tmppath); ++ } ++ ++ return ret; + } + + int +-- +1.7.4.4 +