all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Help with simple function
@ 2003-01-09 16:22 Peter Davis
  2003-01-09 19:26 ` Kalle Olavi Niemitalo
  2003-01-09 19:28 ` Adrian Aichner
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Davis @ 2003-01-09 16:22 UTC (permalink / raw)



I'm using gnus to read mail and news.  For various reasons (explained
below, if anyone's interested), I use my own Perl script to fetch mail
from a couple of different POP3 servers.  I have a simple function
which calls the Perl script:

(defun pd-fetch-mail ()
  (interactive)
  (message "Running popfetch.pl... ")
  (shell-command "perl c:/home/popfetch.pl")
  )

This works perfectly.  However, because the Perl script is stateless,
I keep all the POP account information, including passwords, in a
file.  I *hate* that.  What I'd like to do is:

1) Keep all the POP account info in a list, sort of like:

    (setq pop-servers '((:server mail.myhomeisp.com
                         :username "pd"
                         :password ""
                         :lmos t)
                        (:server mail.mywork.com
                         :username "pdavis"
                         :password ""
                         :lmos nil)
                        ))

2) Have emacs/XEmacs prompt for the password the first time this is
   used, and store it in there (so I don't have to keep it in my .gnus
   file)

3) Call the Perl script once for each server, passing the arguments,
   password, etc.

I'm sure this can all be done, but I'm not lisp-savvy enough to know
how to do it.  Anyone have some code that does anything like this that
I can use as a starting point?  I don't even know how to create the
pop-servers variable so it will accept this list format.

Thanks *very* much,

-pd


P.S. - If you want to know *why* I'm using my own Perl script, it's
basically for two reasons:

1) I keep track of UIDLs, so can I leave messages on the POP server,
   and not fetch them over and over again, and

2) I add X-POP-Server and X-POP-UIDL fields to the mail headers.  I
   have another lisp function which writes the UIDL to a file whose
   name is the server name.  That way, I can selectively delete
   messages from the POP server if I've left them there.


-- 
--------
                             Peter Davis
               Funny stuff at http://www.pfdstudio.com
                 The artwork formerly shown as prints
    List of resources for children's writers and illustrators at:
                  http://www.pfdstudio.com/cwrl.html

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

* Re: Help with simple function
  2003-01-09 16:22 Help with simple function Peter Davis
@ 2003-01-09 19:26 ` Kalle Olavi Niemitalo
  2003-01-09 20:24   ` Peter Davis
  2003-01-09 19:28 ` Adrian Aichner
  1 sibling, 1 reply; 7+ messages in thread
From: Kalle Olavi Niemitalo @ 2003-01-09 19:26 UTC (permalink / raw)


Peter Davis <pd@world.std.com> writes:

> I don't even know how to create the pop-servers variable so it
> will accept this list format.

If you assign a value to a variable (with setq), you implicitly
create it.  Variables thus created accept all types of values.
Only some built-in variables have type restrictions.

Of course, there is plenty of code that assumes that the value of
compile-command is a string, for example; but if you choose a
name that is not already in use, there is no conflict.

> 2) Have emacs/XEmacs prompt for the password the first time this is
>    used, and store it in there (so I don't have to keep it in my .gnus
>    file)

(defun pd-server-password (server)
  "Return the password for SERVER.
If it is empty, prompt for it and save the value."
  (let ((password (plist-get server :password)))
    (when (equal password "")
      (setq password (read-passwd (format "Password for %s@%s: "
					  (plist-get server :username)
					  (plist-get server :server))))
      ;; The docstring of plist-put says you should save the value it
      ;; returns.  However, we know that :password is already a key
      ;; in the plist, so plist-put will destructively change the value.
      (plist-put server :password password))
    password))

> 3) Call the Perl script once for each server, passing the arguments,
>    password, etc.

(with-output-to-temp-buffer "*popfetch*"
  (dolist (server pop-servers)
    (call-process "perl" nil standard-output nil
		  "c:/home/popfetch.pl"
		  (plist-get server :server)
		  (plist-get server :username)
		  (pd-server-password server))))

One should probably display the buffer earlier.

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

* Re: Help with simple function
  2003-01-09 16:22 Help with simple function Peter Davis
  2003-01-09 19:26 ` Kalle Olavi Niemitalo
@ 2003-01-09 19:28 ` Adrian Aichner
  2003-01-09 21:07   ` Peter Davis
  1 sibling, 1 reply; 7+ messages in thread
From: Adrian Aichner @ 2003-01-09 19:28 UTC (permalink / raw)


