11 main(int argc, char *argv[])
17 char file[MAXPATHLEN];
36 Binit(&bin, 0, OREAD);
38 fprint(2, "usage: filter rcvr mailfile [regexp mailfile ...]\n");
41 mp = m_read(&bin, 1, 0);
43 /* get rid of local system name */
44 cp = strchr(s_to_c(mp->sender), '!');
47 mp->sender = s_copy(cp);
50 dp = d_new(s_copy(argv[0]));
51 strecpy(file, file+sizeof file, argv[1]);
52 cp = findbody(s_to_c(mp->body));
53 for(i = 2; i < argc; i += 2){
57 if(regexec(p, s_to_c(mp->sender), match, 10)){
58 regsub(argv[i+1], file, sizeof(file), match, 10);
61 if(header == 0 && body == 0)
63 if(regexec(p, s_to_c(mp->body), match, 10)){
64 if(body == 0 && match[0].s.sp >= cp)
66 regsub(argv[i+1], file, sizeof(file), match, 10);
72 * always lock the normal mail file to avoid too many lock files
73 * lying about. This isn't right but it's what the majority prefers.
77 fprint(2, "can't lock mail file %s\n", argv[1]);
82 * open the destination mail file
84 fp = sysopen(file, "ca", MBOXMODE);
86 tmp = s_append(0, file);
87 s_append(tmp, ".tmp");
88 fp = sysopen(s_to_c(tmp), "cal", MBOXMODE);
91 fprint(2, "can't open mail file %s\n", file);
94 syslog(0, "mail", "error: used %s", s_to_c(tmp));
98 if(m_print(mp, fp, (char *)0, 1) < 0
99 || Bprint(fp, "\n") < 0
103 fprint(2, "can't write mail file %s\n", file);
110 if(cp = strrchr(rcvr, '!'))
112 logdelivery(dp, rcvr, mp);
123 if(*p == '\n' && *(p+1) == '\n')