mess822x
1.24
mess822x
Loading...
Searching...
No Matches
mess822x-1.24
src
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
14
static
void
nomem
()
15
{
16
logmsg(
WHO
,111,FATAL,
"out of memory"
);
17
}
18
19
stralloc
addrlist
= {0};
20
21
mess822_header
h
=
MESS822_HEADER
;
22
mess822_action
a
[] = {
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
28
char
strnum
[FMT_ULONG];
29
stralloc
line
= {0};
30
int
match
;
31
32
char
*
recipient
= 0;
33
char
**
recips
= {0};
34
35
static
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
44
int
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
}
addrlist
stralloc addrlist
Definition
addrlist.c:28
mess822.h
mess822_line
int mess822_line(mess822_header *, stralloc *)
Definition
mess822_line.c:107
mess822_end
int mess822_end(mess822_header *)
Definition
mess822_line.c:26
mess822_ok
int mess822_ok(stralloc *)
Definition
mess822_ok.c:4
MESS822_HEADER
#define MESS822_HEADER
Definition
mess822.h:48
mess822_begin
int mess822_begin(mess822_header *, mess822_action *)
Definition
mess822_line.c:5
strnum
char strnum[FMT_ULONG]
Definition
ifvalidto.c:28
line
stralloc line
Definition
822body.c:9
match
int match
Definition
822body.c:10
WHO
#define WHO
Definition
822body.c:7
nomem
void nomem()
Definition
quote.c:8
recips
char ** recips
Definition
iftocc.c:29
recipient
char * recipient
Definition
iftocc.c:28
a
mess822_action a[]
Definition
822date.c:25
h
mess822_header h
Definition
822date.c:24
main
int main()
Definition
822print.c:351
mess822_action
Definition
mess822.h:12
mess822_header
Definition
mess822.h:22
Generated on
for mess822x by
1.14.0