aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Poznyakoff2017-04-08 18:40:53 -0700
committerGlenn Morris2017-04-08 18:40:53 -0700
commit48536f67e009bb8c5e2d5a0ee38f50cd546a84c6 (patch)
tree10ad6ce88dea4d7cbee88f51a9e47ce49667c61a
parent79b1669c24fc57d6613e0ae660b277a1b37d724a (diff)
downloademacs-48536f67e009bb8c5e2d5a0ee38f50cd546a84c6.tar.gz
emacs-48536f67e009bb8c5e2d5a0ee38f50cd546a84c6.zip
Fix rmail handling of movemail protocols (bug#18278)
* lisp/mail/rmail.el (rmail-remote-proto-p): New function. (rmail-parse-url): Return protocol in second list element. Only use passwords with remote mailboxes. (rmail-insert-inbox-text): Handle non-simple local mailboxes (maildir, MH, etc.).
-rw-r--r--lisp/mail/rmail.el65
1 files changed, 38 insertions, 27 deletions
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 4b72b3562d1..209b5a7140b 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -1884,14 +1884,19 @@ not be a new one). It returns non-nil if it got any new messages."
1884 (setq result (> new-messages 0)) 1884 (setq result (> new-messages 0))
1885 result)))) 1885 result))))
1886 1886
1887(defun rmail-remote-proto-p (proto)
1888 "Return non-nil if string PROTO refers to a remote mailbox protocol."
1889 (string-match-p "^\\(imap\\|pop\\)s?$" proto))
1890
1887(defun rmail-parse-url (file) 1891(defun rmail-parse-url (file)
1888 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD) 1892 "Parse a mailbox URL string FILE.
1889WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the 1893Return (MAILBOX-NAME PROTO PASSWORD GOT-PASSWORD), where MAILBOX-NAME is
1890actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to 1894the name of the mailbox suitable as argument to the actual version of
1891a remote mailbox, PASSWORD is the password if it should be 1895`movemail', PROTO is the movemail protocol (use `rmail-remote-proto-p'
1892supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD 1896to see if it refers to a remote mailbox), PASSWORD is the password if it
1893is non-nil if the user has supplied the password interactively. 1897should be supplied as a separate argument to `movemail' or nil otherwise,
1894" 1898and GOT-PASSWORD is non-nil if the user has supplied the password
1899interactively."
1895 (cond 1900 (cond
1896 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file) 1901 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file)
1897 (let (got-password supplied-password 1902 (let (got-password supplied-password
@@ -1901,24 +1906,26 @@ is non-nil if the user has supplied the password interactively.
1901 (host (substring file (or (match-end 2) 1906 (host (substring file (or (match-end 2)
1902 (+ 3 (match-end 1)))))) 1907 (+ 3 (match-end 1))))))
1903 1908
1904 (if (not pass) 1909 (if (rmail-remote-proto-p proto)
1905 (when rmail-remote-password-required 1910 (if (not pass)
1906 (setq got-password (not (rmail-have-password))) 1911 (when rmail-remote-password-required
1907 (setq supplied-password (rmail-get-remote-password 1912 (setq got-password (not (rmail-have-password)))
1908 (string-equal proto "imap")))) 1913 (setq supplied-password (rmail-get-remote-password
1909 ;; The password is embedded. Strip it out since movemail 1914 (string-match "^imaps?" proto))))
1910 ;; does not really like it, in spite of the movemail spec. 1915 ;; FIXME
1911 (setq file (concat proto "://" user "@" host))) 1916 ;; The password is embedded. Strip it out since movemail
1917 ;; does not really like it, in spite of the movemail spec.
1918 (setq file (concat proto "://" user "@" host))))
1912 1919
1913 (if (rmail-movemail-variant-p 'emacs) 1920 (if (rmail-movemail-variant-p 'emacs)
1914 (if (string-equal proto "pop") 1921 (if (string-equal proto "pop")
1915 (list (concat "po:" user ":" host) 1922 (list (concat "po:" user ":" host)
1916 t 1923 proto
1917 (or pass supplied-password) 1924 (or pass supplied-password)
1918 got-password) 1925 got-password)
1919 (error "Emacs movemail does not support %s protocol" proto)) 1926 (error "Emacs movemail does not support %s protocol" proto))
1920 (list file 1927 (list file
1921 (or (string-equal proto "pop") (string-equal proto "imap")) 1928 proto
1922 (or supplied-password pass) 1929 (or supplied-password pass)
1923 got-password)))) 1930 got-password))))
1924 1931
@@ -1981,18 +1988,18 @@ Value is the size of the newly read mail after conversion."
1981 size)) 1988 size))
1982 1989
1983(defun rmail-insert-inbox-text (files renamep) 1990(defun rmail-insert-inbox-text (files renamep)
1984 (let (file tofile delete-files popmail got-password password) 1991 (let (file tofile delete-files proto got-password password)
1985 (while files 1992 (while files
1986 ;; Handle remote mailbox names specially; don't expand as filenames 1993 ;; Handle remote mailbox names specially; don't expand as filenames
1987 ;; in case the userid contains a directory separator. 1994 ;; in case the userid contains a directory separator.
1988 (setq file (car files)) 1995 (setq file (car files))
1989 (let ((url-data (rmail-parse-url file))) 1996 (let ((url-data (rmail-parse-url file)))
1990 (setq file (nth 0 url-data)) 1997 (setq file (nth 0 url-data))
1991 (setq popmail (nth 1 url-data)) 1998 (setq proto (nth 1 url-data))
1992 (setq password (nth 2 url-data)) 1999 (setq password (nth 2 url-data))
1993 (setq got-password (nth 3 url-data))) 2000 (setq got-password (nth 3 url-data)))
1994 2001
1995 (if popmail 2002 (if proto
1996 (setq renamep t) 2003 (setq renamep t)
1997 (setq file (file-truename 2004 (setq file (file-truename
1998 (substitute-in-file-name (expand-file-name file))))) 2005 (substitute-in-file-name (expand-file-name file)))))
@@ -2013,14 +2020,17 @@ Value is the size of the newly read mail after conversion."
2013 (expand-file-name buffer-file-name)))) 2020 (expand-file-name buffer-file-name))))
2014 ;; Always use movemail to rename the file, 2021 ;; Always use movemail to rename the file,
2015 ;; since there can be mailboxes in various directories. 2022 ;; since there can be mailboxes in various directories.
2016 (when (not popmail) 2023 (when (not proto)
2017 ;; On some systems, /usr/spool/mail/foo is a directory 2024 ;; On some systems, /usr/spool/mail/foo is a directory
2018 ;; and the actual inbox is /usr/spool/mail/foo/foo. 2025 ;; and the actual inbox is /usr/spool/mail/foo/foo.
2019 (if (file-directory-p file) 2026 (if (file-directory-p file)
2020 (setq file (expand-file-name (user-login-name) 2027 (setq file (expand-file-name (user-login-name)
2021 file)))) 2028 file))))
2022 (cond (popmail 2029 (cond (proto
2023 (message "Getting mail from the remote server ...")) 2030 (message "Getting mail from %s..."
2031 (if (rmail-remote-proto-p proto)
2032 "the remote server"
2033 proto)))
2024 ((and (file-exists-p tofile) 2034 ((and (file-exists-p tofile)
2025 (/= 0 (nth 7 (file-attributes tofile)))) 2035 (/= 0 (nth 7 (file-attributes tofile))))
2026 (message "Getting mail from %s..." tofile)) 2036 (message "Getting mail from %s..." tofile))
@@ -2031,7 +2041,7 @@ Value is the size of the newly read mail after conversion."
2031 ;; rename or copy the file FILE to TOFILE if and as appropriate. 2041 ;; rename or copy the file FILE to TOFILE if and as appropriate.
2032 (cond ((not renamep) 2042 (cond ((not renamep)
2033 (setq tofile file)) 2043 (setq tofile file))
2034 ((or (file-exists-p tofile) (and (not popmail) 2044 ((or (file-exists-p tofile) (and (not proto)
2035 (not (file-exists-p file)))) 2045 (not (file-exists-p file))))
2036 nil) 2046 nil)
2037 (t 2047 (t
@@ -2066,9 +2076,10 @@ Value is the size of the newly read mail after conversion."
2066 ;; If we just read the password, most likely it is 2076 ;; If we just read the password, most likely it is
2067 ;; wrong. Otherwise, see if there is a specific 2077 ;; wrong. Otherwise, see if there is a specific
2068 ;; reason to think that the problem is a wrong passwd. 2078 ;; reason to think that the problem is a wrong passwd.
2069 (if (or got-password 2079 (if (and (rmail-remote-proto-p proto)
2070 (re-search-forward rmail-remote-password-error 2080 (or got-password
2071 nil t)) 2081 (re-search-forward rmail-remote-password-error
2082 nil t)))
2072 (rmail-set-remote-password nil)) 2083 (rmail-set-remote-password nil))
2073 2084
2074 ;; If using Mailutils, remove initial error code 2085 ;; If using Mailutils, remove initial error code