Subject: bug#31737: 26.1.50; Gnus does not use mailutils movemail

From: Robert Pluim <[email-masked]>
Date: Thu, 14 Jun 2018 15:04:20 +0200

Robert Pluim <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Robert Pluim <[email-masked]>
>>> Cc: Eli Zaretskii <[email-masked]>,  Colin Baxter <[email-masked]>,  [email-masked]
>>> Date: Wed, 13 Jun 2018 16:08:53 +0200
>>> 
>>> Eli, were you thinking that mail-source should duplicate the movemail
>>> detection logic in rmail? Or should it just assume Mailutils movemail
>>> and pass '--emacs'?
>>
>> The former.
>
> Something like this? Testing definitely required by someone who uses
> mailutils movemail for Gnus. Not sure this is emacs-26 material
> anymore.

*sigh*. With the typo fixed now.

diff --git i/lisp/gnus/mail-source.el w/lisp/gnus/mail-source.el
index d2850f4cee..37bcb716f9 100644
--- i/lisp/gnus/mail-source.el
+++ w/lisp/gnus/mail-source.el
@@ -301,7 +301,7 @@ mail-source-idle-time-delay
   :group 'mail-source
   :type 'number)
 
-(defcustom mail-source-movemail-program nil
+(defcustom mail-source-movemail-program "movemail"
   "If non-nil, name of program for fetching new mail."
   :version "22.1"
   :group 'mail-source
@@ -653,6 +653,12 @@ mail-source-delete-crash-box
 	     mail-source-delete-incoming
 	     mail-source-delete-old-incoming-confirm)))))))
 
+(defun mail-source-movemail-variant-p (variant)
+  "Return t if the current movemail variant is VARIANT.
+See `rmail-movemail-variant-p' for details"
+  (let ((rmail-movemail-program mail-source-movemail-program))
+    (rmail-movemail-variant-p variant)))
+
 (defun mail-source-movemail (from to)
   "Move FROM to TO using movemail."
   (if (not (file-writable-p to))
@@ -682,13 +688,20 @@ mail-source-movemail
 	      (setq errors (generate-new-buffer " *mail source loss*"))
 	      (let ((default-directory "/"))
 		(setq result
+                      ;; call-proces looks in exec-path, which
+                      ;; contains exec-directory, so will find
+                      ;; Mailutils movemail if it exists, else it will
+                      ;; find "our" movemail in exec-directory.
+                      ;; Bug#31737
 		      (apply
 		       'call-process
 		       (append
 			(list
-			 (or mail-source-movemail-program
-			     (expand-file-name "movemail" exec-directory))
-			 nil errors nil from to)))))
+			 mail-source-movemail-program
+			 nil errors nil)
+                        (when (mail-source-movemail-variant-p 'mailutils)
+                          (list "--emacs"))
+                        (list from to)))))
 	      (when (file-exists-p to)
 		(set-file-modes to mail-source-default-file-modes))
 	      (if (and (or (not (buffer-modified-p errors))