Skip to content

Instantly share code, notes, and snippets.

@jcowgar
Created December 28, 2019 13:41
Show Gist options
  • Save jcowgar/1b25eff411a1d3884f6c9ceacb189414 to your computer and use it in GitHub Desktop.
Save jcowgar/1b25eff411a1d3884f6c9ceacb189414 to your computer and use it in GitHub Desktop.
(require 'org-mime)
(defvar jc/outlook-citation-line-separator "-----------------------")
(defun jc/outlook-citation-line-function ()
(interactive)
(let* ((subject-start-point (save-excursion
(message-goto-subject)
(beginning-of-line)
(search-forward "Subject: ")
(point)))
(subject-end-point (save-excursion
(message-goto-subject)
(end-of-line)
(point)))
(subject-header (buffer-substring subject-start-point subject-end-point))
(subject (replace-regexp-in-string "Re: " "" subject-header)))
(insert "\n" jc/outlook-citation-line-separator "\n")
(insert "*From*: " (mail-header-from message-reply-headers) "\n")
(insert "*Sent*: " (mail-header-date message-reply-headers) "\n")
(insert "*Subject*: " subject "\n")
(insert "\n")
))
(defun jc/outlook-message-get-quote ()
(save-excursion
(goto-char (point-min))
(if (search-forward jc/outlook-citation-line-separator nil t)
(progn
(beginning-of-line)
(buffer-substring (point) (point-max)))
"")))
(defun jc/outlook-message-send-hook ()
(interactive)
(let* ((message-start-point (save-excursion
(goto-char (point-min))
(search-forward mail-header-separator)
(+ (point) 1)))
(message-end-point (save-excursion
(goto-char (point-min))
(if (search-forward jc/outlook-citation-line-separator nil t)
(progn
(beginning-of-line)
(- (point) 1))
(point-max))))
(plain-body (buffer-substring message-start-point message-end-point))
(plain-quote (jc/outlook-message-get-quote))
(plain-signature (jc/read-file-to-string "~/.signature-amps.txt"))
(html-body (org-mime-export-string plain-body))
(html-signature (jc/read-file-to-string "~/.signature-amps.html"))
(plain-quote-eols (replace-regexp-in-string "$" "\\\\\\\\" plain-quote))
(html-quote (replace-regexp-in-string jc/outlook-citation-line-separator "<hr>"
(org-mime-export-string plain-quote-eols)))
(encoded (concat "<#multipart type=alternative>\n"
"<#part type=text/plain>"
plain-body "\n\n"
"--\n"
plain-signature "\n"
plain-quote "\n"
"<#part type=text/html>"
html-body "\n"
html-signature "\n"
html-quote "\n"
"<#/multipart>\n")))
(delete-region message-start-point (point-max))
(insert encoded)))
(defun jc/mimic-outlook-send-and-reply ()
(interactive)
(add-hook 'notmuch-mua-send-hook #'jc/outlook-message-send-hook)
(setq message-citation-line-function 'jc/outlook-citation-line-function
message-cite-function 'message-site-original
message-cite-reply-position 'above
message-yank-prefix ""
message-yank-cited-prefix ""
message-yank-empty-prefix ""))
(defun jc/reset-send-and-reply ()
(interactive)
(remove-hook 'notmuch-mua-send-hook #'jc/outlook-message-send-hook)
(setq message-citation-line-function #'message-insert-formatted-citation-line
message-citation-line-format "%f writes:"
message-cite-function 'message-site-original
message-cite-reply-position 'traditional
message-yank-prefix "> "
message-yank-cited-prefix "> "
message-yank-empty-prefix "> "))
(provide 'jc-send-and-reply-formats)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment