]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-wash.el
test: Add --format=json testing to the "notmuch search --format" tests.
[notmuch] / emacs / notmuch-wash.el
index 57f0cc5cbe4781a14b7897ea475b7bab884fd6ea..cfcfb21c01d4982ad2482ea3133708cfd6af40b2 100644 (file)
@@ -23,6 +23,8 @@
 
 (require 'coolj)
 
+(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth))
+
 ;;
 
 (defvar notmuch-wash-signature-regexp
@@ -143,7 +145,7 @@ is what to put on the button."
           (re-search-forward notmuch-wash-signature-regexp nil t))
       (let* ((sig-start (match-beginning 0))
             (sig-end (match-end 0))
-            (sig-lines (1- (count-lines sig-start (point-max)))))
+            (sig-lines (count-lines sig-start (point-max))))
        (if (<= sig-lines notmuch-wash-signature-lines-max)
            (let ((sig-start-marker (make-marker))
                  (sig-end-marker (make-marker)))
@@ -212,7 +214,17 @@ Perform four transformations on the message body:
   ;; text.
   (goto-char (point-min))
   (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
-    (replace-match "\\2")))
+    (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")))
 
 ;;
 
@@ -231,4 +243,40 @@ When doing so, maintaining citation leaders in the wrapped text."
 
 ;;
 
+(require 'diff-mode)
+
+(defvar diff-file-header-re) ; From `diff-mode.el'.
+
+(defun notmuch-wash-convert-inline-patch-to-part (depth)
+  "Convert an inline patch into a fake 'text/x-diff' attachment.
+
+Given that this function guesses whether a buffer includes a
+patch and then guesses the extent of the patch, there is scope
+for error."
+
+  (goto-char (point-min))
+  (if (re-search-forward diff-file-header-re nil t)
+      (progn
+       (beginning-of-line -1)
+       (let ((patch-start (point))
+             (patch-end (point-max))
+             part)
+         (goto-char patch-start)
+         (if (or
+              ;; Patch ends with signature.
+              (re-search-forward notmuch-wash-signature-regexp nil t)
+              ;; Patch ends with bugtraq comment.
+              (re-search-forward "^\\*\\*\\* " nil t))
+             (setq patch-end (match-beginning 0)))
+         (save-restriction
+           (narrow-to-region patch-start patch-end)
+           (setq part (plist-put part :content-type "text/x-diff"))
+           (setq part (plist-put part :content (buffer-string)))
+           (setq part (plist-put part :id -1))
+           (setq part (plist-put part :filename "inline patch"))
+           (delete-region (point-min) (point-max))
+           (notmuch-show-insert-bodypart nil part depth))))))
+
+;;
+
 (provide 'notmuch-wash)