>>>>> "Peter" == Peter Davis <pd@world.std.com> writes:

    Peter> I'm using gnus to read mail and news.  For various reasons (explained
    Peter> below, if anyone's interested), I use my own Perl script to fetch mail
    Peter> from a couple of different POP3 servers.  I have a simple function
    Peter> which calls the Perl script:

    Peter> (defun pd-fetch-mail ()
    Peter>   (interactive)
    Peter>   (message "Running popfetch.pl... ")
    Peter>   (shell-command "perl c:/home/popfetch.pl")
    Peter>   )

    Peter> This works perfectly.  However, because the Perl script is stateless,
    Peter> I keep all the POP account information, including passwords, in a
    Peter> file.  I *hate* that.  What I'd like to do is:

    Peter> 1) Keep all the POP account info in a list, sort of like:

    Peter>     (setq pop-servers '((:server mail.myhomeisp.com
    Peter>                          :username "pd"
    Peter>                          :password ""
    Peter>                          :lmos t)
    Peter>                         (:server mail.mywork.com
    Peter>                          :username "pdavis"
    Peter>                          :password ""
    Peter>                          :lmos nil)
    Peter>                         ))

See
`mail-sources' (buffer: .gnus, mode: Emacs-Lisp)


Customizable user variable:

  value: see below

  *Where the mail backends will look for incoming mail.
  This variable is a list of mail source specifiers.
  See Info node `(gnus)Mail Source Specifiers'.

Adrian

    Peter> 2) Have emacs/XEmacs prompt for the password the first time this is
    Peter>    used, and store it in there (so I don't have to keep it in my .gnus
    Peter>    file)

    Peter> 3) Call the Perl script once for each server, passing the arguments,
    Peter>    password, etc.

    Peter> I'm sure this can all be done, but I'm not lisp-savvy enough to know
    Peter> how to do it.  Anyone have some code that does anything like this that
    Peter> I can use as a starting point?  I don't even know how to create the
    Peter> pop-servers variable so it will accept this list format.

    Peter> Thanks *very* much,

    Peter> -pd


    Peter> P.S. - If you want to know *why* I'm using my own Perl script, it's
    Peter> basically for two reasons:

    Peter> 1) I keep track of UIDLs, so can I leave messages on the POP server,
    Peter>    and not fetch them over and over again, and

    Peter> 2) I add X-POP-Server and X-POP-UIDL fields to the mail headers.  I
    Peter>    have another lisp function which writes the UIDL to a file whose
    Peter>    name is the server name.  That way, I can selectively delete
    Peter>    messages from the POP server if I've left them there.


    Peter> -- 
    Peter> --------
    Peter>                              Peter Davis
    Peter>                Funny stuff at http://www.pfdstudio.com
    Peter>                  The artwork formerly shown as prints
    Peter>     List of resources for children's writers and illustrators at:
    Peter>                   http://www.pfdstudio.com/cwrl.html

-- 
Adrian Aichner
 mailto:adrian@xemacs.org
 http://www.xemacs.org/

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

* Re: Help with simple function
  2003-01-09 19:26 ` Kalle Olavi Niemitalo
@ 2003-01-09 20:24   ` Peter Davis
  2003-01-09 22:44     ` Kalle Olavi Niemitalo
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Davis @ 2003-01-09 20:24 UTC (permalink / raw)



Wow!  Thanks *very* much.  Can I use your name/contact info in the
.gnus sources?

Kalle Olavi Niemitalo <kon@iki.fi> writes:

> Peter Davis <pd@world.std.com> writes:
> 
> > I don't even know how to create the pop-servers variable so it
> > will accept this list format.
> 
> If you assign a value to a variable (with setq), you implicitly
> create it.  Variables thus created accept all types of values.
> Only some built-in variables have type restrictions.

Great.  I thought I had to do defvar or something like that.

> Of course, there is plenty of code that assumes that the value of
> compile-command is a string, for example; but if you choose a
> name that is not already in use, there is no conflict.

I can make it pd-pop-servers, or something else that's unlikely to
conflict. 


[...]

> > 3) Call the Perl script once for each server, passing the arguments,
> >    password, etc.
> 
> (with-output-to-temp-buffer "*popfetch*"
>   (dolist (server pop-servers)
>     (call-process "perl" nil standard-output nil
> 		  "c:/home/popfetch.pl"
> 		  (plist-get server :server)
> 		  (plist-get server :username)
> 		  (pd-server-password server))))
> 
> One should probably display the buffer earlier.

The Perl script lists some info on each message as its processed, so
it would be nice to see the output in a buffer as it's being
generated.  That's really just a frill, though.

Thanks again for your help!

-pd


-- 
--------
                             Peter Davis
               Funny stuff at http://www.pfdstudio.com
                 The artwork formerly shown as prints
    List of resources for children's writers and illustrators at:
                  http://www.pfdstudio.com/cwrl.html

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

* Re: Help with simple function
  2003-01-09 19:28 ` Adrian Aichner
