emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: David Maus <dmaus@ictsoc.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: using orgmode to send html mail?
Date: Tue, 23 Mar 2010 13:54:39 -0600	[thread overview]
Message-ID: <871vfa24qo.fsf@gmail.com> (raw)
In-Reply-To: 878w9krtyn.wl%dmaus@ictsoc.de

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

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

[-- Attachment #2.1: Type: text/html, Size: 364 bytes --]

[-- Attachment #3: Type: text/plain, Size: 49 bytes --]


The function is provided in the attached file.


[-- Attachment #4: org-mml-htmlize.el --]
[-- Type: application/emacs-lisp, Size: 1871 bytes --]

[-- Attachment #5: Type: text/plain, Size: 8128 bytes --]


Best -- Eric

David Maus <dmaus@ictsoc.de> 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

[-- Attachment #6: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

  reply	other threads:[~2010-03-23 19:54 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-22  2:34 using orgmode to send html mail? Matt Price
2010-03-22 15:44 ` Matt Price
2010-03-22 20:18 ` David Maus
2010-03-23 19:54   ` Eric Schulte [this message]
2010-03-23 21:46     ` Xiao-Yong Jin
2010-03-24 15:00       ` Eric Schulte
2010-03-24 17:50         ` Dan Davison
2010-03-24 18:01           ` Eric Schulte
2010-03-24 19:12             ` David Maus
2010-03-24 20:19               ` Eric Schulte
2010-03-25 21:17                 ` David Maus
2010-03-26 14:53                   ` Eric Schulte
2010-03-26 16:04                     ` David Maus
2010-03-26 16:32                       ` Eric Schulte
2010-03-31 18:12                         ` [CONTRIB?] " Eric Schulte
2010-03-31 20:05                           ` Dan Davison
2010-03-31 21:10                             ` Eric Schulte
2010-03-31 21:37                               ` Dan Davison
2010-04-01 14:22                                 ` Eric Schulte
2010-04-05  5:39                                   ` Eric Schulte
2010-04-05  6:49                                     ` Carsten Dominik
2010-04-05 15:31                                       ` Eric Schulte
2010-04-09 16:41                                         ` [ANN] org-mime -- " Eric Schulte
2010-04-09 17:41                                           ` Matt Price
2010-04-09 19:11                                             ` Eric Schulte
2010-04-09 19:22                                             ` David Maus
2010-04-09 20:34                                               ` Eric Schulte
2010-04-12 13:37                                           ` Andrew Hyatt
2010-04-12 17:22                                             ` Eric Schulte
2010-04-13  1:31                                               ` Andrew Hyatt
2010-04-14  0:57                                                 ` Eric Schulte
2010-04-14  1:57                                                   ` Andrew Hyatt
2010-04-14 14:59                                                     ` Eric Schulte
2010-04-14 18:00                                                       ` Andrew Hyatt
2010-04-14 19:26                                                         ` Bernt Hansen
2010-04-14  8:39                                                   ` Eric S Fraga
2010-04-14 15:12                                                     ` Eric Schulte
2010-04-14 19:38                                                       ` Eric S Fraga
2010-04-15  2:49                                                         ` Eric Schulte
2010-04-15 15:47                                                           ` Eric Schulte
2010-04-13 23:03                                           ` Eric S Fraga
2010-04-14  1:22                                             ` Eric Schulte
2010-04-05 13:54                                     ` [CONTRIB?] " Dan Davison
2010-04-05 14:50                                       ` David Maus
2010-04-05 14:53                                       ` Dan Davison
2010-04-05 15:30                                         ` Eric Schulte
2010-04-01 17:37                           ` Sivaram Neelakantan
2010-04-01 17:45                           ` Sivaram Neelakantan
2010-03-31 20:37                         ` David Maus
2010-03-31 22:03                           ` Eric Schulte
2010-04-02  7:04                             ` David Maus
2010-04-02 23:01                               ` Eric Schulte
2010-04-03  9:19                                 ` David Maus
2010-04-04 17:52                                   ` Eric Schulte
2010-04-01  7:53                           ` Vagn Johansen
2010-04-02  6:34                             ` David Maus
2010-04-02 14:57                               ` Dan Davison
2010-04-02 17:25                                 ` David Maus
2010-04-02 21:10                                   ` Eric Schulte
2010-04-03  9:00                                     ` David Maus
2010-04-03 12:03                                       ` David Maus
2010-04-04  2:41                                         ` Eric Schulte
2010-04-04 10:00                                           ` David Maus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871vfa24qo.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=dmaus@ictsoc.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).