]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/mailclient.el
Merge changes from emacs-23 branch
[gnu-emacs] / lisp / mail / mailclient.el
index eb12d97f57656b0b6d946a921b7194375e42d877..2a5d77d4f74508250ec78b26e292ee78cda2d654 100644 (file)
@@ -1,16 +1,16 @@
 ;;; mailclient.el --- mail sending via system's mail client.  -*- byte-compile-dynamic: t -*-
 
-;; Copyright (C) 2005 Free Software Foundation
+;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation
 
 ;; Author: David Reitter <david.reitter@gmail.com>
 ;; Keywords: mail
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; 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.
+;; the Free Software Foundation, either version 3 of the License, 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
 ;; 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.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
-;; This package allows to hand over a buffer to be sent off 
-;; via the system's designated e-mail client. 
+;; 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'. 
+;; via `browse-url'.
 ;; Mailto: URLs are composed according to RFC2368.
 
 ;; MIME bodies are not supported - we rather expect the mail client
 ;; to encode the body and add, for example, a digital signature.
 ;; The mailto URL RFC calls for "short text messages that are
-;; actually the content of automatic processing." 
+;; actually the content of automatic processing."
 ;; So mailclient.el is ideal for situations where an e-mail is
-;; generated automatically, and the user can edit it in the 
-;; mail client (e.g. bug-reports). 
+;; generated automatically, and the user can edit it in the
+;; mail client (e.g. bug-reports).
 
 ;; To activate:
 ;; (setq send-mail-function 'mailclient-send-it) ; if you use `mail'
 
 (require 'sendmail)   ;; for mail-sendmail-undelimit-header
 (require 'mail-utils) ;; for mail-fetch-field
+(require 'browse-url)
 
-(defcustom mailclient-place-body-on-clipboard-flag  
+(defcustom mailclient-place-body-on-clipboard-flag
   (fboundp 'w32-set-clipboard-data)
   "If non-nil, put the e-mail body on the clipboard in mailclient.
-This is useful on systems where only short mailto:// URLs are 
-supported. Defaults to non-nil on Windows, nil otherwise."
+This is useful on systems where only short mailto:// URLs are
+supported.  Defaults to non-nil on Windows, nil otherwise."
   :type 'boolean
   :group 'mail)
 
@@ -64,7 +63,7 @@ supported. Defaults to non-nil on Windows, nil otherwise."
          (lambda (char)
            (cond
             ((eq char ?\x20) "%20")   ;; space
-            ((eq char ?\n) "%0D%0A")  ;; newline 
+            ((eq char ?\n) "%0D%0A")  ;; newline
             ((string-match "[-a-zA-Z0-9_:/.@]" (char-to-string char))
              (char-to-string char))   ;; printable
             (t                        ;; everything else
@@ -75,33 +74,35 @@ supported. Defaults to non-nil on Windows, nil otherwise."
 (defvar mailclient-delim-static "?")
 (defun mailclient-url-delim ()
   (let ((current mailclient-delim-static))
-    (setq mailclient-delim-static "&") 
+    (setq mailclient-delim-static "&")
     current))
 
 (defun mailclient-gather-addresses (str &optional drop-first-name)
   (let ((field (mail-fetch-field str nil t)))
     (if field
        (save-excursion
-         (let ((first t) 
+         (let ((first t)
                (result ""))
            (mapc
             (lambda (recp)
-              (setq result 
-                    (concat 
+              (setq result
+                    (concat
                      result
                      (if (and drop-first-name
                               first)
                          ""
                        (concat (mailclient-url-delim) str "="))
-                     (mailclient-encode-string-as-url 
+                     (mailclient-encode-string-as-url
                       recp)))
               (setq first nil))
-            (split-string 
+            (split-string
              (mail-strip-quoted-names field) "\, *"))
            result)))))
 
+(declare-function clipboard-kill-ring-save "menu-bar.el" (beg end))
+
 ;;;###autoload
-(defun mailclient-send-it () 
+(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."
@@ -122,19 +123,22 @@ The mail client is taken to be the handler of mailto URLs."
          (while (and (re-search-forward "\n\n\n*" delimline t)
                      (< (point) delimline))
            (replace-match "\n"))
-         (let ((case-fold-search t))  
+         (let ((case-fold-search t)
+               ;; Use the external browser function to send the
+               ;; message.
+               (browse-url-mailto-function nil))
            ;; initialize limiter
            (setq mailclient-delim-static "?")
            ;; construct and call up mailto URL
-           (browse-url 
-            (concat 
+           (browse-url
+            (concat
              (save-excursion
                (narrow-to-region (point-min) delimline)
-               (concat 
+               (concat
                 "mailto:"
                 ;; some of the headers according to RFC822
-                (mailclient-gather-addresses "To"   
-                                             'drop-first-name)          
+                (mailclient-gather-addresses "To"
+                                             'drop-first-name)
                 (mailclient-gather-addresses "cc"  )
                 (mailclient-gather-addresses "bcc"  )
                 (mailclient-gather-addresses "Resent-To"  )
@@ -151,20 +155,20 @@ The mail client is taken to be the handler of mailto URLs."
                   (if subj ;; if non-blank
                       ;; the mail client will deal with
                       ;; warning the user etc.
-                      (concat (mailclient-url-delim) "subject=" 
+                      (concat (mailclient-url-delim) "subject="
                               (mailclient-encode-string-as-url subj))
                     ""))))
              ;; body
-             (concat 
-              (mailclient-url-delim) "body=" 
+             (concat
+              (mailclient-url-delim) "body="
               (mailclient-encode-string-as-url
                (if mailclient-place-body-on-clipboard-flag
                    (progn
-                     (clipboard-kill-ring-save  
+                     (clipboard-kill-ring-save
                       (+ 1 delimline) (point-max))
                      (concat
                       "*** E-Mail body has been placed on clipboard, "
-                      "please paste them here! ***"))
+                      "please paste it here! ***"))
                  ;; else
                  (buffer-substring (+ 1 delimline) (point-max))))))))))))