Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / c3 / abc4b658ef11d511ba5245abf1b21ff4019bbf
1 Return-Path: <awg@lagos.xvx.ca>\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 7052D431FAE\r
6         for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:52 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 19VIA8JYfpU4 for <notmuch@notmuchmail.org>;\r
16         Tue, 21 Feb 2012 22:46:50 -0800 (PST)\r
17 Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])\r
18         by olra.theworths.org (Postfix) with ESMTP id 1D03F431FD0\r
19         for <notmuch@notmuchmail.org>; Tue, 21 Feb 2012 22:46:47 -0800 (PST)\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd6ml1no-ssvc.prod.shaw.ca)\r
21         ([10.0.144.222])\r
22         by pd6mo1no-svcs.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700\r
23 X-Cloudmark-SP-Filtered: true\r
24 X-Cloudmark-SP-Result: v=1.1 cv=Cufqhujp69hR+MhiHu40yK/USb/hlYs0+irVU46A6+k=\r
25         c=1 sm=1\r
26         a=k_O8UeI3qqUA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
27         a=IRZdaMhHRr9h3ODv8asA:9 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
28 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
29         by pd6ml1no-dmz.prod.shaw.ca with ESMTP; 21 Feb 2012 23:46:45 -0700\r
30 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
31         id 0466C8095C57; Tue, 21 Feb 2012 23:46:44 -0700 (MST)\r
32 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH v6 08/10] emacs: Factor out useful functions into notmuch-lib\r
35 Date: Tue, 21 Feb 2012 23:46:37 -0700\r
36 Message-Id: <1329893199-21630-9-git-send-email-awg+notmuch@xvx.ca>\r
37 X-Mailer: git-send-email 1.7.5.4\r
38 In-Reply-To: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
39 References: <1329893199-21630-1-git-send-email-awg+notmuch@xvx.ca>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Wed, 22 Feb 2012 06:46:52 -0000\r
53 \r
54 Move a few functions related to handling multipart/alternative parts\r
55 into notmuch-lib.el, so they can be used by future reply code.\r
56 ---\r
57  emacs/notmuch-lib.el  |   33 +++++++++++++++++++++++++++++++++\r
58  emacs/notmuch-show.el |   24 ++----------------------\r
59  2 files changed, 35 insertions(+), 22 deletions(-)\r
60 \r
61 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
62 index d315f76..7e3f110 100644\r
63 --- a/emacs/notmuch-lib.el\r
64 +++ b/emacs/notmuch-lib.el\r
65 @@ -21,6 +21,8 @@\r
66  \r
67  ;; This is an part of an emacs-based interface to the notmuch mail system.\r
68  \r
69 +(eval-when-compile (require 'cl))\r
70 +\r
71  (defvar notmuch-command "notmuch"\r
72    "Command to run the notmuch binary.")\r
73  \r
74 @@ -173,6 +175,37 @@ the user hasn't set this variable with the old or new value."\r
75    (list 'when (< emacs-major-version 23)\r
76         form))\r
77  \r
78 +(defun notmuch-split-content-type (content-type)\r
79 +  "Split content/type into 'content' and 'type'"\r
80 +  (split-string content-type "/"))\r
81 +\r
82 +(defun notmuch-match-content-type (t1 t2)\r
83 +  "Return t if t1 and t2 are matching content types, taking wildcards into account"\r
84 +  (let ((st1 (notmuch-split-content-type t1))\r
85 +       (st2 (notmuch-split-content-type t2)))\r
86 +    (if (or (string= (cadr st1) "*")\r
87 +           (string= (cadr st2) "*"))\r
88 +       (string= (car st1) (car st2))\r
89 +      (string= t1 t2))))\r
90 +\r
91 +(defvar notmuch-multipart/alternative-discouraged\r
92 +  '(\r
93 +    ;; Avoid HTML parts.\r
94 +    "text/html"\r
95 +    ;; multipart/related usually contain a text/html part and some associated graphics.\r
96 +    "multipart/related"\r
97 +    ))\r
98 +\r
99 +(defun notmuch-multipart/alternative-choose (types)\r
100 +  "Return a list of preferred types from the given list of types"\r
101 +  ;; Based on `mm-preferred-alternative-precedence'.\r
102 +  (let ((seq types))\r
103 +    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))\r
104 +      (dolist (elem (copy-sequence seq))\r
105 +       (when (string-match pref elem)\r
106 +         (setq seq (nconc (delete elem seq) (list elem))))))\r
107 +    seq))\r
108 +\r
109  ;; Compatibility functions for versions of emacs before emacs 23.\r
110  ;;\r
111  ;; Both functions here were copied from emacs 23 with the following copyright:\r
112 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
113 index aa9ccee..3618f88 100644\r
114 --- a/emacs/notmuch-show.el\r
115 +++ b/emacs/notmuch-show.el\r
116 @@ -513,30 +513,13 @@ current buffer, if possible."\r
117             (mm-display-part handle)\r
118             t))))))\r
119  \r
120 -(defvar notmuch-show-multipart/alternative-discouraged\r
121 -  '(\r
122 -    ;; Avoid HTML parts.\r
123 -    "text/html"\r
124 -    ;; multipart/related usually contain a text/html part and some associated graphics.\r
125 -    "multipart/related"\r
126 -    ))\r
127 -\r
128  (defun notmuch-show-multipart/*-to-list (part)\r
129    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
130           (plist-get part :content)))\r
131  \r
132 -(defun notmuch-show-multipart/alternative-choose (types)\r
133 -  ;; Based on `mm-preferred-alternative-precedence'.\r
134 -  (let ((seq types))\r
135 -    (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))\r
136 -      (dolist (elem (copy-sequence seq))\r
137 -       (when (string-match pref elem)\r
138 -         (setq seq (nconc (delete elem seq) (list elem))))))\r
139 -    seq))\r
140 -\r
141  (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
142    (notmuch-show-insert-part-header nth declared-type content-type nil)\r
143 -  (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
144 +  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
145         (inner-parts (plist-get part :content))\r
146         (start (point)))\r
147      ;; This inserts all parts of the chosen type rather than just one,\r
148 @@ -775,9 +758,6 @@ current buffer, if possible."\r
149  \r
150  ;; Functions for determining how to handle MIME parts.\r
151  \r
152 -(defun notmuch-show-split-content-type (content-type)\r
153 -  (split-string content-type "/"))\r
154 -\r
155  (defun notmuch-show-handlers-for (content-type)\r
156    "Return a list of content handlers for a part of type CONTENT-TYPE."\r
157    (let (result)\r
158 @@ -788,7 +768,7 @@ current buffer, if possible."\r
159           (list (intern (concat "notmuch-show-insert-part-*/*"))\r
160                 (intern (concat\r
161                          "notmuch-show-insert-part-"\r
162 -                        (car (notmuch-show-split-content-type content-type))\r
163 +                        (car (notmuch-split-content-type content-type))\r
164                          "/*"))\r
165                 (intern (concat "notmuch-show-insert-part-" content-type))))\r
166      result))\r
167 -- \r
168 1.7.5.4\r
169 \r