]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/feedmail.el
Don’t create unnecessary marker in ‘delete-trailing-whitespace’
[gnu-emacs] / lisp / mail / feedmail.el
index 4305094611a24476600bcac4199bc2b7f2d5784a..bb93cff96bc39a5a5402192e953f016ef5328bed 100644 (file)
 
 (require 'mail-utils)               ; pick up mail-strip-quoted-names
 
-(eval-when-compile
-  (require 'smtpmail))
-
 (autoload 'mail-do-fcc "sendmail")
 
 (defgroup feedmail nil
   "If non-nil, give a y-or-n confirmation prompt before sending mail.
 This is done after the message is completely prepped, and you'll be
 looking at the top of the message in a buffer when you get the prompt.
-If set to the symbol 'queued, give the confirmation prompt only while
+If set to the symbol `queued', give the confirmation prompt only while
 running the queue (however, the prompt is always suppressed if you are
 processing the queue via `feedmail-run-the-queue-no-prompts').  If set
-to the symbol 'immediate, give the confirmation prompt only when
+to the symbol `immediate', give the confirmation prompt only when
 sending immediately.  For any other non-nil value, prompt in both
 cases.  You can give a timeout for the prompt; see variable
 `feedmail-confirm-outgoing-timeout'."
   :group 'feedmail-misc
-  :type 'boolean
-  )
+  :type '(choice (const nil)
+                (const queued)
+                (const immediate)
+                (other t)))
 
 
 (defcustom feedmail-display-full-frame 'queued
@@ -419,17 +418,19 @@ cases.  You can give a timeout for the prompt; see variable
 If nil, the prepped message will be shown, for confirmation or
 otherwise, in some window in the current frame without resizing
 anything.  That may or may not display enough of the message to
-distinguish it from others.  If set to the symbol 'queued, take
+distinguish it from others.  If set to the symbol `queued', take
 this action only when running the queue.  If set to the symbol
-'immediate, take this action only when sending immediately.  For
+`immediate', take this action only when sending immediately.  For
 any other non-nil value, take the action in both cases.  Even if
 you're not confirming the sending of immediate or queued messages,
 it can still be interesting to see a lot about them as they are
 shuttled robotically onward."
   :version "24.1"
   :group 'feedmail-misc
-  :type 'boolean
-  )
+  :type '(choice (const nil)
+                (const queued)
+                (const immediate)
+                (other t)))
 
 
 (defcustom feedmail-confirm-outgoing-timeout nil
@@ -437,7 +438,7 @@ shuttled robotically onward."
 If a positive number, it's a timeout before sending.  If a negative
 number, it's a timeout before not sending.  This will not work if your
 version of Emacs doesn't include the function `y-or-n-p-with-timeout'
-\(e.g., some versions of XEmacs\)."
+\(e.g., some versions of XEmacs)."
   :version "24.1"
   :group 'feedmail-misc
   :type '(choice (const nil) integer)
@@ -448,7 +449,7 @@ version of Emacs doesn't include the function `y-or-n-p-with-timeout'
   "If non-nil remove Bcc: lines from the message headers.
 In any case, the Bcc: lines do participate in the composed address
 list.  You may want to leave them in if you're using sendmail
-\(see `feedmail-buffer-eating-function'\)."
+\(see `feedmail-buffer-eating-function')."
   :group 'feedmail-headers
   :type 'boolean
   )
@@ -458,7 +459,7 @@ list.  You may want to leave them in if you're using sendmail
   "If non-nil remove Resent-Bcc: lines from the message headers.
 In any case, the Resent-Bcc: lines do participate in the composed
 address list.  You may want to leave them in if you're using sendmail
-\(see `feedmail-buffer-eating-function'\)."
+\(see `feedmail-buffer-eating-function')."
   :group 'feedmail-headers
   :type 'boolean
   )
@@ -470,9 +471,9 @@ Addresses for the message envelope are deduced by examining
 appropriate address headers in the message.  Generally, they will show
 up in the list of deduced addresses in the order that the headers
 happen to appear (duplicate addresses are eliminated in any case).
-This variable can be set to the symbol 'first, in which case the
+This variable can be set to the symbol `first', in which case the
 Bcc:/Resent-Bcc: addresses will appear at the beginning in the list;
-or, it can be set to the symbol 'last, in which case they will appear
+or, it can be set to the symbol `last', in which case they will appear
 at the end of the list.
 
 Why should you care?  Well, maybe you don't, and certainly the same
@@ -483,11 +484,12 @@ addresses are not handled first, there can be substantial delays in
 seeing the message again.  Some configurations of sendmail, for example,
 seem to try to deliver to each addressee at least once, immediately
 and serially, so slow SMTP conversations can add up to a delay.  There
-is an option for either 'first or 'last because you might have a
+is an option for either `first' or `last' because you might have a
 delivery agent that processes the addresses backwards."
   :group 'feedmail-headers
-  :type 'boolean
-  )
+  :type '(choice (const nil)
+                (const first)
+                (const last)))
 
 
 (defcustom feedmail-fill-to-cc t
@@ -564,7 +566,7 @@ but common in some proprietary systems."
   "If non-nil and the email has no Sender: header, use this value.
 May be nil, in which case nothing in particular is done with respect
 to Sender: lines.  By design, will not replace an existing Sender:
-line, but you can achieve that with a fiddle-plex 'replace action.
+line, but you can achieve that with a fiddle-plex replace action.
 NB: it makes no sense to use the value t since there is no sensible
 default for Sender:.
 
@@ -590,7 +592,7 @@ header is fiddled after the From: header is fiddled."
 (defcustom feedmail-force-binary-write t
   "If non-nil, force writing file as binary (this applies to queues and Fcc:).
 On systems where there is a difference between binary and text files,
-feedmail will temporarily manipulate the value of `buffer-file-type'
+feedmail will temporarily manipulate the value of `coding-system-for-write'
 to make the writing as binary.  If nil, writing will be in text mode.
 On systems where there is no distinction or where it is controlled by other
 variables or other means, this option has no effect."
@@ -604,7 +606,7 @@ variables or other means, this option has no effect."
 May be t, in which case a default is computed (and you probably won't
 be happy with it).  May be nil, in which case nothing in particular is
 done with respect to From: lines.  By design, will not replace an
-existing From: line, but you can achieve that with a fiddle-plex 'replace
+existing From: line, but you can achieve that with a fiddle-plex `replace'
 action.
 
 If neither nil nor t, it may be a string, a fiddle-plex, or a function
@@ -643,7 +645,7 @@ is not an option for many users.  As this is the default behavior of most
 sendmail installations, one can mostly only wish it were otherwise.  If feedmail
 believes the sendmail program will sell you out this way, it won't use the \"-f\"
 option when calling sendmail.  If it doesn't think sendmail will sell you out,
-it will use the \"-f\" \(since it is a handy feature\).  You control what
+it will use the \"-f\" \(since it is a handy feature).  You control what
 feedmail thinks with this variable.  The default is nil, meaning that feedmail
 will believe that sendmail will sell you out."
   :version "24.1"
@@ -859,7 +861,7 @@ as well."
   "User-supplied specification for a crude form of mailmerge capability.
 When spraying is enabled, feedmail composes a list of envelope addresses.
 In turn, `feedmail-spray-this-address' is temporarily set to each address
-\(stripped of any comments and angle brackets\) and a function is called which
+\(stripped of any comments and angle brackets) and a function is called which
 fiddles message headers according to this variable.  See the documentation for
 `feedmail-fiddle-plex-blurb', for an overview of fiddle-plex data structures.
 
@@ -868,11 +870,11 @@ headers for specific addresses.
 
 May be t, in which case a \"To:\" header is added to the message with
 the stripped address as the header contents.  The fiddle-plex operator
-is 'supplement.
+is `supplement'.
 
 May be a string, in which case the string is assumed to be the name of
 a message header field with the stripped address serving as the value.
-The fiddle-plex operator is 'supplement.
+The fiddle-plex operator is `supplement'.
 
 May be a function, in which case it is called with no arguments and is
 expected to return nil, t, a string, another function, or a fiddle-plex.
@@ -889,7 +891,7 @@ If a list, each item is acted on in turn as described above.
 
 For example,
 
-  (setq feedmail-spray-address-fiddle-plex-list 'feedmail-spray-via-bbdb)
+  (setq feedmail-spray-address-fiddle-plex-list \\='feedmail-spray-via-bbdb)
 
 The idea of the example is that, during spray mode, as each message is
 about to be transmitted to an individual address, the function will be
@@ -1229,7 +1231,7 @@ If a string, it is used directly.
 If a function, it is called with no arguments from the buffer containing the raw
 text of the message.  It must return a string (which may be empty).
 
-If the symbol 'ask, you will be prompted for a string in the mini-buffer.
+If the symbol `ask', you will be prompted for a string in the mini-buffer.
 Filename completion is available so that you can inspect what's already been
 used, but feedmail will do further manipulation on the string you return, so
 it's not expected to be a complete filename."
@@ -1299,27 +1301,27 @@ the fact in the messages buffer."
 
 
 (defvar feedmail-queue-buffer-file-name nil
-  "If non-nil, has the value normally expected of 'buffer-file-name'.
+  "If non-nil, has the value normally expected of `buffer-file-name'.
 You are not intended to set this to something in your configuration.  Rather,
 you might programmatically set it to something via a hook or function
 advice or whatever.  You might like to do this if you are using a mail
-composition program that eventually uses sendmail.el's 'mail-send'
+composition program that eventually uses sendmail.el's `mail-send'
 function to process the message.  If there is a filename associated
-with the message buffer, 'mail-send' will ask you for confirmation.
+with the message buffer, `mail-send' will ask you for confirmation.
 There's no trivial way to avoid it.  It's unwise to just set the value
-of 'buffer-file-name' to nil because that will defeat feedmail's file
+of `buffer-file-name' to nil because that will defeat feedmail's file
 management features.  Instead, arrange for this variable to be set to
-the value of 'buffer-file-name' before setting that to nil.  An easy way
-to do that would be with defadvice on 'mail-send' \(undoing the
-assignments in a later advice\).
+the value of `buffer-file-name' before setting that to nil.  An easy way
+to do that would be with defadvice on `mail-send' \(undoing the
+assignments in a later advice).
 
-feedmail will pretend that 'buffer-file-name', if nil, has the value
-assigned of 'feedmail-queue-buffer-file-name' and carry out its normal
+feedmail will pretend that `buffer-file-name', if nil, has the value
+assigned of `feedmail-queue-buffer-file-name' and carry out its normal
 activities.  feedmail does not restore the non-nil value of
-'buffer-file-name'.  For safe bookkeeping, the user should insure that
+`buffer-file-name'.  For safe bookkeeping, the user should insure that
 feedmail-queue-buffer-file-name is restored to nil.
 
-Example 'defadvice' for mail-send:
+Example `defadvice' for mail-send:
 
    (defadvice mail-send (before feedmail-mail-send-before-advice activate)
      (setq feedmail-queue-buffer-file-name buffer-file-name)
@@ -1352,7 +1354,7 @@ If you have `mail-send-hook' functions that should only be called for sending/
 queueing messages or only be called for the sending of queued messages, this is
 for you.  Add this function to `mail-send-hook' with something like this:
 
-       (add-hook 'mail-send-hook 'feedmail-mail-send-hook-splitter)
+       (add-hook \\='mail-send-hook \\='feedmail-mail-send-hook-splitter)
 
 Then add the functions you want called to either `feedmail-mail-send-hook-queued'
 or `feedmail-mail-send-hook', as appropriate.  The distinction is that
@@ -1381,7 +1383,7 @@ See documentation of `feedmail-mail-send-hook-splitter' for details."
 (defun feedmail-confirm-addresses-hook-example ()
   "An example of a `feedmail-last-chance-hook'.
 It shows the simple addresses and gets a confirmation.  Use as:
- (setq feedmail-last-chance-hook 'feedmail-confirm-addresses-hook-example)."
+ (setq feedmail-last-chance-hook \\='feedmail-confirm-addresses-hook-example)."
   (save-window-excursion
     (display-buffer (set-buffer (get-buffer-create " F-C-A-H-E")))
     (erase-buffer)
@@ -1505,7 +1507,7 @@ The default action is an anonymous function which gets rid of the file
 from the queue directory.  With a non-nil second argument, a brief
 message is give for each file deleted.  You could replace this
 function, for example, to archive all of your sent messages someplace
-\(though there are better ways to get that particular result\)."
+\(though there are better ways to get that particular result)."
   :group 'feedmail-queue
   :type 'function
   )
@@ -1549,7 +1551,7 @@ See feedmail-binmail-template documentation."
                                           "/bin/rmail %s" "/bin/mail %s"))
   "Command template for the subprocess which will get rid of the mail.
 It can result in any command understandable by /bin/sh.  Might not
-work at all in non-UNIX environments.  The single '%s', if present,
+work at all in non-UNIX environments.  The single `%s', if present,
 gets replaced by the space-separated, simplified list of addressees.
 Used in `feedmail-buffer-to-binmail' to form the shell command which
 will receive the contents of the prepped buffer as stdin.  The default
@@ -1619,6 +1621,10 @@ local gurus."
                 ;; These mean "report errors by mail" and "deliver in background".
                 (if (null mail-interactive) '("-oem" "-odb")))))
 
+(declare-function smtpmail-via-smtp "smtpmail"
+                 (recipient smtpmail-text-buffer &optional ask-for-password))
+(defvar smtpmail-smtp-server)
+
 ;; provided by jam@austin.asc.slb.com (James A. McLaughlin);
 ;; simplified by WJC after more feedmail development;
 ;; idea (but not implementation) of copying smtpmail trace buffer to
@@ -1709,7 +1715,7 @@ for ACTION (default is `supplement'):
                 VAL-LIKE is not used.  Else, if VAL-LIKE is a function,
                 it is called with two arguments: NAME and the
                 aggregate like values.  Else, if VAL-LIKE is a string, it is
-                used as a format string where a single \%s will be
+                used as a format string where a single %s will be
                 replaced by the aggregate values of like fields.
 
                 VAL-PRE, the results of using VAL-LIKE, and VAL-POST
@@ -1739,7 +1745,8 @@ applied to a file after you've just read it from disk: for example, a
 feedmail FQM message file from a queue.  You could use something like
 this:
 
-\(setq auto-mode-alist \(cons \'\(\"\\\\.fqm$\" . feedmail-vm-mail-mode\) auto-mode-alist\)\)
+\(setq auto-mode-alist
+      (cons \\='(\"\\\\.fqm$\" . feedmail-vm-mail-mode) auto-mode-alist))
 "
   (feedmail-say-debug ">in-> feedmail-vm-mail-mode")
   (let ((the-buf (current-buffer)))
@@ -1883,32 +1890,33 @@ with various lower-level mechanisms to provide features such as queueing."
 (defun feedmail-message-action-help-blat (d-string)
   (feedmail-say-debug ">in-> feedmail-message-action-help-blat")
   (with-output-to-temp-buffer feedmail-p-h-b-n
-    (princ "You're dispatching a message and feedmail queuing is enabled.
+    (princ (substitute-command-keys "\
+You're dispatching a message and feedmail queuing is enabled.
 Typing ? again will normally scroll this help buffer.
 
 Choices:
-   q  QUEUE        for later sending \(via feedmail-run-the-queue\)
+   q  QUEUE        for later sending (via feedmail-run-the-queue)
    Q  QUEUE!       like \"q\", but always make a new file
-   i  IMMEDIATELY  send this \(but not the other queued messages\)
+   i  IMMEDIATELY  send this (but not the other queued messages)
    I  IMMEDIATELY! like \"i\", but skip following confirmation prompt
    d  DRAFT        queue in the draft directory
    D  DRAFT!       like \"d\", but always make a new file
-   e  EDIT         return to the message edit buffer \(don't send or queue\)
-   *  SPRAY        toggle spray mode \(individual message transmissions\)
-   >  SCROLL UP    scroll message up \(toward end of message\)
-   <  SCROLL DOWN  scroll message down \(toward beginning of message\)
+   e  EDIT         return to the message edit buffer (don't send or queue)
+   *  SPRAY        toggle spray mode (individual message transmissions)
+   >  SCROLL UP    scroll message up (toward end of message)
+   <  SCROLL DOWN  scroll message down (toward beginning of message)
    ?  HELP         show or scroll this help buffer
 
 Synonyms:
-   s  SEND         immediately \(same as \"i\"\)
-   S  SEND!        immediately \(same as \"I\"\)
-   r  ROUGH        draft \(same as \"d\"\)
-   R  ROUGH!       draft \(same as \"D\"\)
-   n  NOPE         didn't mean it \(same as \"e\"\)
-   y  YUP          do the default behavior \(same as \"C-m\"\)
-  SPC SCROLL UP    \(same as \">\"\)
-
-The user-configurable default is currently \"")
+   s  SEND         immediately (same as \"i\")
+   S  SEND!        immediately (same as \"I\")
+   r  ROUGH        draft (same as \"d\")
+   R  ROUGH!       draft (same as \"D\")
+   n  NOPE         didn't mean it (same as \"e\")
+   y  YUP          do the default behavior (same as \"C-m\")
+  SPC SCROLL UP    (same as \">\")
+
+The user-configurable default is currently \""))
        (princ d-string)
        (princ "\".  For other possibilities,
 see the variable feedmail-prompt-before-queue-user-alist.
@@ -2016,7 +2024,6 @@ backup file names and the like)."
              (setq buffer-offer-save nil)
              (buffer-disable-undo blobby-buffer)
              (insert-file-contents-literally maybe-file)
-             (setq buffer-file-type t) ; binary
              (goto-char (point-min))
              ;; if at least two line-endings with CRLF, translate the file
              (if (looking-at ".*\r\n.*\r\n")
@@ -2048,7 +2055,7 @@ backup file names and the like)."
                ;; the handler for the condition-case
                (error (setq messages-skipped (1+ messages-skipped))
                       (ding t)
-                      (message "FQM: Trapped '%s', message left in queue." (car signal-stuff))
+                      (message "FQM: Trapped `%s', message left in queue." (car signal-stuff))
                       (sit-for 3)
                       (message "FQM: Trap details: \"%s\""
                                (mapconcat 'identity (cdr signal-stuff) "\" \""))
@@ -2073,7 +2080,7 @@ backup file names and the like)."
 (defun feedmail-queue-reminder (&optional what-event)
   "Perform some kind of reminder activity about queued and draft messages.
 Called with an optional symbol argument which says what kind of event
-is triggering the reminder activity.  The default is 'on-demand, which
+is triggering the reminder activity.  The default is `on-demand', which
 is what you typically would use if you were putting this in your Emacs start-up
 or mail hook code.  Other recognized values for WHAT-EVENT (these are passed
 internally by feedmail):
@@ -2334,7 +2341,10 @@ mapped to mostly alphanumerics for safety."
        (setq filename buffer-file-name)
       (setq filename (feedmail-create-queue-filename queue-directory)))
     ;; make binary file on DOS/Windows 95/Windows NT, etc
-    (let ((buffer-file-type feedmail-force-binary-write))
+    (let ((coding-system-for-write
+          (if feedmail-force-binary-write
+              'no-conversion
+            coding-system-for-write)))
       (write-file filename))
     ;; convenient for moving from draft to q, for example
     (if (and previous-buffer-file-name (or (not is-fqm) (not is-in-this-dir))
@@ -2571,26 +2581,27 @@ mapped to mostly alphanumerics for safety."
                  ;; Re-insert and handle any Fcc fields (and, optionally,
                   ;; any Bcc).
                  (when fcc
-                    (let ((old (default-value 'buffer-file-type)))
+                    (let ((coding-system-for-write
+                          (if (and (memq system-type '(ms-dos windows-nt))
+                                   feedmail-force-binary-write)
+                              'no-conversion
+                            coding-system-for-write)))
                       (unwind-protect
                           (progn
-                            (setq-default buffer-file-type 
-                                          feedmail-force-binary-write)
                             (insert fcc)
                             (unless feedmail-nuke-bcc-in-fcc
                               (if bcc-holder (insert bcc-holder))
                               (if resent-bcc-holder
                                   (insert resent-bcc-holder)))
-                          
+
                             (run-hooks 'feedmail-before-fcc-hook)
-                          
+
                             (when feedmail-nuke-body-in-fcc
                               (goto-char eoh-marker)
                               (if (natnump feedmail-nuke-body-in-fcc)
                                   (forward-line feedmail-nuke-body-in-fcc))
                               (delete-region (point) (point-max)))
-                            (mail-do-fcc eoh-marker))
-                        (setq-default buffer-file-type old)))))
+                            (mail-do-fcc eoh-marker))))))
              ;; User bailed out of one-last-look.
              (if feedmail-queue-runner-is-active
                  (throw 'skip-me-q 'skip-me-q)