分享
 
 
 

qmail-local代码分析

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

我分析的代码没有“夜未眠”大哥的好,可能还有的不正确,就请各位多多指教,谢谢

[code:1:c552cb0758]#include

#include

#include "readwrite.h"

#include "sig.h"

#include "env.h"

#include "byte.h"

#include "exit.h"

#include "fork.h"

#include "open.h"

#include "wait.h"

#include "lock.h"

#include "seek.h"

#include "substdio.h"

#include "getln.h"

#include "strerr.h"

#include "subfd.h"

#include "sgetopt.h"

#include "alloc.h"

#include "error.h"

#include "stralloc.h"

#include "fmt.h"

#include "str.h"

#include "now.h"

#include "case.h"

#include "quote.h"

#include "qmail.h"

#include "slurpclose.h"

#include "myctime.h"

#include "gfrom.h"

#include "auto_patrn.h"

void usage() { strerr_die1x(100,"qmail-local: usage: qmail-local [ -nN ] user homedir local dash ext domain sender aliasempty"); }

void temp_nomem() { strerr_die1x(111,"Out of memory. (#4.3.0)"); }

void temp_rewind() { strerr_die1x(111,"Unable to rewind message. (#4.3.0)"); }

void temp_childcrashed() { strerr_die1x(111,"Aack, child crashed. (#4.3.0)"); }

void temp_fork() { strerr_die3x(111,"Unable to fork: ",error_str(errno),". (#4.3.0)"); }

void temp_read() { strerr_die3x(111,"Unable to read message: ",error_str(errno),". (#4.3.0)"); }

void temp_slowlock()

{ strerr_die1x(111,"File has been locked for 30 seconds straight. (#4.3.0)"); }

void temp_qmail(fn) char *fn;

{ strerr_die5x(111,"Unable to open ",fn,": ",error_str(errno),". (#4.3.0)"); }

int flagdoit;

int flag99;

char *user;

char *homedir;

char *local;

char *dash;

char *ext;

char *host;

char *sender;

char *aliasempty;

stralloc safeext = {0};

stralloc ufline = {0};

stralloc rpline = {0};

stralloc envrecip = {0};

stralloc dtline = {0};

stralloc qme = {0};

stralloc ueo = {0};

stralloc cmds = {0};

stralloc messline = {0};

stralloc foo = {0};

char buf[1024];

char outbuf[1024];

/* child process */

char fntmptph[80 + FMT_ULONG * 2];

char fnnewtph[80 + FMT_ULONG * 2];

void tryunlinktmp() { unlink(fntmptph); }/*删除fntmptph文件,或连接*/

void sigalrm() { tryunlinktmp(); _exit(3); }

void maildir_child(dir)

char *dir;

{

unsigned long pid;

unsigned long time;

char host[64];

char *s;

int loop;

struct stat st;

int fd;

substdio ss;

substdio ssout;

sig_alarmcatch(sigalrm);//捕捉时间信号。

if (chdir(dir) == -1) { if (error_temp(errno)) _exit(1); _exit(2); }

pid = getpid();//获取当前的进程号。

host[0] = 0;

gethostname(host,sizeof(host));

for (loop = 0;;++loop)

{

time = now();

s = fntmptph;

s += fmt_str(s,"tmp/");/*将"tmp/"拷到s中*/

s += fmt_ulong(s,time); *s++ = '.';/*将时间转化为字符串*/

s += fmt_ulong(s,pid); *s++ = '.';

s += fmt_strn(s,host,sizeof(host)); *s++ = 0;

if (stat(fntmptph,%26amp;st) == -1) if (errno == error_noent) break;

/* really should never get to this point */

if (loop == 2) _exit(1);

sleep(2);

}

str_copy(fnnewtph,fntmptph);

byte_copy(fnnewtph,3,"new");

//时间为24小时

alarm(86400);

fd = open_excl(fntmptph);

if (fd == -1) _exit(1);

///////////////////////////////////////////////////

substdio_fdbuf(%26amp;ss,read,0,buf,sizeof(buf));

substdio_fdbuf(%26amp;ssout,write,fd,outbuf,sizeof(outbuf));

//dtline:邮件头Delivered-To部分

//rpline:邮件头返回路径

//无需"From "头部

if (substdio_put(%26amp;ssout,rpline.s,rpline.len) == -1) goto fail;

if (substdio_put(%26amp;ssout,dtline.s,dtline.len) == -1) goto fail;

//将邮件写到文件fd中

switch(substdio_copy(%26amp;ssout,%26amp;ss))

{

case -2: tryunlinktmp(); _exit(4);

case -3: goto fail;

}

if (substdio_flush(%26amp;ssout) == -1) goto fail;

//将fd所指文件数据由系统缓冲区写回磁盘正确返回0,错误返回-1

if (fsync(fd) == -1) goto fail;

if (close(fd) == -1) goto fail; /* NFS dorks */

if (link(fntmptph,fnnewtph) == -1) goto fail;

/* if it was error_exist, almost certainly successful; i hate NFS */

tryunlinktmp(); _exit(0);

fail: tryunlinktmp(); _exit(1);

}

