⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dummy.c

📁 广泛使用的邮件服务器!同时
💻 C
📖 第 1 页 / 共 2 页
字号:
		   long attributes,char *contents){  DRIVER *d;  DIR *dp;  struct direct *dr;  dirfmttest_t dt;  unsigned long csiz;  struct stat sbuf;  int nochild;  char *s,tmp[MAILTMPLEN];  if (!(attributes & LATT_NOINFERIORS) && mailboxdir (tmp,name,NIL) &&      (dp = opendir (tmp))) {	/* if not \NoInferiors */				/* locate dirfmttest if any */    for (d = (DRIVER *) mail_parameters (NIL,GET_DRIVERS,NIL), dt = NIL;	 !dt && d; d = d->next)      if (!(d->flags & DR_DISABLE) && (d->flags & DR_DIRFMT) &&	  (*d->valid) (name))	dt = mail_parameters ((*d->open) (NIL),GET_DIRFMTTEST,NIL);				/* scan directory for children */    for (nochild = T; nochild && (dr = readdir (dp)); )      if ((!(dt && (*dt) (dr->d_name))) &&	  ((dr->d_name[0] != '.') ||	   (((long) mail_parameters (NIL,GET_HIDEDOTFILES,NIL)) ? NIL :	    (dr->d_name[1] && ((dr->d_name[1] != '.') || dr->d_name[2])))))	nochild = NIL;    attributes |= nochild ? LATT_HASNOCHILDREN : LATT_HASCHILDREN;    closedir (dp);		/* all done, flush directory */  }  d = NIL;			/* don't \NoSelect dir if it has a driver */  if ((attributes & LATT_NOSELECT) && (d = mail_valid (NIL,name,NIL)) &&      (d != &dummydriver)) attributes &= ~LATT_NOSELECT;  if (!contents ||		/* notify main program */      (!(attributes & LATT_NOSELECT) && (csiz = strlen (contents)) &&       (s = mailboxfile (tmp,name)) &&       (*s || (s = mail_parameters (NIL,GET_INBOXPATH,tmp))) &&       !stat (s,&sbuf) && (d || (csiz <= sbuf.st_size)) &&       SAFE_SCAN_CONTENTS (d,tmp,contents,csiz,sbuf.st_size)))    mm_list (stream,delimiter,name,attributes);  return T;}/* Dummy create mailbox * Accepts: mail stream *	    mailbox name to create * Returns: T on success, NIL on failure */long dummy_create (MAILSTREAM *stream,char *mailbox){  char *s,tmp[MAILTMPLEN];  long ret = NIL;				/* validate name */  if (!(compare_cstring (mailbox,"INBOX") && (s = dummy_file (tmp,mailbox)))) {    sprintf (tmp,"Can't create %.80s: invalid name",mailbox);    MM_LOG (tmp,ERROR);  }				/* create the name, done if made directory */  else if ((ret = dummy_create_path (stream,tmp,get_dir_protection(mailbox)))&&	   (s = strrchr (s,'/')) && !s[1]) return T;  return ret ? set_mbx_protections (mailbox,tmp) : NIL;}/* Dummy create path * Accepts: mail stream *	    path name to create *	    directory mode * Returns: T on success, NIL on failure */long dummy_create_path (MAILSTREAM *stream,char *path,long dirmode){  struct stat sbuf;  char c,*s,tmp[MAILTMPLEN];  int fd;  long ret = NIL;  char *t = strrchr (path,'/');  int wantdir = t && !t[1];  int mask = umask (0);  if (wantdir) *t = '\0';	/* flush trailing delimiter for directory */  if (s = strrchr (path,'/')) {	/* found superior to this name? */    c = *++s;			/* remember first character of inferior */    *s = '\0';			/* tie off to get just superior */				/* name doesn't exist, create it */    if ((stat (path,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&	!dummy_create_path (stream,path,dirmode)) {      umask (mask);		/* restore mask */      return NIL;    }    *s = c;			/* restore full name */  }  if (wantdir) {		/* want to create directory? */    ret = !mkdir (path,(int) dirmode);    *t = '/';			/* restore directory delimiter */  }				/* create file */  else if ((fd = open (path,O_WRONLY|O_CREAT|O_EXCL,		       (long) mail_parameters(NIL,GET_MBXPROTECTION,NIL))) >=0)    ret = !close (fd);  if (!ret) {			/* error? */    sprintf (tmp,"Can't create mailbox node %.80s: %.80s",path,strerror (errno));    MM_LOG (tmp,ERROR);  }  umask (mask);			/* restore mask */  return ret;			/* return status */}/* Dummy delete mailbox * Accepts: mail stream *	    mailbox name to delete * Returns: T on success, NIL on failure */long dummy_delete (MAILSTREAM *stream,char *mailbox){  struct stat sbuf;  char *s,tmp[MAILTMPLEN];  if (!(s = dummy_file (tmp,mailbox))) {    sprintf (tmp,"Can't delete - invalid name: %.80s",s);    MM_LOG (tmp,ERROR);  }				/* no trailing / (workaround BSD kernel bug) */  if ((s = strrchr (tmp,'/')) && !s[1]) *s = '\0';  if (stat (tmp,&sbuf) || ((sbuf.st_mode & S_IFMT) == S_IFDIR) ?      rmdir (tmp) : unlink (tmp)) {    sprintf (tmp,"Can't delete mailbox %.80s: %.80s",mailbox,strerror (errno));    MM_LOG (tmp,ERROR);    return NIL;  }  return T;			/* return success */}/* Mail rename mailbox * Accepts: mail stream *	    old mailbox name *	    new mailbox name * Returns: T on success, NIL on failure */long dummy_rename (MAILSTREAM *stream,char *old,char *newname){  struct stat sbuf;  char c,*s,tmp[MAILTMPLEN],mbx[MAILTMPLEN],oldname[MAILTMPLEN];				/* no trailing / allowed */  if (!dummy_file (oldname,old) || !(s = dummy_file (mbx,newname)) ||      stat (oldname,&sbuf) || ((s = strrchr (s,'/')) && !s[1] &&			       ((sbuf.st_mode & S_IFMT) != S_IFDIR))) {    sprintf (mbx,"Can't rename %.80s to %.80s: invalid name",old,newname);    MM_LOG (mbx,ERROR);    return NIL;  }  if (s) {			/* found a directory delimiter? */    if (!s[1]) *s = '\0';	/* ignore trailing delimiter */    else {			/* found superior to destination name? */      c = *++s;			/* remember first character of inferior */      *s = '\0';		/* tie off to get just superior */				/* name doesn't exist, create it */      if ((stat (mbx,&sbuf) || ((sbuf.st_mode & S_IFMT) != S_IFDIR)) &&	  !dummy_create (stream,mbx)) return NIL;      *s = c;			/* restore full name */    }  }				/* rename of non-ex INBOX creates dest */  if (!compare_cstring (old,"INBOX") && stat (oldname,&sbuf))    return dummy_create (NIL,mbx);  if (rename (oldname,mbx)) {    sprintf (tmp,"Can't rename mailbox %.80s to %.80s: %.80s",old,newname,	     strerror (errno));    MM_LOG (tmp,ERROR);    return NIL;  }  return T;			/* return success */}/* Dummy open * Accepts: stream to open * Returns: stream on success, NIL on failure */MAILSTREAM *dummy_open (MAILSTREAM *stream){  int fd;  char err[MAILTMPLEN],tmp[MAILTMPLEN];  struct stat sbuf;				/* OP_PROTOTYPE call */  if (!stream) return &dummyproto;  err[0] = '\0';		/* no error message yet */				/* can we open the file? */  if (!dummy_file (tmp,stream->mailbox))    sprintf (err,"Can't open this name: %.80s",stream->mailbox);  else if ((fd = open (tmp,O_RDONLY,NIL)) < 0) {				/* no, error unless INBOX */    if (compare_cstring (stream->mailbox,"INBOX"))      sprintf (err,"%.80s: %.80s",strerror (errno),stream->mailbox);  }  else {			/* file had better be empty then */    fstat (fd,&sbuf);		/* sniff at its size */    close (fd);    if ((sbuf.st_mode & S_IFMT) != S_IFREG)      sprintf (err,"Can't open %.80s: not a selectable mailbox",	       stream->mailbox);    else if (sbuf.st_size)	/* bogus format if non-empty */      sprintf (err,"Can't open %.80s (file %.80s): not in valid mailbox format",	       stream->mailbox,tmp);  }  if (err[0]) {			/* if an error happened */    MM_LOG (err,stream->silent ? WARN : ERROR);    return NIL;  }  else if (!stream->silent) {	/* only if silence not requested */    mail_exists (stream,0);	/* say there are 0 messages */    mail_recent (stream,0);	/* and certainly no recent ones! */    stream->uid_validity = time (0);  }  stream->inbox = T;		/* note that it's an INBOX */  return stream;		/* return success */}/* Dummy close * Accepts: MAIL stream *	    options */void dummy_close (MAILSTREAM *stream,long options){				/* return silently */}/* Dummy ping mailbox * Accepts: MAIL stream * Returns: T if stream alive, else NIL */long dummy_ping (MAILSTREAM *stream){  MAILSTREAM *test;  if (time (0) >=		/* time to do another test? */      ((time_t) (stream->gensym +		 (long) mail_parameters (NIL,GET_SNARFINTERVAL,NIL)))) {				/* has mailbox format changed? */    if ((test = mail_open (NIL,stream->mailbox,OP_PROTOTYPE)) &&	(test->dtb != stream->dtb) &&	(test = mail_open (NIL,stream->mailbox,NIL))) {				/* preserve some resources */      test->original_mailbox = stream->original_mailbox;      stream->original_mailbox = NIL;      test->sparep = stream->sparep;      stream->sparep = NIL;      test->sequence = stream->sequence;      mail_close ((MAILSTREAM *) /* flush resources used by dummy stream */		  memcpy (fs_get (sizeof (MAILSTREAM)),stream,			  sizeof (MAILSTREAM)));				/* swap the streams */      memcpy (stream,test,sizeof (MAILSTREAM));      fs_give ((void **) &test);/* flush test now that copied */				/* make sure application knows */      mail_exists (stream,stream->recent = stream->nmsgs);    }				/* still hasn't changed */    else stream->gensym = time (0);  }  return T;}/* Dummy check mailbox * Accepts: MAIL stream * No-op for readonly files, since read/writer can expunge it from under us! */void dummy_check (MAILSTREAM *stream){  dummy_ping (stream);		/* invoke ping */}/* Dummy expunge mailbox * Accepts: MAIL stream *	    sequence to expunge if non-NIL *	    expunge options * Returns: T, always */long dummy_expunge (MAILSTREAM *stream,char *sequence,long options){  return LONGT;}/* Dummy copy message(s) * Accepts: MAIL stream *	    sequence *	    destination mailbox *	    options * Returns: T if copy successful, else NIL */long dummy_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options){  if ((options & CP_UID) ? mail_uid_sequence (stream,sequence) :      mail_sequence (stream,sequence)) fatal ("Impossible dummy_copy");  return NIL;}/* Dummy append message string * Accepts: mail stream *	    destination mailbox *	    append callback function *	    data for callback * Returns: T on success, NIL on failure */long dummy_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data){  struct stat sbuf;  int fd = -1;  int e;  char tmp[MAILTMPLEN];  MAILSTREAM *ts = default_proto (T);				/* append to INBOX? */  if (!compare_cstring (mailbox,"INBOX")) {				/* yes, if no empty proto try creating */    if (!ts && !(*(ts = default_proto (NIL))->dtb->create) (ts,"INBOX"))      ts = NIL;  }  else if (dummy_file (tmp,mailbox) && ((fd = open (tmp,O_RDONLY,NIL)) < 0)) {    if ((e = errno) == ENOENT) /* failed, was it no such file? */      MM_NOTIFY (stream,"[TRYCREATE] Must create mailbox before append",NIL);    sprintf (tmp,"%.80s: %.80s",strerror (e),mailbox);    MM_LOG (tmp,ERROR);		/* pass up error */    return NIL;			/* always fails */  }  else if (fd >= 0) {		/* found file? */    fstat (fd,&sbuf);		/* get its size */    close (fd);			/* toss out the fd */    if (sbuf.st_size) ts = NIL; /* non-empty file? */  }  if (ts) return (*ts->dtb->append) (stream,mailbox,af,data);  sprintf (tmp,"Indeterminate mailbox format: %.80s",mailbox);  MM_LOG (tmp,ERROR);  return NIL;}/* Dummy mail generate file string * Accepts: temporary buffer to write into *	    mailbox name string * Returns: local file string or NIL if failure */char *dummy_file (char *dst,char *name){  char *s = mailboxfile (dst,name);				/* return our standard inbox */  return (s && !*s) ? strcpy (dst,sysinbox ()) : s;}/* Dummy canonicalize name * Accepts: buffer to write name *	    reference *	    pattern * Returns: T if success, NIL if failure */long dummy_canonicalize (char *tmp,char *ref,char *pat){  unsigned long i;  char *s;  if (ref) {			/* preliminary reference check */    if (*ref == '{') return NIL;/* remote reference not allowed */    else if (!*ref) ref = NIL;	/* treat empty reference as no reference */  }  switch (*pat) {  case '#':			/* namespace name */    if (mailboxfile (tmp,pat)) strcpy (tmp,pat);    else return NIL;		/* unknown namespace */    break;  case '{':			/* remote names not allowed */    return NIL;  case '/':			/* rooted name */  case '~':			/* home directory name */    if (!ref || (*ref != '#')) {/* non-namespace reference? */      strcpy (tmp,pat);		/* yes, ignore */      break;    }				/* fall through */  default:			/* apply reference for all other names */    if (!ref) strcpy (tmp,pat);	/* just copy if no namespace */    else if ((*ref != '#') || mailboxfile (tmp,ref)) {				/* wants root of name? */      if (*pat == '/') strcpy (strchr (strcpy (tmp,ref),'/'),pat);				/* otherwise just append */      else sprintf (tmp,"%s%s",ref,pat);    }    else return NIL;		/* unknown namespace */  }				/* count wildcards */  for (i = 0, s = tmp; *s; *s++) if ((*s == '*') || (*s == '%')) ++i;  if (i > MAXWILDCARDS) {	/* ridiculous wildcarding? */    MM_LOG ("Excessive wildcards in LIST/LSUB",ERROR);    return NIL;  }  return T;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -