18#define WHO "qmail-mfrules"
20int rename(
const char *,
const char *);
38 logmsg(
WHO,112,FATAL,
"out of memory");
40static void die_parse()
43 logmsg(
WHO,100,ERROR,B(
"unable to parse this line: ",
line.s));
47 logmsg(
WHO,111,ERROR,
"unable to read control/mailfromrules");
51 logmsg(
WHO,111,ERROR,
"unable to write to control/mailfromrules.tmp");
57static void getnum(
char *
buf,
int len,
unsigned long *u)
61 if (
sanum.s[scan_ulong(
sanum.s,u)]) die_parse();
64static void doaddressdata()
76 left = byte_rchr(
address.s,i,
'.');
77 if (left == i) left = 0;
else ++left;
82 getnum(
address.s + left,i - 1 - left,&bot);
83 getnum(
address.s + i,right - i,&top);
84 if (top > 255) top = 255;
90 case_lowerb(
key.s,
key.len);
116 fd = open_read(
"control/mailfromrules");
121 fdtemp = open_trunc(
"control/mailfromrules.tmp");
132 if (x[0] ==
'#')
continue;
133 if (x[0] ==
'\n')
continue;
137 if (ch !=
'\n')
if (ch !=
' ')
if (ch !=
'\t')
break;
142 amper = byte_chr(x,len,
'&');
143 if (!amper) die_parse();
144 if (amper)
if (amper == len || amper < 2) die_parse();
149 x =
line.s + amper + 1; len =
line.len - amper - 1;
152 if (len < 3) die_parse();
153 if ( *x ==
',' || *x ==
' ' || *x ==
'\t') die_parse();
154 i = byte_chr(x,len,
',');
155 if (i > 0 && i < len) {
158 x += i + 1; len -= i + 1; }
170 if (
rename(
"control/mailfromrules.tmp",
"control/mailfromrules.cdb") == -1)
171 logmsg(
WHO,111,ERROR,
"unable to move control/mailfromrules.tmp to control/mailfromrules.cdb");
int stralloc_copys(stralloc *, char const *)
int rename(const char *, const char *)