@ 2003-01-09 21:07   ` Peter Davis
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Davis @ 2003-01-09 21:07 UTC (permalink / raw)


Adrian Aichner <adrian@xemacs.org> writes:

> >>>>> "Peter" == Peter Davis <pd@world.std.com> writes:

[...]

>     Peter> 1) Keep all the POP account info in a list, sort of like:
> 
>     Peter>     (setq pop-servers '((:server mail.myhomeisp.com
>     Peter>                          :username "pd"
>     Peter>                          :password ""
>     Peter>                          :lmos t)
>     Peter>                         (:server mail.mywork.com
>     Peter>                          :username "pdavis"
>     Peter>                          :password ""
>     Peter>                          :lmos nil)
>     Peter>                         ))
> 
> See
> `mail-sources' (buffer: .gnus, mode: Emacs-Lisp)
> 
> 
> Customizable user variable:
> 
>   value: see below
> 
>   *Where the mail backends will look for incoming mail.
>   This variable is a list of mail source specifiers.
>   See Info node `(gnus)Mail Source Specifiers'.
> 
> Adrian

Thanks.  I'm familiar with mail-sources, but not the code that
actually processes it.  Actually, my Perl script puts all the messages
into a maildir format, which gnus then inhales via the appropriate
mail-sources.

Thanks,

-pd


-- 
--------
                             Peter Davis
               Funny stuff at http://www.pfdstudio.com
                 The artwork formerly shown as prints
    List of resources for children's writers and illustrators at:
                  http://www.pfdstudio.com/cwrl.html

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

* Re: Help with simple function
  2003-01-09 20:24   ` Peter Davis
@ 2003-01-09 22:44     ` Kalle Olavi Niemitalo
  2003-01-10 14:51       ` Peter Davis
  0 siblings, 1 reply; 7+ messages in thread
From: Kalle Olavi Niemitalo @ 2003-01-09 22:44 UTC (permalink / raw)


Peter Davis <pd@world.std.com> writes:

> Wow!  Thanks *very* much.  Can I use your name/contact info in the
> .gnus sources?

Name and email address, sure; but the rest I'm trying to keep out
of databases.

> I thought I had to do defvar or something like that.

It's good practice, but not required.  With defvar, you can
attach a documentation string to the variable.  It also makes
Emacs remember which file defined the variable, so that you can
easily browse it if you just remember the name of the variable,
and M-x unload-feature can undefine the variable.  Finally, the
byte compiler warns if you use undefined variables; but this only
matters if you compile your ~/.gnus, and you can disable those
warnings (see byte-compile-warnings) if you want.

> The Perl script lists some info on each message as its processed, so
> it would be nice to see the output in a buffer as it's being
> generated.  That's really just a frill, though.

This might work:

  (let ((output (get-buffer-create "*popfetch*")))
    (with-current-buffer output
      (erase-buffer))
    (display-buffer output)
    (dolist (server pd-pop-servers)
      (call-process "perl" nil output t
                    "c:/home/popfetch.pl"
                    (plist-get server :server)
                    (plist-get server :username)
                    (pd-server-password server))))

Actually, if you store server names as symbols (:server
mail.mywork.com ...) like you originally wrote, this loop will
have to convert them to strings with symbol-name.

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

* Re: Help with simple function
  2003-01-09 22:44     ` Kalle Olavi Niemitalo
@ 2003-01-10 14:51       ` Peter Davis
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Davis @ 2003-01-10 14:51 UTC (permalink / raw)


Kalle Olavi Niemitalo <kon@iki.fi> writes:

> Peter Davis <pd@world.std.com> writes:
> 
> > Wow!  Thanks *very* much.  Can I use your name/contact info in the
> > .gnus sources?
> 
> Name and email address, sure; but the rest I'm trying to keep out
> of databases.

Thanks.


[...]

> Actually, if you store server names as symbols (:server
> mail.mywork.com ...) like you originally wrote, this loop will
> have to convert them to strings with symbol-name.

I realized that, and changed them to strings.  It works beautifully!

Thanks again.

-pd


-- 
--------
                             Peter Davis
               Funny stuff at http://www.pfdstudio.com
                 The artwork formerly shown as prints
    List of resources for children's writers and illustrators at:
                  http://www.pfdstudio.com/cwrl.html

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

end of thread, other threads:[~2003-01-10 14:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-09 16:22 Help with simple function Peter Davis
2003-01-09 19:26 ` Kalle Olavi Niemitalo
2003-01-09 20:24   ` Peter Davis
2003-01-09 22:44     ` Kalle Olavi Niemitalo
2003-01-10 14:51       ` Peter Davis
2003-01-09 19:28 ` Adrian Aichner
2003-01-09 21:07   ` Peter Davis

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.