I saw that "mailsync doesn't work from cron" problem under Ubuntu
6.06, using mailsync 5.2.1-2build1; given that unstable has 5.2.2 and
it (and libc-client) has the exact same lines of code, the analysis
below applies there too...

Given a .mailsyncrc including

channel slurp imapmail localfile {
        msinfo  mailsync-mail.msinfo
}

(imapmail and localfile left out as irrelevant)

I put "strace mailsync -n slurp" in cron, and saw this:

21438 open("/var/mail/anonymous/mailsync-mail/", 
O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = -1 ENOENT (No such file or 
directory)
21438 open("/var/mail/anonymous", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) 
= -1 ENOENT (No such file or directory)

"That's not right" :-)  Turns out that the execve line shows that cron
has a very limited environment - the only settings are

    SHELL, PATH, PWD, LANG, SHLVL, HOME, LANGUAGE, LOGNAME, and _

Note that this *doesn't* include USER; I can trigger the problem
directly by doing

   (unset USER; mailsync -n slurp)

Synchronizing stores "imapmail" <-> "localfile"...
Authorizing against {..../imap}
Error: Can't open mailbox mailsync-mail.msinfo: no such mailbox
Error: Couldn't open msinfo box mailsync-mail.msinfo.
       Aborting!

Adding an explicit USER=eichin to the crontab *worked*, so is a
plausible workaround.

Looking at the code...

mailsync-5.2.1/src/mailsync_main.cc line 93 (in main):
  // initialize c-client environment (~/.imparc etc.)
  env_init( getenv("USER"), getenv("HOME"));

uw-imap-2002edebian1/src/osdep/unix/env_unix.c line 656 (in env_init):
  /* myUserName must be set before dorc() call */
  myUserName = cpystr (user ? user : ANONYMOUSUSER);

Also, the comment describing env_init says:
 * Accepts: user name (NIL for anonymous)

I'd suggest that perhaps instead of getenv("USER") perhaps
getpwuid(geteuid()) is appropriate... or even something like
  getenv("USER") || getpwuid(geteuid())->pw_name
to allow the user to set $USER and fall back to getpwuid, rather than
doing the unintentional anonymous path.  The UW docs do talk about
customizing env_init, as an alternative:

  http://www.washington.edu/imap/documentation/CONFIG.html

but it looks like that should be site-specific, not application
specific, and just passing something different to env_init is a better
fix.

                        _Mark_ <[EMAIL PROTECTED]>
                        The Herd Of Kittens


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to