]>
diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/scansub.c
4 #define FROM 13 /* Start of From field */
5 #define SFROM 16 /* Length of " " */
6 #define DATE 5 /* Start of Date field */
7 #define SDATE 7 /* Length */
8 #define SUBJ 31 /* Start of Subject field */
9 #define SSUBJ (79-SUBJ) /* Size of Subject field */
10 #define BSUBJ 20 /* Room needed in Sub field to */
11 /* add stuff from the body */
12 #define MSGN 0 /* Start of msg name field */
13 #define SMSGN 3 /* Length */
14 #define FLGS 3 /* Start of flags field */
15 #define SFLGS 2 /* Width of flag field */
17 struct iobuf scnout
, fout
;
21 scan(inb
, innum
, outnum
, curflg
)
26 char buf
[512], name
[NAMESZ
], tobuf
[32], frombuf
[32];
28 int state
, subsz
, first
, compnum
;
32 myname
= getlogn(getruid());
33 tobuf
[0] = frombuf
[0] = 0;
40 state
= m_getfld(state
, name
, buf
, sizeof buf
, inb
);
41 if(!first
++ && state
>= FLD
&& state
!= FILEEOF
) {
43 if(fcreat((cp
= m_name(outnum
)),&scnout
)<0) {
44 printf("Error creating msg "); flush();
47 chmod(cp
, m_gmprot());
49 sfill(scanl
, sizeof scanl
);
50 scanl
[sizeof scanl
- 1] = 0;
61 if(uleq(name
, "from"))
62 frombuf
[cpyfrm(buf
, frombuf
, sizeof frombuf
)]=0;
63 else if(uleq(name
, "date"))
64 cpydat(buf
, scanl
+DATE
, SDATE
);
65 else if(uleq(name
, "subject") && scanl
[SUBJ
] == ' ')
66 subsz
= cpy(buf
, scanl
+SUBJ
, SSUBJ
);
67 else if(uleq(name
, "to") && !tobuf
[0])
68 tobuf
[cpyfrm(buf
, tobuf
, sizeof tobuf
-1)] = 0;
69 else if(uleq(name
, "replied"))
70 cpy("-", scanl
+FLGS
+1, 1);
71 put(name
, buf
, &scnout
);
72 while(state
== FLDPLUS
) {
73 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
83 if(buf
[0] && subsz
< SSUBJ
- BSUBJ
) {
84 scanl
[SUBJ
+subsz
+1] = '<';
85 scanl
[SUBJ
+subsz
+2] = '<';
86 cpy(buf
, scanl
+SUBJ
+subsz
+3, SSUBJ
-subsz
-3);
89 if(buf
[0] && scnout
.b_fildes
) {
92 perror("Write error:");exit(-1);
96 while(state
== BODY
) {
97 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
100 if(state
== BODYEOF
) {
101 putscan
: cpymsgn(m_name(innum
), scanl
+MSGN
, SMSGN
);
102 if(!frombuf
[0] || uleq(frombuf
, myname
)) {
103 cpy("To:", scanl
+FROM
, 3);
104 cpy(tobuf
, scanl
+FROM
+3, SFROM
-3);
106 cpy(frombuf
, scanl
+FROM
, SFROM
);
108 cpy("+", scanl
+FLGS
, SFLGS
);
112 if(scnout
.b_fildes
) {
115 perror("Write error");
118 close(scnout
.b_fildes
);
127 printf("??Message Format Error ");
128 if(outnum
) printf("(Message %d) ", outnum
);
129 if(compnum
< 0) printf("in the Body.\n");
130 else printf("in Component #%d.\n", compnum
);
133 printf("Getfld returned %d\n", state
);
134 badret
: if(scnout
.b_fildes
)
152 while(*--cp
== ' ') ;
172 register struct iobuf
*ip
;
178 if(errno
) { perror("Write error");exit(-1);}
186 register char *from
, *to
;
190 from
= sfrom
; to
= sto
;
192 while(*from
== ' ' || *from
== '\t' || *from
== '\n')
196 if(c
== '\t' || c
== ' ' || c
== '\n') {
200 while((c
= *from
)==' '||c
=='\t'||c
=='\n');
207 return(from
- sfrom
- 1);
211 cpydat(sfrom
, sto
, cnt
)
213 register char *from
, *cp
;
221 locvec
= localtime(&now
);
224 for(from
= sfrom
; (c
= *from
) < '0' || c
> '9'; from
++)
228 for(cp
= from
; (*cp
>= '0' && *cp
<= '9') || *cp
== ' '; cp
++);
229 if(cp
= findmonth(cp
)) {
241 while(*from
>= '0' && *from
<= '9' && c
--)
244 while(*from
< '0' || *from
> '9') from
++;
245 if((c
= atoi(from
)) > 1970 && c
-1900 < locvec
[5]) {
247 *to
++ = c
- 1970 + '0';
261 char *fromp
, fromdlm
, pfromdlm
;
263 cpyfrm(sfrom
, sto
, cnt
)
265 register char *to
, *cp
;
269 fromp
= sfrom
; to
= sto
;
279 if(*(cp
= frmtok()) == 0) break;
280 if(*cp
== '@' || uleq(cp
, "at")) {
282 if(!uleq(cp
, "rand-unix")) {
293 cnt
--; *to
++ = pfromdlm
;
313 cp
= tokbuf
; *cp
= 0;
314 while(c
= *fromp
++) {
317 if(c
== ' ' && cp
== tokbuf
)
319 if(c
== ' ' || c
== '\n' || c
== ',')
323 if(c
== '@' || *fromp
== '@' || cp
== &tokbuf
[63])
333 cpymsgn(msgnam
, addr
, len
)
336 register char *cp
, *sp
;
339 cp
= addr
+ (len
- length(sp
));
345 "jan", "feb", "mar", "apr", "may", "jun",
346 "jul", "aug", "sep", "oct", "nov", "dec",
351 register char *cp
, *sp
;
355 for(cp
=str
, sp
=buf
; (*sp
++ = *cp
++) && sp
< &buf
[3] && *cp
!= ' '; );
357 for(i
= 0; i
< 12; i
++)
358 if(uleq(buf
, monthtab
[i
]))
359 return(locv(0, i
+1));