--- /dev/null
+Return-Path: <self@antono.info>\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 07CE9431FD0\r
+ for <notmuch@notmuchmail.org>; Sun, 4 Sep 2011 21:14:50 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.363\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.363 tagged_above=-999 required=5\r
+ tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] 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 S7lbjL54rjSu for <notmuch@notmuchmail.org>;\r
+ Sun, 4 Sep 2011 21:14:49 -0700 (PDT)\r
+Received: from mail.antono.info (ec2-50-19-243-116.compute-1.amazonaws.com\r
+ [50.19.243.116])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 8807E431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 4 Sep 2011 21:14:49 -0700 (PDT)\r
+Received: by mail.antono.info (Postfix, from userid 1003)\r
+ id A543261477; Mon, 5 Sep 2011 04:15:19 +0000 (UTC)\r
+Received: from localhost.localdomain (unknown [178.121.201.33])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by mail.antono.info (Postfix) with ESMTPSA id 2DEE660381;\r
+ Mon, 5 Sep 2011 04:15:18 +0000 (UTC)\r
+From: Antono Vasiljev <self@antono.info>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Perform mail polling asynchronously\r
+Date: Mon, 5 Sep 2011 07:14:36 +0300\r
+Message-Id: <1315196076-9254-1-git-send-email-self@antono.info>\r
+X-Mailer: git-send-email 1.7.5.4\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: Mon, 05 Sep 2011 04:14:50 -0000\r
+\r
+ * reimplemented notmuch-poll(&optional callback) so that it\r
+ calls process asynchronously and run callback after process\r
+ finished\r
+ * changed usage of notmuch-poll in notmuch-hello-poll-and-update\r
+ and notmuch-search-poll-and-refresh-view\r
+---\r
+ emacs/notmuch-hello.el | 4 +---\r
+ emacs/notmuch.el | 33 +++++++++++++++++++++++++++------\r
+ 2 files changed, 28 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 65fde75..03739e5 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -304,9 +304,7 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
+ (defun notmuch-hello-poll-and-update ()\r
+ "Invoke `notmuch-poll' to import mail, then refresh the current view."\r
+ (interactive)\r
+- (notmuch-poll)\r
+- (notmuch-hello-update))\r
+-\r
++ (notmuch-poll 'notmuch-hello-update))\r
+ \r
+ (defvar notmuch-hello-mode-map\r
+ (let ((map (make-sparse-keymap)))\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index f11ec24..2c3f8a8 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -954,19 +954,40 @@ the user's needs:\r
+ :type 'string\r
+ :group 'notmuch)\r
+ \r
+-(defun notmuch-poll ()\r
+- "Run external script to import mail.\r
+ \r
+-Invokes `notmuch-poll-script' if it is not set to an empty string."\r
++(defun notmuch-poll (&optional poll-callback)\r
++ "Asyncronously run external script to import mail.\r
++\r
++Invokes `notmuch-poll-script' if it is not set to an empty string.\r
++After script finished `callback' will be called.\r
++"\r
+ (interactive)\r
+ (if (not (string= notmuch-poll-script ""))\r
+- (call-process notmuch-poll-script nil nil)))\r
++ (message "Notmuch: starting mail poll script")\r
++ (progn\r
++ (defun notmuch-poll-sentinel (processs event)\r
++ (if (string-match "^finished" event)\r
++ (progn\r
++ (message "Notmuch: poll finished")\r
++ (if (boundp 'poll-callback)\r
++ (poll-callback)))\r
++ (progn\r
++ ((message event)\r
++ (message "Notmuch: something gone wrong when polling mail...")))))\r
++ (set-process-sentinel\r
++ (start-process "notmuch-poll"\r
++ "*notmuch-poll*"\r
++ notmuch-poll-script)\r
++ 'notmuch-poll-sentinel)\r
++ (switch-to-buffer "*notmuch-poll*")\r
++ (comint-mode)\r
++ (switch-to-buffer (other-buffer -1)))))\r
++\r
+ \r
+ (defun notmuch-search-poll-and-refresh-view ()\r
+ "Invoke `notmuch-poll' to import mail, then refresh the current view."\r
+ (interactive)\r
+- (notmuch-poll)\r
+- (notmuch-search-refresh-view))\r
++ (notmuch-poll 'notmuch-search-refresh-view))\r
+ \r
+ (defun notmuch-search-toggle-order ()\r
+ "Toggle the current search order.\r
+-- \r
+1.7.5.4\r
+\r