From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: using orgmode to send html mail? Date: Wed, 24 Mar 2010 09:00:09 -0600 Message-ID: <87tys5zrwm.fsf@gmail.com> References: <878w9krtyn.wl%dmaus@ictsoc.de> <871vfa24qo.fsf@gmail.com> <87pr2uww2d.fsf@columbia.edu> 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 1NuS4D-0004eh-SC for emacs-orgmode@gnu.org; Wed, 24 Mar 2010 11:00:22 -0400 Received: from [140.186.70.92] (port=58088 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NuS4B-0004dI-QZ for emacs-orgmode@gnu.org; Wed, 24 Mar 2010 11:00:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NuS49-0000Bg-8Q for emacs-orgmode@gnu.org; Wed, 24 Mar 2010 11:00:19 -0400 Received: from mail-px0-f194.google.com ([209.85.216.194]:60117) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NuS48-0000BE-Vp for emacs-orgmode@gnu.org; Wed, 24 Mar 2010 11:00:17 -0400 Received: by pxi32 with SMTP id 32so2399849pxi.1 for ; Wed, 24 Mar 2010 08:00:15 -0700 (PDT) In-Reply-To: <87pr2uww2d.fsf@columbia.edu> (Xiao-Yong Jin's message of "Tue, 23 Mar 2010 17:46:18 -0400") 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: Eric Schulte Cc: emacs-orgmode@gnu.org --=-=-= Xiao-Yong Jin writes: > On Tue, 23 Mar 2010 13:54:39 -0600, Eric Schulte wrote: > >> 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. > I've cleaned up the function somewhat, I'll include it immediately below by inserting it in a org-mode src_block and then exporting it to html, so those with html mail readers should see a nicely fontified version of the source code. --=-=-= Content-Type: multipart/alternative; boundary="==-=-=" --==-=-= Content-Type: text/html
(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)))))
--==-=-=-- --=-=-= > > Thumbs up for this one. It should be included in > org-contrib, probably after taken care of other mail client > in emacs? > I have looked somewhat at both VM and Wanderlust, but they appear to use their own mime encoding schemes other than mml, so this won't work as-is in those mail clients. That said, assuming they also use simple mime encoding strings it should be hard to replace the mml specific mime delimiters presented as strings in the above functions with string delimiters appropriate for the other mail agents. also, I have to say I feel bad about publishing code which promotes the use of HTML mail. Generally I feel that everyone would be better off if they just used fixed width text email clients. As a concession to that intuition, if this function is called with a prefix argument, it will wrap the region (or entire email) as html in
 tags ensuring
that it will be rendered in a fixed-with font no-matter the receivers
email client, so the following table should actually look like a
table...


--=-=-=
Content-Type: multipart/alternative; boundary="===-=-="

--===-=-=
Content-Type: text/html

| this table   |   | n | fibb(n) |
|--------------+---+---+---------|
| is           |   | 0 |       0 |
| inside       |   | 1 |       1 |
| of a pre box |   | 2 |       1 |
|              |   | 3 |       2 |
--===-=-=-- --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 DQpCZXN0IC0tIEVyaWMNCg0KPg0KPj4gU28gZm9yIGV4YW1wbGUgdGhpcw0KPj4+IDEgfCAgICAg IDIgfCAgICAgMyB8DQo+Pj4gLS0tLS0tLS0tLS0tLS0rLS0tLS0tLS0rLS0tLS0tLXwNCj4+PiBm aXJzdCBjb2x1bW4gfCBzZWNvbmQgfCB0aGlyZCB8DQo+DQo+PiB3aWxsIGJlIGV4cG9ydGVkIGFz IHRoaXMNCj4+IOKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgeKUgQ0KPj4g ICAgICAgIDEgICAgICAgICAgMiAgICAgICAzICAgDQo+PiDilIDilIDilIDilIDilIDilIDilIDi lIDilIDilIDilIDilIDilIDilIANCj4+ICBmaXJzdCBjb2x1bW4gICBzZWNvbmQgIHRoaXJkIA0K Pj4g4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSB4pSBDQo+DQo+IEkgdXNl IGVtYWNzLXczbSBpbiBnbnVzLCBhbmQgdGhlIHRhYmxlIGxvb2tzIGdyZWF0Lg0K --=-=-= 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 --=-=-=--