s/qmail
4.3.21
Next generation secure email transport
Loading...
Searching...
No Matches
4.3
sqmail-4.3.21
src
qreceipt.c
Go to the documentation of this file.
1
#include <unistd.h>
2
#include "sig.h"
3
#include "env.h"
4
#include "error.h"
5
#include "buffer.h"
6
#include "stralloc.h"
7
#include "getln.h"
8
#include "alloc.h"
9
#include "str.h"
10
#include "
hfield.h
"
11
#include "
token822.h
"
12
#include "
headerbody.h
"
13
#include "
exit.h
"
14
#include "open.h"
15
#include "
quote.h
"
16
#include "
qmail.h
"
17
18
#define WHO "qreceipt"
19
20
void
die_noreceipt
() {
_exit
(0); }
21
void
die
() {
_exit
(100); }
22
void
die_temp
() {
_exit
(111); }
23
void
die_nomem
() {
24
buffer_putsflush(buffer_2,
"qreceipt: fatal: out of memory\n"
);
die_temp
(); }
25
void
die_fork
() {
26
buffer_putsflush(buffer_2,
"qreceipt: fatal: unable to fork\n"
);
die_temp
(); }
27
void
die_qqperm
() {
28
buffer_putsflush(buffer_2,
"qreceipt: fatal: permanent qmail-queue error\n"
);
die
(); }
29
void
die_qqtemp
() {
30
buffer_putsflush(buffer_2,
"qreceipt: fatal: temporary qmail-queue error\n"
);
die_temp
(); }
31
void
die_usage
() {
32
buffer_putsflush(buffer_2,
33
"qreceipt: usage: qreceipt deliveryaddress\n"
);
die
(); }
34
void
die_read
() {
35
if
(errno == ENOMEM)
die_nomem
();
36
buffer_putsflush(buffer_2,
"qreceipt: fatal: read error\n"
);
die_temp
(); }
37
void
doordie
(
sa
,r) stralloc *
sa
;
int
r; {
38
if
(r == 1)
return
;
if
(r == -1)
die_nomem
();
39
buffer_putsflush(buffer_2,
"qreceipt: fatal: unable to parse this: "
);
40
buffer_putflush(buffer_2,
sa
->s,
sa
->len);
die
(); }
41
42
char
*
target
;
43
44
int
flagreceipt
= 0;
45
46
char
*
returnpath
;
47
stralloc
messageid
= {0};
48
stralloc
sanotice
= {0};
49
50
int
rwnotice
(token822_alloc *
addr
)
51
{
52
token822_reverse
(
addr
);
53
if
(
token822_unquote
(&
sanotice
,
addr
) != 1)
die_nomem
();
54
if
(
sanotice
.len == str_len(
target
))
55
if
(!str_diffn(
sanotice
.s,
target
,
sanotice
.len))
56
flagreceipt
= 1;
57
token822_reverse
(
addr
);
58
return
1;
59
}
60
61
struct
qmail
qqt
;
62
63
stralloc
quoted
= {0};
64
65
void
finishheader
()
66
{
67
char
*qqx;
68
69
if
(!
flagreceipt
)
die_noreceipt
();
70
if
(str_equal(
returnpath
,
""
))
die_noreceipt
();
71
if
(str_equal(
returnpath
,
"#@[]"
))
die_noreceipt
();
72
73
if
(!
quote2
(&
quoted
,
returnpath
))
die_nomem
();
74
75
if
(
qmail_open
(&
qqt
) == -1)
die_fork
();
76
77
qmail_puts
(&
qqt
,
"From: DELIVERY NOTICE SYSTEM <"
);
78
qmail_put
(&
qqt
,
quoted
.s,
quoted
.len);
79
qmail_puts
(&
qqt
,
">\n"
);
80
qmail_puts
(&
qqt
,
"To: <"
);
81
qmail_put
(&
qqt
,
quoted
.s,
quoted
.len);
82
qmail_puts
(&
qqt
,
">\n"
);
83
qmail_puts
(&
qqt
,
"Subject: success notice\n\
84
\n\
85
Hi! This is the qreceipt program. Your message was delivered to the\n\
86
following address: "
);
87
qmail_puts
(&
qqt
,
target
);
88
qmail_puts
(&
qqt
,
". Thanks for asking.\n"
);
89
if
(
messageid
.s) {
90
qmail_puts
(&
qqt
,
"Your "
);
91
qmail_put
(&
qqt
,
messageid
.s,
messageid
.len);
92
}
93
94
qmail_from
(&
qqt
,
""
);
95
qmail_to
(&
qqt
,
returnpath
);
96
qqx =
qmail_close
(&
qqt
);
97
98
if
(*qqx)
99
if
(*qqx ==
'D'
)
die_qqperm
();
100
else
die_qqtemp
();
101
}
102
103
stralloc
hfbuf
= {0};
104
token822_alloc
hfin
= {0};
105
token822_alloc
hfrewrite
= {0};
106
token822_alloc
hfaddr
= {0};
107
108
void
doheaderfield
(stralloc *
h
)
109
{
110
switch
(
hfield_known
(
h
->s,
h
->len)) {
111
case
H_MESSAGEID
:
112
if
(!stralloc_copy(&
messageid
,
h
))
die_nomem
();
113
break
;
114
case
H_NOTICEREQUESTEDUPONDELIVERYTO
:
115
doordie
(
h
,
token822_parse
(&
hfin
,
h
,&
hfbuf
));
116
doordie
(
h
,
token822_addrlist
(&
hfrewrite
,&
hfaddr
,&
hfin
,
rwnotice
));
117
break
;
118
}
119
}
120
121
void
dobody
(stralloc *
h
) { ; }
122
123
int
main
(
int
argc,
char
*
const
*argv)
124
{
125
sig_pipeignore();
126
if
(!(
target
= argv[1]))
die_usage
();
127
if
(!(
returnpath
= env_get(
"SENDER"
)))
die_usage
();
128
if
(
headerbody
(buffer_0,doheaderfield,finishheader,dobody) == -1)
die_read
();
129
die_noreceipt
();
130
}
main
int main()
Definition
chkshsgr.c:6
qqt
struct qmail qqt
Definition
condredirect.c:14
sa
stralloc sa
Definition
dnscname.c:11
exit.h
_exit
void _exit(int)
headerbody
int headerbody(buffer *b, void(*dohf)(), void(*hdone)(), void(*dobl)())
Definition
headerbody.c:21
headerbody.h
hfield_known
int hfield_known(char *s, int len)
Definition
hfield.c:57
hfield.h
H_MESSAGEID
#define H_MESSAGEID
Definition
hfield.h:15
H_NOTICEREQUESTEDUPONDELIVERYTO
#define H_NOTICEREQUESTEDUPONDELIVERYTO
Definition
hfield.h:34
h
void h(char *, char *, int, int, int)
Definition
install.c:15
target
stralloc target
Definition
newaliases.c:83
hfbuf
stralloc hfbuf
Definition
qmail-inject.c:367
hfrewrite
token822_alloc hfrewrite
Definition
qmail-inject.c:369
hfin
token822_alloc hfin
Definition
qmail-inject.c:368
hfaddr
token822_alloc hfaddr
Definition
qmail-inject.c:370
addr
stralloc addr
Definition
qmail-smtpd.c:529
qmail.h
qmail_to
void qmail_to(struct qmail *, char *)
Definition
qmail.c:83
qmail_from
void qmail_from(struct qmail *, char *)
Definition
qmail.c:73
qmail_put
void qmail_put(struct qmail *, char *, int)
Definition
qmail.c:63
qmail_close
char * qmail_close(struct qmail *)
Definition
qmail.c:90
qmail_puts
void qmail_puts(struct qmail *, char *)
Definition
qmail.c:68
qmail_open
int qmail_open(struct qmail *)
Definition
qmail.c:21
die
void die()
Definition
qreceipt.c:21
die_noreceipt
void die_noreceipt()
Definition
qreceipt.c:20
doheaderfield
void doheaderfield(stralloc *h)
Definition
qreceipt.c:108
die_qqperm
void die_qqperm()
Definition
qreceipt.c:27
die_nomem
void die_nomem()
Definition
qreceipt.c:23
quoted
stralloc quoted
Definition
qreceipt.c:63
dobody
void dobody(stralloc *h)
Definition
qreceipt.c:121
die_usage
void die_usage()
Definition
qreceipt.c:31
flagreceipt
int flagreceipt
Definition
qreceipt.c:44
die_fork
void die_fork()
Definition
qreceipt.c:25
returnpath
char * returnpath
Definition
qreceipt.c:46
die_temp
void die_temp()
Definition
qreceipt.c:22
die_read
void die_read()
Definition
qreceipt.c:34
sanotice
stralloc sanotice
Definition
qreceipt.c:48
messageid
stralloc messageid
Definition
qreceipt.c:47
rwnotice
int rwnotice(token822_alloc *addr)
Definition
qreceipt.c:50
die_qqtemp
void die_qqtemp()
Definition
qreceipt.c:29
finishheader
void finishheader()
Definition
qreceipt.c:65
doordie
void doordie(stralloc *sa, int r)
Definition
qreceipt.c:37
quote.h
quote2
int quote2(stralloc *, char *)
Definition
quote.c:70
qmail
Definition
qmail.h:14
token822_parse
int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf)
Definition
token822.c:220
token822.h
token822_addrlist
stralloc stralloc *int token822_addrlist(token822_alloc *, token822_alloc *, token822_alloc *, int(*)())
Definition
token822.c:378
token822_unquote
int token822_unquote(stralloc *, token822_alloc *)
Definition
token822.c:168
token822_reverse
void token822_reverse(token822_alloc *)
Definition
token822.c:9
Generated on
for s/qmail by
1.14.0