Merge from emacs--rel--22
[bpt/emacs.git] / lisp / mail / pmail.el
index 712a921..38a6a2c 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
 ;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: mail
@@ -186,6 +186,11 @@ please report it with \\[report-emacs-bug].")
 
 (defvar pmail-encoded-remote-password nil)
 
+(defvar pmail-expunge-counter 0
+  "A counter used to keep track of the number of expunged
+messages with a lower message number than the current message
+index.")
+
 (defcustom pmail-preserve-inbox nil
   "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
   :type 'boolean
@@ -199,6 +204,11 @@ please report it with \\[report-emacs-bug].")
 (declare-function mail-position-on-field "sendmail" (field &optional soft))
 (declare-function mail-text-start "sendmail" ())
 (declare-function pmail-update-summary "pmailsum" (&rest ignore))
+(declare-function unrmail "unrmail" (file to-file))
+(declare-function rmail-dont-reply-to "mail-utils" (destinations))
+(declare-function pmail-summary-goto-msg "pmailsum" (&optional n nowarn skip-pmail))
+(declare-function pmail-summary-pmail-update "pmailsum" ())
+(declare-function pmail-summary-update "pmailsum" (n))
 
 (defun pmail-probe (prog)
   "Determine what flavor of movemail PROG is.
@@ -289,20 +299,20 @@ It is useful to set this variable in the site customization file.")
 ;;;###autoload
 (defcustom pmail-ignored-headers
   (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
-         "\\|^status:\\|^received:\\|^content-transfer-encoding:"
-         "\\|^x400-\\(received\\|mts-identifier\\|content-type\\|originator\\|recipients\\):"
-         "\\|^list-\\(help\\|post\\|subscribe\\|id\\|unsubscribe\\|archive\\):"
-         "\\|^resent-\\(face\\|x-.*\\|organization\\|openpgp\\|date\\|message-id\\):"
-         "\\|^thread-\\(topic\\|index\\)"
-         "\\|^summary-line:\\|^precedence:\\|^message-id:"
-         "\\|^path:\\|^face:\\|^delivered-to:\\|^lines:"
-         "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
-         "\\|^content-\\(length\\|type\\|class\\|disposition\\):"
+         "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
+         "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
+         "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
          "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
+         "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
+         "\\|^content-transfer-encoding:\\|^x-coding-system:"
+         "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
+         "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
+         "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
+         "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
          "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
-         "\\|^mbox-line:\\|^cancel-lock:\\|^in-reply-to:\\|^comment:"
-         "\\|^x-.*:\\|^domainkey-signature:"
-         "\\|^original-recipient:\\|^from ")
+         "\\|^mbox-line:\\|^cancel-lock:\\|^DomainKey-Signature:"
+         "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
+         "\\|^x-.*:\\|^domainkey-signature:\\|^original-recipient:\\|^from ")
   "*Regexp to match header fields that Pmail should normally hide.
 \(See also `pmail-nonignored-headers', which overrides this regexp.)
 This variable is used for reformatting the message header,
@@ -867,7 +877,7 @@ If `pmail-display-summary' is non-nil, make a summary for this PMAIL file."
          (unwind-protect
              (progn
                (write-region (point-min) (point-max) old-file)
-               (unpmail old-file new-file)
+               (unrmail old-file new-file)
                (message "Replacing BABYL format with mbox format...")
                (let ((inhibit-read-only t))
                  (erase-buffer)
@@ -1609,9 +1619,9 @@ is non-nil if the user has supplied the password interactively.
                      (or pass supplied-password)
                      got-password)
              (error "Emacs movemail does not support %s protocol" proto))
-         (list file
+         (list (concat proto "://" user "@" host)
                (or (string-equal proto "pop") (string-equal proto "imap"))
-               supplied-password
+               (or supplied-password pass)
                got-password))))
 
    ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
@@ -1655,9 +1665,9 @@ is non-nil if the user has supplied the password interactively.
                    ;; in case of multiple inboxes that need moving.
                    (concat ".newmail-"
                            (file-name-nondirectory
-                            (if (memq system-type '(windows-nt cygwin))
-                                ;; cannot have "po:" in file name
-                                (substring file 3)
+                            (if (memq system-type '(windows-nt cygwin ms-dos))
+                                ;; cannot have colons in file name
+                                (replace-regexp-in-string ":" "-" file)
                               file)))
                    ;; Use the directory of this pmail file
                    ;; because it's a nuisance to use the homedir
@@ -1695,7 +1705,7 @@ is non-nil if the user has supplied the password interactively.
                 (buffer-disable-undo errors)
                 (let ((args
                        (append
-                        (list pmail-movemail-program nil errors nil)
+                        (list (or pmail-movemail-program "movemail") nil errors nil)
                         (if pmail-preserve-inbox
                             (list "-p")
                           nil)
@@ -1903,7 +1913,7 @@ default, the current message is changed."
       (let ((attr-index (pmail-desc-get-attr-index attr)))
        (set-buffer pmail-buffer)
        (or msgnum (setq msgnum pmail-current-message))
-       (pmail-desc-set-attribute attr-index state msgnum)
+       (pmail-desc-set-attribute msgnum attr-index state)
         ;; Deal with the summary buffer.
         (when pmail-summary-buffer
          (pmail-summary-update msgnum))))))
@@ -2138,7 +2148,7 @@ If NO-SUMMARY is non-nil, then do not update the summary buffer."
         ;; Clear the "unseen" attribute when we show a message, unless
        ;; it is already cleared.
        (when (pmail-desc-attr-p pmail-desc-unseen-index n)
-         (pmail-desc-set-attribute pmail-desc-unseen-index nil n))
+         (pmail-desc-set-attribute n pmail-desc-unseen-index nil))
        (pmail-display-labels)
        ;; Deal with MIME
        (if (eq pmail-enable-mime t)
@@ -2549,7 +2559,7 @@ If N is negative, go forwards instead."
 (defun pmail-delete-message ()
   "Delete this message and stay on it."
   (interactive)
-  (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message)
+  (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
   (run-hooks 'pmail-delete-message-hook)
   (pmail-show-message pmail-current-message))
 
@@ -2563,7 +2573,7 @@ If N is negative, go forwards instead."
       (setq msg (1- msg)))
     (if (= msg 0)
        (error "No previous deleted message")
-      (pmail-desc-set-attribute pmail-desc-deleted-index nil msg)
+      (pmail-desc-set-attribute msg pmail-desc-deleted-index nil)
       (pmail-show-message msg)
       (if (pmail-summary-exists)
          (save-excursion
@@ -2579,7 +2589,7 @@ With prefix argument, delete and move backward.
 
 Returns t if a new message is displayed after the delete, or nil otherwise."
   (interactive "P")
-  (pmail-desc-set-attribute pmail-desc-deleted-index t pmail-current-message)
+  (pmail-desc-set-attribute pmail-current-message pmail-desc-deleted-index t)
   (run-hooks 'pmail-delete-message-hook)
   (let ((del-msg pmail-current-message))
     (if (pmail-summary-exists)
@@ -2616,11 +2626,11 @@ See also user-option `pmail-confirm-expunge'."
   (or (eq buffer-undo-list t) (setq buffer-undo-list nil))
   ;; Remove the messages from the buffer and from the Pmail message
   ;; descriptor vector.
+  (setq pmail-expunge-counter 0)
   (pmail-desc-prune-deleted-messages 'pmail-expunge-callback)
-  ;; Update the Pmail message counter, deal with the summary buffer,
-  ;; show the current message and update the User status.
-  (setq pmail-total-messages (pmail-desc-get-count))
-  (pmail-show-message pmail-current-message t)
+  (setq pmail-current-message (- pmail-current-message pmail-expunge-counter))
+  ;; Deal with the summary buffer and update
+  ;; the User status.
   (let* ((omax (- (buffer-size) (point-max)))
         (omin (- (buffer-size) (point-min)))
         (opoint (if (and (> pmail-current-message 0)
@@ -2645,8 +2655,11 @@ See also user-option `pmail-confirm-expunge'."
 (defun pmail-expunge-callback (n)
   "Called after message N has been pruned to update the current Pmail
   message counter."
-  (if (< n pmail-current-message)
-      (setq pmail-current-message (1- pmail-current-message))))
+  ;; Process the various possible states to set the current message
+  ;; counter.
+  (setq pmail-total-messages (1- pmail-total-messages))
+  (if (>= pmail-current-message n)
+      (setq pmail-expunge-counter (1+ pmail-expunge-counter))))
 
 ;;; mbox: ready
 (defun pmail-expunge ()
@@ -2747,15 +2760,15 @@ use \\[mail-yank-original] to yank the original message into it."
         ;; Remove unwanted names from reply-to, since Mail-Followup-To
         ;; header causes all the names in it to wind up in reply-to, not
         ;; in cc.  But if what's left is an empty list, use the original.
-        (let* ((reply-to-list (pmail-dont-reply-to reply-to)))
+        (let* ((reply-to-list (rmail-dont-reply-to reply-to)))
           (if (string= reply-to-list "") reply-to reply-to-list))
          subject
          (pmail-make-in-reply-to-field from date message-id)
          (if just-sender
              nil
            ;; mail-strip-quoted-names is NOT necessary for
-           ;; pmail-dont-reply-to to do its job.
-           (let* ((cc-list (pmail-dont-reply-to
+           ;; rmail-dont-reply-to to do its job.
+           (let* ((cc-list (rmail-dont-reply-to
                             (mail-strip-quoted-names
                              (if (null cc) to (concat to ", " cc))))))
              (if (string= cc-list "") nil cc-list)))
@@ -2772,7 +2785,8 @@ non-nil, otherwise clears it.  N is the message number.
 BUFFER, possibly narrowed, contains an mbox mail message."
   (save-excursion
     (set-buffer buffer)
-    (pmail-set-attribute attr state n)))
+    (pmail-set-attribute attr state n)
+    (pmail-show-message)))
 
 (defun pmail-mark-message (msgnum-list attr-index)
   "Set attribute ATTRIBUTE-INDEX in the message of the car of MSGNUM-LIST.
@@ -2782,7 +2796,7 @@ message buffers.  MSGNUM-LIST is a list of the form (MSGNUM)."
     (let ((n (car msgnum-list)))
       (set-buffer pmail-buffer)
       (pmail-narrow-to-message n)
-      (pmail-desc-set-attribute attr-index t n))))
+      (pmail-desc-set-attribute n attr-index t))))
 
 (defun pmail-narrow-to-message (n)
   "Narrow the current (pmail) buffer to bracket message N."
@@ -3099,20 +3113,12 @@ specifying headers which should not be copied into the new message."
     ;; Now start sending new message; default header fields from original.
     ;; Turn off the usual actions for initializing the message body
     ;; because we want to get only the text from the failure message.
-    ;;
-    ;; NOTE: the use of pmail-msgref-vector is a red flag.  I'm not
-    ;; sure (yet) what the right thing to do here is but I strongly
-    ;; suspect it needs something along the lines of:
-    ;; ...(pmail-desc-set-attribute pmail-desc-resent-index nil n)...
-    ;; The test to run to see the breakage and figure out what needs
-    ;; to be done is to cause a "resend" to happen and verify that it
-    ;; is either broken or works properly.  For now the unbound
-    ;; variable is being left intact. -pmr 8/12/2008
     (let (mail-signature mail-setup-hook)
       (if (pmail-start-mail nil nil nil nil nil pmail-this-buffer
                            (list (list 'pmail-mark-message
                                        pmail-this-buffer
-                                       (aref pmail-msgref-vector msgnum)
+                                       (with-current-buffer pmail-buffer
+                                         (pmail-desc-get-start msgnum))
                                        "retried")))
          ;; Insert original text as initial text of new draft message.
          ;; Bind inhibit-read-only since the header delimiter