/* end child process */

//maildir 格式邮箱的邮件投递,不要锁定

void maildir(fn)

char *fn;

{

int child;

int wstat;

//#define seek_begin(fd) (seek_set((fd),(seek_pos) 0))

//指向文件0的开头

if (seek_begin(0) == -1) temp_rewind();

switch(child = fork())

{

case -1:

temp_fork();

case 0:

maildir_child(fn);/////////////////////////////////////

_exit(111);

}

//返回子进程fd的结束状态值于wstat中

wait_pid(%26amp;wstat,child);

//#define wait_crashed(w) ((w) %26amp; 127)

if (wait_crashed(wstat))

temp_childcrashed();

//#define wait_exitcode(w) ((w) 8)

switch(wait_exitcode(wstat))

{

case 0: break;

case 2: strerr_die1x(111,"Unable to chdir to maildir. (#4.2.1)");

case 3: strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)");

case 4: strerr_die1x(111,"Unable to read message. (#4.3.0)");

default: strerr_die1x(111,"Temporary error on maildir delivery. (#4.3.0)");

}

}

//mbox 格式邮箱的邮件投递,必须锁定

void mailfile(fn)

char *fn;

{

int fd;

substdio ss;

substdio ssout;

int match;

seek_pos pos;

int flaglocked;

//到文件0开头

if (seek_begin(0) == -1) temp_rewind();

//打开文件fn

fd = open_append(fn);

if (fd == -1)

strerr_die5x(111,"Unable to open ",fn,": ",error_str(errno),". (#4.2.1)");

//时间信号,30秒

sig_alarmcatch(temp_slowlock);

alarm(30);

//锁定

flaglocked = (lock_ex(fd) != -1);

alarm(0);

sig_alarmdefault();

//结尾

seek_end(fd);

//pos实际指向文件尾(文件大小)

pos = seek_cur(fd);

substdio_fdbuf(%26amp;ss,read,0,buf,sizeof(buf));

substdio_fdbuf(%26amp;ssout,write,fd,outbuf,sizeof(outbuf));

//dtline:邮件头Delivered-To部分

//rpline:邮件头返回路径

//ufline:mbox 是标准的UNIX邮箱格式, 多个邮件存放在一个独立文件内, 每个邮件由一个"From" 的行开始.

//这一行看起来像一个标题字段, 不过那不是标题, 那仅仅是传送代理添加的, 便于邮件读出器可以找到每个邮件开始部分的一个标记.

if (substdio_put(%26amp;ssout,ufline.s,ufline.len)) goto writeerrs;

if (substdio_put(%26amp;ssout,rpline.s,rpline.len)) goto writeerrs;

if (substdio_put(%26amp;ssout,dtline.s,dtline.len)) goto writeerrs;

for (;;)

{//读一行

if (getln(%26amp;ss,%26amp;messline,%26amp;match,'\n') != 0)

{

strerr_warn3("Unable to read message: ",error_str(errno),". (#4.3.0)",0);

if (flaglocked) seek_trunc(fd,pos); close(fd);

_exit(111);

}

if (!match %26amp;%26amp; !messline.len) break;

if (gfrom(messline.s,messline.len))

if (substdio_bput(%26amp;ssout,"",1)) goto writeerrs;

if (substdio_bput(%26amp;ssout,messline.s,messline.len)) goto writeerrs;

if (!match)

{

if (substdio_bputs(%26amp;ssout,"\n")) goto writeerrs;

break;

}

}

if (substdio_bputs(%26amp;ssout,"\n")) goto writeerrs;

if (substdio_flush(%26amp;ssout)) goto writeerrs;

//由缓冲区写回磁盘

if (fsync(fd) == -1) goto writeerrs;

close(fd);

return;

writeerrs:

strerr_warn5("Unable to write ",fn,": ",error_str(errno),". (#4.3.0)",0);

if (flaglocked) seek_trunc(fd,pos);

close(fd);

_exit(111);

}

