40#define WHO "ezmlm-manage"
66static const char hex[]=
"0123456789ABCDEF";
75static void die_usage(
void) {
logmsg(
WHO,100,USAGE,
"ezmlm-manage [-bBcCdDeEfFlLmMnNqQsSuUvV] dir"); }
80stralloc outhost = {0};
81stralloc outlocal = {0};
87stralloc verptarget = {0};
88stralloc confirm = {0};
109static char strnum[FMT_ULONG];
139 i = str_rchr(target.s,
'@');
140 if (!stralloc_copyb(&verptarget,target.s,i))
die_nomem();
142 if (!stralloc_append(&verptarget,
"="))
die_nomem();
143 if (!stralloc_cats(&verptarget,target.s + i + 1))
die_nomem();
145 if (!stralloc_0(&verptarget))
die_nomem();
161 unsigned long linetime;
165 if ((
fdout = open_trunc(
"fromn")) == -1)
168 if ((
fdin = open_read(
"from")) == -1) {
172 buffer_init(&bt,buffer_unixread,
fdin,textbuf,(
int)
sizeof(textbuf));
174 if (getln(&bt,&line,&
match,
'\n') == -1)
177 scan_ulong(line.s,&linetime);
178 if (linetime + 1000000 >
when && linetime <=
when)
179 if (buffer_put(&
bf,line.s,line.len))
186 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,
when)))
die_nomem();
187 if (!stralloc_append(&line,
" "))
die_nomem();
188 if (!stralloc_cats(&line,adr))
die_nomem();
190 if (!stralloc_catb(&line,frl->s,frl->len))
die_nomem();
191 if (!stralloc_append(&line,
"\n"))
die_nomem();
192 if (buffer_put(&
bf,line.s,line.len) == -1)
194 if (buffer_flush(&
bf) == -1)
196 if (fsync(
fdout) == -1)
198 if (close(
fdout) == -1)
200 if (rename(
"fromn",
"from") == -1)
226 unsigned long thistime;
227 unsigned long linetime;
236 scan_ulong(
act+3,&thistime);
237 if ((
fd = open_read(
"from")) == -1)
243 buffer_init(&bt,buffer_unixread,
fd,textbuf,(
int)
sizeof(textbuf));
252 pos = scan_ulong(
fromline.s,&linetime);
253 if (linetime != thistime)
continue;
254 if (!str_diff(
fromline.s + pos + 1,adr)) {
272 x += scan_ulong(x,&u);
278 strnum[fmt_ulong(strnum,(
unsigned long) u)] = 0;
282 if (str_len(x) !=
COOKIE)
return 0;
283 return byte_equal(hash,
COOKIE,x);
294buffer
bq = BUFFER_INIT(
qqwrite,-1,qqbuf,(
int)
sizeof(qqbuf));
367 hdr_add2(
"List-ID: ",line.s,line.len);
401 if (getln(&
bi,&line,&
match,
'\n') == -1)
404 if (line.len == 1)
break;
405 if ((line.s[0] !=
' ') && (line.s[0] !=
'\t')) {
408 if (case_startb(line.s,line.len,
"mailing-list:"))
411 if (byte_equal(line.s,line.len,
mydtline.s))
413 if (case_startb(line.s,line.len,
"delivered-to:"))
415 else if (case_startb(line.s,line.len,
"received:"))
417 else if (case_startb(line.s,line.len,
"content-transfer-encoding:")) {
419 while (line.s[pos] ==
' ' || line.s[pos] ==
'\t') ++pos;
420 if (case_startb(line.s+pos,line.len-pos,
"base64"))
422 else if (case_startb(line.s+pos,line.len-pos,
"quoted-printable"))
424 }
else if (flaggetfrom && case_startb(line.s,line.len,
"from:")) {
427 while (line.s[pos] ==
' ' || line.s[pos] ==
'\t') ++pos;
428 if (!stralloc_copyb(&
fromline,line.s + pos,line.len - pos - 1))
432 if (flagfromline == 1)
455 for (i = 0; i < verptarget.len - 1; i++) {
456 ch = verptarget.s[i];
457 if (str_chr(
"\"?;<>&/:%+#",ch) < 10 || (ch <=
' ') || (ch & 0x80)) {
459 urlstr[2] = hex[ch & 0xf];
470 if (!stralloc_copy(&confirm,&outlocal))
die_nomem();
471 if (!stralloc_append(&confirm,
"unsubscribe-"))
die_nomem();
472 if (!stralloc_cats(&confirm,verptarget.s))
die_nomem();
473 if (!stralloc_append(&confirm,
"@"))
die_nomem();
474 if (!stralloc_cat(&confirm,&outhost))
die_nomem();
526 strnum[fmt_ulong(strnum,(
unsigned long)
when)] = 0;
528 if (!stralloc_copy(&confirm,&outlocal))
die_nomem();
529 if (!stralloc_append(&confirm,
"-"))
die_nomem();
531 if (!stralloc_cats(&confirm,
"c."))
die_nomem();
532 if (!stralloc_cats(&confirm,strnum))
die_nomem();
533 if (!stralloc_append(&confirm,
"."))
die_nomem();
535 if (!stralloc_append(&confirm,
"-"))
die_nomem();
536 if (!stralloc_cats(&confirm,verptarget.s))
die_nomem();
537 if (!stralloc_append(&confirm,
"@"))
die_nomem();
538 if (!stralloc_cat(&confirm,&outhost))
die_nomem();
571 hdr_adds(
"Content-Disposition: inline; filename=request.msg");
578 if (seek_begin(0) == -1)
580 if (buffer_copy(&
bq,&
bj) != 0)
601 char *
cp, *cpfirst, *cplast, *cpnext, *cpafter;
616 while ((
opt = getoptb(argc,argv,
"bBcCdDeEfFlLmMnNqQsSuUvV")) != opteof)
642 default: die_usage();
646 if (!
dir) die_usage();
648 sender = env_get(
"SENDER");
650 action = env_get(
"DEFAULT");
655 if (!sender[str_chr(sender,
'@')])
657 if (str_equal(sender,
"#@[]"))
660 if (chdir(
dir) == -1)
663 switch (openreadclose(
"key",&key,32)) {
687 if (case_starts(
action,
"digest")) {
689 if (!stralloc_cats(&outlocal,
"-digest"))
die_nomem();
694 if (!stralloc_append(&outlocal,
"-"))
die_nomem();
700 if (!stralloc_append(&outlocal,
"-"))
die_nomem();
706 if (*(
action++) !=
'-') die_badaddr();
712 if (!stralloc_copys(&target,sender))
die_nomem();
718 i = byte_rchr(target.s,target.len,
'=');
776 if ((
flagpublic = openreadclose(
"public",&line,1)) == -1)
782 if (!
pmod || !flagremote)
803 if (
pmod && flagremote) {
828 if (
flagmod && !(
pmod && str_equal(sender,target.s))) {
855 if (!
pmod || !flagremote)
865 if (
pmod && flagremote) {
925 if (!
pmod || !flagremote)
985 while ((ch =
fnedit.s[i++])) {
986 if (((ch >
'z') || (ch <
'a')) && (ch !=
'_'))
988 if (ch ==
'_')
fnedit.s[i-1] =
'-';
1000 s = line.s; n = line.len;
1001 while(n--) {
if (!*s) *s =
'_'; ++s; }
1004 strnum[fmt_ulong(strnum,(
unsigned long)
when)] = 0;
1005 cookie(hash,key.s,key.len,strnum,line.s,
"-e");
1006 if (!stralloc_copy(&confirm,&outlocal))
die_nomem();
1007 if (!stralloc_append(&confirm,
"-"))
die_nomem();
1009 if (!stralloc_cats(&confirm,strnum))
die_nomem();
1010 if (!stralloc_append(&confirm,
"."))
die_nomem();
1013 if (!stralloc_append(&confirm,
"."))
die_nomem();
1015 if (!stralloc_append(&confirm,
"@"))
die_nomem();
1016 if (!stralloc_cat(&confirm,&outhost))
die_nomem();
1049 x += scan_ulong(x,&u);
1050 if ((u >
when) || (u <
when - 100000)) die_cookie();
1053 x += str_chr(x,
'.');
1054 if (!*x) die_cookie();
1063 if (((*y >
'z') || (*y <
'a')) && (*y !=
'_'))
1065 if (*y ==
'_') *y =
'-';
1070 switch (openreadclose(
fnedit.s,&
text,1024)) {
1079 s = line.s; n = line.len;
1080 while(n--) {
if (!*s) *s =
'_'; ++s; }
1083 strnum[fmt_ulong(strnum,(
unsigned long) u)] = 0;
1084 cookie(hash,key.s,key.len,strnum,line.s,
"-e");
1085 if (str_len(x) !=
COOKIE) die_cookie();
1086 if (byte_diff(hash,
COOKIE,x)) die_cookie();
1094 buffer_init(&bt,buffer_unixwrite,
fd,textbuf,
sizeof(textbuf));
1099 if (getln(&
bi,&line,&
match,
'\n') == -1)
1116 while ((cpnext =
cp + byte_chr(
cp,cpafter-
cp,
'\n')) != cpafter) {
1117 i = byte_chr(
cp,cpnext-
cp,
'%');
1118 if (i != (
unsigned int) (cpnext -
cp)) {
1119 if (!flaggoodfield) {
1134 if (flaggoodfield) {
1141 cplast = cpnext - 1;
1142 if (*cplast ==
'\r')
1146 if (buffer_put(&bt,
cp,cplast-
cp+1) == -1)
1153 if (buffer_flush(&bt) == -1)
1155 if (fsync(
fd) == -1)
1157 if (fchmod(
fd, 0600) == -1)
1159 if (close(
fd) == -1)
1191 scan_ulong(
action + pos,&u);
1193 if (!stralloc_copys(&line,
"archive/"))
die_nomem();
1194 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,u / 100)))
die_nomem();
1195 if (!stralloc_cats(&line,
"/"))
die_nomem();
1196 if (!stralloc_catb(&line,strnum,fmt_uint0(strnum,(
unsigned int) (u % 100),2)))
die_nomem();
1199 fd = open_read(line.s);
1201 if (errno != ENOENT)
1206 if (fstat(
fd,&st) == -1)
1208 else if (!(st.st_mode & 0100))
1211 buffer_init(&bt,buffer_unixread,
fd,textbuf,
sizeof(textbuf));
1214 r = buffer_get(&bt,&ch,1);
#define TXT_UNSUBSCRIBE_FROM
#define TXT_EDIT_RESPONSE
#define TXT_SUB_LOG_SEARCH
#define ACTION_UNSUBSCRIBE
int issub()
Returns (char *) to match if userhost is in the subscriber database dbname, 0 otherwise....
int quote2(stralloc *sa, const char *s)
int quote(stralloc *saout, const stralloc *sain)
const char auto_version[]
#define hdr_listsubject1(a)
#define hdr_listsubject2(a, b)
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOT_AVAILABLE
#define ERR_TMP_QMAIL_QUEUE
int lockfile(const char *)
const char * qmail_close(struct qmail *)
void qmail_puts(struct qmail *, const char *)
void qmail_put(struct qmail *, const char *, int)
void qmail_from(struct qmail *, const char *)
void qmail_to(struct qmail *, const char *)
unsigned long qmail_qp(struct qmail *)
int qmail_open(struct qmail *, const stralloc *)
charset, outhost, outlocal and flagcd are shared
void closesql(void)
close connection to SQL server, if open
unsigned long putsubs(const char *dir, unsigned long hash_lo, unsigned long hash_hi, int subwrite(), int flagsql)
int subscribe(const char *dir, const char *username, int flagadd, const char *from, const char *event, int flagmysql, int forcehash, const char *table_override)
void searchlog(const char *dir, char *search, int subwrite())
int getconf_line(stralloc *sa, const char *fn, int flagrequired, const char *dir)
void ezcopy(struct qmail *qqp, const char *fn, char q)
void set_cpoutlocal(const stralloc *ln)
void set_cpverptarget(const char *tg)
void set_cptarget(const char *tg)
void set_cpouthost(const stralloc *ln)
void set_cpconfirm(const char *cf)
void encode_qp(const char *indata, unsigned int n, stralloc *outdata)
int subto(char *s, unsigned int l)
void hdr_listsubject3(const char *a, const char *b, const char *c)
void hdr_from(const char *append)
char * get_from(char *adr, char *act)
void doconfirm(char *act)
void msg_headers()
Writes all the headers up to but not including subject.
int subto(char *s, unsigned int l)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
int hashok(char *action, char *ac)
int dummy_to(char *s, unsigned int l)
int code_subto(char *s, unsigned int l)
void store_from(stralloc *frl, char *adr)
void make_verptarget()
puts target with '=' instead of last '@' into stralloc verptarget and does set_cpverptarget
int code_qput(char *s, unsigned int n)
void decode_b64(const char *cpfrom, unsigned int n, stralloc *outdata)
void hdr_boundary(int last)
void hdr_datemsgid(unsigned long when)
void cookie(char *hash, const char *key, unsigned int keylen, const char *date, const char *addr, const char *action)
ssize_t qqwrite(int fd, char *buf, unsigned int len)
void hdr_add2(const char *start, const char *value, unsigned int len)
void hdr_adds(const char *line)
void hdr_ctboundary(void)
void encode_b64(const unsigned char *indata, unsigned int n, stralloc *outdata, int control)
void hdr_ctype(enum ctype ctype)
void hdr_mime(enum ctype ctype)
void decode_qp(const char *cpfrom, unsigned int n, stralloc *outdata)
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)