2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
8 /* the only thing wrong with this version is that
9 the numeric date format needs to be adjusted for
10 the timezone. See adjtime() at the end of the file.
11 -- dave yost, june, 1981
18 #include "../adrparse.h"
26 #define MSGN 0 /* Start of msg name field */
27 #define SMSGN DMAXFOLDER /* Length */
28 #define SFLGS 2 /* Width of flag field */
29 #define SDATE 7 /* Length of Date field */
30 #define STIME 8 /* Length of time field */
31 #define SNDATE 6 /* Length of numeric date */
32 #define SNTIME 4 /* Length of numeric time */
33 #define SFROM 16 /* Length of " " */
34 #define SLINE 79 /* size of line */
35 #define BSUBJ 20 /* Room needed in Sub field to */
36 /* add stuff from the body */
44 scan(inb
, innum
, outnum
, curflg
, howdate
, header
)
49 char buf
[BUFSIZ
], name
[NAMESZ
], tobuf
[32], frombuf
[32];
50 register char *cp
, **tok1
;
51 int state
, subsz
, first
, compnum
;
53 int f_msgn
; /* Start of msg name field */
54 int f_smsgn
; /* Length */
55 int f_flgs
; /* Start of flags field */
56 int f_sflgs
; /* Width of flag field */
57 int f_date
; /* Start of Date field */
58 int f_sdate
; /* Length */
59 int f_from
; /* Start of From field */
60 int f_sfrom
; /* Length of " " */
61 int f_subj
; /* Start of Subject field */
62 int f_ssubj
; /* Size of Subject field */
63 int f_bsubj
; /* Room needed in Sub field to */
64 /* add stuff from the body */
68 f_flgs
= f_msgn
+ f_smsgn
;
70 f_date
= f_flgs
+ f_sflgs
;
78 f_sdate
= SDATE
+ 1 + STIME
;
85 case DOTIME
| NUMDATE
:
86 f_sdate
= SNDATE
+ SNTIME
;
89 f_from
= f_date
+ f_sdate
+ 1;
91 f_subj
= f_from
+ f_sfrom
+ 2;
92 f_ssubj
= SLINE
- f_subj
;
95 local
= 0; hostseen
= 0;
97 myname
= getenv("USER");
98 tobuf
[0] = 0; frombuf
[0] = 0;
104 printf (" # %-*sFrom Subject [<<Body]\n\n",
106 howdate
== DOTIME
? "Date Time" : "Date");
109 state
= m_getfld(state
, name
, buf
, sizeof buf
, inb
);
110 if(!first
++ && state
!= FILEEOF
) { /*##*/
113 if(*cp
== '?') /* msg num out of range */
115 if((scnout
= fopen(cp
, "w")) == NULL
) {
116 fprintf(stderr
, "Error creating msg ");
117 perror(cp
); done(-1);
119 VOID
chmod(cp
, m_gmprot());
121 sfill(scanl
, sizeof scanl
);
122 scanl
[sizeof scanl
- 1] = 0;
133 if(uleq(name
, "from"))
134 frombuf
[cpyfrm(buf
,frombuf
,sizeof frombuf
,_FROM
)]
136 else if(uleq(name
, "date"))
137 cpydat(buf
, &scanl
[f_date
], f_sdate
, howdate
);
138 else if(uleq(name
, "subject") && scanl
[f_subj
] == ' ')
139 subsz
= cpy(buf
, &scanl
[f_subj
], f_ssubj
);
140 else if(uleq(name
, "to") && !tobuf
[0])
142 cpyfrm(buf
,tobuf
,sizeof tobuf
-1,_NOTFROM
)]=0;
143 else if(uleq(name
, "replied"))
144 VOID
cpy("-", &scanl
[f_flgs
+1], 1);
145 put(name
, buf
, scnout
);
146 while(state
== FLDPLUS
) {
147 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
158 if(buf
[0] && subsz
< f_ssubj
- f_bsubj
) {
160 scanl
[f_subj
+subsz
+1] = '<';
161 scanl
[f_subj
+subsz
+2] = '<';
162 bodsz
= cpy(buf
, scanl
+f_subj
+subsz
+3,
164 if(bodsz
< f_ssubj
- subsz
- 3)
165 scanl
[f_subj
+subsz
+3 + bodsz
] = '>';
166 if(bodsz
< f_ssubj
- subsz
- 4)
167 scanl
[f_subj
+subsz
+4 + bodsz
] = '>';
170 if(buf
[0] && scnout
) {
174 fprintf(stderr
, "Write error on ");
175 perror(m_name(outnum
));done(-1);
180 state
= FILEEOF
; /* stop now if scan cmd */
181 else while(state
== BODY
) { /*else inc, so copy body*/
182 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
186 if(state
== BODYEOF
|| state
== FILEEOF
) {
187 putscan
: cpymsgn(m_name(innum
), &scanl
[f_msgn
], f_smsgn
);
188 tok1
= brkstring(getcpy(frombuf
), " ", "\n");
189 if(!frombuf
[0] || uleq(frombuf
, myname
) ||
190 (local
&& uleq(*tok1
, myname
))) {
191 VOID
cpy("To:", &scanl
[f_from
], 3);
192 VOID
cpy(tobuf
, &scanl
[f_from
+3], f_sfrom
-3);
194 VOID
cpy(frombuf
, &scanl
[f_from
], f_sfrom
);
196 VOID
cpy("+", &scanl
[f_flgs
], f_sflgs
);
198 fputs(scanl
, stdout
);
203 perror("Write error on ");
204 perror(m_name(outnum
));
216 fprintf(stderr
, "??Message Format Error ");
217 fprintf(stderr
, "(Message %d) ", outnum
? outnum
:innum
);/*##*/
218 if(compnum
< 0) fprintf(stderr
, "in the Body.\n");
219 else fprintf(stderr
, "in Component #%d.\n", compnum
);
220 fprintf(stderr
, "-----------------------------------------");
221 fprintf(stderr
, "-------------------------------------\n");
224 fprintf(stderr
, "Getfld returned %d\n", state
);
228 fputs("\n\nBAD MSG:\n", scnout
);
235 /*** ungetc(inb); ***/
259 while(*--cp
== ' ') ;
286 if(ferror(ip
)) { perror("Write error");done(-1);}
292 register char *from
, *to
;
299 while(*from
== ' ' || *from
== '\t' || *from
== '\n' || *from
== '\f')
303 if(c
== '\t' || c
== ' ' || c
== '\n' || c
== '\f') {
307 while((c
= *from
)==' '||c
=='\t'||c
=='\n'||c
=='\f');
315 return(to
- savto
); /*Includes 1 char trailing white space, if any*/
318 struct tm
*localtime();
331 cpydat(sfrom
, sto
, cnt
, how
)
336 static struct tm
*locvec
;
338 char buf
[30]; /* should be char buf[cnt + 1] */
342 strncpy(frombuf
, sfrom
, sizeof frombuf
);
343 frombuf
[sizeof frombuf
-1] = '\0';
345 now
= time((long *)0);
346 locvec
= localtime(&now
);
349 /* Collect the various fields of the date */
350 for(cp
= frombuf
; *cp
< '0' || *cp
> '9'; cp
++)
362 while (*cp
&& !isalpha(*cp
))
365 while (isalpha (*cp
))
371 while (*cp
&& !isdigit(*cp
))
379 /* Point timestr at the time, and remove colons, if present */
380 while (*cp
&& !isdigit(*cp
))
382 dt
.timestr
= to
= cp
;
383 for (; isdigit(*cp
) || *cp
== ':'; cp
++)
390 /* get the time zone. */
391 /* Can be alphas as in PST */
392 /* If plus/minus digits, then set zoneadd to the + or - */
393 /* point zone at the string of digits or alphas */
395 while (*cp
&& !isalpha(*cp
) && !isdigit(*cp
)) {
396 if (*cp
== '+' || *cp
== '-')
402 while (isdigit (*cp
))
406 while (isalpha (*cp
))
412 /* printf ("Yr='%s' Mo='%s' Day='%s' Time='%s' Zone='%s'\n",
413 dt.year, dt.month, dt.day, dt.timestr, dt.zone);
414 if(cp = findmonth(dt.month))
415 printf ("month='%s'\n", cp);
419 if(cp
= findmonth(dt
.month
)) {
422 if(strlen(dt
.year
) >= 2) {
423 cp
= &dt
.year
[strlen(dt
.year
) - 2];
431 if ((cp
= findmonth(dt
.month
))[1])
436 if (*(cp
= dt
.day
)) {
450 dt
.timestr
[4] = '\0';
451 strcpy (to
, dt
.timestr
);
464 while(*cp
>= '0' && *cp
<= '9')
468 if( ( (yr
= atoi(dt
.year
)) > 1970
469 && yr
- 1900 < locvec
->tm_year
471 || yr
< locvec
->tm_year
474 *to
++ = (yr
- (yr
< 100 ? 70 : 1970))
485 sprintf (to
, "%4.4s", dt
.timestr
);
489 strncpy(to
, dt
.zone
, 3);
503 if (cnt
< (tmp
= strlen(buf
)))
505 strncpy(sto
, buf
, tmp
);
511 char *fromp
, fromdlm
, pfromdlm
;
513 cpyfrm(sfrom
, sto
, cnt
, fromcall
)
516 register char *to
, *cp
;
520 fromp
= sfrom
; to
= sto
;
530 if(*(cp
= frmtok()) == 0) break;
531 if(*cp
== '@' || uleq(cp
, "at")) {
533 if(uleq(cp
, HOSTNAME
)) {
534 /* if the first "From:" host is local */
535 if(fromcall
!= _NOTFROM
&& !hostseen
++)
548 cnt
--; *to
++ = pfromdlm
;
557 if(fromcall
!= _NOTFROM
)
565 static char tokbuf
[64];
570 cp
= tokbuf
; *cp
= 0;
571 while(c
= *fromp
++) {
574 if(c
== ' ' && cp
== tokbuf
)
576 if(c
== ' ' || c
== '\n' || c
== ',')
580 if(c
== '@' || *fromp
== '@' || cp
== &tokbuf
[63])
590 /* copy msgnam to addr, right justified */
591 cpymsgn(msgnam
, addr
, len
)
594 register char *cp
, *sp
;
597 cp
= &addr
[len
- strlen(sp
)];
605 "jan", "feb", "mar", "apr", "may", "jun",
606 "jul", "aug", "sep", "oct", "nov", "dec",
612 register char *cp
, *sp
;
616 for(cp
=str
, sp
=buf
; (*sp
++ = *cp
++) && sp
< &buf
[3] && *cp
!= ' '; )
619 for(i
= 0; i
< 12; i
++)
620 if(uleq(buf
, monthtab
[i
])) {
621 VOID
sprintf(buf
, "%d", i
+1);
632 struct tzone zonetab
[] = {
659 /* adjust for timezone */
661 register struct date
*dt
;
663 /* what we should do here is adjust all other timezones to our own */
666 /* if (isdigit (dt->zone[0])) {
668 if (dt->zoneadd == '+')