Re: [PATCH v4 02/16] Move crypto.c into libutil
[notmuch-archives.git] / 0c / 63a943a8cf84a38d433e6b7bdfbce398f8fcd4
1 Return-Path: <sojkam1@fel.cvut.cz>\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 EAE8C41733F\r
6         for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:42 -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: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id yeccuoZvhcac for <notmuch@notmuchmail.org>;\r
16         Sat, 27 Mar 2010 13:44:40 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 6CC0A418C25\r
19         for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:34 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id CC09D19F3395;\r
22         Sat, 27 Mar 2010 21:44:33 +0100 (CET)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id xfMwZc49rxFs; Sat, 27 Mar 2010 21:44:32 +0100 (CET)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id A35DC19F3420;\r
30         Sat, 27 Mar 2010 21:44:31 +0100 (CET)\r
31 Received: from steelpick.2x.cz (r5da224.net.upc.cz [86.49.116.224])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 897DAFA003;\r
34         Sat, 27 Mar 2010 21:44:31 +0100 (CET)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.71)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1Nvcru-0001o1-9v; Sat, 27 Mar 2010 21:44:30 +0100\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: notmuch@notmuchmail.org\r
40 Date: Sat, 27 Mar 2010 21:44:21 +0100\r
41 Message-Id: <1269722661-6894-6-git-send-email-sojkam1@fel.cvut.cz>\r
42 X-Mailer: git-send-email 1.7.0.2\r
43 In-Reply-To: <8739zlijhp.fsf@steelpick.2x.cz>\r
44 References: <8739zlijhp.fsf@steelpick.2x.cz>\r
45 Subject: [notmuch] [PATCH v3 6/6] Add 'cat' subcommand\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Sat, 27 Mar 2010 20:44:43 -0000\r
59 \r
60 This command dumps raw message identified by filename to standard\r
61 output. It uses mail store interface to get the message from the right\r
62 place.\r
63 \r
64 notmuch.el was modified to use this command to access the raw message\r
65 content (view/save attachments and view raw message).\r
66 \r
67 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
68 ---\r
69  emacs/notmuch.el |    8 +++++-\r
70  notmuch-client.h |    3 ++\r
71  notmuch-show.c   |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
72  notmuch.c        |    4 +++\r
73  4 files changed, 75 insertions(+), 2 deletions(-)\r
74 \r
75 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
76 index 117a365..38ba0e8 100644\r
77 --- a/emacs/notmuch.el\r
78 +++ b/emacs/notmuch.el\r
79 @@ -357,7 +357,11 @@ buffer."\r
80  (defun notmuch-show-view-raw-message ()\r
81    "View the raw email of the current message."\r
82    (interactive)\r
83 -  (view-file (notmuch-show-get-filename)))\r
84 +  (let ((filename (notmuch-show-get-filename)))\r
85 +    (let ((buf (get-buffer-create (concat "*notmuch-raw-" filename "*"))))\r
86 +      (switch-to-buffer buf)\r
87 +      (save-excursion\r
88 +       (call-process notmuch-command nil t nil "cat" filename)))))\r
89  \r
90  (defmacro with-current-notmuch-show-message (&rest body)\r
91    "Evaluate body with current buffer set to the text of current message"\r
92 @@ -365,7 +369,7 @@ buffer."\r
93       (let ((filename (notmuch-show-get-filename)))\r
94         (let ((buf (generate-new-buffer (concat "*notmuch-msg-" filename "*"))))\r
95           (with-current-buffer buf\r
96 -           (insert-file-contents filename nil nil nil t)\r
97 +           (call-process notmuch-command nil t nil "cat" filename)\r
98             ,@body)\r
99          (kill-buffer buf)))))\r
100  \r
101 diff --git a/notmuch-client.h b/notmuch-client.h\r
102 index f5106cd..b9ddad2 100644\r
103 --- a/notmuch-client.h\r
104 +++ b/notmuch-client.h\r
105 @@ -107,6 +107,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]);\r
106  int\r
107  notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
108  \r
109 +int\r
110 +notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
111 +\r
112  const char *\r
113  notmuch_time_relative_date (const void *ctx, time_t then);\r
114  \r
115 diff --git a/notmuch-show.c b/notmuch-show.c\r
116 index 0fcaacf..537d2e2 100644\r
117 --- a/notmuch-show.c\r
118 +++ b/notmuch-show.c\r
119 @@ -510,3 +510,65 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
120  \r
121      return 0;\r
122  }\r
123 +\r
124 +int\r
125 +notmuch_cat_command (void *ctx, unused (int argc), unused (char *argv[]))\r
126 +{\r
127 +    notmuch_config_t *config;\r
128 +    notmuch_database_t *notmuch;\r
129 +    notmuch_mailstore_t *mailstore;\r
130 +    int i;\r
131 +    FILE *file;\r
132 +    const char *filename;\r
133 +    size_t size;\r
134 +    char buf[4096];\r
135 +\r
136 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
137 +/*     if (STRNCMP_LITERAL (argv[i], "--part=") == 0) { */\r
138 +/*         part = atoi(argv[i] + sizeof ("--part=") - 1); */\r
139 +/*     } else { */\r
140 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
141 +/*         return 1; */\r
142 +/*     } */\r
143 +    }\r
144 +\r
145 +    argc -= i;\r
146 +    argv += i;\r
147 +\r
148 +    if (argc == 0) {\r
149 +       fprintf (stderr, "Error: No filename given\n");\r
150 +       return 1;\r
151 +    }\r
152 +    filename = argv[0];\r
153 +\r
154 +    config = notmuch_config_open (ctx, NULL, NULL);\r
155 +    if (config == NULL)\r
156 +       return 1;\r
157 +\r
158 +    mailstore = notmuch_config_get_mailstore (config);\r
159 +\r
160 +    if (mailstore == NULL) {\r
161 +       fprintf (stderr, "Error: I have no mailstore\n");\r
162 +       return 1;\r
163 +    }\r
164 +\r
165 +    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
166 +                                    NOTMUCH_DATABASE_MODE_READ_ONLY,\r
167 +                                    mailstore);\r
168 +\r
169 +    file = notmuch_mailstore_open_file(mailstore, filename);\r
170 +    if (file == NULL) {\r
171 +       fprintf (stderr, "Error: Cannot open %s in %s: %s\n", filename,\r
172 +                notmuch_mailstore_get_type (mailstore), strerror (errno));\r
173 +       return 1;\r
174 +    }\r
175 +    while  (!feof (file)) {\r
176 +       size = fread(buf, 1, sizeof(buf), file);\r
177 +       fwrite (buf, size, 1, stdout);\r
178 +    }\r
179 +    fclose (file);\r
180 +\r
181 +    notmuch_database_close (notmuch);\r
182 +\r
183 +    return 0;\r
184 +}\r
185 diff --git a/notmuch.c b/notmuch.c\r
186 index 95f057e..f8bb8f5 100644\r
187 --- a/notmuch.c\r
188 +++ b/notmuch.c\r
189 @@ -294,6 +294,10 @@ command_t commands[] = {\r
190        "\t\tcontain tags only from messages that match the search-term(s).\n"\r
191        "\n"\r
192        "\t\tIn both cases the list will be alphabetically sorted." },\r
193 +    { "cat", notmuch_cat_command,\r
194 +      "<path>",\r
195 +      "\t\tDumps raw message identified by <path> to standard output.",\r
196 +      "\n" },\r
197      { "help", notmuch_help_command,\r
198        "[<command>]",\r
199        "\t\tThis message, or more detailed help for the named command.",\r
200 -- \r
201 1.7.0.2\r
202 \r