Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f6 / 6fd96272e2e3b2d125a3fb0b7a5e611530d4ad
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 165E1431FC1\r
6         for <notmuch@notmuchmail.org>; Thu,  8 Apr 2010 07:43:16 -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 lKFo38+khVyD for <notmuch@notmuchmail.org>;\r
16         Thu,  8 Apr 2010 07:43:13 -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 DA6644196F3\r
19         for <notmuch@notmuchmail.org>; Thu,  8 Apr 2010 07:43:08 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 4C9F519F33D8;\r
22         Thu,  8 Apr 2010 16:43:08 +0200 (CEST)\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 Mn6Z2lqs+6Be; Thu,  8 Apr 2010 16:43:05 +0200 (CEST)\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 61EC719F3409;\r
30         Thu,  8 Apr 2010 16:43:05 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 5159A15C062;\r
34         Thu,  8 Apr 2010 16:43:05 +0200 (CEST)\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 1Nzswj-0007cL-11; Thu, 08 Apr 2010 16:43:05 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 4/4] Add 'cat' subcommand\r
41 Date: Thu,  8 Apr 2010 16:42:46 +0200\r
42 Message-Id: <1270737766-29237-5-git-send-email-sojkam1@fel.cvut.cz>\r
43 X-Mailer: git-send-email 1.7.0.2\r
44 In-Reply-To: <1270737766-29237-1-git-send-email-sojkam1@fel.cvut.cz>\r
45 References: <1270737766-29237-1-git-send-email-sojkam1@fel.cvut.cz>\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: Thu, 08 Apr 2010 14:43:16 -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, view raw message and pipe message to\r
66 command).\r
67 \r
68 With this patch, it is straightforward to use notmuch emacs interface\r
69 remotely over SSH. To do this, it is sufficient to redefine\r
70 notmuch-command variable to contain the name of a script containing:\r
71 \r
72     ssh user@host notmuch "$@"\r
73 \r
74 Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
75 ---\r
76  NEWS                  |    3 ++\r
77  emacs/notmuch-show.el |   11 ++++++--\r
78  notmuch-client.h      |    3 ++\r
79  notmuch-show.c        |   62 +++++++++++++++++++++++++++++++++++++++++++++++++\r
80  notmuch.c             |    4 +++\r
81  5 files changed, 80 insertions(+), 3 deletions(-)\r
82 \r
83 diff --git a/NEWS b/NEWS\r
84 index f29ac27..3bd21fa 100644\r
85 --- a/NEWS\r
86 +++ b/NEWS\r
87 @@ -1,3 +1,6 @@\r
88 +A new subcommand 'cat' was added, which simplifies use of Emacs\r
89 +interface with remote database (accessed over SSH).\r
90 +\r
91  Notmuch 0.1 (2010-04-05)\r
92  ========================\r
93  This is the first release of the notmuch mail system.\r
94 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
95 index 6f5a55d..45d49d1 100644\r
96 --- a/emacs/notmuch-show.el\r
97 +++ b/emacs/notmuch-show.el\r
98 @@ -328,7 +328,11 @@ buffer."\r
99  (defun notmuch-show-view-raw-message ()\r
100    "View the raw email of the current message."\r
101    (interactive)\r
102 -  (view-file (notmuch-show-get-filename)))\r
103 +  (let ((filename (notmuch-show-get-filename)))\r
104 +    (let ((buf (get-buffer-create (concat "*notmuch-raw-" filename "*"))))\r
105 +      (switch-to-buffer buf)\r
106 +      (save-excursion\r
107 +       (call-process notmuch-command nil t nil "cat" filename)))))\r
108  \r
109  (defmacro with-current-notmuch-show-message (&rest body)\r
110    "Evaluate body with current buffer set to the text of current message"\r
111 @@ -336,7 +340,7 @@ buffer."\r
112       (let ((filename (notmuch-show-get-filename)))\r
113         (let ((buf (generate-new-buffer (concat "*notmuch-msg-" filename "*"))))\r
114           (with-current-buffer buf\r
115 -           (insert-file-contents filename nil nil nil t)\r
116 +           (call-process notmuch-command nil t nil "cat" filename)\r
117             ,@body)\r
118          (kill-buffer buf)))))\r
119  \r
120 @@ -390,7 +394,8 @@ current email message as stdin. Anything printed by the command\r
121  to stdout or stderr will appear in the *Messages* buffer."\r
122    (interactive "sPipe message to command: ")\r
123    (apply 'start-process-shell-command "notmuch-pipe-command" "*notmuch-pipe*"\r
124 -        (list command " < " (shell-quote-argument (notmuch-show-get-filename)))))\r
125 +        (list notmuch-command "cat"\r
126 +              (shell-quote-argument (notmuch-show-get-filename) " | " command))))\r
127  \r
128  (defun notmuch-show-move-to-current-message-summary-line ()\r
129    "Move to the beginning of the one-line summary of the current message.\r
130 diff --git a/notmuch-client.h b/notmuch-client.h\r
131 index 728e448..666e70d 100644\r
132 --- a/notmuch-client.h\r
133 +++ b/notmuch-client.h\r
134 @@ -111,6 +111,9 @@ int\r
135  notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
136  \r
137  int\r
138 +notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
139 +\r
140 +int\r
141  notmuch_part_command (void *ctx, int argc, char *argv[]);\r
142  \r
143  const char *\r
144 diff --git a/notmuch-show.c b/notmuch-show.c\r
145 index 66fd773..dbab9a7 100644\r
146 --- a/notmuch-show.c\r
147 +++ b/notmuch-show.c\r
148 @@ -515,6 +515,68 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
149  }\r
150  \r
151  int\r
152 +notmuch_cat_command (void *ctx, unused (int argc), unused (char *argv[]))\r
153 +{\r
154 +    notmuch_config_t *config;\r
155 +    notmuch_database_t *notmuch;\r
156 +    notmuch_mailstore_t *mailstore;\r
157 +    int i;\r
158 +    FILE *file;\r
159 +    const char *filename;\r
160 +    size_t size;\r
161 +    char buf[4096];\r
162 +\r
163 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
164 +/*     if (STRNCMP_LITERAL (argv[i], "--part=") == 0) { */\r
165 +/*         part = atoi(argv[i] + sizeof ("--part=") - 1); */\r
166 +/*     } else { */\r
167 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
168 +/*         return 1; */\r
169 +/*     } */\r
170 +    }\r
171 +\r
172 +    argc -= i;\r
173 +    argv += i;\r
174 +\r
175 +    if (argc == 0) {\r
176 +       fprintf (stderr, "Error: No filename given\n");\r
177 +       return 1;\r
178 +    }\r
179 +    filename = argv[0];\r
180 +\r
181 +    config = notmuch_config_open (ctx, NULL, NULL);\r
182 +    if (config == NULL)\r
183 +       return 1;\r
184 +\r
185 +    mailstore = notmuch_config_get_mailstore (config);\r
186 +\r
187 +    if (mailstore == NULL) {\r
188 +       fprintf (stderr, "Error: I have no mailstore\n");\r
189 +       return 1;\r
190 +    }\r
191 +\r
192 +    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
193 +                                    NOTMUCH_DATABASE_MODE_READ_ONLY,\r
194 +                                    mailstore);\r
195 +\r
196 +    file = notmuch_mailstore_open_file(mailstore, filename);\r
197 +    if (file == NULL) {\r
198 +       fprintf (stderr, "Error: Cannot open %s in %s: %s\n", filename,\r
199 +                notmuch_mailstore_get_type (mailstore), strerror (errno));\r
200 +       return 1;\r
201 +    }\r
202 +    while  (!feof (file)) {\r
203 +       size = fread(buf, 1, sizeof(buf), file);\r
204 +       fwrite (buf, size, 1, stdout);\r
205 +    }\r
206 +    fclose (file);\r
207 +\r
208 +    notmuch_database_close (notmuch);\r
209 +\r
210 +    return 0;\r
211 +}\r
212 +\r
213 +int\r
214  notmuch_part_command (void *ctx, unused (int argc), unused (char *argv[]))\r
215  {\r
216         notmuch_config_t *config;\r
217 diff --git a/notmuch.c b/notmuch.c\r
218 index f5669fc..bcebcdc 100644\r
219 --- a/notmuch.c\r
220 +++ b/notmuch.c\r
221 @@ -294,6 +294,10 @@ command_t commands[] = {\r
222        "\tcontain tags only from messages that match the search-term(s).\n"\r
223        "\n"\r
224        "\tIn both cases the list will be alphabetically sorted." },\r
225 +    { "cat", notmuch_cat_command,\r
226 +      "<path>",\r
227 +      "Dump raw message identified by path to standard output.",\r
228 +      "" },\r
229      { "part", notmuch_part_command,\r
230        "--part=<num> <search-terms>",\r
231        "Output a single MIME part of a message.",\r
232 -- \r
233 1.7.0.2\r
234 \r