From: David Maus <dmaus@ictsoc.de>
To: Matt Price <moptop99@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: using orgmode to send html mail?
Date: Mon, 22 Mar 2010 21:18:24 +0100 [thread overview]
Message-ID: <878w9krtyn.wl%dmaus@ictsoc.de> (raw)
In-Reply-To: <f22f52181003211934s70fe468fk54d126dc811c45d2@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 7511 bytes --]
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
[-- Attachment #1.2: Type: application/pgp-signature, Size: 230 bytes --]
[-- Attachment #2: 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
next prev parent reply other threads:[~2010-03-22 20:18 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 [this message]
2010-03-23 19:54 ` Eric Schulte
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878w9krtyn.wl%dmaus@ictsoc.de \
--to=dmaus@ictsoc.de \
--cc=emacs-orgmode@gnu.org \
--cc=moptop99@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.