Ê×Ò³ | Óʼþ×ÊѶ | ¼¼Êõ½Ì³Ì | ½â¾ö·½°¸ | ²úÆ·ÆÀ²â | ÓʼþÈ˲Š| Óʼþ²©¿Í | ÓʼþϵͳÂÛ̳ | Èí¼þÏÂÔØ | ÓʼþÖÜ¿¯ | ÈȵãרÌâ | ¹¤¾ß
ÍøÂç¼¼Êõ | ²Ù×÷ϵͳ | Óʼþϵͳ | ¿Í»§¶Ë | µç×ÓÓÊÏä | ·´À¬»øÓʼþ | Óʼþ°²È« | ÓʼþÓªÏú | ÒÆ¶¯µçÓÊ | ÓʼþÈí¼þÏÂÔØ | µç×ÓÊéÏÂÔØ

Óʼþ·þÎñÆ÷

¼¼ÊõÇ°ÑØ | Exchange | Domino | Sendmail | Postfix | Qmail | IMail | MDaemon | Foxmail | James | Kerio | JavaMail | WinMail | Winwebmail | Merak | CMailServer | ½ðµÑ | ÆäËü | ÓʼþÓ뿪·¢ |
Ê×Ò³ > Óʼþ·þÎñÆ÷ > Qmail > qmail-local´úÂë·ÖÎö > ÕýÎÄ

qmail-local´úÂë·ÖÎö

³ö´¦£ºwww.chinaunix.net ×÷Õߣºhitdwb ʱ¼ä£º2005-9-1 13:58:00

ÎÒ·ÖÎöµÄ´úÂëûÓС°Ò¹Î´Ãß¡±´ó¸çµÄºÃ£¬¿ÉÄÜ»¹ÓеIJ»ÕýÈ·£¬¾ÍÇë¸÷λ¶à¶àÖ¸½Ì£¬Ð»Ð»
[code:1:c552cb0758]#include <sys/types.h>
#include <sys/stat.h>
#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,&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(&ss,read,0,buf,sizeof(buf));
 substdio_fdbuf(&ssout,write,fd,outbuf,sizeof(outbuf));
//dtline:ÓʼþÍ·Delivered-To²¿·Ö
//rpline:ÓʼþÍ··µ»ØÂ·¾¶
//ÎÞÐè"From "Í·²¿ 
 if (substdio_put(&ssout,rpline.s,rpline.len) == -1) goto fail;
 if (substdio_put(&ssout,dtline.s,dtline.len) == -1) goto fail;
