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 7FA0E40DDD5 for ; Fri, 12 Nov 2010 04:52:04 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham 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 RKfDMg-cH8Df for ; Fri, 12 Nov 2010 04:51:54 -0800 (PST) Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com [74.125.82.53]) by olra.theworths.org (Postfix) with ESMTP id CC07440DDCF for ; Fri, 12 Nov 2010 04:51:53 -0800 (PST) Received: by wwe15 with SMTP id 15so2321450wwe.34 for ; Fri, 12 Nov 2010 04:51:53 -0800 (PST) Received: by 10.216.24.206 with SMTP id x56mr2022490wex.2.1289566311213; Fri, 12 Nov 2010 04:51:51 -0800 (PST) Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com [81.149.164.25]) by mx.google.com with ESMTPS id y15sm2119092weq.6.2010.11.12.04.51.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Nov 2010 04:51:50 -0800 (PST) Received: by ut.hh.sledj.net (Postfix, from userid 1000) id 2C25959405B; Fri, 12 Nov 2010 12:50:05 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH] emacs: Avoid regexp overflow when tidying citations. Date: Fri, 12 Nov 2010 12:50:02 +0000 Message-Id: <1289566202-24148-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.2.3 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: Fri, 12 Nov 2010 12:52:04 -0000 Declare `notmuch-wash-tidy-citations-max', which is the largest region that `notmuch-wash-tidy-citations' will attempt to improve. --- emacs/notmuch-wash.el | 61 ++++++++++++++++++++++++++++--------------------- 1 files changed, 35 insertions(+), 26 deletions(-) diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index cfcfb21..a7ea5e9 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -187,6 +187,11 @@ is what to put on the button." ;; +(defcustom notmuch-wash-tidy-citations-max (* 10 1024) + "Maximum size of region to tidy." + :group 'notmuch + :type 'int) + (defun notmuch-wash-tidy-citations (depth) "Improve the display of cited regions of a message. @@ -199,32 +204,36 @@ Perform four transformations on the message body: - Remove citation trailers standing alone after a block of cited text." - ;; Remove lines of repeated citation leaders with no other content. - (goto-char (point-min)) - (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t) - (replace-match "\\1")) - - ;; Remove citation leaders standing alone before a block of cited - ;; text. - (goto-char (point-min)) - (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t) - (replace-match "\\1\n")) - - ;; Remove citation trailers standing alone after a block of cited - ;; text. - (goto-char (point-min)) - (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t) - (replace-match "\\2")) - - ;; Insert a blank line before a citation if there isn't one. - (goto-char (point-min)) - (while (re-search-forward "\\(^[^>]+\\)\n>" nil t) - (replace-match "\\1\n\n>")) - - ;; Insert a blank line after a citation if there isn't one. - (goto-char (point-min)) - (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t) - (replace-match "\\1\n\n\\2"))) + ;; If the message is long, don't bother. + (unless (> (- (point-max) (point-min)) + notmuch-wash-tidy-citations-max) + + ;; Remove lines of repeated citation leaders with no other content. + (goto-char (point-min)) + (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t) + (replace-match "\\1")) + + ;; Remove citation leaders standing alone before a block of cited + ;; text. + (goto-char (point-min)) + (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t) + (replace-match "\\1\n")) + + ;; Remove citation trailers standing alone after a block of cited + ;; text. + (goto-char (point-min)) + (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t) + (replace-match "\\2")) + + ;; Insert a blank line before a citation if there isn't one. + (goto-char (point-min)) + (while (re-search-forward "\\(^[^>]+\\)\n>" nil t) + (replace-match "\\1\n\n>")) + + ;; Insert a blank line after a citation if there isn't one. + (goto-char (point-min)) + (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t) + (replace-match "\\1\n\n\\2")))) ;; -- 1.7.2.3