4 (defun attachment-check-test (&optional fn)
5 "Test `notmuch-mua-attachment-check' using a message where optional FN is evaluated.
7 Return `t' if the message would be sent, otherwise `nil'"
14 ;; Force `y-or-n-p' to always return `nil', as if the user
16 (cl-letf (((symbol-function 'y-or-n-p)
17 (lambda (&rest args) nil)))
18 (notmuch-mua-attachment-check)
21 (set-buffer-modified-p nil)
22 (kill-buffer (current-buffer))))
24 (defvar attachment-check-tests
26 ;; These are all okay:
28 (t . (lambda () (insert "Nothing is a-tt-a-ch-ed!\n")))
30 (insert "Here is an attachment:\n")
31 (insert "<#part filename=\"foo\" />\n")))
32 (t . (lambda () (insert "<#part filename=\"foo\" />\n")))
34 ;; "attachment" is only mentioned in a quoted section.
35 (insert "> I sent you an attachment!\n")
36 ;; Code in `notmuch-mua-attachment-check' avoids matching on
37 ;; "attachment" in a quoted section of the message by looking at
38 ;; fontification properties. For fontification to happen we need to
39 ;; allow some time for redisplay.
42 ;; "attach" is only mentioned in a forwarded message.
44 (insert "<#mml type=message/rfc822 disposition=inline>\n")
45 (insert "X-Has-Attach:\n")
46 (insert "<#/mml>\n")))
48 ;; These should not be okay:
49 (nil . (lambda () (insert "Here is an attachment:\n")))
51 ;; "attachment" is mentioned in both a quoted section and
53 (insert "> I sent you an attachment!\n")
54 (insert "The attachment was missing!\n")
55 ;; Code in `notmuch-mua-attachment-check' avoids matching
56 ;; on "attachment" in a quoted section of the message by
57 ;; looking at fontification properties. For fontification
58 ;; to happen we need to allow some time for redisplay.
61 ;; "attachment" is mentioned before a forwarded message.
62 (insert "I also attach something.\n")
63 (insert "<#mml type=message/rfc822 disposition=inline>\n")
64 (insert "X-Has-Attach:\n")
65 (insert "<#/mml>\n")))
68 (defun notmuch-test-attachment-warning-1 ()
69 (let (output expected)
70 (dolist (test attachment-check-tests)
71 (let* ((expect (car test))
73 (result (attachment-check-test body)))
74 (push expect expected)
75 (push (if (eq result expect)
77 ;; In the case of a failure, include the test
78 ;; details to make it simpler to debug.
79 (format "%S <-- %S" result body))
81 (notmuch-test-expect-equal output expected)))