//½«Óʼþдµ½ÎļþfdÖÐ
 switch(substdio_copy(&ssout,&ss))
  {
   case -2: tryunlinktmp(); _exit(4);
   case -3: goto fail;
  }

 if (substdio_flush(&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(&wstat,child);
//#define wait_crashed(w) ((w) & 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(&ss,read,0,buf,sizeof(buf));
 substdio_fdbuf(&ssout,write,fd,outbuf,sizeof(outbuf));
//dtline:ÓʼþÍ·Delivered-To²¿·Ö
//rpline:ÓʼþÍ··µ»ØÂ·¾¶
//ufline:mbox ÊDZê×¼µÄUNIXÓÊÏä¸ñʽ, ¶à¸öÓʼþ´æ·ÅÔÚÒ»¸ö¶ÀÁ¢ÎļþÄÚ, Ã¿¸öÓʼþÓÉÒ»¸ö"From" µÄÐпªÊ¼.
//ÕâÒ»Ðп´ÆðÀ´ÏñÒ»¸ö±êÌâ×Ö¶Î, ²»¹ýÄDz»ÊDZêÌâ, Äǽö½öÊÇ´«ËÍ´úÀíÌí¼ÓµÄ, ±ãÓÚÓʼþ¶Á³öÆ÷¿ÉÒÔÕÒµ½Ã¿¸öÓʼþ¿ªÊ¼²¿·ÖµÄÒ»¸ö±ê¼Ç. 
 if (substdio_put(&ssout,ufline.s,ufline.len)) goto writeerrs;
 if (substdio_put(&ssout,rpline.s,rpline.len)) goto writeerrs;
 if (substdio_put(&ssout,dtline.s,dtline.len)) goto writeerrs;
 for (;;)
  {//¶ÁÒ»ÐÐ
   if (getln(&ss,&messline,&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 && !messline.len) break;
   if (gfrom(messline.s,messline.len))
     if (substdio_bput(&ssout,">",1)) goto writeerrs;
   if (substdio_bput(&ssout,messline.s,messline.len)) goto writeerrs;
   if (!match)
    {
     if (substdio_bputs(&ssout,"\n")) goto writeerrs;
     break;
    }
  }
 if (substdio_bputs(&ssout,"\n")) goto writeerrs;
 if (substdio_flush(&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(&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(&ss,read,0,buf,sizeof(buf));

 if (qmail_open(&qqt) == -1) temp_fork();
 mailforward_qp = qmail_qp(&qqt);
 qmail_put(&qqt,dtline.s,dtline.len);
 do
  {
   if (getln(&ss,&messline,&match,'\n') != 0) { qmail_fail(&qqt); break; }
   qmail_put(&qqt,messline.s,messline.len);
  }
 while (match);
 qmail_from(&qqt,ueo.s);
 while (*recips) qmail_to(&qqt,*recips++);
 qqx = qmail_close(&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(&ss,read,0,buf,sizeof(buf));
 for (;;)
  {
   if (getln(&ss,&messline,&match,'\n') != 0) temp_read();
   if (!match) break;
//ÅжÏÎļþÊÇ·ñ½áÊø
   if (messline.len <= 1)
     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(".",&st) == -1)
   strerr_die3x(111,"Unable to stat home directory: ",error_str(errno),". (#4.3.0)");
 if (st.st_mode & auto_patrn)
   strerr_die1x(111,"Uh-oh: home directory is writable. (#4.7.0)");
 if (st.st_mode & 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(&qme,".qmail")) temp_nomem();
 if (!stralloc_cats(&qme,dash)) temp_nomem();
 if (!stralloc_cat(&qme,&safeext)) temp_nomem();
 if (!stralloc_cats(&qme,dashowner)) temp_nomem();
 if (!stralloc_0(&qme)) temp_nomem();
 if (stat(qme.s,&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(&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);
//S_IFREG±íʾһ°ãÎļþ  
  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);//¿´ÎļþµÄ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" */
//´ò¿ªÎļþ&qme£¬ÈçÊÇÒ»°ãÎļþÔÙ¿´ÊÇ·ñΪdefault,Èç¹ûÊÇ£¬"DEFAULT"+*(ext+i)½áºÏ¼ÓÈë
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);//½«ÏµÍ³umaskÖµÉèΪ077&0777µÄÖµ¡£openº¯ÊýµÄÕæÕýȨÏÞΪmode&-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(&envrecip,local)) temp_nomem();
 if (!stralloc_cats(&envrecip,"@")) temp_nomem();
 if (!stralloc_cats(&envrecip,host)) temp_nomem();
//½«envrecip->s¼Ó'Z'¿½µ½foo->s.
 if (!stralloc_copy(&foo,&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(&foo)) temp_nomem();
//½«"RECIPIENT"ºÍfoo.s½áºÏΪ"RECIPIENT="+foo.s£¬¼Óµ½environºóÃæ¡£ÏÂͬ
//ÐÅ·âÉϽÓÊÕÕߵĵØÖ·  
 if (!env_put2("RECIPIENT",foo.s)) temp_nomem();
//ÓʼþÍ·Delivered-To²¿·Ö 
 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();
//½«"SENDER"ºÍsender½áºÏΪ"SENDER="+sender£¬¼Óµ½environºóÃæ¡£
// ÐÅ·âÉÏ·¢ËÍÕßµØÖ·  
 if (!env_put2("SENDER",sender)) temp_nomem();
//½«"RPLINE"ºÍ"Return-Path:<"+"SENDER"+sender+">\n"½áºÏºó¼ÓÈëenviron
 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();
//½«"From"+*sender¿½µ½uflineÖС£*senderΪ¿Õ£¬Ôò½«"From"+"MAILER-DAEMON"¿½½øÈ¥  
 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();
 //ÔÚuflineºóÃæ¼ÓÉÏÏÖÔÚʱ¼ä¡£
 starttime = now();
 if (!stralloc_cats(&ufline,myctime(starttime))) temp_nomem();

 if (!stralloc_copy(&foo,&ufline)) temp_nomem();
 if (!stralloc_0(&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(&safeext,ext)) temp_nomem();
//½«safeextÖÐ×Ö·û´®×ª»¯ÎªÐ¡Ð´µÄ 
 case_lowerb(safeext.s,safeext.len);
 for (i = 0;i < safeext.len;++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(&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,""))/*sender²»¿Õ*/
   if (str_diff(sender,"#@[]"))/*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();
}/*ueoΪlocal+"-owner-@"+host+"-@[]"*/
       else
{
         if (!stralloc_copys(&ueo,local)) temp_nomem();
         if (!stralloc_cats(&ueo,"-owner@")) temp_nomem();
         if (!stralloc_cats(&ueo,host)) temp_nomem();
}/*ueoΪlocal+"-owner@"+host*/
      }
 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)/*Èç¹ûfdÎļþÖÐûÓÐÄÚÈÝ*/
  {
   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;/*iΪÿÐеĿªÊ¼Î»ÖÃ*/
 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;
//        ×Ö·û         ´«ËÍÀàÐÍ                                                    Öµ  
//         #           ÎÞ (×¢ÊÍ)                                                 ºöÂÔ 
//         |           ³ÌÐò                                                      ÓÉshell Ö´ÐеÄÃüÁî  
//       / »òÕß .       mboxÓÊÏä¸ñʽ (Èç¹û·¾¶×îºóÒ»¸ö×Ö·û²»ÊÇÒ»¸öб¸Ü)              mbox µÄ·¾¶Ãû (°üÀ¨Ð±¸Ü"/"»òÕß µã".") 
//       / »òÕß .       maildirÓÊÏä¸ñʽ (Èç¹û·¾¶×îºóÒ»¸ö×Ö·ûÊÇÒ»¸ö·´Ð±¸Ü)           maildir µÄ·¾¶Ãû (°üÀ¨Ð±¸Ü"/"»òÕß µã".")  
//         &           ×ª·¢                                                      ×ª·¢ÓʼþµÄµØÖ·  
//       ×Öĸ»òÕßÊý×Ö   ×ª·¢                                                      ×ª·¢ÓʼþµÄµØÖ· (°üÀ¨µÚÒ»¸ö×Ö·û)  
       
     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;
    }
//ת·¢µÄµØÖ·Êý²»Îª0¾Íת·¢
 if (numforward) if (flagdoit)
  {
   recips[numforward] = 0;
   mailforward(recips);
  }

 count_print();
 _exit(0);
}[/code:1:c552cb0758]
,
Ïà¹ØÎÄÕ ÈÈÃÅÎÄÕÂ
  • ³ÌÐòÔ±ÑÛÖеÄqmail(qmailÔ´´úÂë·ÖÎö)
  • qmail-send´úÂë·ÖÎö
  • qmailÔ´´úÂë·ÖÎöÖ®qmail-start.c
  • qmailÔ´´úÂë·ÖÎöÖ®qmail-popup.c
  • qmailÔ´´úÂë·ÖÎöÖ®qmail-queue
  • qmailÔ´´úÂë·ÖÎöÖ®qmail-pop3d
  • qmailÔ´´úÂë·ÖÎöÖ®qmail-smtpd.c
  • LinuxÓʼþ·þÎñÆ÷Èí¼þ±È½Ï
  • ÓòÃûºÍÓʼþ·þÎñÆ÷FAQ
  • Qmail×Ô¶¯°²×°°üQmail_setup-v1.5.3·¢²¼
  • freebsd+qmail+mysql+vpopmailÖ®ÍêÈ«ports°²×°
  • qmail+vpopmail+MySQL+igenus+RedHat 7Ͻ¨Á¢Óʼþϵͳ
  • QMAILÖÕ¼«°²×°Ö¸ÄÏ
  • ÅäÖÃÄãµÄµÚһ̨e-mail·þÎñÆ÷
  • qmail+webmail on Linux9 °²×°È«¹ý³Ì
  • ·Ö²¼Ê½µÄQmailÓʼþϵͳ
  • qmail+vpopmail+mysql+qmailadmin+ezmlm+igenus¹¹½¨Æó..
  • qmail+webmail on Linux9 °²×°È«¹ý³Ì
  • Qmail Server Howto
  • ×ÔÓÉ¹ã¸æÇø
    ¡¡
     
    ×îÐÂÈí¼þÏÂÔØ
  • ORF Enterprise Edition 4.2 Õýʽ°æ
  • WinWebMail 3.7.7.3 ±ê×¼°æ
  • WinWebMail 3.7.7.3 ÆóÒµ°æ
  • BMailì÷ÓÊ
  • Merak Email Server for Windows 9.3.1..
  • Merak Email Server for Linux 9.3.1 ¼..
  • Merak Email Server 9.3.1 For Windwos..
  • AXIGEN Mail Server 6.1.1 for Windows
  • AXIGEN Mail Server 6.1.0 for Linux
  • ADModify.NETÏÂÔØ
  • symantec10.1»ù±¾°²×°¼°ÅäÖÃÊÓÆµ½Ì³Ì
  • Backup Exec System RecoveryÖ®±¸·ÝÊÓÆ..
  • ½ñÈÕÓʼþ¼¼ÊõÎÄÕÂ
  • ÃÀ´óѧÉúÇÖÈëÅåÁÖÖݳ¤¸öÈËÓʼþÕË»§±»´þ²¶
  • ˼¿ÆIronPort·¢²¼Ðµç×ÓÓʼþ°²È«É豸
  • Éî¸û"Èí¼þ+·þÎñ" ΢Èí300³ÇÊÐѲչî£ÓÊ
  • ´ÓºÚ¿Í³£Óù¥»÷Êֶο´WEBÓ¦Ó÷À»¤
  • ÏûÏ¢ÈËʿ͸¶ÑÅ»¢ÓëAOLºÏ²¢Ï¸½Ú½«ÓÚ±¾Ô..
  • ¹È¸èÌṩµÄµç×ÓÓʼþ´æµµÊ±¼äÑÓ³¤ÎªÊ®Äê
  • ÑÅ»¢½«ÔÚÓÊÏä·þÎñÖÐÕûºÏаæÔÚÏßÈÕÀú
  • 9ÔÂÀ¬»øÓʼþ×ÜÁ¿¼õÉÙ ÓëISPµ¹±ÕÓйØ
  • À¬»øÓʼþ·¢Õ¹µÄËÄ´óÇ÷ÊÆ
  • º«¹úÒéÔ±³ÆÖйúºÚ¿Íð³äÇàÍß̨·¢ËͲ¡¶¾..
  • VistaÄÑ³ÉÆøºò Windows XPÊÙÃü±»ÑÓ³¤
  • ÈüÃÅÌú¿ËÉý¼¶DLP²úÆ·¼°·´À¬»øÓʼþÍø¹Ø
  • ×îÐÂרÌâ
  • Sendmail ÓʼþϵͳÅäÖÃ
  • ×齨Exchange 2003Óʼþϵͳ
  • Windows Server 2008 רÌâ
  • ORF ·´À¬»øÓʼþϵͳ
  • Exchange Server 2007 רÌâ
  • ISA Server 2006 ½Ì³ÌרÌâ
  • Windows Vista ¼¼ÊõרÌâ
  • ¡°ºÚÝ®¡±£¨BlackBerry£©×¨Ìâ
  • ÒÆ¶¯µç×ÓÓʼþרÌâ
  • Apache James רÌâ
  • IMail Server ²Ù×÷Ö¸ÄÏ
  • ISA Server 2004 ʹÓÃרÌâ
  • ·ÖÀർº½
    ÓʼþÐÂÎÅ×ÊѶ:
    ITÒµ½ç | Óʼþ·þÎñÆ÷ | ÓʼþȤÎÅ | ÒÆ¶¯µçÓÊ
    µç×ÓÓÊÏä | ·´À¬»øÓʼþ|Óʼþ¿Í»§¶Ë|ÍøÂ簲ȫ
    ÐÐÒµÊý¾Ý | ÓʼþÈËÎï | ÍøÕ¾¹«¸æ | ÐÐÒµ·¨¹æ
    ÍøÂç¼¼Êõ:
    ÓʼþÔ­Àí | ÍøÂçЭÒé | ÍøÂç¹ÜÀí | ´«Êä½éÖÊ
    Ïß·½ÓÈë | ·ÓÉ½Ó¿Ú | Óʼþ´æ´¢ | »ªÎª3Com
    CISCO¼¼Êõ | ÍøÂçÓë·þÎñÆ÷Ó²¼þ
    ²Ù×÷ϵͳ:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | ÆäËü²Ù×÷ϵͳ
    Óʼþ·þÎñÆ÷:
    ³ÌÐòÓ뿪·¢ | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    ½ðµÑÓʼþϵͳ | ÆäËü |
    ·´À¬»øÓʼþ:
    ×ÛÊö| ¿Í»§¶Ë·´À¬»øÓʼþ|·þÎñÆ÷¶Ë·´À¬»øÓʼþ
    Óʼþ¿Í»§¶ËÈí¼þ:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | À×Äñ | Eudora |Becky! |Pegasus
    IncrediMail |ÆäËü
    µç×ÓÓÊÏä: ¸öÈËÓÊÏä | ÆóÒµÓÊÏä |Gmail
    ÒÆ¶¯µç×ÓÓʼþ:·þÎñÆ÷ | ¿Í»§¶Ë | ¼¼ÊõÇ°ÑØ
    ÓʼþÍøÂ簲ȫ:
    Èí¼þ©¶´ | °²È«ÖªÊ¶ | ²¡¶¾¹«¸æ |·À»ðǽ
    ¹¥·À¼¼Êõ | ²¡¶¾²éɱ| ISA | Êý×ÖÇ©Ãû
    ÓʼþÓªÏú:
    EmailÓªÏú | ÍøÂçÓªÏú | ÓªÏú¼¼ÇÉ |ÓªÏú°¸Àý
    ÓʼþÈ˲Å:ÕÐÆ¸ | Ö°³¡ | Åàѵ | Ö¸ÄÏ | Ö°³¡
    ½â¾ö·½°¸:
    Óʼþϵͳ|·´À¬»øÓʼþ |°²È« |ÒÆ¶¯µçÓÊ |Õбê
    ²úÆ·ÆÀ²â:
    Óʼþϵͳ |·´À¬»øÓʼþ |ÓÊÏä |°²È« |¿Í»§¶Ë
    ¹ã¸æÁªÏµ | ºÏ×÷ÁªÏµ | ¹ØÓÚÎÒÃÇ | ÁªÏµÎÒÃÇ | ·±ówÖÐÎÄ
    °æÈ¨ËùÓУºÓʼþ¼¼Êõ×ÊÑ¶Íø©2003-2007 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   ÔÁICP±¸05009143ºÅ