[PATCH v7.1 08/11] emacs: Factor out useful functions into notmuch-lib
authorAdam Wolfe Gordon <awg+notmuch@xvx.ca>
Wed, 14 Mar 2012 04:30:13 +0000 (22:30 +1800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:28 +0000 (09:45 -0800)
73/a40ee50d679e14de9a9e8e7ac50554b42016d0 [new file with mode: 0644]

diff --git a/73/a40ee50d679e14de9a9e8e7ac50554b42016d0 b/73/a40ee50d679e14de9a9e8e7ac50554b42016d0
new file mode 100644 (file)
index 0000000..c837ddd
--- /dev/null
@@ -0,0 +1,171 @@
+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 B4001431FD6\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Mar 2012 21:30:26 -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 nz0ppL9DV+bM for <notmuch@notmuchmail.org>;\r
+       Tue, 13 Mar 2012 21:30:24 -0700 (PDT)\r
+Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])\r
+       by olra.theworths.org (Postfix) with ESMTP id A0BE5431FD7\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Mar 2012 21:30:22 -0700 (PDT)\r
+Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd6ml3no-ssvc.prod.shaw.ca)\r
+       ([10.0.144.222])\r
+       by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 13 Mar 2012 22:30:21 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=gFGh1ScE7ROJHT2jhivHYaSHya8441O0LZB7wkhlVyo=\r
+       c=1 sm=1\r
+       a=aj0SqZEsnloA: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 pd6ml3no-dmz.prod.shaw.ca with ESMTP; 13 Mar 2012 22:30:21 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+       id 0273380002C3; Tue, 13 Mar 2012 22:30:20 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v7.1 08/11] emacs: Factor out useful functions into\r
+ notmuch-lib\r
+Date: Tue, 13 Mar 2012 22:30:13 -0600\r
+Message-Id: <1331699416-30775-9-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1331699416-30775-1-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1331525142-30539-1-git-send-email-awg+notmuch@xvx.ca>\r
+       <1331699416-30775-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: Wed, 14 Mar 2012 04:30:27 -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