Include <config.h> instead of "config.h".
[bpt/emacs.git] / lib-src / movemail.c
index d129478..0063e1d 100644 (file)
@@ -53,7 +53,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/file.h>
 #include <errno.h>
 #define NO_SHORTNAMES   /* Tell config not to load remap.h */
-#include "../src/config.h"
+#include <../src/config.h>
 
 #ifdef USG
 #include <fcntl.h>
@@ -81,6 +81,7 @@ extern int lk_open (), lk_close ();
 #undef close
 
 char *malloc ();
+char *strcpy ();
 char *concat ();
 char *xmalloc ();
 #ifndef errno
@@ -96,7 +97,6 @@ main (argc, argv)
 {
   char *inname, *outname;
   int indesc, outdesc;
-  char buf[1024];
   int nread;
 
 #ifndef MAIL_USE_FLOCK
@@ -140,11 +140,14 @@ main (argc, argv)
   }
 
 #ifdef MAIL_USE_POP
-  if (!bcmp (inname, "po:", 3))
+  if (!strncmp (inname, "po:", 3))
     {
       int status; char *user;
 
-      user = (char *) rindex (inname, ':') + 1;
+      for (user = &inname[strlen (inname) - 1]; user >= inname; user--)
+       if (*user == ':')
+         break;
+
       status = popmail (user, outname);
       exit (status);
     }
@@ -182,8 +185,7 @@ main (argc, argv)
      to bug-gnu-emacs@prep.ai.mit.edu so we can fix it.  */
 
   lockname = concat (inname, ".lock", "");
-  tempname = (char *) xmalloc (strlen (inname) + 20);
-  strcpy (tempname, inname);
+  tempname = strcpy (xmalloc (strlen (inname)+1), inname);
   p = tempname + strlen (tempname);
   while (p != tempname && p[-1] != '/')
     p--;
@@ -249,19 +251,23 @@ main (argc, argv)
 #endif
 #endif /* MAIL_USE_FLOCK */
 
-  while (1)
-    {
-      nread = read (indesc, buf, sizeof buf);
-      if (nread != write (outdesc, buf, nread))
-       {
-         int saved_errno = errno;
-         unlink (outname);
-         errno = saved_errno;
-         pfatal_with_name (outname);
-       }
-      if (nread < sizeof buf)
-       break;
-    }
+  {
+    char buf[1024];
+
+    while (1)
+      {
+       nread = read (indesc, buf, sizeof buf);
+       if (nread != write (outdesc, buf, nread))
+         {
+           int saved_errno = errno;
+           unlink (outname);
+           errno = saved_errno;
+           pfatal_with_name (outname);
+         }
+       if (nread < sizeof buf)
+         break;
+      }
+  }
 
 #ifdef BSD
   if (fsync (outdesc) < 0)
@@ -390,6 +396,7 @@ xmalloc (size)
 #include <netinet/in.h>
 #include <netdb.h>
 #include <stdio.h>
+#include <pwd.h>
 
 #ifdef USG
 #include <fcntl.h>
@@ -425,6 +432,9 @@ popmail (user, outfile)
   register int i;
   int mbfi;
   FILE *mbf;
+  struct passwd *pw = (struct passwd *) getpwuid (getuid ());
+  if (pw == NULL)
+    fatal ("cannot determine user name");
 
   host = getenv ("MAILHOST");
   if (host == NULL)
@@ -443,7 +453,7 @@ popmail (user, outfile)
     }
 
   if (pop_command ("USER %s", user) == NOTOK
-      || pop_command ("RPOP %s", user) == NOTOK)
+      || pop_command ("RPOP %s", pw->pw_name) == NOTOK)
     {
       pop_command ("QUIT");
       fatal (Errmsg);