all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* multiple POP support for RMAIL
@ 2004-02-21 21:56 Thien-Thi Nguyen
  2004-02-22  0:05 ` Robert J. Chassell
  0 siblings, 1 reply; 5+ messages in thread
From: Thien-Thi Nguyen @ 2004-02-21 21:56 UTC (permalink / raw)


RMS asks in message:

 http://mail.gnu.org/archive/html/emacs-devel/2003-04/msg00216.html

if anyone wants to implement multiple POP support for RMAIL.

please find below a diff against cvs HEAD rmail.el that does the job, w/
the design constraint of being backward compatible w/ the user command
`rmail-set-pop-password'.  if this constraint can be avoided, it should
be possible to come up w/ a cleaner design, but IMHO it's not worth it.
(put enough design effort to RMAIL pop support and you wind up w/ Gnus
and/or the question of "why not use Gnus?".)

this has been tested (by an interested non-programmer emacs user -- i
don't use POP mail personally so i don't have a way to test it w/ cvs
HEAD) by back porting the change to 21.3 rmail.el.

here is a small blurb that can be massaged into the docs:

 If you wish to receive mail from more than one POP
 account, you must set @code{rmail-pop-password} to
 nil, @code{rmail-pop-password-required} non-nil, and
 include appropriate @code{po:USER:HOSTNAME} entries
 in @code{rmail-primary-inbox-list}.  This causes
 Emacs to prompt you for each account's password once
 per session; there is currently no way to specify
 multiple passwords non-interactively.

that last part sticks in my craw a bit, but fwiw the tester doesn't seem
to mind the extra interaction w/ emacs in exchange for the new support.

thi




Index: rmail.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/mail/rmail.el,v
retrieving revision 1.385
diff -c -p -w -c -r1.385 rmail.el
*** rmail.el	17 Feb 2004 19:54:49 -0000	1.385
--- rmail.el	19 Feb 2004 08:43:13 -0000
*************** unknown user name or bad password"
*** 122,127 ****
--- 122,129 ----
  If you get an incorrect-password error that this expression does not match,
  please report it with \\[report-emacs-bug].")

