From: David Reitter <david.reitter@gmail.com>
Subject: Sending e-mail via system's mail client from sendmail.el
Date: Sun, 10 Jul 2005 12:34:06 +0100 [thread overview]
Message-ID: <4A08801D-0AD9-4874-A008-A066E8E5EDDF@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2628 bytes --]
The enclosed package allows to hand over a mail buffer from sendmail.el
to the system's designated e-mail client.
Note that the e-mail client will display the contents of the buffer
again for editing. The e-mail client is taken to be whoever handles a
mailto: URL
via `browse-url'.
To activate:
(setq send-mail-function 'mailclient-send-it)
If this is acceptable, I can rework my earlier patch for emacsbug.el
so that it goes through sendmail, but doesn't display the mail for
editing before handing it over to the mail client, if send-mail-
function is mailclient-send-it.
I've tested this on the Mac and on a KDE installation with Mozilla.
It addresses long-standing problems on the Mac, but should be equally
useful on all systems where users use some mail application instead
of emacs. I conjecture it will make sendmail mail easier (or even
functional) on WIndows as well.
diff -c -r1.285 sendmail.el
*** sendmail.el 23 Jun 2005 21:22:43 -0000 1.285
--- sendmail.el 10 Jul 2005 11:28:45 -0000
***************
*** 1,6 ****
;;; sendmail.el --- mail sending commands for Emacs. -*- byte-
compile-dynamic: t -*-
! ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 98, 2000, 2001,
2002, 03, 2004
;; Free Software Foundation, Inc.
;; Maintainer: FSF
--- 1,6 ----
;;; sendmail.el --- mail sending commands for Emacs. -*- byte-
compile-dynamic: t -*-
! ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 98, 2000, 2001,
2002, 2003, 2004, 2005
;; Free Software Foundation, Inc.
;; Maintainer: FSF
***************
*** 120,126 ****
;; Useful to set in site-init.el
;;;###autoload
! (defcustom send-mail-function 'sendmail-send-it
"Function to call to send the current buffer as mail.
The headers should be delimited by a line which is
not a valid RFC822 header or continuation line,
--- 120,129 ----
;; Useful to set in site-init.el
;;;###autoload
! (defcustom send-mail-function
! (if (eq system-type 'darwin)
! 'mailclient-send-it
! 'sendmail-send-it)
"Function to call to send the current buffer as mail.
The headers should be delimited by a line which is
not a valid RFC822 header or continuation line,
***************
*** 130,135 ****
--- 133,139 ----
:type '(radio (function-item sendmail-send-it :tag "Use Sendmail
package")
(function-item smtpmail-send-it :tag "Use SMTPmail
package")
(function-item feedmail-send-it :tag "Use Feedmail
package")
+ (function-item mailclient-send-it :tag "Use
Mailclient package")
function)
:group 'sendmail)
[-- Attachment #2: mailclient.el --]
[-- Type: application/octet-stream, Size: 4381 bytes --]
;;; mailclient.el --- mail sending via system's mail client. -*- byte-compile-dynamic: t -*-
;; Copyright (C) 2005
;; David Reitter
;; Maintainer: FSF
;; Keywords: mail
;; This file is not yet part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; This package allows to hand over a buffer to be sent off
;; via the system's designated e-mail client.
;; Note that the e-mail client will display the contents of the buffer
;; again for editing.
;; The e-mail client is taken to be whoever handles a mailto: URL
;; via `browse-url'.
;; To activate:
;; (setq send-mail-function 'mailclient-send-it) ; if you use `mail'
;;; Code:
;; Copied from w3m-url-encode-string (w3m.el)
(defun url-encode-string (string &optional coding)
"Encode STRING by url-encoding.
Optional CODING is used for encoding coding-system."
(apply (function concat)
(mapcar
(lambda (ch)
(cond
((eq ch ?\n) ; newline
"%0D%0A")
((string-match "[-a-zA-Z0-9_:/.]" (char-to-string ch))
(char-to-string ch)) ; printable
((char-equal ch ?\x20) ; space
"%20")
(t
(format "%%%02x" ch)))) ; escape
;; Coerce a string to a list of chars.
(append (encode-coding-string (or string "")
(or coding
file-name-coding-system))
nil))))
(defvar mailclient-delim-static "?")
(defmacro mailclient-url-delim ()
(let ((current mailclient-delim-static))
(setq mailclient-delim-static "&")
current))
(defmacro mailclient-gather-addresses (str &optional drop-first-name)
(let ((cc "")
end)
(goto-char (point-min))
;; find all cc's
(while
(re-search-forward
(format "^%s:[ ]*" (upcase-initials str)) delimline t)
(let ((beg (point)))
(re-search-forward "\n" delimline t)
(setq end (point))
(goto-char beg))
(while
(re-search-forward "[ ]*\\([^ ,\n]+\\)" end t)
(setq cc
(concat cc
(if (and drop-first-name
(= (length cc) 0))
""
(concat (mailclient-url-delim) str "="))
(url-encode-string (match-string 1))))))
cc))
(defun mailclient-send-it ()
"Pass current buffer on to the system's mail client.
Suitable value for `send-mail-function'.
The mail client is taken to be the handler of mailto URLs.
"
(let ((case-fold-search nil)
delimline
(mailbuf (current-buffer))
(tembuf (generate-new-buffer " mailclient temp")))
(unwind-protect
(save-excursion
(set-buffer tembuf)
(erase-buffer)
(insert-buffer-substring mailbuf)
;; Move to header delimiter
(mail-sendmail-undelimit-header)
(setq delimline (point-marker))
(if mail-aliases
(expand-mail-aliases (point-min) delimline))
(goto-char (point-min))
;; ignore any blank lines in the header
(while (and (re-search-forward "\n\n\n*" delimline t)
(< (point) delimline))
(replace-match "\n"))
(let ((case-fold-search t))
;; initialize limiter
(setq mailclient-delim-static "?")
;; construct and call up mailto URL
(browse-url
(concat "mailto:"
(mailclient-gather-addresses "to" 'drop-first-name)
(mailclient-gather-addresses "cc")
(mailclient-gather-addresses "bcc")
(mailclient-gather-addresses "reply-to")
;; subject line
(if (and (goto-char (point-min))
(re-search-forward
"^Subject:\\([^\n]*[^ ]\\)\n" delimline t))
(concat (mailclient-url-delim) "subject="
(url-encode-string (match-string 1)))
"")
;; body
(concat (mailclient-url-delim) "body="
(url-encode-string
(buffer-substring delimline (point-max))))))))
(kill-buffer tembuf))))
(provide 'mailclient)
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
next reply other threads:[~2005-07-10 11:34 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-10 11:34 David Reitter [this message]
2005-07-10 13:14 ` Sending e-mail via system's mail client from sendmail.el Lennart Borgman
2005-07-10 13:19 ` Lennart Borgman
2005-07-10 23:44 ` David Reitter
2005-07-11 5:34 ` Richard M. Stallman
2005-07-11 5:34 ` Richard M. Stallman
2005-07-11 6:41 ` Lennart Borgman
-- strict thread matches above, loose matches on Subject: below --
2005-07-11 9:30 LENNART BORGMAN
2005-07-11 9:36 ` David Reitter
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.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A08801D-0AD9-4874-A008-A066E8E5EDDF@gmail.com \
--to=david.reitter@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.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).