summaryrefslogtreecommitdiff
path: root/src/qmail-inject.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/qmail-inject.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/qmail-inject.c')
-rw-r--r--src/qmail-inject.c539
1 files changed, 267 insertions, 272 deletions
diff --git a/src/qmail-inject.c b/src/qmail-inject.c
index 0071316..dd8bb21 100644
--- a/src/qmail-inject.c
+++ b/src/qmail-inject.c
@@ -1,26 +1,28 @@
#include <unistd.h>
-#include "sig.h"
+
+#include "alloc.h"
#include "buffer.h"
+#include "constmap.h"
+#include "env.h"
+#include "error.h"
+#include "exit.h"
+#include "fmt.h"
#include "genalloc.h"
-#include "stralloc.h"
-#include "getoptb.h"
#include "getln.h"
-#include "alloc.h"
+#include "getoptb.h"
+#include "sig.h"
#include "str.h"
-#include "fmt.h"
-#include "hfield.h"
-#include "token822.h"
+#include "stralloc.h"
+
+#include "auto_qmail.h"
#include "control.h"
-#include "env.h"
-#include "qmail.h"
-#include "now.h"
-#include "exit.h"
-#include "error.h"
-#include "quote.h"
#include "headerbody.h"
-#include "auto_qmail.h"
+#include "hfield.h"
#include "newfield.h"
-#include "constmap.h"
+#include "now.h"
+#include "qmail.h"
+#include "quote.h"
+#include "token822.h"
#define LINELEN 80
@@ -52,57 +54,68 @@ int flagrh;
int flagqueue;
struct qmail qqt;
-void out(char *s,int len)
+void out(char *s, int len)
{
- if (flagqueue) qmail_put(&qqt,s,len);
- else buffer_putflush(buffer_1,s,len);
+ if (flagqueue)
+ qmail_put(&qqt, s, len);
+ else
+ buffer_putflush(buffer_1, s, len);
}
-void outs(char *s) { out(s,str_len(s)); }
+void outs(char *s)
+{
+ out(s, str_len(s));
+}
-void perm() { _exit(100); }
-void temp() { _exit(111); }
+void perm()
+{
+ _exit(100);
+}
+void temp()
+{
+ _exit(111);
+}
-void die_nomem()
+void die_nomem()
{
- buffer_putsflush(buffer_2,"qmail-inject: fatal: out of memory\n");
- temp();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: out of memory\n");
+ temp();
}
-void die_invalid(stralloc *sa)
+void die_invalid(stralloc *sa)
{
- buffer_putsflush(buffer_2,"qmail-inject: fatal: invalid header field: ");
- buffer_putflush(buffer_2,sa->s,sa->len);
- perm();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: invalid header field: ");
+ buffer_putflush(buffer_2, sa->s, sa->len);
+ perm();
}
-void die_qqt()
+void die_qqt()
{
- buffer_putsflush(buffer_2,"qmail-inject: fatal: unable to run qmail-queue\n");
- temp();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: unable to run qmail-queue\n");
+ temp();
}
-void die_chdir()
+void die_chdir()
{
- buffer_putsflush(buffer_2,"qmail-inject: fatal: internal bug\n");
- temp();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: internal bug\n");
+ temp();
}
-void die_read()
+void die_read()
{
if (errno == ENOMEM) die_nomem();
- buffer_putsflush(buffer_2,"qmail-inject: fatal: read error\n");
- temp();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: read error\n");
+ temp();
}
-void doordie(stralloc *sa,int r)
+void doordie(stralloc *sa, int r)
{
- if (r == 1) return;
+ if (r == 1) return;
if (r == -1) die_nomem();
- buffer_putsflush(buffer_2,"qmail-inject: fatal: unable to parse this line:\n");
- buffer_putflush(buffer_2,sa->s,sa->len);
- perm();
+ buffer_putsflush(buffer_2, "qmail-inject: fatal: unable to parse this line:\n");
+ buffer_putflush(buffer_2, sa->s, sa->len);
+ perm();
}
-GEN_ALLOC_typedef(saa,stralloc,sa,len,a)
-GEN_ALLOC_readyplus(saa,stralloc,sa,len,a,i,n,x,10,saa_readyplus)
+GEN_ALLOC_typedef(saa, stralloc, sa, len, a)
+ GEN_ALLOC_readyplus(saa, stralloc, sa, len, a, i, n, x, 10, saa_readyplus)
-static stralloc sauninit = {0};
+ static stralloc sauninit = {0};
saa savedh = {0};
saa hrlist = {0};
@@ -113,60 +126,60 @@ int flagresent;
void exitnicely()
{
- char *qqx;
-
- if (!flagqueue) buffer_flush(buffer_1);
-
- if (flagqueue) {
- int i;
-
- if (!stralloc_0(&sender)) die_nomem();
- qmail_from(&qqt,sender.s);
-
- for (i = 0; i < reciplist.len; ++i) {
- if (!stralloc_0(&reciplist.sa[i])) die_nomem();
- qmail_to(&qqt,reciplist.sa[i].s);
- }
- if (flagrh) {
- if (flagresent) {
- for (i = 0; i < hrrlist.len; ++i) {
- if (!stralloc_0(&hrrlist.sa[i])) die_nomem();
- qmail_to(&qqt,hrrlist.sa[i].s);
- }
- } else {
- for (i = 0; i < hrlist.len; ++i) {
- if (!stralloc_0(&hrlist.sa[i])) die_nomem();
- qmail_to(&qqt,hrlist.sa[i].s);
- }
- }
- }
-
- qqx = qmail_close(&qqt);
- if (*qqx) {
- if (*qqx == 'D') {
- buffer_puts(buffer_2,"qmail-inject: fatal: ");
- buffer_puts(buffer_2,qqx + 1);
- buffer_puts(buffer_2,"\n");
- buffer_flush(buffer_2);
- perm();
- } else {
- buffer_puts(buffer_2,"qmail-inject: fatal: ");
- buffer_puts(buffer_2,qqx + 1);
- buffer_puts(buffer_2,"\n");
- buffer_flush(buffer_2);
- temp();
- }
- }
- }
-
- _exit(0);
+ char *qqx;
+
+ if (!flagqueue) buffer_flush(buffer_1);
+
+ if (flagqueue) {
+ int i;
+
+ if (!stralloc_0(&sender)) die_nomem();
+ qmail_from(&qqt, sender.s);
+
+ for (i = 0; i < reciplist.len; ++i) {
+ if (!stralloc_0(&reciplist.sa[i])) die_nomem();
+ qmail_to(&qqt, reciplist.sa[i].s);
+ }
+ if (flagrh) {
+ if (flagresent) {
+ for (i = 0; i < hrrlist.len; ++i) {
+ if (!stralloc_0(&hrrlist.sa[i])) die_nomem();
+ qmail_to(&qqt, hrrlist.sa[i].s);
+ }
+ } else {
+ for (i = 0; i < hrlist.len; ++i) {
+ if (!stralloc_0(&hrlist.sa[i])) die_nomem();
+ qmail_to(&qqt, hrlist.sa[i].s);
+ }
+ }
+ }
+
+ qqx = qmail_close(&qqt);
+ if (*qqx) {
+ if (*qqx == 'D') {
+ buffer_puts(buffer_2, "qmail-inject: fatal: ");
+ buffer_puts(buffer_2, qqx + 1);
+ buffer_puts(buffer_2, "\n");
+ buffer_flush(buffer_2);
+ perm();
+ } else {
+ buffer_puts(buffer_2, "qmail-inject: fatal: ");
+ buffer_puts(buffer_2, qqx + 1);
+ buffer_puts(buffer_2, "\n");
+ buffer_flush(buffer_2);
+ temp();
+ }
+ }
+ }
+
+ _exit(0);
}
void savedh_append(stralloc *h)
{
- if (!saa_readyplus(&savedh,1)) die_nomem();
+ if (!saa_readyplus(&savedh, 1)) die_nomem();
savedh.sa[savedh.len] = sauninit;
- if (!stralloc_copy(savedh.sa + savedh.len,h)) die_nomem();
+ if (!stralloc_copy(savedh.sa + savedh.len, h)) die_nomem();
++savedh.len;
}
@@ -174,8 +187,7 @@ void savedh_print()
{
int i;
- for (i = 0; i < savedh.len; ++i)
- out(savedh.sa[i].s,savedh.sa[i].len);
+ for (i = 0; i < savedh.len; ++i) out(savedh.sa[i].s, savedh.sa[i].len);
}
stralloc defaultdomainbuf = {0};
@@ -189,8 +201,7 @@ void rwroute(token822_alloc *addr)
{
if (addr->t[addr->len - 1].type == TOKEN822_AT)
while (addr->len)
- if (addr->t[--addr->len].type == TOKEN822_COLON)
- return;
+ if (addr->t[--addr->len].type == TOKEN822_COLON) return;
}
void rwextraat(token822_alloc *addr)
@@ -199,9 +210,8 @@ void rwextraat(token822_alloc *addr)
if (addr->t[0].type == TOKEN822_AT) {
--addr->len;
- for (i = 0; i < addr->len; ++i)
- addr->t[i] = addr->t[i + 1];
- }
+ for (i = 0; i < addr->len; ++i) addr->t[i] = addr->t[i + 1];
+ }
}
void rwextradot(token822_alloc *addr)
@@ -210,8 +220,7 @@ void rwextradot(token822_alloc *addr)
if (addr->t[0].type == TOKEN822_DOT) {
--addr->len;
- for (i = 0; i < addr->len; ++i)
- addr->t[i] = addr->t[i + 1];
+ for (i = 0; i < addr->len; ++i) addr->t[i] = addr->t[i + 1];
}
}
@@ -221,17 +230,14 @@ void rwnoat(token822_alloc *addr)
int shift;
for (i = 0; i < addr->len; ++i)
- if (addr->t[i].type == TOKEN822_AT)
- return;
+ if (addr->t[i].type == TOKEN822_AT) return;
shift = defaulthost.len;
- if (!token822_readyplus(addr,shift)) die_nomem();
- for (i = addr->len - 1; i >= 0; --i)
- addr->t[i + shift] = addr->t[i];
+ if (!token822_readyplus(addr, shift)) die_nomem();
+ for (i = addr->len - 1; i >= 0; --i) addr->t[i + shift] = addr->t[i];
addr->len += shift;
- for (i = 0; i < shift; ++i)
- addr->t[i] = defaulthost.t[shift - 1 - i];
+ for (i = 0; i < shift; ++i) addr->t[i] = defaulthost.t[shift - 1 - i];
}
void rwnodot(token822_alloc *addr)
@@ -240,27 +246,21 @@ void rwnodot(token822_alloc *addr)
int shift;
for (i = 0; i < addr->len; ++i) {
- if (addr->t[i].type == TOKEN822_DOT)
- return;
- if (addr->t[i].type == TOKEN822_AT)
- break;
+ if (addr->t[i].type == TOKEN822_DOT) return;
+ if (addr->t[i].type == TOKEN822_AT) break;
}
for (i = 0; i < addr->len; ++i) {
- if (addr->t[i].type == TOKEN822_LITERAL)
- return;
- if (addr->t[i].type == TOKEN822_AT)
- break;
+ if (addr->t[i].type == TOKEN822_LITERAL) return;
+ if (addr->t[i].type == TOKEN822_AT) break;
}
shift = defaultdomain.len;
- if (!token822_readyplus(addr,shift)) die_nomem();
+ if (!token822_readyplus(addr, shift)) die_nomem();
- for (i = addr->len - 1; i >= 0; --i)
- addr->t[i + shift] = addr->t[i];
+ for (i = addr->len - 1; i >= 0; --i) addr->t[i + shift] = addr->t[i];
addr->len += shift;
-
- for (i = 0; i < shift; ++i)
- addr->t[i] = defaultdomain.t[shift - 1 - i];
+
+ for (i = 0; i < shift; ++i) addr->t[i] = defaultdomain.t[shift - 1 - i];
}
void rwplus(token822_alloc *addr)
@@ -275,15 +275,13 @@ void rwplus(token822_alloc *addr)
--addr->t[0].slen; /* remove + */
shift = plusdomain.len;
- if (!token822_readyplus(addr,shift)) die_nomem();
+ if (!token822_readyplus(addr, shift)) die_nomem();
+
+ for (i = addr->len - 1; i >= 0; --i) addr->t[i + shift] = addr->t[i];
- for (i = addr->len - 1; i >= 0; --i)
- addr->t[i + shift] = addr->t[i];
-
addr->len += shift;
-
- for (i = 0; i < shift; ++i)
- addr->t[i] = plusdomain.t[shift - 1 - i];
+
+ for (i = 0; i < shift; ++i) addr->t[i] = plusdomain.t[shift - 1 - i];
}
void rwgeneric(token822_alloc *addr)
@@ -293,7 +291,7 @@ void rwgeneric(token822_alloc *addr)
if (addr->t[1].type == TOKEN822_AT)
if (addr->t[0].type == TOKEN822_LITERAL)
if (!addr->t[0].slen) /* don't rewrite <foo@[]> */
- return;
+ return;
rwroute(addr);
if (!addr->len) return; /* <@foo:> -> <> */
@@ -310,9 +308,9 @@ int setreturn(token822_alloc *addr)
{
if (!sender.s) {
token822_reverse(addr);
- if (token822_unquote(&sender,addr) != 1) die_nomem();
+ if (token822_unquote(&sender, addr) != 1) die_nomem();
if (flaghackrecip)
- if (!stralloc_cats(&sender,"-@[]")) die_nomem();
+ if (!stralloc_cats(&sender, "-@[]")) die_nomem();
token822_reverse(addr);
}
return 1;
@@ -331,36 +329,36 @@ int rwsender(token822_alloc *addr)
return 1;
}
-void rwappend(token822_alloc *addr,saa *xl)
+void rwappend(token822_alloc *addr, saa *xl)
{
token822_reverse(addr);
- if (!saa_readyplus(xl,1)) die_nomem();
+ if (!saa_readyplus(xl, 1)) die_nomem();
xl->sa[xl->len] = sauninit;
- if (token822_unquote(&xl->sa[xl->len],addr) != 1) die_nomem();
+ if (token822_unquote(&xl->sa[xl->len], addr) != 1) die_nomem();
++xl->len;
token822_reverse(addr);
}
int rwhrr(token822_alloc *addr)
-{
- rwgeneric(addr);
- rwappend(addr,&hrrlist);
- return 1;
+{
+ rwgeneric(addr);
+ rwappend(addr, &hrrlist);
+ return 1;
}
int rwhr(token822_alloc *addr)
-{
- rwgeneric(addr);
- rwappend(addr,&hrlist);
- return 1;
+{
+ rwgeneric(addr);
+ rwappend(addr, &hrlist);
+ return 1;
}
int rwtocc(token822_alloc *addr)
-{
- rwgeneric(addr);
- rwappend(addr,&hrlist);
- rwappend(addr,&tocclist);
- return 1;
+{
+ rwgeneric(addr);
+ rwappend(addr, &hrlist);
+ rwappend(addr, &tocclist);
+ return 1;
}
int htypeseen[H_NUM];
@@ -373,40 +371,45 @@ void doheaderfield(stralloc *h)
{
int htype;
int (*rw)() = 0;
-
- htype = hfield_known(h->s,h->len);
- if (flagdeletefrom) if (htype == H_FROM) return;
- if (flagdeletemessid) if (htype == H_MESSAGEID) return;
- if (flagdeletesender) if (htype == H_RETURNPATH) return;
-
+
+ htype = hfield_known(h->s, h->len);
+ if (flagdeletefrom)
+ if (htype == H_FROM) return;
+ if (flagdeletemessid)
+ if (htype == H_MESSAGEID) return;
+ if (flagdeletesender)
+ if (htype == H_RETURNPATH) return;
+
if (htype)
htypeseen[htype] = 1;
- else
- if (!hfield_valid(h->s,h->len))
- die_invalid(h);
-
+ else if (!hfield_valid(h->s, h->len))
+ die_invalid(h);
+
switch (htype) {
- case H_TO: case H_CC:
- rw = rwtocc; break;
- case H_BCC: case H_APPARENTLYTO:
- rw = rwhr; break;
- case H_R_TO: case H_R_CC: case H_R_BCC:
- rw = rwhrr; break;
- case H_RETURNPATH:
- rw = rwreturn; break;
- case H_SENDER: case H_FROM: case H_REPLYTO:
- case H_RETURNRECEIPTTO: case H_ERRORSTO:
- case H_R_SENDER: case H_R_FROM: case H_R_REPLYTO:
- rw = rwsender; break;
+ case H_TO:
+ case H_CC: rw = rwtocc; break;
+ case H_BCC:
+ case H_APPARENTLYTO: rw = rwhr; break;
+ case H_R_TO:
+ case H_R_CC:
+ case H_R_BCC: rw = rwhrr; break;
+ case H_RETURNPATH: rw = rwreturn; break;
+ case H_SENDER:
+ case H_FROM:
+ case H_REPLYTO:
+ case H_RETURNRECEIPTTO:
+ case H_ERRORSTO:
+ case H_R_SENDER:
+ case H_R_FROM:
+ case H_R_REPLYTO: rw = rwsender; break;
}
if (rw) {
- doordie(h,token822_parse(&hfin,h,&hfbuf));
- doordie(h,token822_addrlist(&hfrewrite,&hfaddr,&hfin,rw));
- if (token822_unparse(h,&hfrewrite,LINELEN) != 1)
- die_nomem();
+ doordie(h, token822_parse(&hfin, h, &hfbuf));
+ doordie(h, token822_addrlist(&hfrewrite, &hfaddr, &hfin, rw));
+ if (token822_unparse(h, &hfrewrite, LINELEN) != 1) die_nomem();
}
-
+
if (htype == H_BCC) return;
if (htype == H_R_BCC) return;
if (htype == H_RETURNPATH) return;
@@ -416,7 +419,7 @@ void doheaderfield(stralloc *h)
void dobody(stralloc *h)
{
- out(h->s,h->len);
+ out(h->s, h->len);
}
stralloc torecip = {0};
@@ -424,19 +427,19 @@ token822_alloc tr = {0};
void dorecip(char *s)
{
- if (!quote2(&torecip,s)) die_nomem();
+ if (!quote2(&torecip, s)) die_nomem();
- switch (token822_parse(&tr,&torecip,&hfbuf)) {
+ switch (token822_parse(&tr, &torecip, &hfbuf)) {
case -1: die_nomem();
case 0:
- buffer_puts(buffer_2,"qmail-inject: fatal: unable to parse address: ");
- buffer_puts(buffer_2,s);
- buffer_putsflush(buffer_2,"\n");
+ buffer_puts(buffer_2, "qmail-inject: fatal: unable to parse address: ");
+ buffer_puts(buffer_2, s);
+ buffer_putsflush(buffer_2, "\n");
perm();
}
token822_reverse(&tr);
rwgeneric(&tr);
- rwappend(&tr,&reciplist);
+ rwappend(&tr, &reciplist);
}
stralloc defaultfrom = {0};
@@ -448,7 +451,7 @@ void defaultfrommake()
fullname = env_get("QMAILNAME");
if (!fullname) fullname = env_get("MAILNAME");
if (!fullname) fullname = env_get("NAME");
- if (!token822_ready(&df,20)) die_nomem();
+ if (!token822_ready(&df, 20)) die_nomem();
df.len = 0;
df.t[df.len].type = TOKEN822_ATOM;
@@ -493,10 +496,10 @@ void defaultfrommake()
++df.len;
}
- if (token822_unparse(&defaultfrom,&df,LINELEN) != 1) die_nomem();
- doordie(&defaultfrom,token822_parse(&df,&defaultfrom,&hfbuf));
- doordie(&defaultfrom,token822_addrlist(&hfrewrite,&hfaddr,&df,rwsender));
- if (token822_unparse(&defaultfrom,&hfrewrite,LINELEN) != 1) die_nomem();
+ if (token822_unparse(&defaultfrom, &df, LINELEN) != 1) die_nomem();
+ doordie(&defaultfrom, token822_parse(&df, &defaultfrom, &hfbuf));
+ doordie(&defaultfrom, token822_addrlist(&hfrewrite, &hfaddr, &df, rwsender));
+ if (token822_unparse(&defaultfrom, &hfrewrite, LINELEN) != 1) die_nomem();
}
stralloc defaultreturnpath = {0};
@@ -506,18 +509,18 @@ char strnum[FMT_ULONG];
void dodefaultreturnpath()
{
- if (!stralloc_copys(&hackedruser,mailruser)) die_nomem();
+ if (!stralloc_copys(&hackedruser, mailruser)) die_nomem();
if (flaghackmess) {
- if (!stralloc_cats(&hackedruser,"-")) die_nomem();
- if (!stralloc_catb(&hackedruser,strnum,fmt_ulong(strnum,(unsigned long) starttime))) die_nomem();
- if (!stralloc_cats(&hackedruser,".")) die_nomem();
- if (!stralloc_catb(&hackedruser,strnum,fmt_ulong(strnum,(unsigned long) getpid()))) die_nomem();
+ if (!stralloc_cats(&hackedruser, "-")) die_nomem();
+ if (!stralloc_catb(&hackedruser, strnum, fmt_ulong(strnum, (unsigned long)starttime))) die_nomem();
+ if (!stralloc_cats(&hackedruser, ".")) die_nomem();
+ if (!stralloc_catb(&hackedruser, strnum, fmt_ulong(strnum, (unsigned long)getpid()))) die_nomem();
}
if (flaghackrecip)
- if (!stralloc_cats(&hackedruser,"-")) die_nomem();
+ if (!stralloc_cats(&hackedruser, "-")) die_nomem();
- if (!token822_ready(&drp,10)) die_nomem();
+ if (!token822_ready(&drp, 10)) die_nomem();
drp.len = 0;
drp.t[drp.len].type = TOKEN822_ATOM;
@@ -540,10 +543,10 @@ void dodefaultreturnpath()
++drp.len;
}
- if (token822_unparse(&defaultreturnpath,&drp,LINELEN) != 1) die_nomem();
- doordie(&defaultreturnpath,token822_parse(&drp,&defaultreturnpath,&hfbuf));
- doordie(&defaultreturnpath,token822_addrlist(&hfrewrite,&hfaddr,&drp,rwreturn));
- if (token822_unparse(&defaultreturnpath,&hfrewrite,LINELEN) != 1) die_nomem();
+ if (token822_unparse(&defaultreturnpath, &drp, LINELEN) != 1) die_nomem();
+ doordie(&defaultreturnpath, token822_parse(&drp, &defaultreturnpath, &hfbuf));
+ doordie(&defaultreturnpath, token822_addrlist(&hfrewrite, &hfaddr, &drp, rwreturn));
+ if (token822_unparse(&defaultreturnpath, &hfrewrite, LINELEN) != 1) die_nomem();
}
int flagmft = 0;
@@ -558,11 +561,11 @@ void mft_init()
x = env_get("QMAILMFTFILE");
if (!x) return;
- r = control_readfile(&mft,x,0);
+ r = control_readfile(&mft, x, 0);
if (r == -1) die_read(); /*XXX*/
if (!r) return;
- if (!constmap_init(&mapmft,mft.s,mft.len,0)) die_nomem();
+ if (!constmap_init(&mapmft, mft.s, mft.len, 0)) die_nomem();
flagmft = 1;
}
@@ -576,18 +579,17 @@ void finishmft()
if (htypeseen[H_MAILFOLLOWUPTO]) return;
for (i = 0; i < tocclist.len; ++i)
- if (constmap(&mapmft,tocclist.sa[i].s,tocclist.sa[i].len))
- break;
+ if (constmap(&mapmft, tocclist.sa[i].s, tocclist.sa[i].len)) break;
if (i == tocclist.len) return;
outs("Mail-Followup-To: ");
i = tocclist.len;
while (i--) {
- if (!stralloc_copy(&sa,&tocclist.sa[i])) die_nomem();
+ if (!stralloc_copy(&sa, &tocclist.sa[i])) die_nomem();
if (!stralloc_0(&sa)) die_nomem();
- if (!quote2(&sa2,sa.s)) die_nomem();
- out(sa2.s,sa2.len);
+ if (!quote2(&sa2, sa.s)) die_nomem();
+ out(sa2.s, sa2.len);
if (i) outs(",\n ");
}
outs("\n");
@@ -596,27 +598,25 @@ void finishmft()
void finishheader()
{
flagresent =
- htypeseen[H_R_SENDER] || htypeseen[H_R_FROM] || htypeseen[H_R_REPLYTO]
- || htypeseen[H_R_TO] || htypeseen[H_R_CC] || htypeseen[H_R_BCC]
- || htypeseen[H_R_DATE] || htypeseen[H_R_MESSAGEID];
+ htypeseen[H_R_SENDER] || htypeseen[H_R_FROM] || htypeseen[H_R_REPLYTO] || htypeseen[H_R_TO]
+ || htypeseen[H_R_CC] || htypeseen[H_R_BCC] || htypeseen[H_R_DATE] || htypeseen[H_R_MESSAGEID];
- if (!sender.s)
- dodefaultreturnpath();
+ if (!sender.s) dodefaultreturnpath();
if (!flagqueue) {
static stralloc sa = {0};
static stralloc sa2 = {0};
- if (!stralloc_copy(&sa,&sender)) die_nomem();
+ if (!stralloc_copy(&sa, &sender)) die_nomem();
if (!stralloc_0(&sa)) die_nomem();
- if (!quote2(&sa2,sa.s)) die_nomem();
+ if (!quote2(&sa2, sa.s)) die_nomem();
outs("Return-Path: <");
- out(sa2.s,sa2.len);
+ out(sa2.s, sa2.len);
outs(">\n");
}
- /* could check at this point whether there are any recipients */
+ /* could check at this point whether there are any recipients */
if (flagqueue)
if (qmail_open(&qqt) == -1) die_qqt();
@@ -624,35 +624,33 @@ void finishheader()
if (!htypeseen[H_R_DATE]) {
if (!newfield_datemake(starttime)) die_nomem();
outs("Resent-");
- out(newfield_date.s,newfield_date.len);
+ out(newfield_date.s, newfield_date.len);
}
if (!htypeseen[H_R_MESSAGEID]) {
- if (!newfield_msgidmake(control_idhost.s,control_idhost.len,starttime)) die_nomem();
+ if (!newfield_msgidmake(control_idhost.s, control_idhost.len, starttime)) die_nomem();
outs("Resent-");
- out(newfield_msgid.s,newfield_msgid.len);
+ out(newfield_msgid.s, newfield_msgid.len);
}
if (!htypeseen[H_R_FROM]) {
defaultfrommake();
outs("Resent-");
- out(defaultfrom.s,defaultfrom.len);
+ out(defaultfrom.s, defaultfrom.len);
}
- if (!htypeseen[H_R_TO] && !htypeseen[H_R_CC])
- outs("Resent-Cc: recipient list not shown: ;\n");
+ if (!htypeseen[H_R_TO] && !htypeseen[H_R_CC]) outs("Resent-Cc: recipient list not shown: ;\n");
} else {
if (!htypeseen[H_DATE]) {
if (!newfield_datemake(starttime)) die_nomem();
- out(newfield_date.s,newfield_date.len);
+ out(newfield_date.s, newfield_date.len);
}
if (!htypeseen[H_MESSAGEID]) {
- if (!newfield_msgidmake(control_idhost.s,control_idhost.len,starttime)) die_nomem();
- out(newfield_msgid.s,newfield_msgid.len);
+ if (!newfield_msgidmake(control_idhost.s, control_idhost.len, starttime)) die_nomem();
+ out(newfield_msgid.s, newfield_msgid.len);
}
if (!htypeseen[H_FROM]) {
defaultfrommake();
- out(defaultfrom.s,defaultfrom.len);
+ out(defaultfrom.s, defaultfrom.len);
}
- if (!htypeseen[H_TO] && !htypeseen[H_CC])
- outs("Cc: recipient list not shown: ;\n");
+ if (!htypeseen[H_TO] && !htypeseen[H_CC]) outs("Cc: recipient list not shown: ;\n");
finishmft();
}
@@ -669,42 +667,43 @@ void getcontrols()
if (chdir(auto_qmail) == -1) die_chdir();
if (control_init() == -1) die_read();
- if (control_rldef(&control_defaultdomain,"control/defaultdomain",1,"defaultdomain") != 1)
+ if (control_rldef(&control_defaultdomain, "control/defaultdomain", 1, "defaultdomain") != 1)
die_read();
x = env_get("QMAILDEFAULTDOMAIN");
- if (x) if (!stralloc_copys(&control_defaultdomain,x)) die_nomem();
- if (!stralloc_copys(&sa,".")) die_nomem();
- if (!stralloc_cat(&sa,&control_defaultdomain)) die_nomem();
- doordie(&sa,token822_parse(&defaultdomain,&sa,&defaultdomainbuf));
+ if (x)
+ if (!stralloc_copys(&control_defaultdomain, x)) die_nomem();
+ if (!stralloc_copys(&sa, ".")) die_nomem();
+ if (!stralloc_cat(&sa, &control_defaultdomain)) die_nomem();
+ doordie(&sa, token822_parse(&defaultdomain, &sa, &defaultdomainbuf));
- if (control_rldef(&control_defaulthost,"control/defaulthost",1,"defaulthost") != 1)
- die_read();
+ if (control_rldef(&control_defaulthost, "control/defaulthost", 1, "defaulthost") != 1) die_read();
x = env_get("QMAILDEFAULTHOST");
- if (x) if (!stralloc_copys(&control_defaulthost,x)) die_nomem();
- if (!stralloc_copys(&sa,"@")) die_nomem();
- if (!stralloc_cat(&sa,&control_defaulthost)) die_nomem();
- doordie(&sa,token822_parse(&defaulthost,&sa,&defaulthostbuf));
+ if (x)
+ if (!stralloc_copys(&control_defaulthost, x)) die_nomem();
+ if (!stralloc_copys(&sa, "@")) die_nomem();
+ if (!stralloc_cat(&sa, &control_defaulthost)) die_nomem();
+ doordie(&sa, token822_parse(&defaulthost, &sa, &defaulthostbuf));
- if (control_rldef(&control_plusdomain,"control/plusdomain",1,"plusdomain") != 1)
- die_read();
+ if (control_rldef(&control_plusdomain, "control/plusdomain", 1, "plusdomain") != 1) die_read();
x = env_get("QMAILPLUSDOMAIN");
- if (x) if (!stralloc_copys(&control_plusdomain,x)) die_nomem();
- if (!stralloc_copys(&sa,".")) die_nomem();
- if (!stralloc_cat(&sa,&control_plusdomain)) die_nomem();
- doordie(&sa,token822_parse(&plusdomain,&sa,&plusdomainbuf));
+ if (x)
+ if (!stralloc_copys(&control_plusdomain, x)) die_nomem();
+ if (!stralloc_copys(&sa, ".")) die_nomem();
+ if (!stralloc_cat(&sa, &control_plusdomain)) die_nomem();
+ doordie(&sa, token822_parse(&plusdomain, &sa, &plusdomainbuf));
- if (control_rldef(&control_idhost,"control/idhost",1,"idhost") != 1)
- die_read();
+ if (control_rldef(&control_idhost, "control/idhost", 1, "idhost") != 1) die_read();
x = env_get("QMAILIDHOST");
- if (x) if (!stralloc_copys(&control_idhost,x)) die_nomem();
+ if (x)
+ if (!stralloc_copys(&control_idhost, x)) die_nomem();
}
#define RECIP_DEFAULT 1
-#define RECIP_ARGS 2
-#define RECIP_HEADER 3
-#define RECIP_AH 4
+#define RECIP_ARGS 2
+#define RECIP_HEADER 3
+#define RECIP_AH 4
-int main(int argc,char **argv)
+int main(int argc, char **argv)
{
int i;
int opt;
@@ -716,8 +715,8 @@ int main(int argc,char **argv)
qmopts = env_get("QMAILINJECT");
if (qmopts)
- while (*qmopts)
- switch (*qmopts++) {
+ while (*qmopts) switch (*qmopts++)
+ {
case 'c': flagnamecomment = 1; break;
case 's': flagdeletesender = 1; break;
case 'f': flagdeletefrom = 1; break;
@@ -737,7 +736,7 @@ int main(int argc,char **argv)
if (!mailuser) mailuser = env_get("LOGNAME");
if (!mailuser) mailuser = "anonymous";
mailusertokentype = TOKEN822_ATOM;
- if (quote_need(mailuser,str_len(mailuser))) mailusertokentype = TOKEN822_QUOTE;
+ if (quote_need(mailuser, str_len(mailuser))) mailusertokentype = TOKEN822_QUOTE;
mailruser = env_get("QMAILSUSER");
if (!mailruser) mailruser = mailuser;
@@ -748,13 +747,13 @@ int main(int argc,char **argv)
getcontrols();
- if (!saa_readyplus(&hrlist,1)) die_nomem();
- if (!saa_readyplus(&tocclist,1)) die_nomem();
- if (!saa_readyplus(&hrrlist,1)) die_nomem();
- if (!saa_readyplus(&reciplist,1)) die_nomem();
+ if (!saa_readyplus(&hrlist, 1)) die_nomem();
+ if (!saa_readyplus(&tocclist, 1)) die_nomem();
+ if (!saa_readyplus(&hrrlist, 1)) die_nomem();
+ if (!saa_readyplus(&reciplist, 1)) die_nomem();
- while ((opt = getopt(argc,argv,"aAhHnNf:")) != opteof)
- switch (opt) {
+ while ((opt = getopt(argc, argv, "aAhHnNf:")) != opteof) switch (opt)
+ {
case 'a': recipstrategy = RECIP_ARGS; break;
case 'A': recipstrategy = RECIP_DEFAULT; break;
case 'h': recipstrategy = RECIP_HEADER; break;
@@ -762,32 +761,28 @@ int main(int argc,char **argv)
case 'n': flagqueue = 0; break;
case 'N': flagqueue = 1; break;
case 'f':
- if (!quote2(&sender,optarg)) die_nomem();
- doordie(&sender,token822_parse(&envs,&sender,&envsbuf));
+ if (!quote2(&sender, optarg)) die_nomem();
+ doordie(&sender, token822_parse(&envs, &sender, &envsbuf));
token822_reverse(&envs);
rwgeneric(&envs);
token822_reverse(&envs);
- if (token822_unquote(&sender,&envs) != 1) die_nomem();
+ if (token822_unquote(&sender, &envs) != 1) die_nomem();
break;
case '?':
- default:
- perm();
+ default: perm();
}
argc -= optind;
argv += optind;
- if (recipstrategy == RECIP_DEFAULT)
- recipstrategy = (*argv ? RECIP_ARGS : RECIP_HEADER);
+ if (recipstrategy == RECIP_DEFAULT) recipstrategy = (*argv ? RECIP_ARGS : RECIP_HEADER);
if (recipstrategy != RECIP_HEADER)
- while (*argv)
- dorecip(*argv++);
+ while (*argv) dorecip(*argv++);
flagrh = (recipstrategy != RECIP_ARGS);
- if (headerbody(buffer_0,doheaderfield,finishheader,dobody) == -1)
- die_read();
+ if (headerbody(buffer_0, doheaderfield, finishheader, dobody) == -1) die_read();
exitnicely();
}