Forwarding a mail, with a non-ASCII signature
[notmuch-archives.git] / ab / 96be2a3970531cdfca10a2635be2c6598f67e5
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 2E3B0429E34\r
6         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:52:11 -0800 (PST)\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 Zr0FaIggHcyU for <notmuch@notmuchmail.org>;\r
17         Sat, 19 Jan 2013 16:52:10 -0800 (PST)\r
18 Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com\r
19         [209.85.220.42]) (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 13A53429E3C\r
22         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:52 -0800 (PST)\r
23 Received: by mail-pa0-f42.google.com with SMTP id rl6so2773792pac.29\r
24         for <notmuch@notmuchmail.org>; Sat, 19 Jan 2013 16:51:51 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
26         h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
27         :references; bh=Ff7jWpxkQw2Fq70JM+kXXndzZkMnJ0zG1LWai5ZLAIQ=;\r
28         b=CKl1iaRRFnBkTxHLpUs4p9XzqN9/305LTTHnrL4p7cVzeSM3i1P4jFbkbSmu/ZU8YF\r
29         UliVeZrV2eg6ln9skDBzyAQBYK/oEaH0bFz+9v0HFh8lCK9SfHf+ERcK/SN16Y25E5h5\r
30         GDQTp6LTKg2hfyFRP1gmD2ugsNyBKIr9PlDgh/yzcpcQI8Sv4la1p0Mrapx5KmynxD/6\r
31         Gpm1AQjImyNnhYucnBL3YNXhPLOLVW3Y5zFKCnmd1aL0hIEmgCi+pgXwJPhwkJ9maXBL\r
32         39zaiTMYrgSGCxOMh3zxD3kkRB0XZTrZD8zLX0BKx/DXwQffTqoZJsoZ8zWRsrse+V7N\r
33         sg+w==\r
34 X-Received: by 10.66.75.66 with SMTP id a2mr36252872paw.65.1358643111159;\r
35         Sat, 19 Jan 2013 16:51:51 -0800 (PST)\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 nw9sm5801009pbb.42.2013.01.19.16.51.49\r
39         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
40         Sat, 19 Jan 2013 16:51:50 -0800 (PST)\r
41 From: Peter Wang <novalazy@gmail.com>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v3 16/20] insert: trap SIGINT and clean up\r
44 Date: Sun, 20 Jan 2013 11:50:00 +1100\r
45 Message-Id: <1358643004-14522-17-git-send-email-novalazy@gmail.com>\r
46 X-Mailer: git-send-email 1.7.12.1\r
47 In-Reply-To: <1358643004-14522-1-git-send-email-novalazy@gmail.com>\r
48 References: <1358643004-14522-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: Sun, 20 Jan 2013 00:52:11 -0000\r
62 \r
63 The only potentially long-running part of the 'insert' command should be\r
64 copying stdin to the 'tmp' file.  If SIGINT is received during the\r
65 copying process, abort and clean up the file in 'tmp'.  At all other\r
66 points, just ignore the signal and continue.\r
67 ---\r
68  notmuch-insert.c | 28 ++++++++++++++++++++++++++--\r
69  1 file changed, 26 insertions(+), 2 deletions(-)\r
70 \r
71 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
72 index 8012eb4..494a7b0 100644\r
73 --- a/notmuch-insert.c\r
74 +++ b/notmuch-insert.c\r
75 @@ -25,6 +25,21 @@\r
76  #include <sys/stat.h>\r
77  #include <fcntl.h>\r
78  \r
79 +static volatile sig_atomic_t interrupted;\r
80 +\r
81 +static void\r
82 +handle_sigint (unused (int sig))\r
83 +{\r
84 +    static char msg[] = "Stopping...         \n";\r
85 +\r
86 +    /* This write is "opportunistic", so it's okay to ignore the\r
87 +     * result.  It is not required for correctness, and if it does\r
88 +     * fail or produce a short write, we want to get out of the signal\r
89 +     * handler as quickly as possible, not retry it. */\r
90 +    IGNORE_RESULT (write (2, msg, sizeof (msg) - 1));\r
91 +    interrupted = 1;\r
92 +}\r
93 +\r
94  /* Like gethostname but guarantees that a null-terminated hostname is\r
95   * returned, even if it has to make one up.\r
96   * Returns true unless hostname contains a slash. */\r
97 @@ -258,7 +273,7 @@ copy_stdin (int fdin, int fdout)\r
98      ssize_t remain;\r
99      ssize_t written;\r
100  \r
101 -    for (;;) {\r
102 +    while (! interrupted) {\r
103         remain = read (fdin, buf, sizeof (buf));\r
104         if (remain == 0)\r
105             break;\r
106 @@ -287,7 +302,7 @@ copy_stdin (int fdin, int fdout)\r
107         } while (remain > 0);\r
108      }\r
109  \r
110 -    return TRUE;\r
111 +    return ! interrupted;\r
112  }\r
113  \r
114  /* Add the specified message file to the notmuch database, applying tags.\r
115 @@ -372,6 +387,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
116  {\r
117      notmuch_config_t *config;\r
118      notmuch_database_t *notmuch;\r
119 +    struct sigaction action;\r
120      const char *db_path;\r
121      const char **new_tags;\r
122      size_t new_tags_length;\r
123 @@ -443,6 +459,14 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])\r
124         return 1;\r
125      }\r
126  \r
127 +    /* Setup our handler for SIGINT. We do not set SA_RESTART so that copying\r
128 +     * from standard input may be interrupted. */\r
129 +    memset (&action, 0, sizeof (struct sigaction));\r
130 +    action.sa_handler = handle_sigint;\r
131 +    sigemptyset (&action.sa_mask);\r
132 +    action.sa_flags = 0;\r
133 +    sigaction (SIGINT, &action, NULL);\r
134 +\r
135      if (notmuch_database_open (notmuch_config_get_database_path (config),\r
136                                NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch))\r
137         return 1;\r
138 -- \r
139 1.7.12.1\r
140 \r