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 5C325431FBC
\r
6 for <notmuch@notmuchmail.org>; Sun, 11 Mar 2012 21:06:07 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 wV46hBccVMzX for <notmuch@notmuchmail.org>;
\r
16 Sun, 11 Mar 2012 21:06:05 -0700 (PDT)
\r
17 Received: from idcmail-mo1so.shaw.ca (idcmail-mo1so.shaw.ca [24.71.223.10])
\r
18 by olra.theworths.org (Postfix) with ESMTP id DFBA3431FCF
\r
19 for <notmuch@notmuchmail.org>; Sun, 11 Mar 2012 21:06:04 -0700 (PDT)
\r
20 Received: from pd4ml2so-ssvc.prod.shaw.ca ([10.0.141.136])
\r
21 by pd4mo1so-svcs.prod.shaw.ca with ESMTP; 11 Mar 2012 22:06:04 -0600
\r
22 X-Cloudmark-SP-Filtered: true
\r
23 X-Cloudmark-SP-Result: v=1.1 cv=OAanaFJXxrU4geOiks1gk5+7cCarKPEnRlgRWHXA/ts=
\r
25 a=BrvNWVd2rZQA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17
\r
26 a=IRZdaMhHRr9h3ODv8asA:9 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
\r
27 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])
\r
28 by pd4ml2so-dmz.prod.shaw.ca with ESMTP; 11 Mar 2012 22:06:04 -0600
\r
29 Received: by lagos.xvx.ca (Postfix, from userid 1000)
\r
30 id 1F9BE8004958; Sun, 11 Mar 2012 22:06:04 -0600 (MDT)
\r
31 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v7 08/10] emacs: Factor out useful functions into notmuch-lib
\r
34 Date: Sun, 11 Mar 2012 22:05:40 -0600
\r
35 Message-Id: <1331525142-30539-9-git-send-email-awg+notmuch@xvx.ca>
\r
36 X-Mailer: git-send-email 1.7.5.4
\r
37 In-Reply-To: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca>
\r
38 References: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca>
\r
39 X-BeenThere: notmuch@notmuchmail.org
\r
40 X-Mailman-Version: 2.1.13
\r
42 List-Id: "Use and development of the notmuch mail system."
\r
43 <notmuch.notmuchmail.org>
\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
47 List-Post: <mailto:notmuch@notmuchmail.org>
\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
51 X-List-Received-Date: Mon, 12 Mar 2012 04:06:07 -0000
\r
53 Move a few functions related to handling multipart/alternative parts
\r
54 into notmuch-lib.el, so they can be used by future reply code.
\r
56 emacs/notmuch-lib.el | 33 +++++++++++++++++++++++++++++++++
\r
57 emacs/notmuch-show.el | 24 ++----------------------
\r
58 2 files changed, 35 insertions(+), 22 deletions(-)
\r
60 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
61 index d315f76..7e3f110 100644
\r
62 --- a/emacs/notmuch-lib.el
\r
63 +++ b/emacs/notmuch-lib.el
\r
66 ;; This is an part of an emacs-based interface to the notmuch mail system.
\r
68 +(eval-when-compile (require 'cl))
\r
70 (defvar notmuch-command "notmuch"
\r
71 "Command to run the notmuch binary.")
\r
73 @@ -173,6 +175,37 @@ the user hasn't set this variable with the old or new value."
\r
74 (list 'when (< emacs-major-version 23)
\r
77 +(defun notmuch-split-content-type (content-type)
\r
78 + "Split content/type into 'content' and 'type'"
\r
79 + (split-string content-type "/"))
\r
81 +(defun notmuch-match-content-type (t1 t2)
\r
82 + "Return t if t1 and t2 are matching content types, taking wildcards into account"
\r
83 + (let ((st1 (notmuch-split-content-type t1))
\r
84 + (st2 (notmuch-split-content-type t2)))
\r
85 + (if (or (string= (cadr st1) "*")
\r
86 + (string= (cadr st2) "*"))
\r
87 + (string= (car st1) (car st2))
\r
88 + (string= t1 t2))))
\r
90 +(defvar notmuch-multipart/alternative-discouraged
\r
92 + ;; Avoid HTML parts.
\r
94 + ;; multipart/related usually contain a text/html part and some associated graphics.
\r
95 + "multipart/related"
\r
98 +(defun notmuch-multipart/alternative-choose (types)
\r
99 + "Return a list of preferred types from the given list of types"
\r
100 + ;; Based on `mm-preferred-alternative-precedence'.
\r
101 + (let ((seq types))
\r
102 + (dolist (pref (reverse notmuch-multipart/alternative-discouraged))
\r
103 + (dolist (elem (copy-sequence seq))
\r
104 + (when (string-match pref elem)
\r
105 + (setq seq (nconc (delete elem seq) (list elem))))))
\r
108 ;; Compatibility functions for versions of emacs before emacs 23.
\r
110 ;; Both functions here were copied from emacs 23 with the following copyright:
\r
111 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
112 index 4a60631..ed938bf 100644
\r
113 --- a/emacs/notmuch-show.el
\r
114 +++ b/emacs/notmuch-show.el
\r
115 @@ -542,30 +542,13 @@ current buffer, if possible."
\r
116 (mm-display-part handle)
\r
119 -(defvar notmuch-show-multipart/alternative-discouraged
\r
121 - ;; Avoid HTML parts.
\r
123 - ;; multipart/related usually contain a text/html part and some associated graphics.
\r
124 - "multipart/related"
\r
127 (defun notmuch-show-multipart/*-to-list (part)
\r
128 (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
\r
129 (plist-get part :content)))
\r
131 -(defun notmuch-show-multipart/alternative-choose (types)
\r
132 - ;; Based on `mm-preferred-alternative-precedence'.
\r
133 - (let ((seq types))
\r
134 - (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))
\r
135 - (dolist (elem (copy-sequence seq))
\r
136 - (when (string-match pref elem)
\r
137 - (setq seq (nconc (delete elem seq) (list elem))))))
\r
140 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
\r
141 (notmuch-show-insert-part-header nth declared-type content-type nil)
\r
142 - (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
\r
143 + (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
\r
144 (inner-parts (plist-get part :content))
\r
146 ;; This inserts all parts of the chosen type rather than just one,
\r
147 @@ -808,9 +791,6 @@ current buffer, if possible."
\r
149 ;; Functions for determining how to handle MIME parts.
\r
151 -(defun notmuch-show-split-content-type (content-type)
\r
152 - (split-string content-type "/"))
\r
154 (defun notmuch-show-handlers-for (content-type)
\r
155 "Return a list of content handlers for a part of type CONTENT-TYPE."
\r
157 @@ -821,7 +801,7 @@ current buffer, if possible."
\r
158 (list (intern (concat "notmuch-show-insert-part-*/*"))
\r
160 "notmuch-show-insert-part-"
\r
161 - (car (notmuch-show-split-content-type content-type))
\r
162 + (car (notmuch-split-content-type content-type))
\r
164 (intern (concat "notmuch-show-insert-part-" content-type))))
\r