/* movemail foo bar -- move file foo to file bar,
locking file foo the way /bin/mail respects.
- Copyright (C) 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1986, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#undef access
#endif /* MSDOS */
+#ifdef WINDOWSNT
+#undef access
+#undef unlink
+#define fork() 0
+#define sys_wait(var) (*(var) = 0)
+/* Unfortunately, Samba doesn't seem to properly lock Unix files even
+ though the locking call succeeds (and indeed blocks local access from
+ other NT programs). If you have direct file access using an NFS
+ client or something other than Samba, the locking call might work
+ properly - make sure it does before you enable this! */
+#define DISABLE_DIRECT_ACCESS
+#endif /* WINDOWSNT */
+
#ifdef USG
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#endif
-#ifdef XENIX
+#if defined (XENIX) || defined (WINDOWSNT)
#include <sys/locking.h>
#endif
if (argc < 3)
{
- fprintf (stderr, "Usage: movemail inbox destfile\n");
+ fprintf (stderr, "Usage: movemail inbox destfile [POP-password]\n");
exit(1);
}
char *p;
strcpy (buf, outname);
p = buf + strlen (buf);
- while (p > buf && p[-1] != '/')
+ while (p > buf && !IS_DIRECTORY_SEP (p[-1]))
*--p = 0;
if (p == buf)
*p++ = '.';
{
int status;
- status = popmail (inname + 3, outname);
+ status = popmail (inname + 3, outname, argc > 3 ? argv[3] : NULL);
exit (status);
}
setuid (getuid ());
#endif /* MAIL_USE_POP */
+#ifndef DISABLE_DIRECT_ACCESS
+
/* Check access to input file. */
if (access (inname, R_OK | W_OK) != 0)
pfatal_with_name (inname);
tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
strcpy (tempname, inname);
p = tempname + strlen (tempname);
- while (p != tempname && p[-1] != '/')
+ while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
p--;
*p = 0;
strcpy (p, "EXXXXXX");
#else /* not MAIL_USE_LOCKF */
#ifdef XENIX
if (locking (indesc, LK_RLCK, 0L) < 0) pfatal_with_name (inname);
+#else
+#ifdef WINDOWSNT
+ if (locking (indesc, LK_RLCK, -1L) < 0) pfatal_with_name (inname);
#else
if (flock (indesc, LOCK_EX) < 0) pfatal_with_name (inname);
#endif
+#endif
#endif /* not MAIL_USE_LOCKF */
#endif /* MAIL_USE_SYSTEM_LOCK */
pfatal_and_delete (outname);
#ifdef MAIL_USE_SYSTEM_LOCK
-#if defined (STRIDE) || defined (XENIX)
+#if defined (STRIDE) || defined (XENIX) || defined (WINDOWSNT)
/* Stride, xenix have file locking, but no ftruncate. This mess will do. */
close (open (inname, O_CREAT | O_TRUNC | O_RDWR, 0666));
#else
#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
unlink (lockname);
#endif /* not MAIL_USE_MMDF and not MAIL_USE_SYSTEM_LOCK */
+
+#endif /* ! DISABLE_DIRECT_ACCESS */
+
return 0;
}
\f
#ifdef MAIL_USE_POP
+#ifndef WINDOWSNT
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
+#else
+#undef _WINSOCKAPI_
+#include <winsock.h>
+#endif
#include <stdio.h>
#include <pwd.h>
char obuffer[BUFSIZ];
char Errmsg[80];
-popmail (user, outfile)
+popmail (user, outfile, password)
char *user;
char *outfile;
+ char *password;
{
int nmsgs, nbytes;
register int i;
popserver server;
extern char *strerror ();
- server = pop_open (0, user, 0, POP_NO_GETPASS);
+ server = pop_open (0, user, password, POP_NO_GETPASS);
if (! server)
{
error (pop_error);
}
fchown (mbfi, getuid (), -1);
- if ((mbf = fdopen (mbfi, "w")) == NULL)
+ if ((mbf = fdopen (mbfi, "wb")) == NULL)
{
pop_close (server);
error ("Error in fdopen: %s", strerror (errno));