#ifdef COMMENT Proprietary Rand Corporation, 1981. Further distribution of this software subject to the terms of the Rand license agreement. #endif /* the only thing wrong with this version is that the numeric date format needs to be adjusted for the timezone. See adjtime() at the end of the file. -- dave yost, june, 1981 */ #include "../mh.h" #include #include #include #include #include "../adrparse.h" #include "scansub.h" #define Block #define _FROM 1 #define _NOTFROM 0 #define MSGN 0 /* Start of msg name field */ #define SMSGN DMAXFOLDER /* Length */ #define SFLGS 2 /* Width of flag field */ #define SDATE 7 /* Length of Date field */ #define STIME 8 /* Length of time field */ #define SNDATE 6 /* Length of numeric date */ #define SNTIME 4 /* Length of numeric time */ #define SFROM 16 /* Length of " " */ #define SLINE 79 /* size of line */ #define BSUBJ 20 /* Room needed in Sub field to */ /* add stuff from the body */ FILE *scnout; char scanl[512]; int local; int hostseen; char *frmtok(); scan(inb, innum, outnum, curflg, howdate, header) FILE *inb; int outnum; { char buf[BUFSIZ], name[NAMESZ], tobuf[32], frombuf[32]; register char *cp, **tok1; int state, subsz, first, compnum; static char *myname; int f_msgn; /* Start of msg name field */ int f_smsgn; /* Length */ int f_flgs; /* Start of flags field */ int f_sflgs; /* Width of flag field */ int f_date; /* Start of Date field */ int f_sdate; /* Length */ int f_from; /* Start of From field */ int f_sfrom; /* Length of " " */ int f_subj; /* Start of Subject field */ int f_ssubj; /* Size of Subject field */ int f_bsubj; /* Room needed in Sub field to */ /* add stuff from the body */ f_msgn = MSGN; f_smsgn = SMSGN; f_flgs = f_msgn + f_smsgn; f_sflgs = SFLGS; f_date = f_flgs + f_sflgs; switch (howdate) { default: f_sdate = SDATE; break; case DOTIME: f_sdate = SDATE + 1 + STIME; break; case NUMDATE: f_sdate = SNDATE; break; case DOTIME | NUMDATE: f_sdate = SNDATE + SNTIME; break; } f_from = f_date + f_sdate + 1; f_sfrom = SFROM; f_subj = f_from + f_sfrom + 2; f_ssubj = SLINE - f_subj; f_bsubj = BSUBJ; local = 0; hostseen = 0; if(!myname) myname = getenv("USER"); tobuf[0] = 0; frombuf[0] = 0; first = 0; state = FLD; compnum = 1; if (header) printf (" # %-*sFrom Subject [< '9'; cp++) if(!*cp) return; /* get the day */ dt.day = cp; while (isdigit(*cp)) cp++; if (*cp) *cp++ = '\0'; /* get the month */ while (*cp && !isalpha(*cp)) cp++; dt.month = cp; while (isalpha (*cp)) cp++; if (*cp) *cp++ = '\0'; /* get the year */ while (*cp && !isdigit(*cp)) cp++; dt.year = cp; while (isdigit(*cp)) cp++; if (*cp) *cp++ = '\0'; /* Point timestr at the time, and remove colons, if present */ while (*cp && !isdigit(*cp)) cp++; dt.timestr = to = cp; for (; isdigit(*cp) || *cp == ':'; cp++) if (*cp != ':') *to++ = *cp; if (*cp) cp++; *to = '\0'; /* get the time zone. */ /* Can be alphas as in PST */ /* If plus/minus digits, then set zoneadd to the + or - */ /* point zone at the string of digits or alphas */ dt.zoneadd = '\0'; while (*cp && !isalpha(*cp) && !isdigit(*cp)) { if (*cp == '+' || *cp == '-') dt.zoneadd = *cp; cp++; } dt.zone = cp; if (isdigit(*cp)) while (isdigit (*cp)) cp++; else { dt.zoneadd = '\0'; while (isalpha (*cp)) cp++; } if (*cp) *cp++ = '\0'; /* printf ("Yr='%s' Mo='%s' Day='%s' Time='%s' Zone='%s'\n", dt.year, dt.month, dt.day, dt.timestr, dt.zone); if(cp = findmonth(dt.month)) printf ("month='%s'\n", cp); return; /**/ to = buf; if(cp = findmonth(dt.month)) { if (how & NUMDATE) { adjtime(&dt); if(strlen(dt.year) >= 2) { cp = &dt.year[strlen(dt.year) - 2]; *to++ = *cp++; *to++ = *cp++; } else { *to++ = ' '; *to++ = ' '; } if ((cp = findmonth(dt.month))[1]) *to++ = *cp++; else *to++ = '0'; *to++ = *cp++; if (*(cp = dt.day)) { if (cp[1]) *to++ = *cp++; else *to++ = '0'; *to++ = *cp++; } else { *to++ = ' '; *to++ = ' '; } *to = '\0'; if (how & DOTIME) { /* kludge for now */ dt.timestr[4] = '\0'; strcpy (to, dt.timestr); } } else { if(!cp[1]) *to++ = ' '; while(*cp) *to++ = *cp++; *to++ = '/'; cp = dt.day; if(!cp[1]) *to++ = ' '; while(*cp >= '0' && *cp <= '9') *to++ = *cp++; Block { register int yr; if( ( (yr = atoi(dt.year)) > 1970 && yr - 1900 < locvec->tm_year ) || yr < locvec->tm_year ) { *to++ = '/'; *to++ = (yr - (yr < 100 ? 70 : 1970)) % 10 + '0'; } else { *to++ = ' '; *to++ = ' '; } } *to = '\0'; if (how & DOTIME) { *to++ = ' '; sprintf (to, "%4.4s", dt.timestr); to += 4; if (*dt.zone) { *to++ = '-'; strncpy(to, dt.zone, 3); } } } } else { cp = dt.day; if(!cp[1]) *to++ = ' '; while(*cp) *to++ = *cp++; } Block { register int tmp; if (cnt < (tmp = strlen(buf))) tmp = cnt; strncpy(sto, buf, tmp); } return; } char *fromp, fromdlm, pfromdlm; cpyfrm(sfrom, sto, cnt, fromcall) char *sfrom, *sto; { register char *to, *cp; register int c; fromdlm = ' '; fromp = sfrom; to = sto; cp = frmtok(); do if(c = *cp++) *to++ = c; else break; while(--cnt); for(;;) { if(cnt < 3) break; if(*(cp = frmtok()) == 0) break; if(*cp == '@' || uleq(cp, "at")) { cp = frmtok(); if(uleq(cp, HOSTNAME)) { /* if the first "From:" host is local */ if(fromcall != _NOTFROM && !hostseen++) local++; } else { *to++ = '@'; cnt--; do if(c = *cp++) *to++ = c; else break; while(--cnt); } } else if(cnt > 4) { cnt--; *to++ = pfromdlm; do if(c = *cp++) *to++ = c; else break; while(--cnt); } } if(fromcall != _NOTFROM) hostseen++; return(to - sto); } char *frmtok() { static char tokbuf[64]; register char *cp; register int c; pfromdlm = fromdlm; cp = tokbuf; *cp = 0; while(c = *fromp++) { if(c == '\t') c = ' '; if(c == ' ' && cp == tokbuf) continue; if(c == ' ' || c == '\n' || c == ',') break; *cp++ = c; *cp = 0; if(c == '@' || *fromp == '@' || cp == &tokbuf[63]) break; } fromdlm = c; return(tokbuf); } /* num specific! */ /* copy msgnam to addr, right justified */ cpymsgn(msgnam, addr, len) char *msgnam, *addr; { register char *cp, *sp; sp = msgnam; cp = &addr[len - strlen(sp)]; if (cp < addr) cp = addr; while(*sp) *cp++ = *sp++; } char *monthtab[] = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", }; char *findmonth(str) char *str; { register char *cp, *sp; register int i; static char buf[4]; for(cp=str, sp=buf; (*sp++ = *cp++) && sp < &buf[3] && *cp != ' '; ) continue; *sp = 0; for(i = 0; i < 12; i++) if(uleq(buf, monthtab[i])) { VOID sprintf(buf, "%d", i+1); return buf; } return(0); } struct tzone { char *z_nam; int z_hour; int z_min; }; struct tzone zonetab[] = { { "GMT", 0, 0, }, { "NST", -3, -30, }, { "AST", -4, 0, }, { "ADT", -3, 0, }, { "EST", -5, 0, }, { "EDT", -4, 0, }, { "CST", -6, 0, }, { "CDT", -5, 0, }, { "MST", -7, 0, }, { "MDT", -6, 0, }, { "PST", -8, 0, }, { "PDT", -7, 0, }, { "YST", -9, 0, }, { "YDT", -8, 0, }, { "HST", -10, 0, }, { "HDT", -9, 0, }, { "BST", -11, 0, }, { "BDT", -10, 0, }, { "Z", 0, 0, }, { "A", -1, 0, }, { "M", -12, 0, }, { "N", 1, 0, }, { "Y", 12, 0, }, { 0 } }; /* adjust for timezone */ adjtime(dt) register struct date *dt; { /* what we should do here is adjust all other timezones to our own */ return; /* if (isdigit (dt->zone[0])) { atoi ... if (dt->zoneadd == '+') ; } else { } return;