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 74555431FBC for ; Sat, 5 Dec 2009 06:06:10 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 BcKAv7cA6RuA for ; Sat, 5 Dec 2009 06:06:09 -0800 (PST) Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57]) by olra.theworths.org (Postfix) with ESMTP id C6EC4431FAE for ; Sat, 5 Dec 2009 06:06:09 -0800 (PST) Received: from fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net ([142.167.182.194] helo=localhost) by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NGvGy-0004tL-Qu; Sat, 05 Dec 2009 10:06:09 -0400 Received: from bremner by localhost with local (Exim 4.69) (envelope-from ) id 1NGvGt-0000nT-Bf; Sat, 05 Dec 2009 10:06:03 -0400 From: David Bremner To: notmuch@notmuchmail.org Date: Sat, 5 Dec 2009 10:05:51 -0400 Message-Id: <1260021951-3022-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1259979997-31544-1-git-send-email-david@tethera.net> References: <1259979997-31544-1-git-send-email-david@tethera.net> X-Sender-Verified: bremner@pivot.cs.unb.ca Subject: [notmuch] [PATCH] notmuch-show-get-header: new function; return alist of parsed header fields. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Sat, 05 Dec 2009 14:06:10 -0000 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. --- This is another patch needed for org-mode links. Really I just need some way to get the author and subject of the current message in notmuch-show-mode. It seems like a generally useful function, although of course it would be more efficient to cache these headers somewhere if the function is being invoked many times. notmuch.el | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/notmuch.el b/notmuch.el index f7048d5..cf472f7 100644 --- a/notmuch.el +++ b/notmuch.el @@ -203,6 +203,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.3