void mailprogram(prog)

char *prog;

{

int child;

char *(args[4]);

int wstat;

if (seek_begin(0) == -1) temp_rewind();

switch(child = fork())

{

case -1:

temp_fork();

case 0:

args[0] = "/bin/sh"; args[1] = "-c"; args[2] = prog; args[3] = 0;

sig_pipedefault();

execv(*args,args);

strerr_die3x(111,"Unable to run /bin/sh: ",error_str(errno),". (#4.3.0)");

}

wait_pid(%26amp;wstat,child);

if (wait_crashed(wstat))

temp_childcrashed();

switch(wait_exitcode(wstat))

{

case 100:

case 64: case 65: case 70: case 76: case 77: case 78: case 112: _exit(100);

case 0: break;

case 99: flag99 = 1; break;

default: _exit(111);

}

}

unsigned long mailforward_qp = 0;

//转发邮件,地址在recips中

void mailforward(recips)

char **recips;

{//struct qmail {

// int flagerr;

// unsigned long pid;

// int fdm;

// int fde;

// substdio ss;

// char buf[1024];

// } ;

struct qmail qqt;

char *qqx;

substdio ss;

int match;

if (seek_begin(0) == -1) temp_rewind();

substdio_fdbuf(%26amp;ss,read,0,buf,sizeof(buf));

if (qmail_open(%26amp;qqt) == -1) temp_fork();

mailforward_qp = qmail_qp(%26amp;qqt);

qmail_put(%26amp;qqt,dtline.s,dtline.len);

do

{

if (getln(%26amp;ss,%26amp;messline,%26amp;match,'\n') != 0) { qmail_fail(%26amp;qqt); break; }

qmail_put(%26amp;qqt,messline.s,messline.len);

}

while (match);

qmail_from(%26amp;qqt,ueo.s);

while (*recips) qmail_to(%26amp;qqt,*recips++);

qqx = qmail_close(%26amp;qqt);

if (!*qqx) return;

strerr_die3x(*qqx == 'D' ? 100 : 111,"Unable to forward message: ",qqx + 1,".");

}

void bouncexf()

{

int match;

substdio ss;

//#define seek_begin(fd) (seek_set((fd),(seek_pos) 0))

//typedef unsigned long seek_pos

//将文件0的指针移到开始位置。

if (seek_begin(0) == -1) temp_rewind();

//给ss附值,ss-x=buf,s-fd = 0;s-op = read;s-p = 0(字节数);s-n = sizeof(buf)(还有的空间)

substdio_fdbuf(%26amp;ss,read,0,buf,sizeof(buf));

for (;;)

{

if (getln(%26amp;ss,%26amp;messline,%26amp;match,'\n') != 0) temp_read();

if (!match) break;

//判断文件是否结束

if (messline.len

break;

if (messline.len == dtline.len)

if (!str_diffn(messline.s,dtline.s,dtline.len))

strerr_die1x(100,"This message is looping: it already has my Delivered-To line. (#5.4.6)");

}

}

void checkhome()

{

struct stat st;

if (stat(".",%26amp;st) == -1)

strerr_die3x(111,"Unable to stat home directory: ",error_str(errno),". (#4.3.0)");

if (st.st_mode %26amp; auto_patrn)

strerr_die1x(111,"Uh-oh: home directory is writable. (#4.7.0)");

if (st.st_mode %26amp; 01000)

if (flagdoit)

strerr_die1x(111,"Home directory is sticky: user is editing his .qmail file. (#4.2.1)");

else

strerr_warn1("Warning: home directory is sticky.",0);

}

//得到文件".qmail"+dash+safeext+dashowner的权限,正确返回0,错误为-1

int qmeox(dashowner)

char *dashowner;

{

struct stat st;

if (!stralloc_copys(%26amp;qme,".qmail")) temp_nomem();

if (!stralloc_cats(%26amp;qme,dash)) temp_nomem();

if (!stralloc_cat(%26amp;qme,%26amp;safeext)) temp_nomem();

if (!stralloc_cats(%26amp;qme,dashowner)) temp_nomem();

if (!stralloc_0(%26amp;qme)) temp_nomem();

if (stat(qme.s,%26amp;st) == -1)

{

if (error_temp(errno)) temp_qmail(qme.s);

return -1;

}

return 0;

}

//qme文件存在且是一般文件返回1,否则为0

int qmeexists(fd,cutable)

int *fd;

int *cutable;

{

struct stat st;

if (!stralloc_0(%26amp;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,%26amp;st) == -1) temp_qmail(qme.s);

//S_IFREG表示一般文件

if ((st.st_mode %26amp; S_IFMT) == S_IFREG) {

if (st.st_mode %26amp; auto_patrn)

strerr_die1x(111,"Uh-oh: .qmail file is writable. (#4.7.0)");

*cutable = !!(st.st_mode %26amp; 0100);//看文件的owner权限是否为可执行的。是*cutable = 1,不是*cutable = 0

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" */

//打开文件%26amp;qme,如是一般文件再看是否为default,如果是,"DEFAULT"+*(ext+i)结合加入

void qmesearch(fd,cutable)

int *fd;

int *cutable;

{

int i;

if (!stralloc_copys(%26amp;qme,".qmail")) temp_nomem();

if (!stralloc_cats(%26amp;qme,dash)) temp_nomem();

if (!stralloc_cat(%26amp;qme,%26amp;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

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(%26amp;qme,".qmail")) temp_nomem();

if (!stralloc_cats(%26amp;qme,dash)) temp_nomem();

if (!stralloc_catb(%26amp;qme,safeext.s,i)) temp_nomem();

if (!stralloc_cats(%26amp;qme,"default")) temp_nomem();

if (qmeexists(fd,cutable)) {

if (i

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);//将系统umask值设为077%26amp;0777的值。open函数的真正权限为mode%26amp;-umask

sig_pipeignore();//忽略信号

//将environ空间扩大(加10个字符串位置)错误返回0

if (!env_init()) temp_nomem();

//-n Instead of reading and delivering the message, print a description of

// the delivery instructions. (man page)

//-N 是默认值

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();

//将"HOST"和host结合为"HOST="+host,加到environ后面。下同

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();//接收地址的local部分

//将本地的地址扩展。如local为"dingwenbin",host为pact518.hit.edu.cn,则envrecip为"dingwenbin@pact518.hit.edu.cn"

if (!stralloc_copys(%26amp;envrecip,local)) temp_nomem();

if (!stralloc_cats(%26amp;envrecip,"@")) temp_nomem();

if (!stralloc_cats(%26amp;envrecip,host)) temp_nomem();

//将envrecip-s加'Z'拷到foo-s.

if (!stralloc_copy(%26amp;foo,%26amp;envrecip)) temp_nomem();

//#define stralloc_0(sa) stralloc_append(sa,"")

//GEN_ALLOC_append(stralloc,char,s,len,a,i,n,x,30,stralloc_readyplus,stralloc_append)

//struct stralloc{char *s;int len;int a;},len是s的长度,a是总共分配的空间。

//stralloc_ready(x,n)作用是:x没有分配空间就分配n大小空间。已分配了且空间小于n就扩大空间

//stralloc_readyplus(x,n)作用是:x没有分配空间就分配n大小空间。分配给x的空间小于x-len+n,就扩大空间

if (!stralloc_0(%26amp;foo)) temp_nomem();

//将"RECIPIENT"和foo.s结合为"RECIPIENT="+foo.s,加到environ后面。下同

//信封上接收者的地址

if (!env_put2("RECIPIENT",foo.s)) temp_nomem();

//邮件头Delivered-To部分

if (!stralloc_copys(%26amp;dtline,"Delivered-To: ")) temp_nomem();

if (!stralloc_cat(%26amp;dtline,%26amp;envrecip)) temp_nomem();

for (i = 0;i

if (!stralloc_cats(%26amp;dtline,"\n")) temp_nomem();

if (!stralloc_copy(%26amp;foo,%26amp;dtline)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

if (!env_put2("DTLINE",foo.s)) temp_nomem();

if (flagdoit)

bouncexf();

//将"SENDER"和sender结合为"SENDER="+sender,加到environ后面。

// 信封上发送者地址

if (!env_put2("SENDER",sender)) temp_nomem();

//将"RPLINE"和"Return-Path:\n"结合后加入environ

if (!quote2(%26amp;foo,sender)) temp_nomem();

if (!stralloc_copys(%26amp;rpline,"Return-Path:

if (!stralloc_cat(%26amp;rpline,%26amp;foo)) temp_nomem();

for (i = 0;i

if (!stralloc_cats(%26amp;rpline,"\n")) temp_nomem();

if (!stralloc_copy(%26amp;foo,%26amp;rpline)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

//邮件头返回路径

if (!env_put2("RPLINE",foo.s)) temp_nomem();

//将"From"+*sender拷到ufline中。*sender为空,则将"From"+"MAILER-DAEMON"拷进去

if (!stralloc_copys(%26amp;ufline,"From ")) temp_nomem();

if (*sender)

{

int len; int i; char ch;

len = str_len(sender);

if (!stralloc_readyplus(%26amp;ufline,len)) temp_nomem();

for (i = 0;i

{

ch = sender[i];

if ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = '-';

ufline.s[ufline.len + i] = ch;

}

ufline.len += len;

}

else

if (!stralloc_cats(%26amp;ufline,"MAILER-DAEMON")) temp_nomem();

if (!stralloc_cats(%26amp;ufline," ")) temp_nomem();

//在ufline后面加上现在时间。

starttime = now();

if (!stralloc_cats(%26amp;ufline,myctime(starttime))) temp_nomem();

if (!stralloc_copy(%26amp;foo,%26amp;ufline)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

//UUCP风格的"From"行它包含消息所参与的UUCP大宗

//路径形式的路由、最后一台接收消息的机器处理消息的时间和日期以及一

//指明从哪台主机接收来的可选部分。由于每个处理过这个消息的系统都会生成这个字段,所

//以它通常包括在信封数据下。

if (!env_put2("UFLINE",foo.s)) temp_nomem();

//到空行的作用是:如果ext为"aa-bb-cc-dd",则依次把"EXT=aa-bb-cc-dd","EXT2=bb-cc-dd","EXT3=cc-dd","EXT4=dd"加入

//地址扩展

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(%26amp;safeext,ext)) temp_nomem();

//将safeext中字符串转化为小写的

case_lowerb(safeext.s,safeext.len);

for (i = 0;i

if (safeext.s[i] == '.')

safeext.s[i] = ':';

//例如host为202.18.236.150,则"HOST2=202.18.236","HOST3=202.18","HOST4=202",加入其中

//接收地址的域名部分

i = str_len(host);

i = byte_rchr(host,i,'.');

if (!stralloc_copyb(%26amp;foo,host,i)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

if (!env_put2("HOST2",foo.s)) temp_nomem();

i = byte_rchr(host,i,'.');

if (!stralloc_copyb(%26amp;foo,host,i)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

if (!env_put2("HOST3",foo.s)) temp_nomem();

i = byte_rchr(host,i,'.');

if (!stralloc_copyb(%26amp;foo,host,i)) temp_nomem();

if (!stralloc_0(%26amp;foo)) temp_nomem();

if (!env_put2("HOST4",foo.s)) temp_nomem();

flagforwardonly = 0;

qmesearch(%26amp;fd,%26amp;flagforwardonly);

if (fd == -1)/*文件没打开*/

if (*dash)

strerr_die1x(100,"Sorry, no mailbox here by that name. (#5.1.1)");

if (!stralloc_copys(%26amp;ueo,sender)) temp_nomem();

if (str_diff(sender,""))/*sender不空*/

if (str_diff(sender,"#@[]"))/*sender和"#@[]"不同*/

if (qmeox("-owner") == 0)

{

if (qmeox("-owner-default") == 0)

{

if (!stralloc_copys(%26amp;ueo,local)) temp_nomem();

if (!stralloc_cats(%26amp;ueo,"-owner-@")) temp_nomem();

if (!stralloc_cats(%26amp;ueo,host)) temp_nomem();

if (!stralloc_cats(%26amp;ueo,"-@[]")) temp_nomem();

}/*ueo为local+"-owner-@"+host+"-@[]"*/

else

{

if (!stralloc_copys(%26amp;ueo,local)) temp_nomem();

if (!stralloc_cats(%26amp;ueo,"-owner@")) temp_nomem();

if (!stralloc_cats(%26amp;ueo,host)) temp_nomem();

}/*ueo为local+"-owner@"+host*/

}

if (!stralloc_0(%26amp;ueo)) temp_nomem();

//转发的发送人地址

if (!env_put2("NEWSENDER",ueo.s)) temp_nomem();

if (!stralloc_ready(%26amp;cmds,0)) temp_nomem();

cmds.len = 0;

if (fd != -1)

if (slurpclose(fd,%26amp;cmds,256) == -1) temp_nomem();

if (!cmds.len)/*如果fd文件中没有内容*/

{

if (!stralloc_copys(%26amp;cmds,aliasempty)) temp_nomem();

flagforwardonly = 0;

}

if (!cmds.len || (cmds.s[cmds.len - 1] != '\n'))

if (!stralloc_cats(%26amp;cmds,"\n")) temp_nomem();

numforward = 0;/*检查有几行的第一个字符不是'#','.','/','|'*/

i = 0;/*i为每行的开始位置*/

for (j = 0;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

if (cmds.s[j] == '\n')

{

cmds.s[j] = 0;

k = j;

while ((k i) %26amp;%26amp; (cmds.s[k - 1] == ' ') || (cmds.s[k - 1] == '\t'))

cmds.s[--k] = 0;

// 字符 传送类型 值

// # 无 (注释) 忽略

// | 程序 由shell 执行的命令

// / 或者 . mbox邮箱格式 (如果路径最后一个字符不是一个斜杠) mbox 的路径名 (包括斜杠"/"或者 点".")

// / 或者 . maildir邮箱格式 (如果路径最后一个字符是一个反斜杠) maildir 的路径名 (包括斜杠"/"或者 点".")

// %26amp; 转发 转发邮件的地址

// 字母或者数字 转发 转发邮件的地址 (包括第一个字符)

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 '%26amp;':

++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;

}

//转发的地址数不为0就转发

if (numforward) if (flagdoit)

{

recips[numforward] = 0;

mailforward(recips);

}

count_print();

_exit(0);

}[/code:1:c552cb0758]

,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有