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