unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Sending e-mail via system's mail client from sendmail.el
@ 2005-07-10 11:34 David Reitter
  2005-07-10 13:14 ` Lennart Borgman
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: David Reitter @ 2005-07-10 11:34 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-10 11:34 David Reitter
@ 2005-07-10 13:14 ` Lennart Borgman
  2005-07-10 13:19 ` Lennart Borgman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Lennart Borgman @ 2005-07-10 13:14 UTC (permalink / raw)
  Cc: Richard Stallman, emacs-devel '

David Reitter wrote:

> 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'.

I think this is a good suggestion and I believe it can add a lot to the 
quality on Emacs. It can work on w32 too, but there is one problem. The 
mailto url can not be very long on w32. Therefore I have made a 
workaround which I hope you can include.

The workaround (on w32 only) places the actual message body on the 
clipboard and instead gives a short body telling the user to paste the 
clipboard contents into the message:

*** orig\mailclient.el    2005-07-10 14:58:02.595704200 +0200
--- mailclient.el    2005-07-10 15:06:57.593654200 +0200
***************
*** 128,137 ****
                 "")
               ;; body
               (concat (mailclient-url-delim) "body="
!                  (url-encode-string
!                   (buffer-substring delimline (point-max)))))))) 
        (kill-buffer tembuf))))
 
 
 
! (provide 'mailclient)
\ No newline at end of file
--- 128,141 ----
                 "")
               ;; body
               (concat (mailclient-url-delim) "body="
!                              (if (fboundp 'w32-set-clipboard-data)
!                                  (progn
!                                    (w32-set-clipboard-data 
(buffer-substring delimline (point-max)))
!                                    "*** Bug report data has been 
placed on clipboard, please paste them here! ***" )
!                                (url-encode-string
!                                       (buffer-substring delimline 
(point-max)))))))))
        (kill-buffer tembuf))))
 
 
 
! (provide 'mailclient)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-10 11:34 David Reitter
  2005-07-10 13:14 ` 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
  3 siblings, 1 reply; 9+ messages in thread
From: Lennart Borgman @ 2005-07-10 13:19 UTC (permalink / raw)
  Cc: Richard Stallman, emacs-devel '

David Reitter wrote:

> To activate:
> (setq send-mail-function 'mailclient-send-it)

Forgot this: Maybe it would be better to include this in mailclient.el? 
Then you just have to load mailclient.el, that is it. For those who 
accidently loads it give a message and save the old value.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-10 13:19 ` Lennart Borgman
@ 2005-07-10 23:44   ` David Reitter
  0 siblings, 0 replies; 9+ messages in thread
From: David Reitter @ 2005-07-10 23:44 UTC (permalink / raw)
  Cc: emacs-devel '

On 10 Jul 2005, at 14:19, Lennart Borgman wrote:

> David Reitter wrote:
>
>
>> To activate:
>> (setq send-mail-function 'mailclient-send-it)
>>
>
> Forgot this: Maybe it would be better to include this in  
> mailclient.el? Then you just have to load mailclient.el, that is  
> it. For those who accidently loads it give a message and save the  
> old value.

I don't think just loading mailclient.el should change an actual  
setting. See style guide.

But mailclient-send-it should be declared an autoload. I forgot this  
in the file that I sent around.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-10 11:34 David Reitter
  2005-07-10 13:14 ` Lennart Borgman
  2005-07-10 13:19 ` Lennart Borgman
@ 2005-07-11  5:34 ` Richard M. Stallman
  2005-07-11  5:34 ` Richard M. Stallman
  3 siblings, 0 replies; 9+ messages in thread
From: Richard M. Stallman @ 2005-07-11  5:34 UTC (permalink / raw)
  Cc: emacs-devel

I can't check the details, but the overall idea seems like the right
thing.  Thanks for writing it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-10 11:34 David Reitter
                   ` (2 preceding siblings ...)
  2005-07-11  5:34 ` Richard M. Stallman
@ 2005-07-11  5:34 ` Richard M. Stallman
  2005-07-11  6:41   ` Lennart Borgman
  3 siblings, 1 reply; 9+ messages in thread
From: Richard M. Stallman @ 2005-07-11  5:34 UTC (permalink / raw)
  Cc: emacs-devel

I can't check the details, but it seems like basically the right thing.

    > To activate:
    > (setq send-mail-function 'mailclient-send-it)

    Forgot this: Maybe it would be better to include this in mailclient.el? 

No, because just loading a Lisp file shouldn't change the behavior of
Emacs.

But it isn't needed anyway.  This change in sendmail.el

    ! (defcustom send-mail-function
    !   (if (eq system-type 'darwin)
    !       'mailclient-send-it
    !     'sendmail-send-it)

is the right way to do that job.  Nothing more is needed.

Thanks.

Have you signed copyright papers yet?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-11  5:34 ` Richard M. Stallman
@ 2005-07-11  6:41   ` Lennart Borgman
  0 siblings, 0 replies; 9+ messages in thread
From: Lennart Borgman @ 2005-07-11  6:41 UTC (permalink / raw)
  Cc: David Reitter, emacs-devel

Richard M. Stallman wrote:

>But it isn't needed anyway.  This change in sendmail.el
>
>    ! (defcustom send-mail-function
>    !   (if (eq system-type 'darwin)
>    !       'mailclient-send-it
>    !     'sendmail-send-it)
>
>is the right way to do that job.  Nothing more is needed.
>  
>
Then please check for w32 here too.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
@ 2005-07-11  9:30 LENNART BORGMAN
  2005-07-11  9:36 ` David Reitter
  0 siblings, 1 reply; 9+ messages in thread
From: LENNART BORGMAN @ 2005-07-11  9:30 UTC (permalink / raw)
  Cc: emacs-devel '

From: David Reitter <david.reitter@gmail.com>

> > Forgot this: Maybe it would be better to include this in  
> > mailclient.el? Then you just have to load mailclient.el, that is 
> 
> > it. For those who accidently loads it give a message and save 
> the  
> > old value.
> 
> I don't think just loading mailclient.el should change an actual  
> setting. See style guide.

Thanks. I agree, it sounds like a good decision. However I can not find the style guide. Is this somewhere in Info?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Sending e-mail via system's mail client from sendmail.el
  2005-07-11  9:30 Sending e-mail via system's mail client from sendmail.el LENNART BORGMAN
@ 2005-07-11  9:36 ` David Reitter
  0 siblings, 0 replies; 9+ messages in thread
From: David Reitter @ 2005-07-11  9:36 UTC (permalink / raw)
  Cc: emacs-devel '

On 11 Jul 2005, at 10:30, LENNART BORGMAN wrote:

>  Thanks. I agree, it sounds like a good decision. However I can not  
> find the style guide. Is this somewhere in Info?


(info "(elisp)Coding Conventions")

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-07-11  9:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-11  9:30 Sending e-mail via system's mail client from sendmail.el LENNART BORGMAN
2005-07-11  9:36 ` David Reitter
  -- strict thread matches above, loose matches on Subject: below --
2005-07-10 11:34 David Reitter
2005-07-10 13:14 ` 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

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).