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