+# Deliver a message with emacs and add it to the database
+#
+# Uses emacs to generate and deliver a message to the mail store.
+# Accepts arbitrary extra emacs/elisp functions to modify the message
+# before sending, which is useful to doing things like attaching files
+# to the message and encrypting/signing.
+emacs_deliver_message ()
+{
+ local subject="$1"
+ local body="$2"
+ shift 2
+ # before we can send a message, we have to prepare the FCC maildir
+ mkdir -p "$MAIL_DIR"/sent/{cur,new,tmp}
+ # eval'ing smtp-dummy --background will set smtp_dummy_pid
+ smtp_dummy_pid=
+ eval `$TEST_DIRECTORY/smtp-dummy --background sent_message`
+ test -n "$smtp_dummy_pid" || return 1
+
+ test_emacs \
+ "(let ((message-send-mail-function 'message-smtpmail-send-it)
+ (mail-host-address \"example.com\")
+ (smtpmail-smtp-server \"localhost\")
+ (smtpmail-smtp-service \"25025\"))
+ (notmuch-hello)
+ (notmuch-mua-mail)
+ (message-goto-to)
+ (insert \"test_suite@notmuchmail.org\nDate: 01 Jan 2000 12:00:00 -0000\")
+ (message-goto-subject)
+ (insert \"${subject}\")
+ (message-goto-body)
+ (insert \"${body}\")
+ $@
+ (message-send-and-exit))"
+
+ # In case message was sent properly, client waits for confirmation
+ # before exiting and resuming control here; therefore making sure
+ # that server exits by sending (KILL) signal to it is safe.
+ kill -9 $smtp_dummy_pid
+ notmuch new >/dev/null
+}
+