Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 5e / 25b41b612d0b5e4c87407ad5ec7b65a86fc35c
1 Return-Path: <tomi.ollila@iki.fi>\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 31584431FAF\r
6         for <notmuch@notmuchmail.org>; Wed,  3 Oct 2012 06:30:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 oIBhgL2VRcmM for <notmuch@notmuchmail.org>;\r
16         Wed,  3 Oct 2012 06:30:10 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id D4F89431FAE\r
19         for <notmuch@notmuchmail.org>; Wed,  3 Oct 2012 06:30:09 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 179C3100150;\r
22         Wed,  3 Oct 2012 16:30:13 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Aaron Ecay <aaronecay@gmail.com>, Robert Horn <rjhorn@alum.mit.edu>,\r
25         notmuch@notmuchmail.org\r
26 Subject: Re: bug related to ical\r
27 In-Reply-To: <87d319b899.fsf@gmail.com>\r
28 References: <m31ul3qo4w.fsf@quad.robs.office> <87d319b899.fsf@gmail.com>\r
29 User-Agent: Notmuch/0.14+51~g62cd13b (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Wed, 03 Oct 2012 16:30:12 +0300\r
35 Message-ID: <m2obkjlm3f.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain; charset=utf-8\r
38 Content-Transfer-Encoding: quoted-printable\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: Wed, 03 Oct 2012 13:30:11 -0000\r
52 \r
53 On Wed, Sep 26 2012, Aaron Ecay wrote:\r
54 \r
55 > The problem is in the =E2=80=98notmuch-show-insert-part-text/calendar=E2=\r
56 =80=99\r
57 > function.  The call to =E2=80=98icalendar--convert-ical-to-diary=E2=80=99=\r
58  does not\r
59 > create a buffer visiting the temp file, so the call to =E2=80=98set-buffe=\r
60 r=E2=80=99\r
61 > fails.  The following patch fixes the problem.\r
62 >\r
63 > The ical->diary conversion also doesn=E2=80=99t seem to work =E2=80=93 th=\r
64 e calendar\r
65 > attachment shows up as an empty part =E2=80=93 but I guess that=E2=80=99s=\r
66  a separate\r
67 > issue (and not addressed by the patch).\r
68 >\r
69 > I guess that part insertion handlers should be called inside a\r
70 > =E2=80=98condition-case=E2=80=99, so that an error inside of one can be r=\r
71 ecovered from,\r
72 > and doesn=E2=80=99t entirely derail the insertion of the messages in the =\r
73 buffer.\r
74 > (I actually made this patch because I was so annoyed that Olivier=E2=80=\r
75 =99s\r
76 > buggy test attachment made it impossible for me to read Tomi=E2=80=99s re=\r
77 ply.)\r
78 >\r
79 > ----- cut here -----\r
80 >\r
81 > diff --git i/emacs/notmuch-show.el w/emacs/notmuch-show.el\r
82 > index ce5ea6f..4c89d7e 100644\r
83 > --- i/emacs/notmuch-show.el\r
84 > +++ w/emacs/notmuch-show.el\r
85 > @@ -746,7 +746,7 @@ message at DEPTH in the current thread."\r
86 >             (icalendar--convert-ical-to-diary\r
87 >              (icalendar--read-element nil nil)\r
88 >              file t)\r
89 > -           (set-buffer (get-file-buffer file))\r
90 > +           (set-buffer (find-file-noselect file))\r
91 >             (setq result (buffer-substring (point-min) (point-max)))\r
92 >             (set-buffer-modified-p nil)\r
93 >             (kill-buffer (current-buffer))\r
94 >\r
95 > ----- cut here -----\r
96 \r
97 The problem seems to be carriage returns in the attachment -- which goes\r
98 unnotified when converting from octet-stream content.\r
99 \r
100 I've got the example in question to "work" with the following patch_\r
101 \r
102 --8<----8<----8<-- cut here  --8<----8<----8<--\r
103 \r
104 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
105 index 86130ce..f7c08ee 100644\r
106 --- a/emacs/notmuch-show.el\r
107 +++ b/emacs/notmuch-show.el\r
108 @@ -747,17 +747,21 @@ message at DEPTH in the current thread."\r
109    (notmuch-show-insert-part-header nth declared-type content-type (plist-g=\r
110 et part :filename))\r
111    (insert (with-temp-buffer\r
112             (insert (notmuch-get-bodypart-content msg part nth notmuch-show-proce=\r
113 ss-crypto))\r
114 -           (goto-char (point-min))\r
115             (let ((file (make-temp-file "notmuch-ical"))\r
116                   result)\r
117 +             (set-buffer (icalendar--get-unfolded-buffer (current-buffer)))\r
118 +             (beginning-of-buffer)\r
119 +             (replace-string "" "")\r
120 +             (beginning-of-buffer)\r
121               (icalendar--convert-ical-to-diary\r
122                (icalendar--read-element nil nil)\r
123                file t)\r
124 +             (kill-buffer (current-buffer))\r
125               (set-buffer (get-file-buffer file))\r
126               (setq result (buffer-substring (point-min) (point-max)))\r
127               (set-buffer-modified-p nil)\r
128               (kill-buffer (current-buffer))\r
129 -             (delete-file file)\r
130 +             ;;;(delete-file file)\r
131               result)))\r
132    t)\r
133 =20\r
134 --8<----8<----8<-- cut here  --8<----8<----8<--\r
135 \r
136 In our case the icalendar--get-unfolded-buffer doesn't seem\r
137 to do any conversions (the docstring mentions some LF/CR/BLANK\r
138 replacements) -- I just copied that line from icalendar-import-buffer\r
139 which I tried first.\r
140 \r
141 The interesting thing is that the notmuch-icalXXXXXX file is\r
142 still empty ... hmm, the buffer is just not saved (would /dev/null work ;))\r
143 \r
144 To do:\r
145 Check why icalendar--get-unfolded-buffer did not do what it advertised;\r
146 the code seems to support the replacements mentioned -- or maybe I failed ;/\r
147 \r
148 The problem with failing to icalendar--convert-ical-to-diary is that\r
149 the buffer is not created. The find-file-noselect shields about that\r
150 problem here but not elsewhere (and why that failure is so "fatal" ???)\r
151 Some shielding in higher level should be implemented (i.e. the\r
152 "condition-case" suggestion Aaron mentioned or something :)\r
153 \r
154 \r
155 self to remember:  M-x debug-on-entry and keys 'd', 'u' and 'c' in debugger=\r
156  :)\r
157 \r
158 Tomi\r
159 \r
160 >\r
161 > --=20\r
162 > Aaron Ecay\r
163 > _______________________________________________\r
164 > notmuch mailing list\r
165 > notmuch@notmuchmail.org\r
166 > http://notmuchmail.org/mailman/listinfo/notmuch\r