📄 qmail-local.c
字号:
if (!stralloc_0(&qme)) temp_nomem(); *fd = open_read(qme.s); if (*fd == -1) { if (error_temp(errno)) temp_qmail(qme.s); if (errno == error_perm) temp_qmail(qme.s); if (errno == error_acces) temp_qmail(qme.s); return 0; } if (fstat(*fd,&st) == -1) temp_qmail(qme.s); if ((st.st_mode & S_IFMT) == S_IFREG) { if (st.st_mode & auto_patrn) strerr_die1x(111,"Uh-oh: .qmail file is writable. (#4.7.0)"); *cutable = !!(st.st_mode & 0100); return 1; } close(*fd); return 0;}/* "" "": "" *//* "-/" "": "-/" "-/default" *//* "-/" "a": "-/a" "-/default" *//* "-/" "a-": "-/a-" "-/a-default" "-/default" *//* "-/" "a-b": "-/a-b" "-/a-default" "-/default" *//* "-/" "a-b-": "-/a-b-" "-/a-b-default" "-/a-default" "-/default" *//* "-/" "a-b-c": "-/a-b-c" "-/a-b-default" "-/a-default" "-/default" */void qmesearch(fd,cutable)int *fd;int *cutable;{ int i; if (!stralloc_copys(&qme,".qmail")) temp_nomem(); if (!stralloc_cats(&qme,dash)) temp_nomem(); if (!stralloc_cat(&qme,&safeext)) temp_nomem(); if (qmeexists(fd,cutable)) { if (safeext.len >= 7) { i = safeext.len - 7; if (!byte_diff("default",7,safeext.s + i)) if (i <= str_len(ext)) /* paranoia */ if (!env_put2("DEFAULT",ext + i)) temp_nomem(); } return; } for (i = safeext.len;i >= 0;--i) if (!i || (safeext.s[i - 1] == '-')) { if (!stralloc_copys(&qme,".qmail")) temp_nomem(); if (!stralloc_cats(&qme,dash)) temp_nomem(); if (!stralloc_catb(&qme,safeext.s,i)) temp_nomem(); if (!stralloc_cats(&qme,"default")) temp_nomem(); if (qmeexists(fd,cutable)) { if (i <= str_len(ext)) /* paranoia */ if (!env_put2("DEFAULT",ext + i)) temp_nomem(); return; } } *fd = -1;}unsigned long count_file = 0;unsigned long count_forward = 0;unsigned long count_program = 0;char count_buf[FMT_ULONG];void count_print(){ substdio_puts(subfdoutsmall,"did "); substdio_put(subfdoutsmall,count_buf,fmt_ulong(count_buf,count_file)); substdio_puts(subfdoutsmall,"+"); substdio_put(subfdoutsmall,count_buf,fmt_ulong(count_buf,count_forward)); substdio_puts(subfdoutsmall,"+"); substdio_put(subfdoutsmall,count_buf,fmt_ulong(count_buf,count_program)); substdio_puts(subfdoutsmall,"\n"); if (mailforward_qp) { substdio_puts(subfdoutsmall,"qp "); substdio_put(subfdoutsmall,count_buf,fmt_ulong(count_buf,mailforward_qp)); substdio_puts(subfdoutsmall,"\n"); } substdio_flush(subfdoutsmall);}void sayit(type,cmd,len)char *type;char *cmd;int len;{ substdio_puts(subfdoutsmall,type); substdio_put(subfdoutsmall,cmd,len); substdio_putsflush(subfdoutsmall,"\n");}void main(argc,argv)int argc;char **argv;{ int opt; int i; int j; int k; int fd; int numforward; char **recips; datetime_sec starttime; int flagforwardonly; char *x; umask(077); sig_pipeignore(); if (!env_init()) temp_nomem(); flagdoit = 1; while ((opt = getopt(argc,argv,"nN")) != opteof) switch(opt) { case 'n': flagdoit = 0; break; case 'N': flagdoit = 1; break; default: usage(); } argc -= optind; argv += optind; if (!(user = *argv++)) usage(); if (!(homedir = *argv++)) usage(); if (!(local = *argv++)) usage(); if (!(dash = *argv++)) usage(); if (!(ext = *argv++)) usage(); if (!(host = *argv++)) usage(); if (!(sender = *argv++)) usage(); if (!(aliasempty = *argv++)) usage(); if (*argv) usage(); if (homedir[0] != '/') usage(); if (chdir(homedir) == -1) strerr_die5x(111,"Unable to switch to ",homedir,": ",error_str(errno),". (#4.3.0)"); checkhome(); if (!env_put2("HOST",host)) temp_nomem(); if (!env_put2("HOME",homedir)) temp_nomem(); if (!env_put2("USER",user)) temp_nomem(); if (!env_put2("LOCAL",local)) temp_nomem(); if (!stralloc_copys(&envrecip,local)) temp_nomem(); if (!stralloc_cats(&envrecip,"@")) temp_nomem(); if (!stralloc_cats(&envrecip,host)) temp_nomem(); if (!stralloc_copy(&foo,&envrecip)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("RECIPIENT",foo.s)) temp_nomem(); if (!stralloc_copys(&dtline,"Delivered-To: ")) temp_nomem(); if (!stralloc_cat(&dtline,&envrecip)) temp_nomem(); for (i = 0;i < dtline.len;++i) if (dtline.s[i] == '\n') dtline.s[i] = '_'; if (!stralloc_cats(&dtline,"\n")) temp_nomem(); if (!stralloc_copy(&foo,&dtline)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("DTLINE",foo.s)) temp_nomem(); if (flagdoit) bouncexf(); if (!env_put2("SENDER",sender)) temp_nomem(); if (!quote2(&foo,sender)) temp_nomem(); if (!stralloc_copys(&rpline,"Return-Path: <")) temp_nomem(); if (!stralloc_cat(&rpline,&foo)) temp_nomem(); for (i = 0;i < rpline.len;++i) if (rpline.s[i] == '\n') rpline.s[i] = '_'; if (!stralloc_cats(&rpline,">\n")) temp_nomem(); if (!stralloc_copy(&foo,&rpline)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("RPLINE",foo.s)) temp_nomem(); if (!stralloc_copys(&ufline,"From ")) temp_nomem(); if (*sender) { int len; int i; char ch; len = str_len(sender); if (!stralloc_readyplus(&ufline,len)) temp_nomem(); for (i = 0;i < len;++i) { ch = sender[i]; if ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = '-'; ufline.s[ufline.len + i] = ch; } ufline.len += len; } else if (!stralloc_cats(&ufline,"MAILER-DAEMON")) temp_nomem(); if (!stralloc_cats(&ufline," ")) temp_nomem(); starttime = now(); if (!stralloc_cats(&ufline,myctime(starttime))) temp_nomem(); if (!stralloc_copy(&foo,&ufline)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("UFLINE",foo.s)) temp_nomem(); x = ext; if (!env_put2("EXT",x)) temp_nomem(); x += str_chr(x,'-'); if (*x) ++x; if (!env_put2("EXT2",x)) temp_nomem(); x += str_chr(x,'-'); if (*x) ++x; if (!env_put2("EXT3",x)) temp_nomem(); x += str_chr(x,'-'); if (*x) ++x; if (!env_put2("EXT4",x)) temp_nomem(); if (!stralloc_copys(&safeext,ext)) temp_nomem(); case_lowerb(safeext.s,safeext.len); for (i = 0;i < safeext.len;++i) if (safeext.s[i] == '.') safeext.s[i] = ':'; i = str_len(host); i = byte_rchr(host,i,'.'); if (!stralloc_copyb(&foo,host,i)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("HOST2",foo.s)) temp_nomem(); i = byte_rchr(host,i,'.'); if (!stralloc_copyb(&foo,host,i)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("HOST3",foo.s)) temp_nomem(); i = byte_rchr(host,i,'.'); if (!stralloc_copyb(&foo,host,i)) temp_nomem(); if (!stralloc_0(&foo)) temp_nomem(); if (!env_put2("HOST4",foo.s)) temp_nomem(); flagforwardonly = 0; qmesearch(&fd,&flagforwardonly); if (fd == -1) if (*dash) strerr_die1x(100,"Sorry, no mailbox here by that name. (#5.1.1)"); if (!stralloc_copys(&ueo,sender)) temp_nomem(); if (str_diff(sender,"")) if (str_diff(sender,"#@[]")) if (qmeox("-owner") == 0) { if (qmeox("-owner-default") == 0) { if (!stralloc_copys(&ueo,local)) temp_nomem(); if (!stralloc_cats(&ueo,"-owner-@")) temp_nomem(); if (!stralloc_cats(&ueo,host)) temp_nomem(); if (!stralloc_cats(&ueo,"-@[]")) temp_nomem(); } else { if (!stralloc_copys(&ueo,local)) temp_nomem(); if (!stralloc_cats(&ueo,"-owner@")) temp_nomem(); if (!stralloc_cats(&ueo,host)) temp_nomem(); } } if (!stralloc_0(&ueo)) temp_nomem(); if (!env_put2("NEWSENDER",ueo.s)) temp_nomem(); if (!stralloc_ready(&cmds,0)) temp_nomem(); cmds.len = 0; if (fd != -1) if (slurpclose(fd,&cmds,256) == -1) temp_nomem(); if (!cmds.len) { if (!stralloc_copys(&cmds,aliasempty)) temp_nomem(); flagforwardonly = 0; } if (!cmds.len || (cmds.s[cmds.len - 1] != '\n')) if (!stralloc_cats(&cmds,"\n")) temp_nomem(); numforward = 0; i = 0; for (j = 0;j < cmds.len;++j) if (cmds.s[j] == '\n') { switch(cmds.s[i]) { case '#': case '.': case '/': case '|': break; default: ++numforward; } i = j + 1; } recips = (char **) alloc((numforward + 1) * sizeof(char *)); if (!recips) temp_nomem(); numforward = 0; flag99 = 0; i = 0; for (j = 0;j < cmds.len;++j) if (cmds.s[j] == '\n') { cmds.s[j] = 0; k = j; while ((k > i) && (cmds.s[k - 1] == ' ') || (cmds.s[k - 1] == '\t')) cmds.s[--k] = 0; switch(cmds.s[i]) { case 0: /* k == i */ if (i) break; strerr_die1x(111,"Uh-oh: first line of .qmail file is blank. (#4.2.1)"); case '#': break; case '.': case '/': ++count_file; if (flagforwardonly) strerr_die1x(111,"Uh-oh: .qmail has file delivery but has x bit set. (#4.7.0)"); if (cmds.s[k - 1] == '/') if (flagdoit) maildir(cmds.s + i); else sayit("maildir ",cmds.s + i,k - i); else if (flagdoit) mailfile(cmds.s + i); else sayit("mbox ",cmds.s + i,k - i); break; case '|': ++count_program; if (flagforwardonly) strerr_die1x(111,"Uh-oh: .qmail has prog delivery but has x bit set. (#4.7.0)"); if (flagdoit) mailprogram(cmds.s + i + 1); else sayit("program ",cmds.s + i + 1,k - i - 1); break; case '+': if (str_equal(cmds.s + i + 1,"list")) flagforwardonly = 1; break; case '&': ++i; default: ++count_forward; if (flagdoit) recips[numforward++] = cmds.s + i; else sayit("forward ",cmds.s + i,k - i); break; } i = j + 1; if (flag99) break; } if (numforward) if (flagdoit) { recips[numforward] = 0; mailforward(recips); } count_print(); _exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -