mailutil and passwords?
On Fri, 10 Jan 2003 12:30:46 -0500, "wkearney99"
<wkearney99@hotmail.com> wrote:
> Has any consideration been given to allowing the mailutil program
> to support stdin or command line password usage? It'd be nice if
> it would support this. Otherwise scripted use of mailutil ends up
> requiring use of expect. It sort of seems like a real waste.
On Fri, 10 Jan 2003 10:34:38 -0800, Mark Crispin
<mrc@CAC.Washington.EDU> wrote:
> Command line will not happen. Consider "ps" for the reason why.
> Stdin is a possibility, although it can be noted that expect works
> quite well for mailutil and other tools which require passwords.
Ahem.
mailutil calls the c library function "getpass" to get the user's
password. And the (uclibc) libc/unistd/getpass.c source code says:
> /* Try to write to and read from the terminal if we can.
> If we can't open the terminal, use stderr and stdin. */
>
> in = fopen ("/dev/tty", "r+");
> if (in == NULL)
> {
> in = stdin;
> out = stderr;
> }
> else
> out = in;
So if we can find some way to run our script without a controlling
terminal, getpass() will grab the password from stdin, and we won't
need expect.
Hey! How about cron? Here's one that works for me:
> SHELL=/bin/bash
> PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
>
> # m h dom mon dow command
> */20 * * * * mailutil appenddelete '{www.fastmail.fm:993/imap/norsh/notls/ssl/novalidate-cert/user="isp2dial@fastmail.fm"}INBOX' '{mail.isp2dial.com:143/imap/norsh/notls/user="jak"}INBOX' 2>&1 | grep -v '^password: password:'%mypass1%mypass2
The uw-imap docs/naming.txt file describes the {remote_system} /flags,
which are very handy to know! And as the crontab(5) man page says:
> Percent-signs (%) in the command, unless escaped with backslash (\),
> will be changed into newline characters, and all data after the first
> % will be sent to the command as standard input.
To wrap things up:
The getpass() "password:" prompts go to stderr, producing output which
can cause the cron job to send a mail every time it runs.
That's why I redirect stderr to the "grep -v" pipe, filtering out the
password prompts and suppressing the mail on a successful run. Any
other stderr output, such as command failure, will be passed though by
grep, and produce a mail.
And BTW, Mark, thanks for your hard work on imap-2006!
|