--- /dev/null
+#!/bin/bash
+
+test_description=Emacs\'\ forgetfulness
+
+. test-lib.sh
+
+# RFC822 imposes a 998 character limit per line.
+x=0123456789 # 10
+x=$x$x$x$x$x$x$x$x$x$x # 100
+x=$x$x$x$x$x$x$x$x$x # 900
+
+# If setting this ``too high'' (TODO: yet to be determined), Emacs will crash
+# with a segmentation fault.
+n=20
+for i in $(seq 1 $n); do
+ # Roughly 2 KiB per message. That is, we need two messages in order to
+ # exceed the typical size of the pipe buffer (4 KiB on commodity systems).
+ generate_message [subject]=$i-$x [from]=$i-$x@x.x
+done
+# With 20 messages à 2 KiB, we have about 10 full pipe buffers, which should be
+# enough to trigger the erroneous behavior.
+
+notmuch new > /dev/null
+
+test_begin_subtest 'Search for all messages'
+output=$(exec 2>&1; \
+ diff -wu \
+ <(notmuch search \* \
+ | sed \
+ -e 's%^thread:[0-9a-f]*\ %%' \
+ -e 's%;%%'; \
+ echo 'End of search results.'; \
+ echo) \
+ <(test_emacs 2>&1 \
+ '(notmuch-search "*") (notmuch-test-wait) (message (buffer-string))'))
+test_expect_equal "$output" ''
+
+test_done