Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->Linux技术 ->Linux程序设计 ->正文

程序员眼中的qmail(qmail源代码分析)

来源:5dmail.net 作者:未知  时间:2007-04-22 点击: [收藏] [投稿]
smtp_quit()

  {

  smtp_greet("221 "); out("\r\n"); flush(); _exit(0);

  }

  char *remoteip; //远端ip地址

  char *remotehost; //远端主机名

  char *remoteinfo; //远端信息

  char *local; //本地主机

  char *relayclient; //是否检查rcpthosts文件

  stralloc helohost = {0};

  char *fakehelo; /* pointer into helohost, or 0 */

  void dohelo(arg) char *arg; {

  if (!stralloc_copys(&helohost,arg)) die_nomem();

  if (!stralloc_0(&helohost)) die_nomem();

  //fakehelo变量,如果helo 参数指定的主机名与TCPREMOTEHOST环境变量中的主机名不同则

  //fakehelo的值为helo命令的参数指定的主机名.如果两者相同则fekehelo为NULL;

  //data命令处理程式用到这个变量

  fakehelo = case_diffs(remotehost,helohost.s) ? helohost.s : 0;

  }

  int liphostok = 0;

  stralloc liphost = {0};

  int bmfok = 0;

  stralloc bmf = {0};

  struct constmap mapbmf;

  void setup()

  {

  char *x;

  unsigned long u;

  if (control_init() == -1) die_control(); //control/me

  //读入欢迎信息greeting,如果不存在则从me文件复制

  if (control_rldef(&greeting,"control/smtpgreeting",1,(char *) 0) != 1)

  die_control();

  //读入localiphost,如果文件不存在则从me文件复制

  liphostok = control_rldef(&liphost,"control/localiphost",1,(char *) 0);

  if (liphostok == -1) die_control();

  //读control/timeoutsmtpd存入timeout,用于控制超时的情况.

  if (control_readint(&timeout,"control/timeoutsmtpd") == -1) die_control();

  if (timeout <= 0) timeout = 1;

  if (rcpthosts_init() == -1) die_control();

  //读入badmailfrom文件存入 bmf

  bmfok = control_readfile(&bmf,"control/badmailfrom",0);

  if (bmfok == -1) die_control();

  if (bmfok)

  if (!constmap_init(&mapbmf,bmf.s,bmf.len,0)) die_nomem();

  //读入databytes文件存入 databytes,如果该文件不存在,则将

  //databytes的值设为0.

  if (control_readint(&databytes,"control/databytes") == -1) die_control();

  x = env_get("DATABYTES");

  if (x) { scan_ulong(x,&u); databytes = u; }

  if (!(databytes + 1)) --databytes;

  //取tcp-environ环境变量,如果环境变量没有设置,将它的值设置为unknow.

  //这些信息来自tcpserver,或tcp-env之类的程式

  remoteip = env_get("TCPREMOTEIP");

  if (!remoteip) remoteip = "unknown";

  local = env_get("TCPLOCALHOST");

  if (!local) local = env_get("TCPLOCALIP");

  if (!local) local = "unknown";

  remotehost = env_get("TCPREMOTEHOST");

  if (!remotehost) remotehost = "unknown";

  remoteinfo = env_get("TCPREMOTEINFO");

  //从环境变量RELAYCLIENT读入.

  //如果RELAYCLIENT变量没有设置那么relayclient将会是NULL.

  relayclient = env_get("RELAYCLIENT");

  dohelo(remotehost);

  }

  stralloc addr = {0}; /* will be 0-terminated, if addrparse returns 1 */

  //对命令参数arg进行邮件地址分析

  //并将分离出的email地址存入全局缓存addr

  //成功返回值为1,失败返回0

  int addrparse(arg)

  char *arg;

  {

  int i;

  char ch;

  char terminator;

  struct ip_address ip;

  int flagesc;

  int flagquoted;

  //分离出邮件地址

  //例如: arg="",或 arg=": email@eg.org "

  //执行下面这段程式后arg="email@eg.org"

  terminator = '>';

  i = str_chr(arg,'<');

  if (arg[i])

  arg += i + 1;

  else { /* partner should go read rfc 821 */

  terminator = ' ';

  arg += str_chr(arg,':');

  if (*arg == ':') ++arg;

  while (*arg == ' ') ++arg;

  }

  /* strip source route */

  if (*arg == '@') while (*arg) if (*arg++ == ':') break;

  if (!stralloc_copys(&addr,"")) die_nomem();

  flagesc = 0;

  flagquoted = 0;

  for (i = 0;ch = arg[i];++i) { /* copy arg to addr, stripping quotes */

  if (flagesc) {

  if (!stralloc_append(&addr,&ch)) die_nomem();

  flagesc = 0;

  }

  else {

  if (!flagquoted && (ch == terminator)) break;

  switch(ch) {

  case '\': flagesc = 1; break;

  case '"': flagquoted = !flagquoted; break;

  default: if (!stralloc_append(&addr,&ch)) die_nomem();

  }

  }

  }

  /* could check for termination failure here, but why bother? */

  if (!stralloc_append(&addr,"")) die_nomem();

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:使用 Flex 和 Bison 更好地进行错误处理   下一篇:GNU 线性编程工具包(线性优化简介)

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号