From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: using orgmode to send html mail? Date: Tue, 23 Mar 2010 13:54:39 -0600 Message-ID: <871vfa24qo.fsf@gmail.com> References: <878w9krtyn.wl%dmaus@ictsoc.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NuABc-0004y6-NS for emacs-orgmode@gnu.org; Tue, 23 Mar 2010 15:54:48 -0400 Received: from [140.186.70.92] (port=36598 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuABa-0004xd-Ht for emacs-orgmode@gnu.org; Tue, 23 Mar 2010 15:54:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuABY-0007dp-RT for emacs-orgmode@gnu.org; Tue, 23 Mar 2010 15:54:46 -0400 Received: from mail-pv0-f169.google.com ([74.125.83.169]:55259) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuABY-0007da-25 for emacs-orgmode@gnu.org; Tue, 23 Mar 2010 15:54:44 -0400 Received: by pvg2 with SMTP id 2so4192184pvg.0 for ; Tue, 23 Mar 2010 12:54:42 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: David Maus Cc: emacs-orgmode@gnu.org --=-=-= Nice to see this topic has come back to life. I've been playing with my old org-html-mail.el file, and come up with a much simpler solution, which takes advantage of the mml message mode functionality with is used in gnus (and I would imagine in some other Emacs mail clients, but I can't be sure). Just call this function and either the active region of your message buffer or the entire body (if no region is active) will be exported to html using org-mode, and will be wrapped in the appropriate mml wrapper to be sent as the appropriate mime type. So for example this | 1 | 2 | 3 | |--------------+--------+-------| | first column | second | third | will be exported as this --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/html
123
first columnsecondthird
--==-=-=-- --=-=-= The function is provided in the attached file. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-mml-htmlize.el Content-Transfer-Encoding: quoted-printable ;; Eric Schulte ;; 2010-03-23 ;; ;; WYSWYG, html mail composition using org-mode ;; ;; For mail composed using the orgstruct-mode minor mode, this ;; provides a function for converting all or part of your mail buffer ;; to embedded html as exported by org-mode. Call `org-mml-htmlize' ;; in a message buffer to convert either the active region or the ;; entire buffer to html. ;; (defun org-mml-htmlize (arg) (interactive "P") ;; later just do
 wrap if prefix arg
  (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)
         ;; makes the replies with ">"s look nicer
         (org-export-preserve-breaks t)
         (html (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 ''stri=
ng t)))))))
    (delete-region html-start html-end)
    (save-excursion
      (goto-char html-start)
      (insert
       (format
        "\n<#multipart type=3Dalternative>\n<#part type=3Dtext/html>%s<#/mu=
ltipart>\n"
        html)))))

--=-=-=


Best -- Eric

David Maus  writes:

> Matt Price wrote:
>>Hi,
>
>>I just wondered whether anyone composes mail in orgmode & then
>>generates html from the source code.  I'd like to be able to do that
>>sometimes in wanderlust, e.g. when I'm responding to html mail with
>>links in it.
>
> Just pushed to hacks to Worg on how to send html messages in
> Wanderlust using Org's html exporter and how to attach html markup of
> a region or subtree in Wanderlust.  Latter is a follow-up on
>
> http://lists.gnu.org/archive/html/emacs-orgmode/2009-11/msg00746.html
>
> Until Worg picks it up:
>
> 1 Send html messages and attachments with Wanderlust
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   -- David Maus
>
> These two hacks below add the capability of using Org to send out html
> via email.  Both focus on Wanderlust but could be easily adopted for
> Gnus, I think.
>
> 1.1 Send HTML message
> ======================
>
> Putting the code below in your .emacs adds following four functions:
>
>    - dmj/wl-send-html-message
>
>      Function that does the job: Convert everything between "--text
>      follows this line--" and first mime entity (read: attachment) or
>      end of buffer into HTML markup using `org-export-region-as-html'
>      and replaces original body with a mime entity of text/html,
>      content-disposition: inline.  Line breaks of the signature are
>      preserved.
>
>      Cannot be called interactively: It is hooked into SEMI's
>      `mime-edit-translate-hook' if message should be HTML message.
>
>    - dmj/wl-send-html-message-draft-init
>
>      Cannot be called interactively: It is hooked into WL's
>      `wl-mail-setup-hook' and `wl-draft-reedit-hook' and provides a
>      buffer local variable to toggle.
>
>    - dmj/wl-send-html-message-draft-maybe
>
>      Cannot be called interactively: It is hooked into WL's
>      `wl-draft-send-hook' and hooks `dmj/wl-send-html-message' into
>      `mime-edit-translate-hook' depending on whether HTML message is
>      toggled on or off
>
>    - dmj/wl-send-html-message-toggle
>
>      Toggles sending of HTML message.  If toggled on, the letters
>      "HTML" appear in the mode line.
>
>      Call it interactively!  Or bind it to a key in `wl-draft-mode'.
>
> If you have to send HTML messages regularly you can set a global
> variable `dmj/wl-send-html-message-toggled-p' to the string "HTML" to
> toggle on sending HTML message by default.
>
> The image [here] shows an example of how the HTML message looks like in
> Google's web front end.  As you can see you have the whole markup of
> Org at your service: *bold*, /italics/, tables, lists...
>
> So even if you feel uncomfortable with sending HTML messages at least
> you send HTML that looks quite good.
>
>
>   (defun dmj/wl-send-html-message ()
>     "Send message as html message.
>     Convert body of message to html using
>     `org-export-region-as-html'."
>     (require 'org)
>     (save-excursion
>       (let (beg end html text)
>         (goto-char (point-min))
>         (re-search-forward "^--text follows this line--$")
>         ;; move to beginning of next line
>         (beginning-of-line 2)
>         (setq beg (point))
>         (if (not (re-search-forward "^--\\[\\[" nil t))
>             (setq end (point-max))
>           ;; line up
>           (end-of-line 0)
>           (setq end (point)))
>         ;; grab body
>         (setq text (buffer-substring-no-properties beg end))
>         ;; convert to html
>         (with-temp-buffer
>           (org-mode)
>           (insert text)
>           ;; handle signature
>           (when (re-search-backward "^-- \n" nil t)
>             ;; preserve link breaks in signature
>             (insert "\n#+BEGIN_VERSE\n")
>             (goto-char (point-max))
>             (insert "\n#+END_VERSE\n")
>             ;; grab html
>             (setq html (org-export-region-as-html
>                         (point-min) (point-max) t 'string))))
>         (delete-region beg end)
>         (insert
>          (concat
>           "--[text/html\nContent-Disposition: inline]\n"
>           html)))))
>
>   (defun dmj/wl-send-html-message-toggle ()
>     "Toggle sending of html message."
>     (interactive)
>     (setq dmj/wl-send-html-message-toggled-p
>           (if dmj/wl-send-html-message-toggled-p
>               nil "HTML"))
>     (message "Sending html message toggled %s"
>              (if dmj/wl-send-html-message-toggled-p
>                  "on" "off")))
>
>     (defun dmj/wl-send-html-message-draft-init ()
>       "Create buffer local settings for maybe sending html message."
>       (unless (boundp 'dmj/wl-send-html-message-toggled-p)
>         (setq dmj/wl-send-html-message-toggled-p nil))
>       (make-variable-buffer-local 'dmj/wl-send-html-message-toggled-p)
>       (add-to-list 'global-mode-string
>                    '(:eval (if (eq major-mode 'wl-draft-mode)
>                                dmj/wl-send-html-message-toggled-p))))
>
>     (defun dmj/wl-send-html-message-maybe ()
>       "Maybe send this message as html message.
>
>     If buffer local variable `dmj/wl-send-html-message-toggled-p' is
>     non-nil, add `dmj/wl-send-html-message' to
>     `mime-edit-translate-hook'."
>       (if dmj/wl-send-html-message-toggled-p
>           (add-hook 'mime-edit-translate-hook 'dmj/wl-send-html-message)
>         (remove-hook 'mime-edit-translate-hook 'dmj/wl-send-html-message)))
>
>   (add-hook 'wl-draft-reedit-hook 'dmj/wl-send-html-message-draft-init)
>   (add-hook 'wl-mail-setup-hook 'dmj/wl-send-html-message-draft-init)
>   (add-hook 'wl-draft-send-hook 'dmj/wl-send-html-message-maybe)
>
>
>
>   [here]: http://s11.directupload.net/file/u/15851/48ru5wl3.png
>
> 1.2 Attach HTML of region or subtree
> =====================================
>
> Instead of sending a complete HTML message you might only send parts
> of an Org file as HTML for the poor souls who are plagued with
> non-proportional fonts in their mail program that messes up pretty
> ASCII tables.
>
> This short function does the trick: It exports region or subtree to
> HTML, prefixes it with a MIME entity delimiter and pushes to killring
> and clipboard.  If a region is active, it uses the region, the
> complete subtree otherwise.
>
>
>   (defun dmj/org-export-region-as-html-attachment (beg end arg)
>     "Export region between BEG and END as html attachment.
>   If BEG and END are not set, use current subtree.  Region or
>   subtree is exported to html without header and footer, prefixed
>   with a mime entity string and pushed to clipboard and killring.
>   When called with prefix, mime entity is not marked as
>   attachment."
>     (interactive "r\nP")
>     (save-excursion
>       (let* ((beg (if (region-active-p) (region-beginning)
>                     (progn
>                       (org-back-to-heading)
>                       (point))))
>              (end (if (region-active-p) (region-end)
>                     (progn
>                       (org-end-of-subtree)
>                       (point))))
>              (html (concat "--" "[[text/html"
>                            (if arg "" "\nContent-Disposition: attachment")
>                            "]]\n"
>                            (org-export-region-as-html beg end t 'string))))
>         (when (fboundp 'x-set-selection)
>           (ignore-errors (x-set-selection 'PRIMARY html))
>           (ignore-errors (x-set-selection 'CLIPBOARD html)))
>         (message "html export done, pushed to kill ring and clipboard"))))
>
> 1.3 Adopting for Gnus
> ======================
>
> The whole magic lies in the special strings that mark a HTML
> attachment.  So you might just have to find out what these special
> strings are in message-mode and modify the functions accordingly.
> --
> OpenPGP... 0x99ADB83B5A4478E6
> Jabber.... dmjena@jabber.org
> Email..... dmaus@ictsoc.de
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

--=-=-=--