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,9 +358,13 @@ char Errmsg[80];
static int debug = 0; static int debug = 0;
popmail(user, outfile) char *get_errmsg ();
char *user; char *getenv ();
char *outfile; int mbx_write ();
popmail (user, outfile)
char *user;
char *outfile;
{ {
char *host; char *host;
int nmsgs, nbytes; int nmsgs, nbytes;
@ -366,259 +372,286 @@ 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); {
return(1); error (Errmsg);
return 1;
} }
if (getline(response, sizeof response, sfi) != OK) { if (getline (response, sizeof response, sfi) != OK)
error(response); {
return(1); error (response);
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); {
pop_command("QUIT"); error (Errmsg);
return(1); pop_command ("QUIT");
return 1;
} }
if (pop_stat(&nmsgs, &nbytes) == NOTOK) { if (pop_stat (&nmsgs, &nbytes) == NOTOK)
error(Errmsg); {
pop_command("QUIT"); error (Errmsg);
return(1); pop_command ("QUIT");
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);
if (mbfi < 0) if (mbfi < 0)
{ {
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);
if ((mbf = fdopen(mbfi, "w")) == NULL) if ((mbf = fdopen (mbfi, "w")) == NULL)
{ {
pop_command("QUIT"); pop_command ("QUIT");
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); {
if (pop_retr(i, mbx_write, mbf) != OK) { mbx_delimit_begin (mbf);
error(Errmsg); if (pop_retr (i, mbx_write, mbf) != OK)
pop_command("QUIT"); {
close(mbfi); error (Errmsg);
return(1); pop_command ("QUIT");
close (mbfi);
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) { {
error(Errmsg); if (pop_command ("DELE %d", i) == NOTOK)
pop_command("QUIT"); {
close(mbfi); error (Errmsg);
return(1); pop_command ("QUIT");
close (mbfi);
return 1;
} }
} }
pop_command("QUIT"); pop_command ("QUIT");
close(mbfi); close (mbfi);
return(0); return 0;
} }
pop_init(host) pop_init (host)
char *host; char *host;
{ {
register struct hostent *hp; register struct hostent *hp;
register struct servent *sp; register struct servent *sp;
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); {
return(NOTOK); sprintf (Errmsg, "MAILHOST unknown: %s", host);
return NOTOK;
} }
sp = getservbyname("pop", "tcp"); sp = getservbyname ("pop", "tcp");
if (sp == 0) { if (sp == 0)
strcpy(Errmsg, "tcp/pop: unknown service"); {
return(NOTOK); strcpy (Errmsg, "tcp/pop: unknown service");
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()); {
return(NOTOK); sprintf (Errmsg, "error creating socket: %s", get_errmsg ());
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()); {
close(s); sprintf (Errmsg, "error during connect: %s", get_errmsg ());
return(NOTOK); close (s);
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()); {
close(s); sprintf (Errmsg, "error in fdopen: %s", get_errmsg ());
return(NOTOK); close (s);
return NOTOK;
} }
return(OK); return OK;
} }
pop_command(fmt, a, b, c, d) pop_command (fmt, a, b, c, d)
char *fmt; char *fmt;
{ {
char buf[128]; char buf[128];
char errmsg[64]; char errmsg[64];
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); {
return(NOTOK); strcpy (Errmsg, buf);
return NOTOK;
} }
if (debug) fprintf(stderr, "<--- %s\n", buf); if (debug) fprintf (stderr, "<--- %s\n", buf);
if (*buf != '+') { if (*buf != '+')
strcpy(Errmsg, buf); {
return(NOTOK); strcpy (Errmsg, buf);
} else { return NOTOK;
return(OK); }
else
{
return OK;
} }
} }
pop_stat(nmsgs, nbytes) pop_stat (nmsgs, nbytes)
int *nmsgs, *nbytes; 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); {
return(NOTOK); strcpy (Errmsg, buf);
return NOTOK;
} }
if (debug) fprintf(stderr, "<--- %s\n", buf); if (debug) fprintf (stderr, "<--- %s\n", buf);
if (*buf != '+') { if (*buf != '+')
strcpy(Errmsg, buf); {
return(NOTOK); strcpy (Errmsg, buf);
} else { return NOTOK;
sscanf(buf, "+OK %d %d", nmsgs, nbytes); }
return(OK); else
{
sscanf (buf, "+OK %d %d", nmsgs, nbytes);
return OK;
} }
} }
pop_retr(msgno, action, arg) pop_retr (msgno, action, arg)
int (*action)(); int (*action)();
{ {
char buf[128]; char buf[128];
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); {
return(NOTOK); strcpy (Errmsg, buf);
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;
} }
} }
} }
getline(buf, n, f) getline (buf, n, f)
char *buf; char *buf;
register int n; register int n;
FILE *f; FILE *f;
{ {
register char *p; register char *p;
int c; int c;
p = buf; p = buf;
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"); {
return (NOTOK); strcpy (buf, "error on connection");
return NOTOK;
} }
if (c == EOF && p == buf) { if (c == EOF && p == buf)
strcpy(buf, "connection closed by foreign host"); {
return (DONE); strcpy (buf, "connection closed by foreign host");
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)
char *buf; 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 { {
strcpy(buf, buf+1); return DONE;
}
else
{
strcpy (buf, buf+1);
} }
} }
return(OK); return OK;
} }
char * char *
get_errmsg() get_errmsg ()
{ {
extern int errno, sys_nerr; extern int errno, sys_nerr;
extern char *sys_errlist[]; extern char *sys_errlist[];
@ -628,41 +661,42 @@ get_errmsg()
s = sys_errlist[errno]; s = sys_errlist[errno];
else else
s = "unknown error"; s = "unknown error";
return(s); return (s);
} }
putline(buf, err, f) putline (buf, err, f)
char *buf; char *buf;
char *err; char *err;
FILE *f; 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"); {
return(NOTOK); strcpy (err, "lost connection");
return NOTOK;
} }
return(OK); return OK;
} }
mbx_write(line, mbf) mbx_write (line, mbf)
char *line; char *line;
FILE *mbf; FILE *mbf;
{ {
fputs(line, mbf); fputs (line, mbf);
fputc(0x0a, mbf); fputc (0x0a, mbf);
} }
mbx_delimit_begin(mbf) mbx_delimit_begin (mbf)
FILE *mbf; FILE *mbf;
{ {
fputs("\f\n0,unseen,,\n", mbf); fputs ("\f\n0,unseen,,\n", mbf);
} }
mbx_delimit_end(mbf) mbx_delimit_end (mbf)
FILE *mbf; FILE *mbf;
{ {
putc('\037', mbf); putc ('\037', mbf);
} }
#endif /* MAIL_USE_POP */ #endif /* MAIL_USE_POP */