Advertisement
peteresalazar

Untitled

Jun 28th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 2.08 KB | None | 0 0
  1. (defun org-mime-htmlize (&optional arg)
  2. "Export a portion of an email body composed using `mml-mode' to
  3. html using `org-mode'.  If called with an active region only
  4. export that region, otherwise export the entire body."
  5.   (interactive "P")
  6.   (require 'ox-org)
  7.   (require 'ox-html)
  8.   (let* ((region-p (org-region-active-p))
  9.          (html-start (or (and region-p (region-beginning))
  10.                          (save-excursion
  11.                            (goto-char (point-min))
  12.                            (search-forward mail-header-separator)
  13.                            (+ (point) 1))))
  14.          (html-end (or (and region-p (region-end))
  15.                        ;; TODO: should catch signature...
  16.                        (point-max)))
  17.          (raw-body (concat org-mime-default-header
  18.                (buffer-substring html-start html-end)))
  19.          (tmp-file (make-temp-name (expand-file-name
  20.                     "mail" temporary-file-directory)))
  21.          (body (org-export-string-as raw-body 'org t))
  22.          ;; because we probably don't want to export a huge style file
  23.          (org-export-htmlize-output-type 'inline-css)
  24.          ;; makes the replies with ">"s look nicer
  25.          (org-export-preserve-breaks org-mime-preserve-breaks)
  26.      ;; dvipng for inline latex because MathJax doesn't work in mail
  27.      (org-html-with-latex 'dvipng)
  28.          ;; to hold attachments for inline html images
  29.          (html-and-images
  30.           (org-mime-replace-images
  31.        (org-export-string-as raw-body 'html t) tmp-file))
  32.          (html-images (unless arg (cdr html-and-images)))
  33.          (html (org-mime-apply-html-hook
  34.                 (if arg
  35.                     (format org-mime-fixedwith-wrap body)
  36.                   (car html-and-images)))))
  37.     (delete-region html-start html-end)
  38.     (save-excursion
  39.       (goto-char html-start)
  40.       (insert (org-mime-multipart
  41.            body html (mapconcat 'identity html-images "\n"))))))
  42.  
  43. (defun mime-send-mail ()
  44.       "org-mime-subtree and HTMLize"
  45.       (interactive)
  46. (org-mark-subtree)
  47.       (org-mime-subtree)
  48. (insert "\nBest,\nS.\n")
  49.       (org-mime-htmlize)
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement