s/qmail 4.2.29a
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"); die_temp(); }
25void die_fork() {
26 buffer_putsflush(buffer_2,"qreceipt: fatal: unable to fork\n"); die_temp(); }
27void die_qqperm() {
28 buffer_putsflush(buffer_2,"qreceipt: fatal: permanent qmail-queue error\n"); die(); }
29void die_qqtemp() {
30 buffer_putsflush(buffer_2,"qreceipt: fatal: temporary qmail-queue error\n"); die_temp(); }
31void die_usage() {
32 buffer_putsflush(buffer_2,
33 "qreceipt: usage: qreceipt deliveryaddress\n"); die(); }
34void die_read() {
35 if (errno == ENOMEM) die_nomem();
36 buffer_putsflush(buffer_2,"qreceipt: fatal: read error\n"); die_temp(); }
37void 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
42char *target;
43
45
47stralloc messageid = {0};
48stralloc sanotice = {0};
49
50int rwnotice(token822_alloc *addr)
51{
54 if (sanotice.len == str_len(target))
55 if (!str_diffn(sanotice.s,target,sanotice.len))
56 flagreceipt = 1;
58 return 1;
59}
60
61struct qmail qqt;
62
63stralloc quoted = {0};
64
66{
67 char *qqx;
68
70 if (str_equal(returnpath,"")) die_noreceipt();
71 if (str_equal(returnpath,"#@[]")) die_noreceipt();
72
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\
85Hi! This is the qreceipt program. Your message was delivered to the\n\
86following address: ");
88 qmail_puts(&qqt,". Thanks for asking.\n");
89 if (messageid.s) {
90 qmail_puts(&qqt,"Your ");
92 }
93
94 qmail_from(&qqt,"");
96 qqx = qmail_close(&qqt);
97
98 if (*qqx)
99 if (*qqx == 'D') die_qqperm();
100 else die_qqtemp();
101}
102
103stralloc hfbuf = {0};
104token822_alloc hfin = {0};
105token822_alloc hfrewrite = {0};
106token822_alloc hfaddr = {0};
107
108void 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;
117 break;
118 }
119}
120
121void dobody(stralloc *h) { ; }
122
123int main(int argc, char **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();
130}
int main()
Definition: chkshsgr.c:6
stralloc sa
Definition: dnscname.c:11
void _exit()
int headerbody()
int hfield_known()
#define H_MESSAGEID
Definition: hfield.h:15
#define H_NOTICEREQUESTEDUPONDELIVERYTO
Definition: hfield.h:34
void h(char *, int, int, int)
Definition: install.c:15
stralloc addr
Definition: qmail-smtpd.c:521
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:108
stralloc hfbuf
Definition: qreceipt.c:103
char * target
Definition: qreceipt.c:42
void die_qqperm()
Definition: qreceipt.c:27
void die_nomem()
Definition: qreceipt.c:23
stralloc quoted
Definition: qreceipt.c:63
void dobody(stralloc *h)
Definition: qreceipt.c:121
void die_usage()
Definition: qreceipt.c:31
int flagreceipt
Definition: qreceipt.c:44
token822_alloc hfrewrite
Definition: qreceipt.c:105
void die_fork()
Definition: qreceipt.c:25
char * returnpath
Definition: qreceipt.c:46
struct qmail qqt
Definition: qreceipt.c:61
void die_temp()
Definition: qreceipt.c:22
void die_read()
Definition: qreceipt.c:34
token822_alloc hfin
Definition: qreceipt.c:104
stralloc sanotice
Definition: qreceipt.c:48
stralloc messageid
Definition: qreceipt.c:47
int rwnotice(token822_alloc *addr)
Definition: qreceipt.c:50
token822_alloc hfaddr
Definition: qreceipt.c:106
void die_qqtemp()
Definition: qreceipt.c:29
void finishheader()
Definition: qreceipt.c:65
void doordie(stralloc *sa, int r)
Definition: qreceipt.c:37
int quote2(stralloc *, char *)
Definition: quote.c:70
Definition: qmail.h:6
int token822_parse(token822_alloc *ta, stralloc *sa, stralloc *buf)
Definition: token822.c:216
void token822_reverse()
int token822_unquote()
int token822_addrlist()