From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sergey Poznyakoff Newsgroups: gmane.comp.gnu.mailutils.bugs,gmane.emacs.bugs Subject: [PATCH] bug#18130: rmail.el: handle imaps, pops, and local source mailboxes (maildir, MH, etc.) Date: Sat, 16 Aug 2014 15:53:24 +0300 Organization: GNU.org.ua Message-ID: <20140816155324.14384@ulysses.gnu.org.ua> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1408194209 5035 80.91.229.3 (16 Aug 2014 13:03:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 16 Aug 2014 13:03:29 +0000 (UTC) Cc: Carlos Pita , bug-mailutils@gnu.org To: Original-X-From: bug-mailutils-bounces+gcgmb-bug-mailutils=gmane.org@gnu.org Sat Aug 16 15:03:24 2014 Return-path: Envelope-to: gcgmb-bug-mailutils@gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XIdda-0000ZA-Rd for gcgmb-bug-mailutils@gmane.org; Sat, 16 Aug 2014 15:03:15 +0200 Original-Received: from localhost ([::1]:35405 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIdda-00065H-GF for gcgmb-bug-mailutils@gmane.org; Sat, 16 Aug 2014 09:03:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIddT-00065B-0X for bug-mailutils@gnu.org; Sat, 16 Aug 2014 09:03:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XIddO-0007V0-3U for bug-mailutils@gnu.org; Sat, 16 Aug 2014 09:03:06 -0400 Original-Received: from ulysses.gnu.org.ua ([193.186.15.43]:56189 helo=gnu.org.ua) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XIddN-0007Um-NX; Sat, 16 Aug 2014 09:03:02 -0400 X-Mailutils-Message-Id: s7GCrOZv014388 Original-Received: from gnu.org.ua (localhost [127.0.0.1]) by ulysses.gnu.org.ua with ESMTP id s7GCrOZv014388; Sat, 16 Aug 2014 15:53:24 +0300 X-Mailer: MH-E 8.3.1; GNU Mailutils 2.99.98; GNU Emacs 24.2.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.186.15.43 X-BeenThere: bug-mailutils@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports and feature requests for GNU mailutils List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-mailutils-bounces+gcgmb-bug-mailutils=gmane.org@gnu.org Original-Sender: bug-mailutils-bounces+gcgmb-bug-mailutils=gmane.org@gnu.org Xref: news.gmane.org gmane.comp.gnu.mailutils.bugs:1980 gmane.emacs.bugs:92487 Archived-At: Hello, When used with GNU Mailutils movemail, rmail handles only imap and pop mailboxes[1]. However, the Mailutils movemail supports a much wider set of mailbox formats (both remote and local). This patch makes rmail.el fully use the flexibility of GNU Mailutils. In particular, it makes it possible to use imaps and pops encrypted protocols. The patch is against the current Emacs trunk. The bug has been reported by Carlos Pita to both GNU Emacs[2] and Mailutuls[3]. [1] http://lists.gnu.org/archive/html/bug-mailutils/2014-07/msg00008.html. [2] http://lists.gnu.org/archive/html/bug-gnu-emacs/2014-07/msg00867.html http://lists.gnu.org/archive/html/bug-gnu-emacs/2014-07/msg00869.html [3] http://lists.gnu.org/archive/html/bug-mailutils/2014-08/msg00000.html. * lisp/mail/rmail.el (rmail-remote-proto-p): New function. (rmail-parse-url): Return actual proto in the 2nd list element instead of the mere t. All callers updated. Do not require password unless the argument refers to a remote mailbox. (rmail-insert-inbox-text): Select a proper message depending on whether source mailbox is a remote one or not. Hanlde non-plainfile local source mailboxes (maildir, MH, etc.) --- lisp/mail/rmail.el | 58 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index f769204..a3d6343 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el @@ -1869,13 +1869,16 @@ not be a new one). It returns non-nil if it got any new messages." (setq result (> new-messages 0)) result)))) +(defun rmail-remote-proto-p (proto) + (string-match "^\\(\\(imap\\|pop\\)s?\\)$" proto)) + (defun rmail-parse-url (file) - "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD) + "Parse the supplied URL. Return (list MAILBOX-NAME PROTO PASSWORD GOT-PASSWORD) WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the -actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to -a remote mailbox, PASSWORD is the password if it should be -supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD -is non-nil if the user has supplied the password interactively. +actual version of `movemail', PROTO is the protocol (use rmail-remote-proto-p +to see if it refers to a remote mailbox), PASSWORD is the password if it +should be supplied as a separate argument to `movemail' or nil otherwise, +GOT-PASSWORD is non-nil if the user has supplied the password interactively. " (cond ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file) @@ -1886,24 +1889,26 @@ is non-nil if the user has supplied the password interactively. (host (substring file (or (match-end 2) (+ 3 (match-end 1)))))) - (if (not pass) - (when rmail-remote-password-required - (setq got-password (not (rmail-have-password))) - (setq supplied-password (rmail-get-remote-password - (string-equal proto "imap")))) - ;; The password is embedded. Strip it out since movemail - ;; does not really like it, in spite of the movemail spec. - (setq file (concat proto "://" user "@" host))) + (if (rmail-remote-proto-p proto) + (if (not pass) + (when rmail-remote-password-required + (setq got-password (not (rmail-have-password))) + (setq supplied-password (rmail-get-remote-password + (string-match "imaps?" proto)))) + ;; FIXME + ;; The password is embedded. Strip it out since movemail + ;; does not really like it, in spite of the movemail spec. + (setq file (concat proto "://" user "@" host)))) (if (rmail-movemail-variant-p 'emacs) (if (string-equal proto "pop") (list (concat "po:" user ":" host) - t + proto (or pass supplied-password) got-password) (error "Emacs movemail does not support %s protocol" proto)) (list file - (or (string-equal proto "pop") (string-equal proto "imap")) + proto (or supplied-password pass) got-password)))) @@ -1971,18 +1976,18 @@ Value is the size of the newly read mail after conversion." (or (memq (file-locked-p buffer-file-name) '(nil t)) (error "RMAIL file %s is locked" (file-name-nondirectory buffer-file-name))) - (let (file tofile delete-files movemail popmail got-password password) + (let (file tofile delete-files movemail proto got-password password) (while files ;; Handle remote mailbox names specially; don't expand as filenames ;; in case the userid contains a directory separator. (setq file (car files)) (let ((url-data (rmail-parse-url file))) (setq file (nth 0 url-data)) - (setq popmail (nth 1 url-data)) + (setq proto (nth 1 url-data)) (setq password (nth 2 url-data)) (setq got-password (nth 3 url-data))) - (if popmail + (if proto (setq renamep t) (setq file (file-truename (substitute-in-file-name (expand-file-name file))))) @@ -2003,14 +2008,16 @@ Value is the size of the newly read mail after conversion." (expand-file-name buffer-file-name)))) ;; Always use movemail to rename the file, ;; since there can be mailboxes in various directories. - (when (not popmail) + (when (not proto) ;; On some systems, /usr/spool/mail/foo is a directory ;; and the actual inbox is /usr/spool/mail/foo/foo. (if (file-directory-p file) (setq file (expand-file-name (user-login-name) file)))) - (cond (popmail - (message "Getting mail from the remote server ...")) + (cond (proto + (message (if (rmail-remote-proto-p proto) + "Getting mail from the remote server ..." + (concat "Getting mail from " proto)))) ((and (file-exists-p tofile) (/= 0 (nth 7 (file-attributes tofile)))) (message "Getting mail from %s..." tofile)) @@ -2021,7 +2028,7 @@ Value is the size of the newly read mail after conversion." ;; rename or copy the file FILE to TOFILE if and as appropriate. (cond ((not renamep) (setq tofile file)) - ((or (file-exists-p tofile) (and (not popmail) + ((or (file-exists-p tofile) (and (not proto) (not (file-exists-p file)))) nil) (t @@ -2056,9 +2063,10 @@ Value is the size of the newly read mail after conversion." ;; If we just read the password, most likely it is ;; wrong. Otherwise, see if there is a specific ;; reason to think that the problem is a wrong passwd. - (if (or got-password - (re-search-forward rmail-remote-password-error - nil t)) + (if (and (rmail-remote-proto-p proto) + (or got-password + (re-search-forward rmail-remote-password-error + nil t))) (rmail-set-remote-password nil)) ;; If using Mailutils, remove initial error code -- 1.7.12.1