#include "rcv.h"
#include <sys/stat.h>
-#include <sgtty.h>
#include <ctype.h>
/*
* Auxiliary functions.
*/
-static char *SccsId = "@(#)aux.c 1.3 %G%";
+static char *SccsId = "@(#)aux.c 2.8 %G%";
/*
* Return a pointer to a dynamic copy of the argument.
return((sbuf.st_mode & S_IFMT) == S_IFDIR);
}
-/*
- * Compute the size in characters of the passed message
- */
-
-unsigned int
-msize(messp)
- struct message *messp;
-{
- register struct message *mp;
-
- mp = messp;
- return(mp->m_size);
-}
-
/*
* Count the number of arguments in the given string raw list.
*/
return(0);
}
+/*
+ * Copy a string, lowercasing it as we go.
+ */
+istrcpy(dest, src)
+ char *dest, *src;
+{
+ register char *cp, *cp2;
+
+ cp2 = dest;
+ cp = src;
+ do {
+ *cp2++ = little(*cp);
+ } while (*cp++ != 0);
+}
+
/*
* The following code deals with input stacking to do source
* commands. All but the current file pointer are saved on
struct sstack {
FILE *s_file; /* File we were in. */
int s_cond; /* Saved state of conditionals */
+ int s_loading; /* Loading .mailrc, etc. */
} sstack[_NFILE];
/*
char name[];
{
register FILE *fi;
+ register char *cp;
- if ((fi = fopen(name, "r")) == NULL) {
- perror(name);
+ if ((cp = expand(name)) == NOSTR)
+ return(1);
+ if ((fi = fopen(cp, "r")) == NULL) {
+ perror(cp);
return(1);
}
if (ssp >= _NFILE-2) {
}
sstack[++ssp].s_file = input;
sstack[ssp].s_cond = cond;
+ sstack[ssp].s_loading = loading;
+ loading = 0;
cond = CANY;
input = fi;
sourcing++;
if (cond != CANY)
printf("Unmatched \"if\"\n");
cond = sstack[ssp].s_cond;
+ loading = sstack[ssp].s_loading;
input = sstack[ssp--].s_file;
if (ssp < 0)
- sourcing = 0;
+ sourcing = loading;
return(0);
}
time_p[1] = statb.st_mtime;
utime(name, time_p);
#else
- if ((pid = fork()) != 0)
- return;
- clrbuf(stdout);
- clrbuf(stderr);
- clrbuf(stdin);
sleep(1);
if ((f = open(name, 0)) < 0)
- exit(1);
+ return;
read(f, &w, 1);
exit(0);
#endif
return(1);
}
+/*
+ * Get sender's name from this message. If the message has
+ * a bunch of arpanet stuff in it, we may have to skin the name
+ * before returning it.
+ */
+char *
+nameof(mp, reptype)
+ register struct message *mp;
+{
+ register char *cp, *cp2;
+
+ cp = skin(name1(mp, reptype));
+ if (reptype != 0 || charcount(cp, '!') < 2)
+ return(cp);
+ cp2 = rindex(cp, '!');
+ cp2--;
+ while (cp2 > cp && *cp2 != '!')
+ cp2--;
+ if (*cp2 == '!')
+ return(cp2 + 1);
+ return(cp);
+}
+
+/*
+ * Skin an arpa net address according to the RFC 733 interpretation
+ * of "host-phrase."
+ */
+char *
+skin(name)
+ char *name;
+{
+ register int c;
+ register char *cp, *cp2;
+ int gotlt, lastsp;
+ char nbuf[BUFSIZ];
+
+ if (name == NOSTR)
+ return(NOSTR);
+ if (index(name, '(') == NOSTR && index(name, '<') == NOSTR)
+ return(name);
+ gotlt = 0;
+ lastsp = 0;
+ for (cp = name, cp2 = nbuf, c = *cp++; *cp; c = *cp++) {
+ switch (c) {
+ case '(':
+ while (*cp != ')' && *cp != 0)
+ cp++;
+ if (*cp)
+ cp++;
+ break;
+
+ case ' ':
+ lastsp = 1;
+ break;
+
+ case '<':
+ cp2 = nbuf;
+ gotlt++;
+ lastsp = 0;
+ break;
+
+ case '>':
+ if (gotlt)
+ goto done;
+
+ /* Fall into . . . */
+
+ default:
+ if (lastsp) {
+ lastsp = 0;
+ *cp2++ = ' ';
+ }
+ *cp2++ = c;
+ break;
+ }
+ }
+done:
+ *cp2 = 0;
+
+ return(savestr(nbuf));
+}
+
/*
* Fetch the sender's name from the passed message.
+ * Reptype can be
+ * 0 -- get sender's name for display purposes
+ * 1 -- get sender's name for reply
+ * 2 -- get sender's name for Reply
*/
char *
-nameof(mp)
+name1(mp, reptype)
register struct message *mp;
{
char namebuf[LINESIZE];
register FILE *ibuf;
int first = 1;
- if ((cp = hfield("reply-to", mp)) != NOSTR) {
- strcpy(namebuf, cp);
- return(namebuf);
- }
+#ifndef SENDMAIL
+ if ((cp = hfield("from", mp)) != NOSTR)
+ return(cp);
+ if (reptype == 0 && (cp = hfield("sender", mp)) != NOSTR)
+ return(cp);
+#endif
ibuf = setinput(mp);
copy("", namebuf);
if (readline(ibuf, linebuf) <= 0)
return(savestr(namebuf));
}
+/*
+ * Count the occurances of c in str
+ */
+charcount(str, c)
+ char *str;
+{
+ register char *cp;
+ register int i;
+
+ for (i = 0, cp = str; *cp; cp++)
+ if (*cp == c)
+ i++;
+ return(i);
+}
+
/*
* Find the rightmost pointer to an instance of the
* character in the string and return it.
*/
-
char *
rindex(str, c)
char str[];
return(n<0 ? 0 : *s1 - *--s2);
}
+/*
+ * See if the given header field is supposed to be ignored.
+ */
+isign(field)
+ char *field;
+{
+ char realfld[BUFSIZ];
+ register int h;
+ register struct ignore *igp;
+
+ istrcpy(realfld, field);
+ h = hash(realfld);
+ for (igp = ignore[h]; igp != 0; igp = igp->i_link)
+ if (strcmp(igp->i_field, realfld) == 0)
+ return(1);
+ return(0);
+}