1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

*** empty log message ***

This commit is contained in:
Richard M. Stallman 1990-11-13 05:11:43 +00:00
parent ecb7594297
commit b1ce62a86f

View file

@ -104,9 +104,7 @@ main (argc, argv)
mmdf_init (argv[0]); mmdf_init (argv[0]);
#endif #endif
/* Check access to input and output file. */ /* Check access to output file. */
if (access (inname, R_OK | W_OK) != 0)
pfatal_with_name (inname);
if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0) if (access (outname, F_OK) == 0 && access (outname, W_OK) != 0)
pfatal_with_name (outname); pfatal_with_name (outname);
@ -138,6 +136,10 @@ main (argc, argv)
setuid (getuid()); setuid (getuid());
#endif /* MAIL_USE_POP */ #endif /* MAIL_USE_POP */
/* Check access to input file. */
if (access (inname, R_OK | W_OK) != 0)
pfatal_with_name (inname);
#ifndef MAIL_USE_MMDF #ifndef MAIL_USE_MMDF
#ifndef MAIL_USE_FLOCK #ifndef MAIL_USE_FLOCK
/* Use a lock file named /usr/spool/mail/$USER.lock: /* Use a lock file named /usr/spool/mail/$USER.lock:
@ -276,11 +278,11 @@ fatal (s1, s2)
/* Print error message. `s1' is printf control string, `s2' is arg for it. */ /* Print error message. `s1' is printf control string, `s2' is arg for it. */
error (s1, s2) error (s1, s2, s3)
char *s1, *s2; char *s1, *s2, *s3;
{ {
printf ("movemail: "); printf ("movemail: ");
printf (s1, s2); printf (s1, s2, s3);
printf ("\n"); printf ("\n");
} }
@ -356,6 +358,10 @@ char Errmsg[80];
static int debug = 0; static int debug = 0;
char *get_errmsg ();
char *getenv ();
int mbx_write ();
popmail (user, outfile) popmail (user, outfile)
char *user; char *user;
char *outfile; char *outfile;
@ -366,42 +372,44 @@ char *outfile;
register int i; register int i;
int mbfi; int mbfi;
FILE *mbf; FILE *mbf;
char *getenv();
int mbx_write();
char *get_errmsg();
host = getenv ("MAILHOST"); host = getenv ("MAILHOST");
if (host == NULL) { if (host == NULL)
{
fatal ("no MAILHOST defined"); fatal ("no MAILHOST defined");
} }
if (pop_init(host) == NOTOK) { if (pop_init (host) == NOTOK)
{
error (Errmsg); error (Errmsg);
return(1); return 1;
} }
if (getline(response, sizeof response, sfi) != OK) { if (getline (response, sizeof response, sfi) != OK)
{
error (response); error (response);
return(1); return 1;
} }
if (pop_command("USER %s", user) == NOTOK || if (pop_command ("USER %s", user) == NOTOK
pop_command("RPOP %s", user) == NOTOK) { || pop_command ("RPOP %s", user) == NOTOK)
{
error (Errmsg); error (Errmsg);
pop_command ("QUIT"); pop_command ("QUIT");
return(1); return 1;
} }
if (pop_stat(&nmsgs, &nbytes) == NOTOK) { if (pop_stat (&nmsgs, &nbytes) == NOTOK)
{
error (Errmsg); error (Errmsg);
pop_command ("QUIT"); pop_command ("QUIT");
return(1); return 1;
} }
if (!nmsgs) if (!nmsgs)
{ {
pop_command ("QUIT"); pop_command ("QUIT");
return(0); return 0;
} }
mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666); mbfi = open (outfile, O_WRONLY | O_CREAT | O_EXCL, 0666);
@ -409,7 +417,7 @@ char *outfile;
{ {
pop_command ("QUIT"); pop_command ("QUIT");
error ("Error in open: %s, %s", get_errmsg (), outfile); error ("Error in open: %s, %s", get_errmsg (), outfile);
return(1); return 1;
} }
fchown (mbfi, getuid (), -1); fchown (mbfi, getuid (), -1);
@ -419,33 +427,37 @@ char *outfile;
error ("Error in fdopen: %s", get_errmsg ()); error ("Error in fdopen: %s", get_errmsg ());
close (mbfi); close (mbfi);
unlink (outfile); unlink (outfile);
return(1); return 1;
} }
for (i = 1; i <= nmsgs; i++) { for (i = 1; i <= nmsgs; i++)
{
mbx_delimit_begin (mbf); mbx_delimit_begin (mbf);
if (pop_retr(i, mbx_write, mbf) != OK) { if (pop_retr (i, mbx_write, mbf) != OK)
{
error (Errmsg); error (Errmsg);
pop_command ("QUIT"); pop_command ("QUIT");
close (mbfi); close (mbfi);
return(1); return 1;
} }
mbx_delimit_end (mbf); mbx_delimit_end (mbf);
fflush (mbf); fflush (mbf);
} }
for (i = 1; i <= nmsgs; i++) { for (i = 1; i <= nmsgs; i++)
if (pop_command("DELE %d", i) == NOTOK) { {
if (pop_command ("DELE %d", i) == NOTOK)
{
error (Errmsg); error (Errmsg);
pop_command ("QUIT"); pop_command ("QUIT");
close (mbfi); close (mbfi);
return(1); return 1;
} }
} }
pop_command ("QUIT"); pop_command ("QUIT");
close (mbfi); close (mbfi);
return(0); return 0;
} }
pop_init (host) pop_init (host)
@ -456,44 +468,48 @@ char *host;
int lport = IPPORT_RESERVED - 1; int lport = IPPORT_RESERVED - 1;
struct sockaddr_in sin; struct sockaddr_in sin;
register int s; register int s;
char *get_errmsg();
hp = gethostbyname (host); hp = gethostbyname (host);
if (hp == NULL) { if (hp == NULL)
{
sprintf (Errmsg, "MAILHOST unknown: %s", host); sprintf (Errmsg, "MAILHOST unknown: %s", host);
return(NOTOK); return NOTOK;
} }
sp = getservbyname ("pop", "tcp"); sp = getservbyname ("pop", "tcp");
if (sp == 0) { if (sp == 0)
{
strcpy (Errmsg, "tcp/pop: unknown service"); strcpy (Errmsg, "tcp/pop: unknown service");
return(NOTOK); return NOTOK;
} }
sin.sin_family = hp->h_addrtype; sin.sin_family = hp->h_addrtype;
bcopy (hp->h_addr, (char *)&sin.sin_addr, hp->h_length); bcopy (hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
sin.sin_port = sp->s_port; sin.sin_port = sp->s_port;
s = rresvport (&lport); s = rresvport (&lport);
if (s < 0) { if (s < 0)
{
sprintf (Errmsg, "error creating socket: %s", get_errmsg ()); sprintf (Errmsg, "error creating socket: %s", get_errmsg ());
return(NOTOK); return NOTOK;
} }
if (connect(s, (char *)&sin, sizeof sin) < 0) { if (connect (s, (char *)&sin, sizeof sin) < 0)
{
sprintf (Errmsg, "error during connect: %s", get_errmsg ()); sprintf (Errmsg, "error during connect: %s", get_errmsg ());
close (s); close (s);
return(NOTOK); return NOTOK;
} }
sfi = fdopen (s, "r"); sfi = fdopen (s, "r");
sfo = fdopen (s, "w"); sfo = fdopen (s, "w");
if (sfi == NULL || sfo == NULL) { if (sfi == NULL || sfo == NULL)
{
sprintf (Errmsg, "error in fdopen: %s", get_errmsg ()); sprintf (Errmsg, "error in fdopen: %s", get_errmsg ());
close (s); close (s);
return(NOTOK); return NOTOK;
} }
return(OK); return OK;
} }
pop_command (fmt, a, b, c, d) pop_command (fmt, a, b, c, d)
@ -505,19 +521,23 @@ char *fmt;
sprintf (buf, fmt, a, b, c, d); sprintf (buf, fmt, a, b, c, d);
if (debug) fprintf (stderr, "---> %s\n", buf); if (debug) fprintf (stderr, "---> %s\n", buf);
if (putline(buf, Errmsg, sfo) == NOTOK) return(NOTOK); if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
if (getline(buf, sizeof buf, sfi) != OK) { if (getline (buf, sizeof buf, sfi) != OK)
{
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return(NOTOK); return NOTOK;
} }
if (debug) fprintf (stderr, "<--- %s\n", buf); if (debug) fprintf (stderr, "<--- %s\n", buf);
if (*buf != '+') { if (*buf != '+')
{
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return(NOTOK); return NOTOK;
} else { }
return(OK); else
{
return OK;
} }
} }
@ -528,20 +548,24 @@ int *nmsgs, *nbytes;
char buf[128]; char buf[128];
if (debug) fprintf (stderr, "---> STAT\n"); if (debug) fprintf (stderr, "---> STAT\n");
if (putline("STAT", Errmsg, sfo) == NOTOK) return(NOTOK); if (putline ("STAT", Errmsg, sfo) == NOTOK) return NOTOK;
if (getline(buf, sizeof buf, sfi) != OK) { if (getline (buf, sizeof buf, sfi) != OK)
{
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return(NOTOK); return NOTOK;
} }
if (debug) fprintf (stderr, "<--- %s\n", buf); if (debug) fprintf (stderr, "<--- %s\n", buf);
if (*buf != '+') { if (*buf != '+')
{
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return(NOTOK); return NOTOK;
} else { }
else
{
sscanf (buf, "+OK %d %d", nmsgs, nbytes); sscanf (buf, "+OK %d %d", nmsgs, nbytes);
return(OK); return OK;
} }
} }
@ -552,23 +576,26 @@ int (*action)();
sprintf (buf, "RETR %d", msgno); sprintf (buf, "RETR %d", msgno);
if (debug) fprintf (stderr, "%s\n", buf); if (debug) fprintf (stderr, "%s\n", buf);
if (putline(buf, Errmsg, sfo) == NOTOK) return(NOTOK); if (putline (buf, Errmsg, sfo) == NOTOK) return NOTOK;
if (getline(buf, sizeof buf, sfi) != OK) { if (getline (buf, sizeof buf, sfi) != OK)
{
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return(NOTOK); return NOTOK;
} }
while (1) { while (1)
switch (multiline(buf, sizeof buf, sfi)) { {
switch (multiline (buf, sizeof buf, sfi))
{
case OK: case OK:
(*action)(buf, arg); (*action)(buf, arg);
break; break;
case DONE: case DONE:
return (OK); return OK;
case NOTOK: case NOTOK:
strcpy (Errmsg, buf); strcpy (Errmsg, buf);
return (NOTOK); return NOTOK;
} }
} }
} }
@ -585,20 +612,22 @@ FILE *f;
while (--n > 0 && (c = fgetc (f)) != EOF) while (--n > 0 && (c = fgetc (f)) != EOF)
if ((*p++ = c) == '\n') break; if ((*p++ = c) == '\n') break;
if (ferror(f)) { if (ferror (f))
{
strcpy (buf, "error on connection"); strcpy (buf, "error on connection");
return (NOTOK); return NOTOK;
} }
if (c == EOF && p == buf) { if (c == EOF && p == buf)
{
strcpy (buf, "connection closed by foreign host"); strcpy (buf, "connection closed by foreign host");
return (DONE); return DONE;
} }
*p = NULL; *p = NULL;
if (*--p == '\n') *p = NULL; if (*--p == '\n') *p = NULL;
if (*--p == '\r') *p = NULL; if (*--p == '\r') *p = NULL;
return(OK); return OK;
} }
multiline (buf, n, f) multiline (buf, n, f)
@ -606,15 +635,19 @@ char *buf;
register int n; register int n;
FILE *f; FILE *f;
{ {
if (getline(buf, n, f) != OK) return (NOTOK); if (getline (buf, n, f) != OK) return NOTOK;
if (*buf == '.') { if (*buf == '.')
if (*(buf+1) == NULL) { {
return (DONE); if (*(buf+1) == NULL)
} else { {
return DONE;
}
else
{
strcpy (buf, buf+1); strcpy (buf, buf+1);
} }
} }
return(OK); return OK;
} }
char * char *
@ -638,11 +671,12 @@ FILE *f;
{ {
fprintf (f, "%s\r\n", buf); fprintf (f, "%s\r\n", buf);
fflush (f); fflush (f);
if (ferror(f)) { if (ferror (f))
{
strcpy (err, "lost connection"); strcpy (err, "lost connection");
return(NOTOK); return NOTOK;
} }
return(OK); return OK;
} }
mbx_write (line, mbf) mbx_write (line, mbf)