Re: [PATCH v2] Omit User-Agent: header by default
[notmuch-archives.git] / ab / c0a0d5f238ccaec95ca51c787b3d47a9684584
1 Return-Path: <amdragon@mit.edu>\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 01800431FB6\r
6         for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 21:15:30 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 GAr4StNIX5xb for <notmuch@notmuchmail.org>;\r
16         Fri, 14 Dec 2012 21:15:29 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id 82C21431FC2\r
20         for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 21:15:28 -0800 (PST)\r
21 X-AuditID: 12074424-b7fe06d0000008f0-f7-50cc076fb88c\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 3B.38.02288.F670CC05; Sat, 15 Dec 2012 00:15:28 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id qBF5FQ1F021590; \r
27         Sat, 15 Dec 2012 00:15:26 -0500\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBF5FOGp011443\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 15 Dec 2012 00:15:25 -0500 (EST)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1Tjk5s-0002kJ-3a; Sat, 15 Dec 2012 00:15:24 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 1/7] emacs: Centralize notmuch command error handling\r
41 Date: Sat, 15 Dec 2012 00:15:07 -0500\r
42 Message-Id: <1355548513-10085-2-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.10.4\r
44 In-Reply-To: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
45 References: <1355548513-10085-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixCmqrFvAfibA4M07VovVc3ksrt+cyezA\r
48         5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZczoX8ZYMEWsYs2aSawNjPsEuxg5OSQETCSO\r
49         /ulghbDFJC7cW8/WxcjFISSwj1HiSP88dghnA6PE2ud/mECqhAQeMUlc6fCFSMxllDjZspQN\r
50         JMEmoCGxbf9yRhBbREBaYufd2WBjmQUcJT7vXwRWIyzgKnHx5CVmEJtFQFVi6ct+MJtXwAGo\r
51         /hM7xBmKEt3PJoDVcwL1Lvt4jgVisYPE2Vd3WScw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX\r
52         l1qka66Xm1mil5pSuokRFEjsLio7GJsPKR1iFOBgVOLh3RFxOkCINbGsuDL3EKMkB5OSKO8t\r
53         hjMBQnxJ+SmVGYnFGfFFpTmpxYcYJTiYlUR4xbYAlfOmJFZWpRblw6SkOViUxHmvp9z0FxJI\r
54         TyxJzU5NLUgtgsnKcHAoSfCyswENFSxKTU+tSMvMKUFIM3FwggznARp+lhWohre4IDG3ODMd\r
55         In+KUVFKnPcJSEIAJJFRmgfXC4v0V4ziQK8I8z4CqeIBJgm47ldAg5mABsddOg4yuCQRISXV\r
56         wNj+ZX2U2YdFQj2RjowGrdXJSpYvwqbPmc6l7FurczP3QGP1l01y1lYLA6bNO7dS+KzTg3/u\r
57         YZWSvKlh8vz7Tr9Livd3ZjqhO22KSHqDfcq8xC3yCUebhPmdb1k31753lL0m2jD1lJjF9DCD\r
58         Iymv36nXH3mus7XaZePZtX7bdx3+F2WywTZfUImlOCPRUIu5qDgRAM/mKkPPAgAA\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Sat, 15 Dec 2012 05:15:30 -0000\r
72 \r
73 This provides library functions for unified handling of errors from\r
74 the notmuch CLI.  Follow-up patches will convert some scattered error\r
75 handling to use this and add error handling where we currently ignore\r
76 errors.\r
77 ---\r
78  emacs/notmuch-lib.el |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
79  1 file changed, 53 insertions(+)\r
80 \r
81 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
82 index 9c4ee71..851098f 100644\r
83 --- a/emacs/notmuch-lib.el\r
84 +++ b/emacs/notmuch-lib.el\r
85 @@ -316,6 +316,59 @@ string), a property list of face attributes, or a list of these."\r
86         (put-text-property pos next 'face (cons face cur))\r
87         (setq pos next)))))\r
88  \r
89 +(defun notmuch-pop-up-error (msg)\r
90 +  "Pop up an error buffer displaying MSG.\r
91 +\r
92 +This will accumulate error messages in the errors buffer until\r
93 +the user dismisses it."\r
94 +\r
95 +  (let ((buf (get-buffer-create "*Notmuch errors*")))\r
96 +    (with-current-buffer buf\r
97 +      (view-mode-enter nil #'kill-buffer)\r
98 +      (let ((inhibit-read-only t))\r
99 +       (insert msg)\r
100 +       (unless (bolp)\r
101 +         (insert "\n"))\r
102 +       (goto-char (point-min))))\r
103 +    (pop-to-buffer buf)))\r
104 +\r
105 +(defun notmuch-check-exit-status (exit-status command &optional output err-file)\r
106 +  "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error.\r
107 +\r
108 +If EXIT-STATUS is non-zero, pop up a notmuch error buffer\r
109 +describing the error and signal an Elisp error.  EXIT-STATUS must\r
110 +be a number indicating the exit status code of a process or a\r
111 +string describing the signal that terminated the process (such as\r
112 +returned by `call-process').  COMMAND must be a list giving the\r
113 +command and its arguments.  OUTPUT, if provided, is a string\r
114 +giving the output of command.  ERR-FILE, if provided, is the name\r
115 +of a file containing the error output of command.  OUTPUT and the\r
116 +contents of ERR-FILE will be included in the error message."\r
117 +\r
118 +  ;; This is implemented as a cond to make it easy to expand.\r
119 +  (cond\r
120 +   ((eq exit-status 0) t)\r
121 +   (t\r
122 +    (notmuch-pop-up-error\r
123 +     (concat\r
124 +      (format "Error invoking notmuch.  %s exited with %s%s.\n"\r
125 +             (mapconcat #'identity command " ")\r
126 +             ;; Signal strings look like "Terminated", hence the\r
127 +             ;; colon.\r
128 +             (if (integerp exit-status) "status " "signal: ")\r
129 +             exit-status)\r
130 +      (when err-file\r
131 +       (concat "Error:\n"\r
132 +               (with-temp-buffer\r
133 +                 (insert-file-contents err-file)\r
134 +                 (if (eobp)\r
135 +                     "(no error output)\n"\r
136 +                   (buffer-string)))))\r
137 +      (when (and output (not (equal output "")))\r
138 +       (format "Output:\n%s" output))))\r
139 +    ;; Mimic `process-lines'\r
140 +    (error "%s exited with status %s" (car command) exit-status))))\r
141 +\r
142  ;; Compatibility functions for versions of emacs before emacs 23.\r
143  ;;\r
144  ;; Both functions here were copied from emacs 23 with the following copyright:\r
145 -- \r
146 1.7.10.4\r
147 \r