(eword-decode-encoded-text): Fix bug when `must-unfold' is specified;
[elisp/flim.git] / smtpmail.el
index 807b4a7..cdc396c 100644 (file)
@@ -1,6 +1,6 @@
 ;;; smtpmail.el --- SMTP interface for mail-mode
 
-;; Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1996, 1998, 1999, 2000 Free Software Foundation, Inc.
 
 ;; Author: Tomoji Kagatani <kagatani@rbc.ncl.omron.co.jp>
 ;; Keywords: mail
@@ -18,8 +18,8 @@
 ;; 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., 59 Temple Place - Suite 330,
+;; along with this program; see the file COPYING.  If not, write to
+;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
 ;;; Code:
 
+(require 'custom)
 (require 'smtp)
 (require 'sendmail)
 (require 'time-stamp)
+(require 'mel) ; binary-write-decoded-region, binary-find-file-noselect
+
+(eval-when-compile (require 'static))
+
+(static-when (featurep 'xemacs)
+  (define-obsolete-variable-alias 'smtpmail-default-smtp-server
+    'smtp-default-server)
+  (define-obsolete-variable-alias 'smtpmail-smtp-server 'smtp-server)
+  (define-obsolete-variable-alias 'smtpmail-smtp-service 'smtp-service)
+  (define-obsolete-variable-alias 'smtpmail-local-domain 'smtp-local-domain)
+  (define-obsolete-variable-alias 'smtpmail-debug-info 'smtp-debug-info)
+  )
 
 ;;;
 
 (defcustom smtpmail-queue-mail nil 
-  "*Specify if mail is queued (if t) or sent immediately (if nil).
+  "Specify if mail is queued (if t) or sent immediately (if nil).
 If queued, it is stored in the directory `smtpmail-queue-dir'
 and sent with `smtpmail-send-queued-mail'."
   :type 'boolean
   :group 'smtp)
 
 (defcustom smtpmail-queue-dir "~/Mail/queued-mail/"
-  "*Directory where `smtpmail.el' stores queued mail."
+  "Directory where `smtpmail.el' stores queued mail."
   :type 'directory
   :group 'smtp)
 
@@ -64,8 +77,9 @@ and sent with `smtpmail-send-queued-mail'."
   "File name of queued mail index,
 This is relative to `smtpmail-queue-dir'.")
 
-(defvar smtpmail-queue-index (concat smtpmail-queue-dir
-                                    smtpmail-queue-index-file))
+(defvar smtpmail-queue-index
+  (concat (file-name-as-directory smtpmail-queue-dir)
+         smtpmail-queue-index-file))
 
 (defvar smtpmail-recipient-address-list nil)
 
@@ -102,7 +116,7 @@ This is relative to `smtpmail-queue-dir'.")
          (backward-char 1)
          (setq delimline (point-marker))
 ;;       (sendmail-synch-aliases)
-         (if mail-aliases
+         (if (and mail-aliases (fboundp 'expand-mail-aliases)) ; XEmacs
              (expand-mail-aliases (point-min) delimline))
          (goto-char (point-min))
          ;; ignore any blank lines in the header
@@ -117,7 +131,9 @@ This is relative to `smtpmail-queue-dir'.")
                    (save-restriction
                      (narrow-to-region (point)
                                        (save-excursion
-                                         (end-of-line)
+                                         (forward-line 1)
+                                         (while (looking-at "^[ \t]")
+                                           (forward-line 1))
                                          (point)))
                      (append (mail-parse-comma-list)
                              resend-to-addresses))))
@@ -138,8 +154,12 @@ This is relative to `smtpmail-queue-dir'.")
 ;;;               (insert "Sender: " (user-login-name) "\n")))
            ;; Don't send out a blank subject line
            (goto-char (point-min))
-           (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
-               (replace-match ""))
+           (if (re-search-forward "^Subject:\\([ \t]*\n\\)+\\b" delimline t)
+               (replace-match "")
+             ;; This one matches a Subject just before the header delimiter.
+             (if (and (re-search-forward "^Subject:\\([ \t]*\n\\)+" delimline t)
+                      (= (match-end 0) delimline))
+                 (replace-match "")))
            ;; Put the "From:" field in unless for some odd reason
            ;; they put one in themselves.
            (goto-char (point-min))
@@ -210,15 +230,15 @@ This is relative to `smtpmail-queue-dir'.")
          ; Send or queue
          (if (not smtpmail-queue-mail)
              (if smtpmail-recipient-address-list
-                 (if (not (smtp-via-smtp user-mail-address
-                                         smtpmail-recipient-address-list
-                                         tembuf))
-                     (error "Sending failed; SMTP protocol error"))
+                 (smtp-send-buffer user-mail-address
+                                   smtpmail-recipient-address-list
+                                   tembuf)
                (error "Sending failed; no recipients"))
-           (let* ((file-data (concat 
-                              smtpmail-queue-dir
-                              (time-stamp-strftime 
-                               "%02y%02m%02d-%02H%02M%02S")))
+           (let* ((file-data (convert-standard-filename
+                              (concat
+                               (file-name-as-directory smtpmail-queue-dir)
+                               (time-stamp-yyyy-mm-dd)
+                               "_" (time-stamp-hh:mm:ss))))
                   (file-elisp (concat file-data ".el"))
                   (buffer-data (create-file-buffer file-data))
                   (buffer-elisp (create-file-buffer file-elisp))
@@ -227,7 +247,9 @@ This is relative to `smtpmail-queue-dir'.")
                (set-buffer buffer-data)
                (erase-buffer)
                (insert-buffer tembuf)
-               (write-file file-data)
+               (or (file-directory-p smtpmail-queue-dir)
+                   (make-directory smtpmail-queue-dir t))
+               (binary-write-decoded-region (point-min) (point-max) file-data)
                (set-buffer buffer-elisp)
                (erase-buffer)
                (insert (concat
@@ -263,11 +285,10 @@ This is relative to `smtpmail-queue-dir'.")
                                                   (end-of-line)
                                                   (point))))
        (load file-msg)
-       (setq tembuf (find-file-noselect file-msg))
+       (setq tembuf (binary-find-file-noselect file-msg))
        (if smtpmail-recipient-address-list
-           (if (not (smtp-via-smtp user-mail-address
-                                   smtpmail-recipient-address-list tembuf))
-               (error "Sending failed; SMTP protocol error"))
+           (smtp-send-buffer user-mail-address
+                             smtpmail-recipient-address-list tembuf)
          (error "Sending failed; no recipients"))  
        (delete-file file-msg)
        (delete-file (concat file-msg ".el"))