[PATCH v3 2/2] notmuch-show.el: handle the case where icalendar-import-buffer returns nil
authorTomi Ollila <tomi.ollila@iki.fi>
Thu, 8 Nov 2012 12:08:00 +0000 (14:08 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:26 +0000 (09:50 -0800)
7e/0ac3ae26f5e32d6c326e995d2287823fb6a740 [new file with mode: 0644]

diff --git a/7e/0ac3ae26f5e32d6c326e995d2287823fb6a740 b/7e/0ac3ae26f5e32d6c326e995d2287823fb6a740
new file mode 100644 (file)
index 0000000..49c4927
--- /dev/null
@@ -0,0 +1,86 @@
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 01B2E431FAE\r
+       for <notmuch@notmuchmail.org>; Thu,  8 Nov 2012 04:08:04 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id KyBRWWrGP8oe for <notmuch@notmuchmail.org>;\r
+       Thu,  8 Nov 2012 04:08:03 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 785D2431FBC\r
+       for <notmuch@notmuchmail.org>; Thu,  8 Nov 2012 04:08:02 -0800 (PST)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+       id 3784F1000C9; Thu,  8 Nov 2012 14:08:03 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 2/2] notmuch-show.el: handle the case where\r
+       icalendar-import-buffer returns nil\r
+Date: Thu,  8 Nov 2012 14:08:00 +0200\r
+Message-Id: <1352376480-29961-3-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.8.0\r
+In-Reply-To: <1352376480-29961-1-git-send-email-tomi.ollila@iki.fi>\r
+References: <1352376480-29961-1-git-send-email-tomi.ollila@iki.fi>\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 08 Nov 2012 12:08:04 -0000\r
+\r
+icalendar-import-buffer can fail by an error signal (which have been\r
+witnessed) but according to its docstring it can also return nil\r
+when failing (it returns t when succeeding).\r
+\r
+Now that the error is caught by the caller of notmuch-show-inset-part-*\r
+functions in case icalendar-import-buffer returns nil an explicit\r
+error is signaled and unwind-protect takes care of deleting the\r
+temporary file (just in case, it is usually not written to the fs yet).\r
+---\r
+ emacs/notmuch-show.el | 15 +++++++++------\r
+ 1 file changed, 9 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index e3977cc..9fb85c5 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -754,12 +754,15 @@ message at DEPTH in the current thread."\r
+             (replace-match "\n" nil nil))\r
+           (let ((file (make-temp-file "notmuch-ical"))\r
+                 result)\r
+-            (icalendar-import-buffer file t)\r
+-            (set-buffer (get-file-buffer file))\r
+-            (setq result (buffer-substring (point-min) (point-max)))\r
+-            (set-buffer-modified-p nil)\r
+-            (kill-buffer (current-buffer))\r
+-            (delete-file file)\r
++            (unwind-protect\r
++                (progn\r
++                  (unless (icalendar-import-buffer file t)\r
++                    (error "Icalendar import error. See *icalendar-errors* for more information"))\r
++                  (set-buffer (get-file-buffer file))\r
++                  (setq result (buffer-substring (point-min) (point-max)))\r
++                  (set-buffer-modified-p nil)\r
++                  (kill-buffer (current-buffer)))\r
++              (delete-file file))\r
+             result)))\r
+   t)\r
+ \r
+-- \r
+1.8.0\r
+\r