- (dolist (spec notmuch-pick-result-format)
- (notmuch-pick-insert-field (car spec) (cdr spec) msg))
- (notmuch-pick-set-message-properties msg)
- (insert "\n"))
+ ;; We need to save the previous subject as it will get overwritten
+ ;; by the insert-field calls.
+ (let ((previous-subject notmuch-pick-previous-subject))
+ (dolist (spec notmuch-pick-result-format)
+ (notmuch-pick-insert-field (car spec) (cdr spec) msg))
+ (notmuch-pick-set-message-properties msg)
+ (notmuch-pick-set-prop :previous-subject previous-subject)
+ (insert "\n")))
+
+(defun notmuch-pick-goto-and-insert-msg (msg)
+ "Insert msg at the end of the buffer. Move point to msg if it is the target"
+ (save-excursion
+ (goto-char (point-max))
+ (notmuch-pick-insert-msg msg))
+ (let ((msg-id (notmuch-id-to-query (plist-get msg :id)))
+ (target notmuch-pick-target-msg))
+ (when (or (and (not target) (plist-get msg :match))
+ (string= msg-id target))
+ (setq notmuch-pick-target-msg "found")
+ (goto-char (point-max))
+ (forward-line -1)
+ (when notmuch-pick-open-target
+ (notmuch-pick-show-message)))))