Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7B7D5431FBD for ; Thu, 11 Feb 2010 18:37:48 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.948 X-Spam-Level: X-Spam-Status: No, score=-1.948 tagged_above=-999 required=5 tests=[AWL=0.651, BAYES_00=-2.599] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id twizglcairmR for ; Thu, 11 Feb 2010 18:37:47 -0800 (PST) Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57]) by olra.theworths.org (Postfix) with ESMTP id D03F0431FBC for ; Thu, 11 Feb 2010 18:37:47 -0800 (PST) Received: from fctnnbsc30w-142167166109.pppoe-dynamic.high-speed.nb.bellaliant.net ([142.167.166.109] helo=rocinante.cs.unb.ca) by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NflPf-0002KW-Ez; Thu, 11 Feb 2010 22:37:47 -0400 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71) (envelope-from ) id 1NflMy-0007uN-Cf; Thu, 11 Feb 2010 22:35:00 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Date: Thu, 11 Feb 2010 22:34:31 -0400 Message-Id: <1265942072-30247-2-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.6.5 In-Reply-To: <1265942072-30247-1-git-send-email-david@tethera.net> References: <1265942072-30247-1-git-send-email-david@tethera.net> X-Sender-Verified: bremner@pivot.cs.unb.ca Cc: David Bremner Subject: [notmuch] [PATCH 1/2] notmuch-show-get-header: new function; return alist of parsed header fields. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Feb 2010 02:37:48 -0000 From: David Bremner This function parses the displayed message to recover header fields. It uses mailheader.el to do the actual header parsing, after preprocessing to remove indentation. It relies on the variables notmuch-show-message-begin-regexp, notmuch-show-header-begin-regexp, and notmuch-show-message-end-regexp. --- notmuch.el | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/notmuch.el b/notmuch.el index c0bb552..c96fd94 100644 --- a/notmuch.el +++ b/notmuch.el @@ -225,6 +225,30 @@ Unlike builtin `previous-line' this version accepts no arguments." (re-search-forward notmuch-show-tags-regexp) (split-string (buffer-substring (match-beginning 1) (match-end 1))))) +(defun notmuch-show-get-header () + "Retrieve and parse the header from the current message. Returns an alist with of (header . value) +where header is a symbol and value is a string. The summary from notmuch-show is returned as the +pseudoheader summary" + (require 'mailheader) + (save-excursion + (beginning-of-line) + (if (not (looking-at notmuch-show-message-begin-regexp)) + (re-search-backward notmuch-show-message-begin-regexp)) + (re-search-forward (concat notmuch-show-header-begin-regexp "\n[[:space:]]*\\(.*\\)\n")) + (let* ((summary (buffer-substring-no-properties (match-beginning 1) (match-end 1))) + (beg (point))) + (re-search-forward notmuch-show-header-end-regexp) + (let ((text (buffer-substring beg (match-beginning 0)))) + (with-temp-buffer + (insert text) + (goto-char (point-min)) + (while (looking-at "\\([[:space:]]*\\)[A-Za-z][-A-Za-z0-9]*:") + (delete-region (match-beginning 1) (match-end 1)) + (forward-line) + ) + (goto-char (point-min)) + (cons (cons 'summary summary) (mail-header-extract-no-properties))))))) + (defun notmuch-show-add-tag (&rest toadd) "Add a tag to the current message." (interactive -- 1.6.5