]>
diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/cmds/scansub.c
8 #define FROM 13 /* Start of From field */
9 #define SFROM 16 /* Length of " " */
10 #define DATE 5 /* Start of Date field */
11 #define SDATE 7 /* Length */
12 #define SUBJ 31 /* Start of Subject field */
13 #define SSUBJ (79-SUBJ) /* Size of Subject field */
14 #define BSUBJ 20 /* Room needed in Sub field to */
15 /* add stuff from the body */
16 #define MSGN 0 /* Start of msg name field */
17 #define SMSGN 3 /* Length */
18 #define FLGS 3 /* Start of flags field */
19 #define SFLGS 2 /* Width of flag field */
27 scan(inb
, innum
, outnum
, curflg
)
32 char buf
[BUFSIZ
], name
[NAMESZ
], tobuf
[32], frombuf
[32];
33 register char *cp
, **tok1
;
34 int state
, subsz
, first
, compnum
;
37 local
= 0; hostseen
= 0;
39 myname
= getenv("USER");
40 tobuf
[0] = 0; frombuf
[0] = 0;
47 state
= m_getfld(state
, name
, buf
, sizeof buf
, inb
);
48 if(!first
++ && state
!= FILEEOF
) { /*##*/
50 if((scnout
= fopen(cp
= m_name(outnum
), "w")) == NULL
) {
51 fprintf(stderr
, "Error creating msg ");
54 chmod(cp
, m_gmprot());
56 sfill(scanl
, sizeof scanl
);
57 scanl
[sizeof scanl
- 1] = 0;
68 if(uleq(name
, "from"))
70 cpyfrm(buf
,frombuf
,sizeof frombuf
,_FROM
)]=0;
71 else if(uleq(name
, "date"))
72 cpydat(buf
, scanl
+DATE
, SDATE
);
73 else if(uleq(name
, "subject") && scanl
[SUBJ
] == ' ')
74 subsz
= cpy(buf
, scanl
+SUBJ
, SSUBJ
);
75 else if(uleq(name
, "to") && !tobuf
[0])
77 cpyfrm(buf
,tobuf
,sizeof tobuf
-1,_NOTFROM
)]=0;
78 else if(uleq(name
, "replied"))
79 cpy("-", scanl
+FLGS
+1, 1);
80 put(name
, buf
, scnout
);
81 while(state
== FLDPLUS
) {
82 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
93 if(buf
[0] && subsz
< SSUBJ
- BSUBJ
) {
94 scanl
[SUBJ
+subsz
+1] = '<';
95 scanl
[SUBJ
+subsz
+2] = '<';
96 cpy(buf
, scanl
+SUBJ
+subsz
+3, SSUBJ
-subsz
-3);
99 if(buf
[0] && scnout
) {
103 fprintf(stderr
, "Write error on ");
104 perror(m_name(outnum
));done(-1);
107 body
: while(state
== BODY
) {
108 state
=m_getfld(state
,name
,buf
,sizeof buf
,inb
);
112 if(state
== BODYEOF
) {
113 putscan
: cpymsgn(m_name(innum
), scanl
+MSGN
, SMSGN
);
114 tok1
= brkstring(getcpy(frombuf
), " ", "\n");
115 if(!frombuf
[0] || uleq(frombuf
, myname
) ||
116 (local
&& uleq(*tok1
, myname
))) {
117 cpy("To:", scanl
+FROM
, 3);
118 cpy(tobuf
, scanl
+FROM
+3, SFROM
-3);
120 cpy(frombuf
, scanl
+FROM
, SFROM
);
122 cpy("+", scanl
+FLGS
, SFLGS
);
124 fputs(scanl
, stdout
);
129 perror("Write error on ");
130 perror(m_name(outnum
));
142 fprintf(stderr
, "??Message Format Error ");
143 fprintf(stderr
, "(Message %d) ", outnum
? outnum
:innum
);/*##*/
144 if(compnum
< 0) fprintf(stderr
, "in the Body.\n");
145 else fprintf(stderr
, "in Component #%d.\n", compnum
);
146 fprintf(stderr
, "-----------------------------------------");
147 fprintf(stderr
, "-------------------------------------\n");
150 fprintf(stderr
, "Getfld returned %d\n", state
);
154 fputs("\n\nBAD MSG:\n", scnout
);
159 /*** ungetc(inb); ***/
183 while(*--cp
== ' ') ;
209 if(ferror(ip
)) { perror("Write error");done(-1);}
215 register char *from
, *to
;
222 while(*from
== ' ' || *from
== '\t' || *from
== '\n')
226 if(c
== '\t' || c
== ' ' || c
== '\n') {
230 while((c
= *from
)==' '||c
=='\t'||c
=='\n');
237 return(from
- sfrom
- 1);
243 cpydat(sfrom
, sto
, cnt
)
246 register char *from
, *cp
;
254 locvec
= localtime(&now
);
257 for(from
= sfrom
; (c
= *from
) < '0' || c
> '9'; from
++)
261 for(cp
= from
; (*cp
>= '0' && *cp
<= '9') || *cp
== ' '; cp
++);
262 if(cp
= findmonth(cp
)) {
274 while(*from
>= '0' && *from
<= '9' && c
--)
277 while(*from
< '0' || *from
> '9') from
++;
278 if(((c
= atoi(from
)) > 1970 && c
-1900 < locvec
[5])
281 *to
++ = (c
< 100) ? (c
- 70 + '0')
296 char *fromp
, fromdlm
, pfromdlm
;
298 cpyfrm(sfrom
, sto
, cnt
, fromcall
)
301 register char *to
, *cp
;
305 fromp
= sfrom
; to
= sto
;
315 if(*(cp
= frmtok()) == 0) break;
316 if(*cp
== '@' || uleq(cp
, "at")) {
318 if(uleq(cp
, "berkeley")) {
319 /* if the first "From:" host is local */
320 if(fromcall
&& !hostseen
++)
333 cnt
--; *to
++ = pfromdlm
;
350 static char tokbuf
[64];
355 cp
= tokbuf
; *cp
= 0;
356 while(c
= *fromp
++) {
359 if(c
== ' ' && cp
== tokbuf
)
361 if(c
== ' ' || c
== '\n' || c
== ',')
365 if(c
== '@' || *fromp
== '@' || cp
== &tokbuf
[63])
375 cpymsgn(msgnam
, addr
, len
)
378 register char *cp
, *sp
;
381 cp
= addr
+ (len
- strlen(sp
));
387 "jan", "feb", "mar", "apr", "may", "jun",
388 "jul", "aug", "sep", "oct", "nov", "dec",
394 register char *cp
, *sp
;
399 for(cp
=str
, sp
=buf
; (*sp
++ = *cp
++) && sp
< &buf
[3] && *cp
!= ' '; );
401 for(i
= 0; i
< 12; i
++)
402 if(uleq(buf
, monthtab
[i
])) {
403 sprintf(buf
, "%2d", i
+1);