From 889cdc3055e643b12a71d4c205499142144610e0 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins Date: Mon, 30 Jan 2012 11:33:44 +1600 Subject: [PATCH] [PATCH 2/2] emacs: new mua mailto: URI handler --- 63/c0cc3947212ba9682c3b6e24de13e27c781a65 | 149 ++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 63/c0cc3947212ba9682c3b6e24de13e27c781a65 diff --git a/63/c0cc3947212ba9682c3b6e24de13e27c781a65 b/63/c0cc3947212ba9682c3b6e24de13e27c781a65 new file mode 100644 index 000000000..4728234ec --- /dev/null +++ b/63/c0cc3947212ba9682c3b6e24de13e27c781a65 @@ -0,0 +1,149 @@ +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 C2E42429E3F + for ; Sun, 29 Jan 2012 11:33:51 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +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 qwJXBfCHQyFy for ; + Sun, 29 Jan 2012 11:33:47 -0800 (PST) +Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu + [131.215.239.19]) + by olra.theworths.org (Postfix) with ESMTP id AC1D5431E64 + for ; Sun, 29 Jan 2012 11:33:47 -0800 (PST) +Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1]) + by earth-doxen-postvirus (Postfix) with ESMTP id 22BF766E013B + for ; Sun, 29 Jan 2012 11:33:47 -0800 (PST) +X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new +Received: from finestructure.net (cpe-76-174-137-84.socal.res.rr.com + [76.174.137.84]) (Authenticated sender: jrollins) + by earth-doxen-submit (Postfix) with ESMTP id C0D0366E00CF + for ; Sun, 29 Jan 2012 11:33:44 -0800 (PST) +Received: by finestructure.net (Postfix, from userid 1000) + id 3F46C159; Sun, 29 Jan 2012 11:33:44 -0800 (PST) +From: Jameson Graef Rollins +To: Notmuch Mail +Subject: [PATCH 2/2] emacs: new mua mailto: URI handler +Date: Sun, 29 Jan 2012 11:33:44 -0800 +Message-Id: <1327865624-7673-2-git-send-email-jrollins@finestructure.net> +X-Mailer: git-send-email 1.7.8.3 +In-Reply-To: <1327865624-7673-1-git-send-email-jrollins@finestructure.net> +References: <1327865624-7673-1-git-send-email-jrollins@finestructure.net> +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: Sun, 29 Jan 2012 19:33:52 -0000 + +The new function 'notmuch-mua-mailto' provides an interactive handler +for rfc6068 "mailto:" URIs. It attempts to implement the rfc6068 +specification: http://tools.ietf.org/html/rfc6068 + +More decoding of the mailto string needs to be done, as is evident by +the fact that the mailto test remains broken. +--- +Unfortunately I'm not sure how best to do the URI decoding, so I've +left a FIXME in the code, and the test as known_broken. I'm hoping an +elisp/encodings expert out there will pick this up. + + emacs/notmuch-mua.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ + 1 files changed, 62 insertions(+), 0 deletions(-) + +diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +index 023645e..750e8d6 100644 +--- a/emacs/notmuch-mua.el ++++ b/emacs/notmuch-mua.el +@@ -24,6 +24,10 @@ + (require 'notmuch-lib) + (require 'notmuch-address) + ++(require 'rfc2368) ++(require 'rfc2047) ++(require 'mailheader) ++ + ;; + + (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook) +@@ -131,6 +135,64 @@ list." + + (message-goto-to)) + ++(defun notmuch-mua-mailto (mailto) ++ "Invoke the notmuch mail composition window for a `mailto:' URI." ++ ;; this should implement implement rfc6068: http://tools.ietf.org/html/rfc6068 ++ ;; which obsoleted: http://tools.ietf.org/html/rfc2368 ++ ;; this function is based on previous work: http://www.emacswiki.org/emacs/MailtoHandler ++ (interactive) ++ (when (and (stringp mailto) ++ (string-match "\\`mailto:" mailto)) ++ (let* ( ++ ;; FIXME: need to decode all html encodings in uri. ++ (mailto (replace-regexp-in-string "&" "&" mailto)) ++ (hdr-alist (rfc2368-parse-mailto-url mailto)) ++ to subject other-headers body ++ (allowed-xtra-hdrs '(cc bcc in-reply-to))) ++ ++ (with-temp-buffer ++ ;; extract body if it's defined ++ (when (assoc "Body" hdr-alist) ++ (dolist (hdr hdr-alist) ++ (when (equal "Body" (car hdr)) ++ (insert (format "%s\n" (cdr hdr))))) ++ (rfc2047-decode-region (point-min) (point-max)) ++ (setq body (buffer-substring-no-properties ++ (point-min) (point-max))) ++ (erase-buffer)) ++ ++ ;; extract headers ++ (dolist (hdr hdr-alist) ++ (unless (equal "Body" (car hdr)) ++ (insert (format "%s: %s\n" (car hdr) (cdr hdr))))) ++ (rfc2047-decode-region (point-min) (point-max)) ++ (goto-char (point-min)) ++ (setq hdr-alist (mail-header-extract-no-properties))) ++ ++ (setq to (cdr (assoc 'to hdr-alist))) ++ (setq subject (cdr (assoc 'subject hdr-alist))) ++ ++ ;; extract allowed other headers, taking only first defined ++ ;; value ++ (dolist (hdr hdr-alist) ++ (if (and (member (car hdr) allowed-xtra-hdrs) ++ (not (assoc (car hdr) other-headers))) ++ (add-to-list 'other-headers hdr))) ++ ++ (notmuch-mua-mail to subject other-headers) ++ ++ ;; insert the message body - but put it in front of the signature ++ ;; if one is present ++ (goto-char (point-max)) ++ (if (re-search-backward message-signature-separator nil t) ++ (forward-line -1) ++ (goto-char (point-max))) ++ (insert body) ++ (push-mark)) ++ (set-buffer-modified-p nil) ++ ++ (message-goto-body))) ++ + (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args) + "Invoke the notmuch mail composition window. + +-- +1.7.8.3 + -- 2.26.2