-(declare-function notmuch-save-attachments "notmuch" (mm-handle &optional queryp))
-
-(defvar notmuch-show-stash-map
- (let ((map (make-sparse-keymap)))
- (define-key map "c" 'notmuch-show-stash-cc)
- (define-key map "d" 'notmuch-show-stash-date)
- (define-key map "F" 'notmuch-show-stash-filename)
- (define-key map "f" 'notmuch-show-stash-from)
- (define-key map "i" 'notmuch-show-stash-message-id)
- (define-key map "s" 'notmuch-show-stash-subject)
- (define-key map "T" 'notmuch-show-stash-tags)
- (define-key map "t" 'notmuch-show-stash-to)
- map)
- "Submap for stash commands"
- )
-
-(fset 'notmuch-show-stash-map notmuch-show-stash-map)
-
-(defvar notmuch-show-mode-map
- (let ((map (make-sparse-keymap)))
- (define-key map "?" 'notmuch-help)
- (define-key map "q" 'kill-this-buffer)
- (define-key map (kbd "C-p") 'notmuch-show-previous-line)
- (define-key map (kbd "C-n") 'notmuch-show-next-line)
- (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
- (define-key map (kbd "TAB") 'notmuch-show-next-button)
- (define-key map "s" 'notmuch-search)
- (define-key map "m" 'message-mail)
- (define-key map "f" 'notmuch-show-forward-current)
- (define-key map "r" 'notmuch-show-reply)
- (define-key map "|" 'notmuch-show-pipe-message)
- (define-key map "w" 'notmuch-show-save-attachments)
- (define-key map "V" 'notmuch-show-view-raw-message)
- (define-key map "v" 'notmuch-show-view-all-mime-parts)
- (define-key map "c" 'notmuch-show-stash-map)
- (define-key map "b" 'notmuch-show-toggle-current-body)
- (define-key map "h" 'notmuch-show-toggle-current-header)
- (define-key map "-" 'notmuch-show-remove-tag)
- (define-key map "+" 'notmuch-show-add-tag)
- (define-key map "x" 'notmuch-show-archive-thread-then-exit)
- (define-key map "a" 'notmuch-show-archive-thread)
- (define-key map "P" 'notmuch-show-previous-message)
- (define-key map "N" 'notmuch-show-next-message)
- (define-key map "p" 'notmuch-show-previous-open-message)
- (define-key map "n" 'notmuch-show-next-open-message)
- (define-key map (kbd "DEL") 'notmuch-show-rewind)
- (define-key map " " 'notmuch-show-advance-and-archive)
- map)
- "Keymap for \"notmuch show\" buffers.")
-(fset 'notmuch-show-mode-map notmuch-show-mode-map)
-
-(defvar notmuch-show-signature-regexp "\\(-- ?\\|_+\\)$"
- "Pattern to match a line that separates content from signature.
-
-The regexp can (and should) include $ to match the end of the
-line, but should not include ^ to match the beginning of the
-line. This is because notmuch may have inserted additional space
-for indentation at the beginning of the line. But notmuch will
-move past the indentation when testing this pattern, (so that the
-pattern can still test against the entire line).")
-
-(defvar notmuch-show-signature-button-format
- "[ %d-line signature. Click/Enter to toggle visibility. ]"
- "String used to construct button text for hidden signatures
-
-Can use up to one integer format parameter, i.e. %d")
-
-(defvar notmuch-show-citation-button-format
- "[ %d more citation lines. Click/Enter to toggle visibility. ]"
- "String used to construct button text for hidden citations.
-
-Can use up to one integer format parameter, i.e. %d")
-
-(defvar notmuch-show-signature-lines-max 12
- "Maximum length of signature that will be hidden by default.")
-
-(defvar notmuch-show-citation-lines-prefix 3
- "Always show at least this many lines at the start of a citation.
-
-If there is one more line than the sum of
-`notmuch-show-citation-lines-prefix' and
-`notmuch-show-citation-lines-suffix', show that, otherwise
-collapse remaining lines into a button.")
-
-(defvar notmuch-show-citation-lines-suffix 3
- "Always show at least this many lines at the end of a citation.
-
-If there is one more line than the sum of
-`notmuch-show-citation-lines-prefix' and
-`notmuch-show-citation-lines-suffix', show that, otherwise
-collapse remaining lines into a button.")
-
-(defvar notmuch-show-message-begin-regexp "\fmessage{")
-(defvar notmuch-show-message-end-regexp "\fmessage}")
-(defvar notmuch-show-header-begin-regexp "\fheader{")
-(defvar notmuch-show-header-end-regexp "\fheader}")
-(defvar notmuch-show-body-begin-regexp "\fbody{")
-(defvar notmuch-show-body-end-regexp "\fbody}")
-(defvar notmuch-show-attachment-begin-regexp "\fattachment{")
-(defvar notmuch-show-attachment-end-regexp "\fattachment}")
-(defvar notmuch-show-part-begin-regexp "\fpart{")
-(defvar notmuch-show-part-end-regexp "\fpart}")
-(defvar notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
-
-(defvar notmuch-show-id-regexp "\\(id:[^ ]*\\)")
-(defvar notmuch-show-depth-match-regexp " depth:\\([0-9]*\\).*match:\\([01]\\) ")
-(defvar notmuch-show-filename-regexp "filename:\\(.*\\)$")
-(defvar notmuch-show-contentype-regexp "Content-type: \\(.*\\)")
-
-(defvar notmuch-show-tags-regexp "(\\([^)]*\\))$")
-
-(defvar notmuch-show-parent-buffer nil)
-(defvar notmuch-show-body-read-visible nil)
-(defvar notmuch-show-citations-visible nil)
-(defvar notmuch-show-signatures-visible nil)
-(defvar notmuch-show-headers-visible nil)
-
-(defun notmuch-show-next-line ()
- "Like builtin `next-line' but ensuring we end on a visible character.
-
-By advancing forward until reaching a visible character.
-
-Unlike builtin `next-line' this version accepts no arguments."
- (interactive)
- (set 'this-command 'next-line)
- (call-interactively 'next-line)
- (while (point-invisible-p)
- (forward-char)))
-
-(defun notmuch-show-previous-line ()
- "Like builtin `previous-line' but ensuring we end on a visible character.
-
-By advancing forward until reaching a visible character.
-
-Unlike builtin `previous-line' this version accepts no arguments."
- (interactive)
- (set 'this-command 'previous-line)
- (call-interactively 'previous-line)
- (while (point-invisible-p)
- (forward-char)))
-
-(defun notmuch-show-get-message-id ()
- (save-excursion
- (beginning-of-line)
- (if (not (looking-at notmuch-show-message-begin-regexp))
- (re-search-backward notmuch-show-message-begin-regexp))
- (re-search-forward notmuch-show-id-regexp)
- (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
-
-(defun notmuch-show-get-filename ()
- (save-excursion
- (beginning-of-line)
- (if (not (looking-at notmuch-show-message-begin-regexp))
- (re-search-backward notmuch-show-message-begin-regexp))
- (re-search-forward notmuch-show-filename-regexp)
- (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
-
-(defun notmuch-show-set-tags (tags)
- (save-excursion
- (beginning-of-line)
- (if (not (looking-at notmuch-show-message-begin-regexp))
- (re-search-backward notmuch-show-message-begin-regexp))
- (re-search-forward notmuch-show-tags-regexp)
- (let ((inhibit-read-only t)
- (beg (match-beginning 1))
- (end (match-end 1)))
- (delete-region beg end)
- (goto-char beg)
- (insert (mapconcat 'identity tags " ")))))
-
-(defun notmuch-show-get-tags ()
- (save-excursion
- (beginning-of-line)
- (if (not (looking-at notmuch-show-message-begin-regexp))
- (re-search-backward notmuch-show-message-begin-regexp))
- (re-search-forward notmuch-show-tags-regexp)
- (split-string (buffer-substring (match-beginning 1) (match-end 1)))))
-
-(defun notmuch-show-get-bcc ()
- "Return BCC address(es) of current message"
- (notmuch-show-get-header-field 'bcc))
-
-(defun notmuch-show-get-cc ()
- "Return CC address(es) of current message"
- (notmuch-show-get-header-field 'cc))
-
-(defun notmuch-show-get-date ()
- "Return Date of current message"
- (notmuch-show-get-header-field 'date))
-
-(defun notmuch-show-get-from ()
- "Return From address of current message"
- (notmuch-show-get-header-field 'from))
-
-(defun notmuch-show-get-subject ()
- "Return Subject of current message"
- (notmuch-show-get-header-field 'subject))
-
-(defun notmuch-show-get-to ()
- "Return To address(es) of current message"
- (notmuch-show-get-header-field 'to))
-
-(defun notmuch-show-get-header-field (name)
- "Retrieve the header field NAME from the current message.
-NAME should be a symbol, in lower case, as returned by
-mail-header-extract-no-properties"
- (let* ((result (assoc name (notmuch-show-get-header)))
- (val (and result (cdr result))))
- val))
-
-(defun notmuch-show-get-header ()
- "Retrieve and parse the header from the current message. Returns an alist with of (header . value)
-where header is a symbol and value is a string. The summary from notmuch-show is returned as the
-pseudoheader summary"
- (require 'mailheader)
- (save-excursion
- (beginning-of-line)
- (if (not (looking-at notmuch-show-message-begin-regexp))
- (re-search-backward notmuch-show-message-begin-regexp))
- (re-search-forward (concat notmuch-show-header-begin-regexp "\n[[:space:]]*\\(.*\\)\n"))
- (let* ((summary (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
- (beg (point)))
- (re-search-forward notmuch-show-header-end-regexp)
- (let ((text (buffer-substring beg (match-beginning 0))))
- (with-temp-buffer
- (insert text)
- (goto-char (point-min))
- (while (looking-at "\\([[:space:]]*\\)[A-Za-z][-A-Za-z0-9]*:")
- (delete-region (match-beginning 1) (match-end 1))
- (forward-line)
- )
- (goto-char (point-min))
- (cons (cons 'summary summary) (mail-header-extract-no-properties)))))))
-
-(defun notmuch-show-add-tag (&rest toadd)
- "Add a tag to the current message."
- (interactive
- (list (notmuch-select-tag-with-completion "Tag to add: ")))
- (apply 'notmuch-call-notmuch-process
- (append (cons "tag"
- (mapcar (lambda (s) (concat "+" s)) toadd))
- (cons (notmuch-show-get-message-id) nil)))
- (notmuch-show-set-tags (sort (union toadd (notmuch-show-get-tags) :test 'string=) 'string<)))