]> code.delx.au - gnu-emacs/blobdiff - lib-src/movemail.c
* lisp/net/tramp-gvfs.el (tramp-gvfs-mount-spec): Fix typo.
[gnu-emacs] / lib-src / movemail.c
index 1618a6980e984c5b287688a53b47c24d07a32159..45779dae5c2cccf04a5a45f10f0c4388decf1a5c 100644 (file)
@@ -1,15 +1,15 @@
 /* movemail foo bar -- move file foo to file bar,
    locking file foo the way /bin/mail respects.
 
-Copyright (C) 1986, 1992-1994, 1996, 1999, 2001-2015 Free Software
+Copyright (C) 1986, 1992-1994, 1996, 1999, 2001-2016 Free Software
 Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -115,13 +115,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #define MAIL_USE_SYSTEM_LOCK
 #endif
 
-#ifdef MAIL_USE_MMDF
-extern int lk_open (), lk_close ();
-#endif
-
-#if !defined (MAIL_USE_SYSTEM_LOCK) && !defined (MAIL_USE_MMDF) && \
-       (defined (HAVE_LIBMAIL) || defined (HAVE_LIBLOCKFILE)) && \
-        defined (HAVE_MAILLOCK_H)
+#if (!defined MAIL_USE_SYSTEM_LOCK                             \
+     && (defined HAVE_LIBMAIL || defined HAVE_LIBLOCKFILE)     \
+     && defined HAVE_MAILLOCK_H)
 #include <maillock.h>
 /* We can't use maillock unless we know what directory system mail
    files appear in. */
@@ -144,8 +140,7 @@ static bool mbx_delimit_end (FILE *);
 #endif
 
 #if (defined MAIL_USE_MAILLOCK                                         \
-     || (!defined DISABLE_DIRECT_ACCESS && !defined MAIL_USE_MMDF      \
-        && !defined MAIL_USE_SYSTEM_LOCK))
+     || (!defined DISABLE_DIRECT_ACCESS && !defined MAIL_USE_SYSTEM_LOCK))
 /* Like malloc but get fatal error if memory is exhausted.  */
 
 static void *
@@ -179,8 +174,6 @@ main (int argc, char **argv)
   int desc;
 #endif /* not MAIL_USE_SYSTEM_LOCK */
 
-  char *spool_name = 0;
-
 #ifdef MAIL_USE_POP
   bool pop_reverse_order = false;
 # define ARGSTR "pr"
@@ -229,10 +222,6 @@ main (int argc, char **argv)
   inname = argv[optind];
   outname = argv[optind+1];
 
-#ifdef MAIL_USE_MMDF
-  mmdf_init (argv[0]);
-#endif
-
   if (*outname == 0)
     fatal ("Destination file name is empty", 0, 0);
 
@@ -255,14 +244,14 @@ main (int argc, char **argv)
 #ifndef DISABLE_DIRECT_ACCESS
 
   char *lockname = 0;
+  char *spool_name = 0;
 
-#ifndef MAIL_USE_MMDF
-#ifndef MAIL_USE_SYSTEM_LOCK
 #ifdef MAIL_USE_MAILLOCK
   spool_name = mail_spool_name (inname);
 #endif
   if (! spool_name)
     {
+#ifndef MAIL_USE_SYSTEM_LOCK
       /* Use a lock file named after our first argument with .lock appended:
         If it exists, the mail file is locked.  */
       /* Note: this locking mechanism is *required* by the mailer
@@ -333,9 +322,8 @@ main (int argc, char **argv)
        }
 
       delete_lockname = lockname;
-    }
 #endif /* not MAIL_USE_SYSTEM_LOCK */
-#endif /* not MAIL_USE_MMDF */
+    }
 
 #ifdef SIGCHLD
   signal (SIGCHLD, SIG_DFL);
@@ -350,21 +338,17 @@ main (int argc, char **argv)
       int lockcount = 0;
       int status = 0;
 #if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
-      time_t touched_lock IF_LINT (= 0);
+      time_t touched_lock;
 #endif
 
       if (setuid (getuid ()) < 0 || setregid (-1, real_gid) < 0)
        fatal ("Failed to drop privileges", 0, 0);
 
-#ifndef MAIL_USE_MMDF
 #ifdef MAIL_USE_SYSTEM_LOCK
       indesc = open (inname, O_RDWR | O_BINARY);
 #else  /* if not MAIL_USE_SYSTEM_LOCK */
       indesc = open (inname, O_RDONLY | O_BINARY);
 #endif /* not MAIL_USE_SYSTEM_LOCK */
-#else  /* MAIL_USE_MMDF */
-      indesc = lk_open (inname, O_RDONLY | O_BINARY, 0, 0, 10);
-#endif /* MAIL_USE_MMDF */
 
       if (indesc < 0)
        pfatal_with_name (inname);
@@ -474,11 +458,7 @@ main (int argc, char **argv)
        }
 #endif /* MAIL_USE_SYSTEM_LOCK */
 
-#ifdef MAIL_USE_MMDF
-      lk_close (indesc, 0, 0, 0);
-#else
       close (indesc);
-#endif
 
 #ifndef MAIL_USE_SYSTEM_LOCK
       if (! preserve_mail)
@@ -819,6 +799,51 @@ mbx_write (char *line, int len, FILE *mbf)
   return fwrite (line, 1, len, mbf) == len && 0 <= fputc ('\n', mbf);
 }
 
+#ifdef WINDOWSNT
+/* Work around MS-Windows lack of support for %e or %T with a
+   special-purpose strftime that assumes the exact format that
+   movemail uses.  */
+static size_t
+movemail_strftime (char *s, size_t size, char const *format,
+                  struct tm const *tm)
+{
+  char fmt[size + 6], *q;
+  const char *p;
+
+  for (p = format, q = &fmt[0]; *p; )
+    {
+      if (*p == '%' && p[1] == 'e')
+       {
+         memcpy (q, "%d", 2);
+         q += 2;
+         p += 2;
+       }
+      else if (*p == '%' && p[1] == 'T')
+       {
+         memcpy (q, "%H:%M:%S", 8);
+         q += 8;
+         p += 2;
+       }
+      else if (*p == '%' && p[1] == '%')
+       {
+         memcpy (q, p, 2);
+         q += 2;
+         p += 2;
+       }
+      else
+       *q++ = *p++;
+    }
+
+  size_t n = strftime (s, size, fmt, tm);
+  char *mday = s + sizeof "From movemail Sun Jan " - 1;
+  if (*mday == '0')
+    *mday = ' ';
+  return n;
+}
+# undef strftime
+# define strftime movemail_strftime
+#endif
+
 static bool
 mbx_delimit_begin (FILE *mbf)
 {