diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
commit | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch) | |
tree | b88cc7a8457658d67e0321718556ac807f6bccf3 /src/qreceipt.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/qreceipt.c')
-rw-r--r-- | src/qreceipt.c | 157 |
1 files changed, 98 insertions, 59 deletions
diff --git a/src/qreceipt.c b/src/qreceipt.c index 8dacf40..6b629ba 100644 --- a/src/qreceipt.c +++ b/src/qreceipt.c @@ -1,43 +1,76 @@ #include <unistd.h> -#include "sig.h" + +#include "alloc.h" +#include "buffer.h" #include "env.h" #include "error.h" -#include "buffer.h" -#include "stralloc.h" +#include "exit.h" #include "getln.h" -#include "alloc.h" +#include "open.h" +#include "sig.h" #include "str.h" -#include "hfield.h" -#include "token822.h" +#include "stralloc.h" + #include "headerbody.h" -#include "exit.h" -#include "open.h" -#include "quote.h" +#include "hfield.h" #include "qmail.h" +#include "quote.h" +#include "token822.h" #define WHO "qreceipt" -void die_noreceipt() { _exit(0); } -void die() { _exit(100); } -void die_temp() { _exit(111); } -void die_nomem() { - buffer_putsflush(buffer_2,"qreceipt: fatal: out of memory\n"); die_temp(); } -void die_fork() { - buffer_putsflush(buffer_2,"qreceipt: fatal: unable to fork\n"); die_temp(); } -void die_qqperm() { - buffer_putsflush(buffer_2,"qreceipt: fatal: permanent qmail-queue error\n"); die(); } -void die_qqtemp() { - buffer_putsflush(buffer_2,"qreceipt: fatal: temporary qmail-queue error\n"); die_temp(); } -void die_usage() { - buffer_putsflush(buffer_2, - "qreceipt: usage: qreceipt deliveryaddress\n"); die(); } -void die_read() { - if (errno == ENOMEM) die_nomem(); - buffer_putsflush(buffer_2,"qreceipt: fatal: read error\n"); die_temp(); } -void doordie(sa,r) stralloc *sa; int r; { - if (r == 1) return; if (r == -1) die_nomem(); - buffer_putsflush(buffer_2,"qreceipt: fatal: unable to parse this: "); - buffer_putflush(buffer_2,sa->s,sa->len); die(); } +void die_noreceipt() +{ + _exit(0); +} +void die() +{ + _exit(100); +} +void die_temp() +{ + _exit(111); +} +void die_nomem() +{ + buffer_putsflush(buffer_2, "qreceipt: fatal: out of memory\n"); + die_temp(); +} +void die_fork() +{ + buffer_putsflush(buffer_2, "qreceipt: fatal: unable to fork\n"); + die_temp(); +} +void die_qqperm() +{ + buffer_putsflush(buffer_2, "qreceipt: fatal: permanent qmail-queue error\n"); + die(); +} +void die_qqtemp() +{ + buffer_putsflush(buffer_2, "qreceipt: fatal: temporary qmail-queue error\n"); + die_temp(); +} +void die_usage() +{ + buffer_putsflush(buffer_2, "qreceipt: usage: qreceipt deliveryaddress\n"); + die(); +} +void die_read() +{ + if (errno == ENOMEM) die_nomem(); + buffer_putsflush(buffer_2, "qreceipt: fatal: read error\n"); + die_temp(); +} +void doordie(sa, r) stralloc *sa; +int r; +{ + if (r == 1) return; + if (r == -1) die_nomem(); + buffer_putsflush(buffer_2, "qreceipt: fatal: unable to parse this: "); + buffer_putflush(buffer_2, sa->s, sa->len); + die(); +} char *target; @@ -50,12 +83,11 @@ stralloc sanotice = {0}; int rwnotice(token822_alloc *addr) { token822_reverse(addr); - if (token822_unquote(&sanotice,addr) != 1) die_nomem(); + if (token822_unquote(&sanotice, addr) != 1) die_nomem(); if (sanotice.len == str_len(target)) - if (!str_diffn(sanotice.s,target,sanotice.len)) - flagreceipt = 1; - token822_reverse(addr); - return 1; + if (!str_diffn(sanotice.s, target, sanotice.len)) flagreceipt = 1; + token822_reverse(addr); + return 1; } struct qmail qqt; @@ -67,37 +99,41 @@ void finishheader() char *qqx; if (!flagreceipt) die_noreceipt(); - if (str_equal(returnpath,"")) die_noreceipt(); - if (str_equal(returnpath,"#@[]")) die_noreceipt(); + if (str_equal(returnpath, "")) die_noreceipt(); + if (str_equal(returnpath, "#@[]")) die_noreceipt(); - if (!quote2("ed,returnpath)) die_nomem(); + if (!quote2("ed, returnpath)) die_nomem(); if (qmail_open(&qqt) == -1) die_fork(); - qmail_puts(&qqt,"From: DELIVERY NOTICE SYSTEM <"); - qmail_put(&qqt,quoted.s,quoted.len); - qmail_puts(&qqt,">\n"); - qmail_puts(&qqt,"To: <"); - qmail_put(&qqt,quoted.s,quoted.len); - qmail_puts(&qqt,">\n"); - qmail_puts(&qqt,"Subject: success notice\n\ + qmail_puts(&qqt, "From: DELIVERY NOTICE SYSTEM <"); + qmail_put(&qqt, quoted.s, quoted.len); + qmail_puts(&qqt, ">\n"); + qmail_puts(&qqt, "To: <"); + qmail_put(&qqt, quoted.s, quoted.len); + qmail_puts(&qqt, ">\n"); + qmail_puts( + &qqt, + "Subject: success notice\n\ \n\ Hi! This is the qreceipt program. Your message was delivered to the\n\ following address: "); - qmail_puts(&qqt,target); - qmail_puts(&qqt,". Thanks for asking.\n"); + qmail_puts(&qqt, target); + qmail_puts(&qqt, ". Thanks for asking.\n"); if (messageid.s) { - qmail_puts(&qqt,"Your "); - qmail_put(&qqt,messageid.s,messageid.len); + qmail_puts(&qqt, "Your "); + qmail_put(&qqt, messageid.s, messageid.len); } - qmail_from(&qqt,""); - qmail_to(&qqt,returnpath); + qmail_from(&qqt, ""); + qmail_to(&qqt, returnpath); qqx = qmail_close(&qqt); if (*qqx) - if (*qqx == 'D') die_qqperm(); - else die_qqtemp(); + if (*qqx == 'D') + die_qqperm(); + else + die_qqtemp(); } stralloc hfbuf = {0}; @@ -107,24 +143,27 @@ token822_alloc hfaddr = {0}; void doheaderfield(stralloc *h) { - switch (hfield_known(h->s,h->len)) { + switch (hfield_known(h->s, h->len)) { case H_MESSAGEID: - if (!stralloc_copy(&messageid,h)) die_nomem(); + if (!stralloc_copy(&messageid, h)) die_nomem(); break; case H_NOTICEREQUESTEDUPONDELIVERYTO: - doordie(h,token822_parse(&hfin,h,&hfbuf)); - doordie(h,token822_addrlist(&hfrewrite,&hfaddr,&hfin,rwnotice)); + doordie(h, token822_parse(&hfin, h, &hfbuf)); + doordie(h, token822_addrlist(&hfrewrite, &hfaddr, &hfin, rwnotice)); break; } } -void dobody(stralloc *h) { ; } +void dobody(stralloc *h) +{ + ; +} int main(int argc, char **argv) { sig_pipeignore(); if (!(target = argv[1])) die_usage(); if (!(returnpath = env_get("SENDER"))) die_usage(); - if (headerbody(buffer_0,doheaderfield,finishheader,dobody) == -1) die_read(); + if (headerbody(buffer_0, doheaderfield, finishheader, dobody) == -1) die_read(); die_noreceipt(); } |