[PATCH v8 08/11] emacs: Factor out useful functions into notmuch-lib
authorAdam Wolfe Gordon <awg+notmuch@xvx.ca>
Sun, 18 Mar 2012 16:32:40 +0000 (10:32 +1800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:37 +0000 (09:45 -0800)
aa/8957369148cc38ecd978f4c1ef143289cfb5fe [new file with mode: 0644]

diff --git a/aa/8957369148cc38ecd978f4c1ef143289cfb5fe b/aa/8957369148cc38ecd978f4c1ef143289cfb5fe
new file mode 100644 (file)
index 0000000..f4a79f5
--- /dev/null
@@ -0,0 +1,169 @@
+Return-Path: <awg@lagos.xvx.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 2DB95431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Mar 2012 09:33:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id uI2AExbAV3tE for <notmuch@notmuchmail.org>;\r
+       Sun, 18 Mar 2012 09:33:06 -0700 (PDT)\r
+Received: from idcmail-mo1so.shaw.ca (idcmail-mo1so.shaw.ca [24.71.223.10])\r
+       by olra.theworths.org (Postfix) with ESMTP id ABD08431FD4\r
+       for <notmuch@notmuchmail.org>; Sun, 18 Mar 2012 09:33:01 -0700 (PDT)\r
+Received: from pd4ml3so-ssvc.prod.shaw.ca ([10.0.141.150])\r
+       by pd4mo1so-svcs.prod.shaw.ca with ESMTP; 18 Mar 2012 10:33:00 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=b/gStvK98Bs6YfhBwCpxRApoLO2qoBYaarCtclPE+68=\r
+       c=1 sm=1\r
+       a=dHRAfZDHJaYA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
+       a=IRZdaMhHRr9h3ODv8asA:9 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
+Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
+       by pd4ml3so-dmz.prod.shaw.ca with ESMTP; 18 Mar 2012 10:33:00 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+       id 74D7A8004839; Sun, 18 Mar 2012 10:33:00 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v8 08/11] emacs: Factor out useful functions into notmuch-lib\r
+Date: Sun, 18 Mar 2012 10:32:40 -0600\r
+Message-Id: <1332088363-22476-9-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1332088363-22476-1-git-send-email-awg+notmuch@xvx.ca>\r
+References: <87fwd6kqtv.fsf@zancas.localnet>\r
+       <1332088363-22476-1-git-send-email-awg+notmuch@xvx.ca>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 18 Mar 2012 16:33:08 -0000\r
+\r
+Move a few functions related to handling multipart/alternative parts\r
+into notmuch-lib.el, so they can be used by future reply code.\r
+---\r
+ emacs/notmuch-lib.el  |   33 +++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-show.el |   24 ++----------------------\r
+ 2 files changed, 35 insertions(+), 22 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index d315f76..7e3f110 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -21,6 +21,8 @@\r
+ \r
+ ;; This is an part of an emacs-based interface to the notmuch mail system.\r
+ \r
++(eval-when-compile (require 'cl))\r
++\r
+ (defvar notmuch-command "notmuch"\r
+   "Command to run the notmuch binary.")\r
+ \r
+@@ -173,6 +175,37 @@ the user hasn't set this variable with the old or new value."\r
+   (list 'when (< emacs-major-version 23)\r
+       form))\r
+ \r
++(defun notmuch-split-content-type (content-type)\r
++  "Split content/type into 'content' and 'type'"\r
++  (split-string content-type "/"))\r
++\r
++(defun notmuch-match-content-type (t1 t2)\r
++  "Return t if t1 and t2 are matching content types, taking wildcards into account"\r
++  (let ((st1 (notmuch-split-content-type t1))\r
++      (st2 (notmuch-split-content-type t2)))\r
++    (if (or (string= (cadr st1) "*")\r
++          (string= (cadr st2) "*"))\r
++      (string= (car st1) (car st2))\r
++      (string= t1 t2))))\r
++\r
++(defvar notmuch-multipart/alternative-discouraged\r
++  '(\r
++    ;; Avoid HTML parts.\r
++    "text/html"\r
++    ;; multipart/related usually contain a text/html part and some associated graphics.\r
++    "multipart/related"\r
++    ))\r
++\r
++(defun notmuch-multipart/alternative-choose (types)\r
++  "Return a list of preferred types from the given list of types"\r
++  ;; Based on `mm-preferred-alternative-precedence'.\r
++  (let ((seq types))\r
++    (dolist (pref (reverse notmuch-multipart/alternative-discouraged))\r
++      (dolist (elem (copy-sequence seq))\r
++      (when (string-match pref elem)\r
++        (setq seq (nconc (delete elem seq) (list elem))))))\r
++    seq))\r
++\r
+ ;; Compatibility functions for versions of emacs before emacs 23.\r
+ ;;\r
+ ;; Both functions here were copied from emacs 23 with the following copyright:\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 4a60631..ed938bf 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -542,30 +542,13 @@ current buffer, if possible."\r
+           (mm-display-part handle)\r
+           t))))))\r
+ \r
+-(defvar notmuch-show-multipart/alternative-discouraged\r
+-  '(\r
+-    ;; Avoid HTML parts.\r
+-    "text/html"\r
+-    ;; multipart/related usually contain a text/html part and some associated graphics.\r
+-    "multipart/related"\r
+-    ))\r
+-\r
+ (defun notmuch-show-multipart/*-to-list (part)\r
+   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+         (plist-get part :content)))\r
+ \r
+-(defun notmuch-show-multipart/alternative-choose (types)\r
+-  ;; Based on `mm-preferred-alternative-precedence'.\r
+-  (let ((seq types))\r
+-    (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))\r
+-      (dolist (elem (copy-sequence seq))\r
+-      (when (string-match pref elem)\r
+-        (setq seq (nconc (delete elem seq) (list elem))))))\r
+-    seq))\r
+-\r
+ (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
+   (notmuch-show-insert-part-header nth declared-type content-type nil)\r
+-  (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
++  (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
+       (inner-parts (plist-get part :content))\r
+       (start (point)))\r
+     ;; This inserts all parts of the chosen type rather than just one,\r
+@@ -808,9 +791,6 @@ current buffer, if possible."\r
+ \r
+ ;; Functions for determining how to handle MIME parts.\r
+ \r
+-(defun notmuch-show-split-content-type (content-type)\r
+-  (split-string content-type "/"))\r
+-\r
+ (defun notmuch-show-handlers-for (content-type)\r
+   "Return a list of content handlers for a part of type CONTENT-TYPE."\r
+   (let (result)\r
+@@ -821,7 +801,7 @@ current buffer, if possible."\r
+         (list (intern (concat "notmuch-show-insert-part-*/*"))\r
+               (intern (concat\r
+                        "notmuch-show-insert-part-"\r
+-                       (car (notmuch-show-split-content-type content-type))\r
++                       (car (notmuch-split-content-type content-type))\r
+                        "/*"))\r
+               (intern (concat "notmuch-show-insert-part-" content-type))))\r
+     result))\r
+-- \r
+1.7.5.4\r
+\r