mess822x 1.24
mess822x
Loading...
Searching...
No Matches
ifvalidto.c
Go to the documentation of this file.
1#include "buffer.h"
2#include "getln.h"
3#include "mess822.h"
4#include "case.h"
5#include "env.h"
6#include "exit.h"
7#include "getoptb.h"
8#include "scan.h"
9#include "fmt.h"
10#include "logmsg.h"
11
12#define WHO "ifvalidto"
13
14static void nomem()
15{
16 logmsg(WHO,111,FATAL,"out of memory");
17}
18
19stralloc addrlist = {0};
20
23 { "to", 0, 0, 0, &addrlist, 0, 0 }
24, { "cc", 0, 0, 0, &addrlist, 0, 0 }
25, { 0, 0, 0, 0, 0, 0, 0 }
26} ;
27
28char strnum[FMT_ULONG];
29stralloc line = {0};
31
32char *recipient = 0;
33char **recips = {0};
34
35static void check(char *addr)
36{
37 if (recips) {
38 for (int i = 0; recips[i]; ++i)
39 if (case_equals(addr,recips[i])) _exit(0);
40 } else if (recipient)
41 if (case_equals(addr,recipient)) _exit(0);
42}
43
44int main(int argc,char **argv)
45{
46 int i;
47 int j;
48 int opt;
49 unsigned int r = 99;
50
51 while ((opt = getoptb(argc,argv,"br:")) != opteof)
52 switch (opt) {
53 case 'b': r = 100; break;
54 case 'r': if (optarg) scan_uint(optarg,&r); break;
55 }
56 argv += optind;
57 argc -= optind;
58
59 recipient = env_get("RECIPIENT");
60 if (argc) recips = argv;
61
62 if (!mess822_begin(&h,a)) nomem();
63
64 for (;;) {
65 if (getln(buffer_0,&line,&match,'\n') == -1)
66 logmsg(WHO,111,FATAL,"unable to read input: ");
67
68 if (!mess822_ok(&line)) break;
69 if (!mess822_line(&h,&line)) nomem();
70 if (!match) break;
71 }
72
73 if (!mess822_end(&h)) nomem();
74
75 for (j = i = 0; j < addrlist.len; ++j)
76 if (!addrlist.s[j]) {
77 if (addrlist.s[i] == '+')
78 check(addrlist.s + i + 1);
79 i = j + 1;
80 }
81
82 strnum[fmt_uint(strnum,r)] = 0;
83 logmsg(WHO,0,INFO,B("delivery processed with rc=",strnum));
84 _exit(r);
85}
stralloc addrlist
Definition addrlist.c:28
int mess822_line(mess822_header *, stralloc *)
int mess822_end(mess822_header *)
int mess822_ok(stralloc *)
Definition mess822_ok.c:4
#define MESS822_HEADER
Definition mess822.h:48
int mess822_begin(mess822_header *, mess822_action *)
Definition mess822_line.c:5
char strnum[FMT_ULONG]
Definition ifvalidto.c:28
stralloc line
Definition 822body.c:9
int match
Definition 822body.c:10
#define WHO
Definition 822body.c:7
void nomem()
Definition quote.c:8
char ** recips
Definition iftocc.c:29
char * recipient
Definition iftocc.c:28
mess822_action a[]
Definition 822date.c:25
mess822_header h
Definition 822date.c:24
int main()
Definition 822print.c:351