(defun org-mml-htmlize (arg)
  "Export a portion of an email body composed using `mml-mode' to
html using `org-mode'.  If called with an active region only
export that region, otherwise export the entire body."
  (interactive "P")
  (let* ((region-p (org-region-active-p))
         (html-start (or (and region-p (region-beginning))
                         (save-excursion
                           (goto-char (point-min))
                           (search-forward mail-header-separator)
                           (point))))
         (html-end (or (and region-p (region-end))
                       ;; TODO: should catch signature...
                       (point-max)))
         (body (buffer-substring html-start html-end))
         (tmp-file (make-temp-name (expand-file-name "mail" "/tmp/")))
         ;; because we probably don't want to skip part of our mail
         (org-export-skip-text-before-1st-heading nil)
         ;; because we probably don't want to export a huge style file
         (org-export-htmlize-output-type 'inline-css)
         ;; makes the replies with ">"s look nicer
         (org-export-preserve-breaks t)
         (html (if arg
                   (format "<pre style=\"font-family: courier, monospace;\">\n%s</pre>\n" body)
                 (save-excursion
                   (with-temp-buffer
                     (insert body)
                     (write-file tmp-file)
                     ;; convert to html -- mimicing `org-run-like-in-org-mode'
                     (eval (list 'let org-local-vars
                                 (list 'org-export-as-html nil nil nil ''string t))))))))
    (delete-region html-start html-end)
    (save-excursion
      (goto-char html-start)
      (insert
       (format
        "\n<#multipart type=alternative>\n<#part type=text/html>%s<#/multipart>\n"
        html)))))