Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 0f / 77684c9139122faecfdd52a4ac6b41b2891993
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 17F00431FBD\r
6         for <notmuch@notmuchmail.org>; Fri, 21 Jun 2013 22:54:43 -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 SzGkrtxcB5HN for <notmuch@notmuchmail.org>;\r
17         Fri, 21 Jun 2013 22:54:35 -0700 (PDT)\r
18 Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com\r
19         [209.85.220.48]) (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 7F1D9431FAE\r
22         for <notmuch@notmuchmail.org>; Fri, 21 Jun 2013 22:54:35 -0700 (PDT)\r
23 Received: by mail-pa0-f48.google.com with SMTP id kp12so8748553pab.35\r
24         for <notmuch@notmuchmail.org>; Fri, 21 Jun 2013 22:54:34 -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=g2H80/PuFFSB1PFtZQL3zjGorrJhMiGUV1WiUmbhnBE=;\r
28         b=Pt7XxLjbKIjXy6gcoRIb53n/P/z5h8CbAVYe3u3lQSX8K4TExLrxGsW+mt75tApPMy\r
29         GPEZSzIJiLwGVRPFpu8cAL8ImOfc2D+D9m/WvGC+xfRw8kd3AzWMCtZMaBz7gQb03y0D\r
30         5fm2qlNI6ROIed6nmfDmzpcPY/xEX33mcJltYDS+NAPlhXuDIbvmqclsCeSSsKEaIS/2\r
31         BLTWxpSTnsTt8NGXUtBEiZSLudVjJj7zAS0ptFHRG+5poCAf//b7NMlztDv7RcG6kO8P\r
32         KGhyryzxtVhV4NwquZ/X0v6oglYPvpSy6DVq1+M8Uo/ZfKan/S2NQSQloCsm+aHD4WM4\r
33         QkZw==\r
34 X-Received: by 10.66.161.41 with SMTP id xp9mr19351165pab.166.1371880066032;\r
35         Fri, 21 Jun 2013 22:47:46 -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 ESMTPSA id xz1sm8947990pab.5.2013.06.21.22.47.43\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Fri, 21 Jun 2013 22:47:45 -0700 (PDT)\r
42 From: Peter Wang <novalazy@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH v6 10/12] insert: add --create-folder option\r
45 Date: Sat, 22 Jun 2013 15:46:46 +1000\r
46 Message-Id: <1371880008-18312-11-git-send-email-novalazy@gmail.com>\r
47 X-Mailer: git-send-email 1.7.12.1\r
48 In-Reply-To: <1371880008-18312-1-git-send-email-novalazy@gmail.com>\r
49 References: <1371880008-18312-1-git-send-email-novalazy@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 22 Jun 2013 05:54:43 -0000\r
63 \r
64 Allow the insert command to create the maildir folder\r
65 into which the new message should be delivered.\r
66 ---\r
67  notmuch-insert.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
68  1 file changed, 100 insertions(+)\r
69 \r
70 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
71 index a6134a8..25df3be 100644\r
72 --- a/notmuch-insert.c\r
73 +++ b/notmuch-insert.c\r
74 @@ -100,6 +100,99 @@ check_folder_name (const char *folder)\r
75      }\r
76  }\r
77  \r
78 +/* Make the given directory, succeeding if it already exists. */\r
79 +static notmuch_bool_t\r
80 +make_directory (char *path, int mode)\r
81 +{\r
82 +    notmuch_bool_t ret;\r
83 +    char *slash;\r
84 +\r
85 +    if (mkdir (path, mode) != 0)\r
86 +       return (errno == EEXIST);\r
87 +\r
88 +    /* Sync the parent directory for durability. */\r
89 +    ret = TRUE;\r
90 +    slash = strrchr (path, '/');\r
91 +    if (slash) {\r
92 +       *slash = '\0';\r
93 +       ret = sync_dir (path);\r
94 +       *slash = '/';\r
95 +    }\r
96 +    return ret;\r
97 +}\r
98 +\r
99 +/* Make the given directory including its parent directories as necessary.\r
100 + * Return TRUE on success, FALSE on error. */\r
101 +static notmuch_bool_t\r
102 +make_directory_and_parents (char *path, int mode)\r
103 +{\r
104 +    struct stat st;\r
105 +    char *start;\r
106 +    char *end;\r
107 +    notmuch_bool_t ret;\r
108 +\r
109 +    /* First check the common case: directory already exists. */\r
110 +    if (stat (path, &st) == 0)\r
111 +       return S_ISDIR (st.st_mode) ? TRUE : FALSE;\r
112 +\r
113 +    for (start = path; *start != '\0'; start = end + 1) {\r
114 +       /* start points to the first unprocessed character.\r
115 +        * Find the next slash from start onwards. */\r
116 +       end = strchr (start, '/');\r
117 +\r
118 +       /* If there are no more slashes then all the parent directories\r
119 +        * have been made.  Now attempt to make the whole path. */\r
120 +       if (end == NULL)\r
121 +           return make_directory (path, mode);\r
122 +\r
123 +       /* Make the path up to the next slash, unless the current\r
124 +        * directory component is actually empty. */\r
125 +       if (end > start) {\r
126 +           *end = '\0';\r
127 +           ret = make_directory (path, mode);\r
128 +           *end = '/';\r
129 +           if (! ret)\r
130 +               return FALSE;\r
131 +       }\r
132 +    }\r
133 +\r
134 +    return TRUE;\r
135 +}\r
136 +\r
137 +/* Create the given maildir folder, i.e. dir and its subdirectories\r
138 + * 'cur', 'new', 'tmp'. */\r
139 +static notmuch_bool_t\r
140 +maildir_create_folder (void *ctx, const char *dir)\r
141 +{\r
142 +    const int mode = 0700;\r
143 +    char *subdir;\r
144 +    char *tail;\r
145 +\r
146 +    /* Create 'cur' directory, including parent directories. */\r
147 +    subdir = talloc_asprintf (ctx, "%s/cur", dir);\r
148 +    if (! subdir) {\r
149 +       fprintf (stderr, "Out of memory.\n");\r
150 +       return FALSE;\r
151 +    }\r
152 +    if (! make_directory_and_parents (subdir, mode))\r
153 +       return FALSE;\r
154 +\r
155 +    tail = subdir + strlen (subdir) - 3;\r
156 +\r
157 +    /* Create 'new' directory. */\r
158 +    strcpy (tail, "new");\r
159 +    if (! make_directory (subdir, mode))\r
160 +       return FALSE;\r
161 +\r
162 +    /* Create 'tmp' directory. */\r
163 +    strcpy (tail, "tmp");\r
164 +    if (! make_directory (subdir, mode))\r
165 +       return FALSE;\r
166 +\r
167 +    talloc_free (subdir);\r
168 +    return TRUE;\r
169 +}\r
170 +\r
171  /* Open a unique file in the Maildir 'tmp' directory.\r
172   * Returns the file descriptor on success, or -1 on failure.\r
173   * On success, file paths for the message in the 'tmp' and 'new'\r
174 @@ -304,6 +397,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
175      tag_op_list_t *tag_ops;\r
176      char *query_string = NULL;\r
177      const char *folder = NULL;\r
178 +    notmuch_bool_t create_folder = FALSE;\r
179      const char *maildir;\r
180      int opt_index;\r
181      unsigned int i;\r
182 @@ -311,6 +405,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
183  \r
184      notmuch_opt_desc_t options[] = {\r
185         { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },\r
186 +       { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
187         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
188      };\r
189  \r
190 @@ -355,6 +450,11 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
191             fprintf (stderr, "Out of memory\n");\r
192             return 1;\r
193         }\r
194 +       if (create_folder && ! maildir_create_folder (config, maildir)) {\r
195 +           fprintf (stderr, "Error: creating maildir %s: %s\n",\r
196 +                    maildir, strerror (errno));\r
197 +           return 1;\r
198 +       }\r
199      }\r
200  \r
201      /* Setup our handler for SIGINT. We do not set SA_RESTART so that copying\r
202 -- \r
203 1.7.12.1\r
204 \r