Re: crash during saving
[notmuch-archives.git] / 63 / c0cc3947212ba9682c3b6e24de13e27c781a65
1 Return-Path: <jrollins@finestructure.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C2E42429E3F\r
6         for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:51 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id qwJXBfCHQyFy for <notmuch@notmuchmail.org>;\r
16         Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
17 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
18         [131.215.239.19])\r
19         by olra.theworths.org (Postfix) with ESMTP id AC1D5431E64\r
20         for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
21 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
22         by earth-doxen-postvirus (Postfix) with ESMTP id 22BF766E013B\r
23         for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:47 -0800 (PST)\r
24 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
25 Received: from finestructure.net (cpe-76-174-137-84.socal.res.rr.com\r
26         [76.174.137.84]) (Authenticated sender: jrollins)\r
27         by earth-doxen-submit (Postfix) with ESMTP id C0D0366E00CF\r
28         for <notmuch@notmuchmail.org>; Sun, 29 Jan 2012 11:33:44 -0800 (PST)\r
29 Received: by finestructure.net (Postfix, from userid 1000)\r
30         id 3F46C159; Sun, 29 Jan 2012 11:33:44 -0800 (PST)\r
31 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
32 To: Notmuch Mail <notmuch@notmuchmail.org>\r
33 Subject: [PATCH 2/2] emacs: new mua mailto: URI handler\r
34 Date: Sun, 29 Jan 2012 11:33:44 -0800\r
35 Message-Id: <1327865624-7673-2-git-send-email-jrollins@finestructure.net>\r
36 X-Mailer: git-send-email 1.7.8.3\r
37 In-Reply-To: <1327865624-7673-1-git-send-email-jrollins@finestructure.net>\r
38 References: <1327865624-7673-1-git-send-email-jrollins@finestructure.net>\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Sun, 29 Jan 2012 19:33:52 -0000\r
52 \r
53 The new function 'notmuch-mua-mailto' provides an interactive handler\r
54 for rfc6068 "mailto:" URIs.  It attempts to implement the rfc6068\r
55 specification: http://tools.ietf.org/html/rfc6068\r
56 \r
57 More decoding of the mailto string needs to be done, as is evident by\r
58 the fact that the mailto test remains broken.\r
59 ---\r
60 Unfortunately I'm not sure how best to do the URI decoding, so I've\r
61 left a FIXME in the code, and the test as known_broken.  I'm hoping an\r
62 elisp/encodings expert out there will pick this up.\r
63 \r
64  emacs/notmuch-mua.el |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
65  1 files changed, 62 insertions(+), 0 deletions(-)\r
66 \r
67 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
68 index 023645e..750e8d6 100644\r
69 --- a/emacs/notmuch-mua.el\r
70 +++ b/emacs/notmuch-mua.el\r
71 @@ -24,6 +24,10 @@\r
72  (require 'notmuch-lib)\r
73  (require 'notmuch-address)\r
74  \r
75 +(require 'rfc2368)\r
76 +(require 'rfc2047)\r
77 +(require 'mailheader)\r
78 +\r
79  ;;\r
80  \r
81  (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)\r
82 @@ -131,6 +135,64 @@ list."\r
83  \r
84    (message-goto-to))\r
85  \r
86 +(defun notmuch-mua-mailto (mailto)\r
87 +  "Invoke the notmuch mail composition window for a `mailto:' URI."\r
88 +  ;; this should implement implement rfc6068: http://tools.ietf.org/html/rfc6068\r
89 +  ;; which obsoleted: http://tools.ietf.org/html/rfc2368\r
90 +  ;; this function is based on previous work: http://www.emacswiki.org/emacs/MailtoHandler\r
91 +  (interactive)\r
92 +  (when (and (stringp mailto)\r
93 +            (string-match "\\`mailto:" mailto))\r
94 +    (let* (\r
95 +          ;; FIXME: need to decode all html encodings in uri.\r
96 +          (mailto (replace-regexp-in-string "&amp;" "&" mailto))\r
97 +          (hdr-alist (rfc2368-parse-mailto-url mailto))\r
98 +          to subject other-headers body\r
99 +          (allowed-xtra-hdrs '(cc bcc in-reply-to)))\r
100 +\r
101 +      (with-temp-buffer\r
102 +       ;; extract body if it's defined\r
103 +       (when (assoc "Body" hdr-alist)\r
104 +         (dolist (hdr hdr-alist)\r
105 +           (when (equal "Body" (car hdr))\r
106 +             (insert (format "%s\n" (cdr hdr)))))\r
107 +         (rfc2047-decode-region (point-min) (point-max))\r
108 +         (setq body (buffer-substring-no-properties\r
109 +                     (point-min) (point-max)))\r
110 +         (erase-buffer))\r
111 +\r
112 +       ;; extract headers\r
113 +       (dolist (hdr hdr-alist)\r
114 +         (unless (equal "Body" (car hdr))\r
115 +           (insert (format "%s: %s\n" (car hdr) (cdr hdr)))))\r
116 +       (rfc2047-decode-region (point-min) (point-max))\r
117 +       (goto-char (point-min))\r
118 +       (setq hdr-alist (mail-header-extract-no-properties)))\r
119 +\r
120 +      (setq to (cdr (assoc 'to hdr-alist)))\r
121 +      (setq subject (cdr (assoc 'subject hdr-alist)))\r
122 +\r
123 +      ;; extract allowed other headers, taking only first defined\r
124 +      ;; value\r
125 +      (dolist (hdr hdr-alist)\r
126 +       (if (and (member (car hdr) allowed-xtra-hdrs)\r
127 +                (not (assoc (car hdr) other-headers)))\r
128 +           (add-to-list 'other-headers hdr)))\r
129 +\r
130 +      (notmuch-mua-mail to subject other-headers)\r
131 +\r
132 +      ;; insert the message body - but put it in front of the signature\r
133 +      ;; if one is present\r
134 +      (goto-char (point-max))\r
135 +      (if (re-search-backward message-signature-separator nil t)\r
136 +         (forward-line -1)\r
137 +       (goto-char (point-max)))\r
138 +      (insert body)\r
139 +      (push-mark))\r
140 +    (set-buffer-modified-p nil)\r
141 +\r
142 +    (message-goto-body)))\r
143 +\r
144  (defun notmuch-mua-mail (&optional to subject other-headers &rest other-args)\r
145    "Invoke the notmuch mail composition window.\r
146  \r
147 -- \r
148 1.7.8.3\r
149 \r