Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / eb / 169a46e1d3a8aa0a0235c33a8d136638f54013
1 Return-Path: <novalazy@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 89D44431FC7\r
6         for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:43:34 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id nFaOfaNTjffL for <notmuch@notmuchmail.org>;\r
17         Wed, 25 Jul 2012 06:43:34 -0700 (PDT)\r
18 Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com\r
19         [209.85.160.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id CE6DC431FC0\r
22         for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:43:33 -0700 (PDT)\r
23 Received: by pbbrr13 with SMTP id rr13so1767731pbb.26\r
24         for <notmuch@notmuchmail.org>; Wed, 25 Jul 2012 06:43:32 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=FDzi2AF74nfQDqwhuBLhWA2JoXw1SZxEaoP74HHfBMM=;\r
28         b=EqsEh9z1sLN8NcuTLr2YCY8Z6uOUGf+OorDUMZQAKStvR1JcdRG8MWFKCTPnaFRp8i\r
29         oPcqknqoSl4ASVLX73eq3RWFHUE7wdlF/W8Id5V089StT1B7skJzBbNx1wQRh2aFIE8W\r
30         4G6iobs74mcd/wuM/18KCPfd2D9Z5AU+j9ADsn2HeWJyTfr0mqIghLlDCtiU2YdPsohO\r
31         Q5T0R9wwnm68fW12YBySbC22UR+vaubtIF5iOA20uqyuuhDbuvqVDmIKXbPi6qL3G9yM\r
32         ij6TAeIqwrTLHJofPegRC5zCxdhP3p8hu3e3MQZ7lyBFsqcpjN0a3yR+9Ecfa99pKqql\r
33         7lyg==\r
34 Received: by 10.68.223.198 with SMTP id qw6mr53562392pbc.94.1343223812044;\r
35         Wed, 25 Jul 2012 06:43:32 -0700 (PDT)\r
36 Received: from localhost (215.42.233.220.static.exetel.com.au.\r
37         [220.233.42.215])\r
38         by mx.google.com with ESMTPS id nv6sm14410633pbc.42.2012.07.25.06.43.29\r
39         (version=TLSv1/SSLv3 cipher=OTHER);\r
40         Wed, 25 Jul 2012 06:43:31 -0700 (PDT)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH 04/18] insert: copy stdin to Maildir tmp file\r
44 Date: Wed, 25 Jul 2012 23:42:33 +1000\r
45 Message-Id: <1343223767-9812-4-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.4.4\r
47 In-Reply-To: <1343223767-9812-1-git-send-email-novalazy@gmail.com>\r
48 References: <1343223767-9812-1-git-send-email-novalazy@gmail.com>\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Wed, 25 Jul 2012 13:43:34 -0000\r
62 \r
63 Read the new message from standard input into the Maildir tmp file.\r
64 ---\r
65  notmuch-insert.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--\r
66  1 files changed, 49 insertions(+), 2 deletions(-)\r
67 \r
68 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
69 index f01a6f2..340f7e4 100644\r
70 --- a/notmuch-insert.c\r
71 +++ b/notmuch-insert.c\r
72 @@ -75,21 +75,68 @@ maildir_open_tmp (void *ctx, const char *dir, char **tmppath, char **newpath)\r
73  }\r
74  \r
75  static notmuch_bool_t\r
76 +copy_fd_data (int fdin, int fdout)\r
77 +{\r
78 +    char buf[4096];\r
79 +    char *p;\r
80 +    ssize_t remain;\r
81 +    ssize_t written;\r
82 +\r
83 +    for (;;) {\r
84 +       remain = read (fdin, buf, sizeof(buf));\r
85 +       if (remain == 0)\r
86 +           break;\r
87 +       if (remain < 0) {\r
88 +           if (errno == EINTR)\r
89 +               continue;\r
90 +           fprintf (stderr, "Error: reading from standard input: %s\n",\r
91 +                    strerror (errno));\r
92 +           return FALSE;\r
93 +       }\r
94 +\r
95 +       p = buf;\r
96 +       do {\r
97 +           written = write (fdout, p, remain);\r
98 +           if (written == 0)\r
99 +               return FALSE;\r
100 +           if (written < 0) {\r
101 +               if (errno == EINTR)\r
102 +                   continue;\r
103 +               fprintf (stderr, "Error: writing to temporary file: %s",\r
104 +                        strerror (errno));\r
105 +               return FALSE;\r
106 +           }\r
107 +           p += written;\r
108 +           remain -= written;\r
109 +       } while (remain > 0);\r
110 +    }\r
111 +\r
112 +    return TRUE;\r
113 +}\r
114 +\r
115 +static notmuch_bool_t\r
116  insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,\r
117                 const char *dir)\r
118  {\r
119      char *tmppath;\r
120      char *newpath;\r
121      int fdout;\r
122 +    notmuch_bool_t ret;\r
123  \r
124      fdout = maildir_open_tmp (ctx, dir, &tmppath, &newpath);\r
125      if (fdout < 0) {\r
126         return FALSE;\r
127      }\r
128  \r
129 +    ret = copy_fd_data (fdin, fdout);\r
130 +\r
131      close (fdout);\r
132 -    unlink (tmppath);\r
133 -    return FALSE;\r
134 +\r
135 +    if (!ret) {\r
136 +       unlink (tmppath);\r
137 +    }\r
138 +\r
139 +    return ret;\r
140  }\r
141  \r
142  int\r
143 -- \r
144 1.7.4.4\r
145 \r