+ ;; Alist associating pop server w/ password.  If there is only one pop server
+ ;; specified in `rmail-primary-inbox-list', key `t' is used for that.
  (defvar rmail-encoded-pop-password nil)

  (defcustom rmail-preserve-inbox nil
*************** It returns t if it got any new messages.
*** 1518,1524 ****
    (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)
      (while files
        ;; Handle POP mailbox names specially; don't expand as filenames
        ;; in case the userid contains a directory separator.
--- 1520,1532 ----
    (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
!              ;; wasteful --ttn
!              (popcount (apply '+ (mapcar (function
!                                           (lambda (file)
!                                             (if (string-match "^po:" file)
!                                                 1 0)))
!                                          files))))
      (while files
        ;; Handle POP mailbox names specially; don't expand as filenames
        ;; in case the userid contains a directory separator.
*************** It returns t if it got any new messages.
*** 1557,1564 ****
  					     file)))))
        (cond (popmail
  	     (if rmail-pop-password-required
! 		 (progn (setq got-password (not (rmail-have-password)))
! 			(setq password (rmail-get-pop-password))))
  	     (if (memq system-type '(windows-nt cygwin))
  		 ;; cannot have "po:" in file name
  		 (setq tofile
--- 1565,1575 ----
  					     file)))))
        (cond (popmail
  	     (if rmail-pop-password-required
!                  (let ((host (unless (= 1 popcount)
!                                (string-match ".+:" file)
!                                (substring file (match-end 0)))))
!                    (setq got-password (not (rmail-have-password host)))
!                    (setq password (rmail-get-pop-password host))))
  	     (if (memq system-type '(windows-nt cygwin))
  		 ;; cannot have "po:" in file name
  		 (setq tofile
*************** TEXT and INDENT are not used."
*** 3824,3850 ****
  ; nor is it meant to be.

  ;;;###autoload
! (defun rmail-set-pop-password (password)
    "Set PASSWORD to be used for retrieving mail from a POP server."
    (interactive "sPassword: ")
    (if password
        (setq rmail-encoded-pop-password
! 	    (rmail-encode-string password (emacs-pid)))
      (setq rmail-pop-password nil)
      (setq rmail-encoded-pop-password nil)))

! (defun rmail-get-pop-password ()
    "Get the password for retrieving mail from a POP server.  If none
! has been set, then prompt the user for one."
!   (if (not rmail-encoded-pop-password)
!       (progn (if (not rmail-pop-password)
! 		 (setq rmail-pop-password (read-passwd "POP password: ")))
! 	     (rmail-set-pop-password rmail-pop-password)
! 	     (setq rmail-pop-password nil)))
!   (rmail-encode-string rmail-encoded-pop-password (emacs-pid)))
!
! (defun rmail-have-password ()
!   (or rmail-pop-password rmail-encoded-pop-password))

  (defun rmail-encode-string (string mask)
   "Encode STRING with integer MASK, by taking the exclusive OR of the
--- 3835,3871 ----
  ; nor is it meant to be.

  ;;;###autoload
! (defun rmail-set-pop-password (password &optional host)
    "Set PASSWORD to be used for retrieving mail from a POP server."
    (interactive "sPassword: ")
    (if password
        (setq rmail-encoded-pop-password
!             (cons (cons (or host t) (rmail-encode-string password (emacs-pid)))
!                   rmail-encoded-pop-password))
      (setq rmail-pop-password nil)
      (setq rmail-encoded-pop-password nil)))

! (defun rmail-get-pop-password (&optional host)
    "Get the password for retrieving mail from a POP server.  If none
! has been set, then prompt the user for one.  Optional arg HOST means
! this password is to be used for HOST only."
!   (when (or (not rmail-encoded-pop-password)
!             (and host (not (assoc host rmail-encoded-pop-password))))
!     (when (not rmail-pop-password)
!       (setq rmail-pop-password
!             (read-passwd (format "POP password%s: "
!                                  (if (stringp host)
!                                      (concat " for " host)
!                                    "")))))
!     (rmail-set-pop-password rmail-pop-password host)
!     (setq rmail-pop-password nil))
!   (rmail-encode-string (cdr (assoc (or host t) rmail-encoded-pop-password))
!                        (emacs-pid)))
!
! (defun rmail-have-password (&optional host)
!   (or rmail-pop-password
!       (and rmail-encoded-pop-password
!            (assoc (or host t) rmail-encoded-pop-password))))

  (defun rmail-encode-string (string mask)
   "Encode STRING with integer MASK, by taking the exclusive OR of the

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: multiple POP support for RMAIL
  2004-02-21 21:56 multiple POP support for RMAIL Thien-Thi Nguyen
@ 2004-02-22  0:05 ` Robert J. Chassell
  2004-02-22 11:14   ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Robert J. Chassell @ 2004-02-22  0:05 UTC (permalink / raw)


ttn@glug.org did a wonderful thing, with is create
multiple POP support for RMAIL, but he also wrote 

    ...there is currently no way to specify multiple passwords
    non-interactively.

Please implement this feature:  I would very much like to fetch
various email accounts using POP.  At the moment I can only fetch one.
There are 3 others I would like to fetch.  (Right now, I use lftp for
those, which I do not like at all.)

Unfortunately, I lack the time to type in the passwords interactively;
worse, I cannot remember the passwords.  I have a hard enough time
remembering a password for `ssh-agent'.  I should be able to specify
`M-x rmail' and not have to remember any passwords.

Thank you.

(Sadly, Gnus is not an option for me:  when I last spent several days
a couple of years ago trying to configure Gnus for email, I was unable
to figure out and no one was able to tell me how to configure Gnus to
highlight each of the following differently, a minimum of 4 different
highlighting looks for 7 different types of entity:

        in the *Group* buffer

            Summary buffer with unread new email in it
            Summary buffer with unread old email in it
            Summary buffer with only read email in it

        in a *Summary* buffer

            new unread email messages
            old unread email messages
            read email messages

        in any buffer

             that which is marked for deletion 

(Some faces could be specified, but not those I wanted.

(Presumably, `old' is specifed in one of a choice of several ways,
such as `1 day' or `since last invocation of Gnus', or `since last 4
invocations of Gnus'.  I cannot remember what I chose.

(Also, I looked for, but could not find a definitive statement on what
to do actively to prevent automatic `expiration'.  Various people
assured me that the previous documentation I had read that old
messages would be deleted automatically was no longer true, but no one
could provide a clue to how to make sure overtly that Gnus never, ever
mistook old email messages for news messages.

(I know that many people use Gnus and find it wonderful.  My hunch is
that if I could configure it happily, I too would find it wonderful.
It is all a matter of how people do their work and how important
security is.)

-- 
    Robert J. Chassell                         Rattlesnake Enterprises
    http://www.rattlesnake.com                  GnuPG Key ID: 004B4AC8
    http://www.teak.cc                             bob@rattlesnake.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: multiple POP support for RMAIL
  2004-02-22  0:05 ` Robert J. Chassell
@ 2004-02-22 11:14   ` Thien-Thi Nguyen
  2004-02-22 13:43     ` Robert J. Chassell
  0 siblings, 1 reply; 5+ messages in thread
From: Thien-Thi Nguyen @ 2004-02-22 11:14 UTC (permalink / raw)
  Cc: emacs-devel

"Robert J. Chassell" <bob@rattlesnake.com> writes:

       ...there is currently no way to specify multiple passwords
       non-interactively.

   Please implement this feature

actually the code posted does indeed support this usage, although it is
not a very clean interface (IMO), and hence left undocumented to allow a
freer hand to change it based on the outcome of this discussion.

basically, you can evaluate:

(rmail-set-pop-password PASSWORD-1 HOST-1)
(rmail-set-pop-password PASSWORD-2 HOST-2)
  ...

where each HOST-N appears in `rmail-primary-inbox-list'.  although this
works, it is ugly to me because it requires the user to synchronize host
names in two places.  on the other hand, that may not be such a big deal
in practice, and in fact, this scheme makes it easy to place such forms
in a separate chmod go-rwx file (i.e., a security feature of sorts).

what do you think of `rmail-pop-password-required' being allowed to name
a file containing (HOST . PASSWORD) pairs?  this file would be (re-)read
at the appropriate times, and after `M-x rmail-set-pop-password RET RET'.
i chose pairs deliberately to limit the generality of this file -- this
goes back to my reluctance at getting into Gnus-ish design/impl territory.

thi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: multiple POP support for RMAIL
  2004-02-22 11:14   ` Thien-Thi Nguyen
@ 2004-02-22 13:43     ` Robert J. Chassell
  2004-03-06 22:31       ` Thien-Thi Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Robert J. Chassell @ 2004-02-22 13:43 UTC (permalink / raw)


          ...there is currently no way to specify multiple passwords
          non-interactively.

      Please implement this feature

Thien-Thi Nguyen <ttn@glug.org> responded

   actually the code posted does indeed support this usage, ...

Thank you for explaining.  Unfortunately, I tried what I understood to
do and it fails.

I evaluated the following:

    (setq rmail-pop-password nil)
    (setq rmail-pop-password-required t)
    (setq rmail-primary-inbox-list '("po:AAA:foo.edu" 
                                     "po:AAA:bar.net"
                                     "po:BBB:bar.net"
                                     "po:CCC:bar.net"))
    (rmail-set-pop-password "XXX" "foo.edu")
    (rmail-set-pop-password "YYY" "bar.net")
    (rmail-set-pop-password "ZZZ" "bar.net")
    (rmail-set-pop-password "ZZZ" "bar.net")

and then tried to fetch email from my four different accounts.
Instead, I received this error message:

    Getting mail from post office ...
    movemail: Error connecting to POP server: 
        -ERR [AUTH] Password supplied for "bob" is incorrect.
    (No new mail has arrived)

Note that I have the same user name for two different accounts,

    AAA on foo.edu and AAA on bar.net

and the same password on BBB@bar.net and on CCC@bar.net

Thinking that the overlap caused trouble, I commented out

    ;;    (rmail-set-pop-password "YYY" "bar.net")
    ;;    (rmail-set-pop-password "ZZZ" "bar.net")

and reevaluated the other expressions and still received the same
message. (However, I did not set any values to nil first, but that
should not have mattered.)

Before I could fetch email from the one POP account, I had to do this,
including set the various values to nil first (which I find strange):

    (setq rmail-pop-password-required nil)
    (setq rmail-primary-inbox-list '(nil))
    (rmail-set-pop-password nil nil)

    (setq rmail-primary-inbox-list '("po:AAA:foo.edu" "/var/mail/AAA"))
    (setq rmail-pop-password-required t)
    (setq rmail-pop-password "XXX")
    (setq rmail-preserve-inbox nil)

(Normally, I set

 (setq rmail-preserve-inbox nil)

but this time I wanted to make sure I would not lose it.)

(Incidentally, I think the format for rmail-primary-inbox-list should
be

    [METHOD:][USER@](HOST|PATH|HOST/PATH)[:PASSWORD]

such as

    (setq rmail-primary-inbox-list 
     '("po:AAA@foo.edu:XXX" 
       "po:BBB@bar.net/weird/path/to/BBB:YYY"
       "/var/mail/AAA"))

where POP is the default method, the local account's USER is the
default user, localmachine is the default HOST, "/var/mail/USER" is
the default path, and the local account's PASSWORD is the default
password.  Following ttn's good suggestion, this expression could go
into a separate `chmod go-rwx' file to provide at least some security,
like a .netrc file.)

-- 
    Robert J. Chassell                         Rattlesnake Enterprises
    http://www.rattlesnake.com                  GnuPG Key ID: 004B4AC8
    http://www.teak.cc                             bob@rattlesnake.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: multiple POP support for RMAIL
  2004-02-22 13:43     ` Robert J. Chassell
@ 2004-03-06 22:31       ` Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2004-03-06 22:31 UTC (permalink / raw)
  Cc: emacs-devel

"Robert J. Chassell" <bob@rattlesnake.com> writes:

   [problems]

   and reevaluated the other expressions and still received the same
   message. (However, I did not set any values to nil first, but that
   should not have mattered.)

well, there is a slightly tricky interlock involved, so that re-init w/
nil values would probably have helped.  in any case, i think i'll just
go all the way and support full specification (of POP accounts) from a
separate file.  thanks for your suggestions and detailed observations.
hopefully the next revision posted will be less troublesome.

thi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-03-06 22:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-21 21:56 multiple POP support for RMAIL Thien-Thi Nguyen
2004-02-22  0:05 ` Robert J. Chassell
2004-02-22 11:14   ` Thien-Thi Nguyen
2004-02-22 13:43     ` Robert J. Chassell
2004-03-06 22:31       ` Thien-Thi Nguyen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.