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

📄 phile.c

📁 广泛使用的邮件服务器!同时
💻 C
📖 第 1 页 / 共 2 页
字号:
  elt = mail_elt (stream,1);	/* instantiate cache element */  elt->valid = elt->recent = T;	/* mark valid flags */  stream->sequence++;		/* bump sequence number */  stream->rdonly = T;		/* make sure upper level knows readonly */				/* instantiate a new envelope and body */  LOCAL->env = mail_newenvelope ();  LOCAL->body = mail_newbody ();  t = gmtime (&sbuf.st_mtime);	/* get UTC time and Julian day */  i = t->tm_hour * 60 + t->tm_min;  k = t->tm_yday;  t = localtime(&sbuf.st_mtime);/* get local time */				/* calculate time delta */  i = t->tm_hour * 60 + t->tm_min - i;  if (k = t->tm_yday - k) i += ((k < 0) == (abs (k) == 1)) ? -24*60 : 24*60;  k = abs (i);			/* time from UTC either way */  elt->hours = t->tm_hour; elt->minutes = t->tm_min; elt->seconds = t->tm_sec;  elt->day = t->tm_mday; elt->month = t->tm_mon + 1;  elt->year = t->tm_year - (BASEYEAR - 1900);  elt->zoccident = (k == i) ? 0 : 1;  elt->zhours = k/60;  elt->zminutes = k % 60;  sprintf (tmp,"%s, %d %s %d %02d:%02d:%02d %c%02d%02d",	   days[t->tm_wday],t->tm_mday,months[t->tm_mon],t->tm_year+1900,	   t->tm_hour,t->tm_min,t->tm_sec,elt->zoccident ? '-' : '+',	   elt->zhours,elt->zminutes);				/* set up Date field */  LOCAL->env->date = cpystr (tmp);				/* fill in From field from file owner */  LOCAL->env->from = mail_newaddr ();  if (pw = getpwuid (sbuf.st_uid)) strcpy (tmp,pw->pw_name);  else sprintf (tmp,"User-Number-%ld",(long) sbuf.st_uid);  LOCAL->env->from->mailbox = cpystr (tmp);  LOCAL->env->from->host = cpystr (mylocalhost ());				/* set subject to be mailbox name */  LOCAL->env->subject = cpystr (stream->mailbox);				/* slurp the data */  (buf = &elt->private.special.text)->size = sbuf.st_size;  read (fd,buf->data = (unsigned char *) fs_get (buf->size + 1),buf->size);  buf->data[buf->size] = '\0';  close (fd);			/* close the file */				/* analyze data type */  if (i = phile_type (buf->data,buf->size,&j)) {    LOCAL->body->type = TYPETEXT;    LOCAL->body->subtype = cpystr ("PLAIN");    if (!(i & PTYPECRTEXT)) {	/* change Internet newline format as needed */      s = (char *) buf->data;	/* make copy of UNIX-format string */      buf->data = NIL;		/* zap the buffer */      buf->size = strcrlfcpy (&buf->data,&m,s,buf->size);      fs_give ((void **) &s);	/* flush original UNIX-format string */    }    LOCAL->body->parameter = mail_newbody_parameter ();    LOCAL->body->parameter->attribute = cpystr ("charset");    LOCAL->body->parameter->value =      cpystr ((i & PTYPEISO2022JP) ? "ISO-2022-JP" :	      (i & PTYPEISO2022KR) ? "ISO-2022-KR" :	      (i & PTYPEISO2022CN) ? "ISO-2022-CN" :	      (i & PTYPE8) ? "X-UNKNOWN" : "US-ASCII");    LOCAL->body->encoding = (i & PTYPE8) ? ENC8BIT : ENC7BIT;    LOCAL->body->size.lines = j;  }  else {			/* binary data */    LOCAL->body->type = TYPEAPPLICATION;    LOCAL->body->subtype = cpystr ("OCTET-STREAM");    LOCAL->body->parameter = mail_newbody_parameter ();    LOCAL->body->parameter->attribute = cpystr ("name");    LOCAL->body->parameter->value =      cpystr ((s = (strrchr (stream->mailbox,'/'))) ? s+1 : stream->mailbox);    LOCAL->body->encoding = ENCBASE64;    buf->data = rfc822_binary (s = (char *) buf->data,buf->size,&buf->size);    fs_give ((void **) &s);	/* flush originary binary contents */  }  phile_header (stream,1,&j,NIL);  LOCAL->body->size.bytes = LOCAL->body->contents.text.size = buf->size;  elt->rfc822_size = j + buf->size;				/* only one message ever... */  stream->uid_validity = sbuf.st_mtime;  stream->uid_last = elt->private.uid = 1;  return stream;		/* return stream alive to caller */}/* File determine data type * Accepts: data to examine *	    size of data *	    pointer to line count return * Returns: PTYPE mask of data type */int phile_type (unsigned char *s,unsigned long i,unsigned long *j){  int ret = PTYPETEXT;  char *charvec = "bbbbbbbaaalaacaabbbbbbbbbbbebbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";  *j = 0;			/* no lines */				/* check type of every character */  while (i--) switch (charvec[*s++]) {  case 'A':    ret |= PTYPE8;		/* 8bit character */    break;  case 'a':    break;			/* ASCII character */  case 'b':    return PTYPEBINARY;		/* binary byte seen, stop immediately */  case 'c':    ret |= PTYPECRTEXT;		/* CR indicates Internet text */    break;  case 'e':			/* ESC */    if (*s == '$') {		/* ISO-2022 sequence? */      switch (s[1]) {      case 'B': case '@': ret |= PTYPEISO2022JP; break;      case ')':	switch (s[2]) {	case 'A': case 'E': case 'G': ret |= PTYPEISO2022CN; break;	case 'C': ret |= PTYPEISO2022KR; break;	}      case '*':	switch (s[2]) {	case 'H': ret |= PTYPEISO2022CN; break;	}      case '+':	switch (s[2]) {	case 'I': case 'J': case 'K': case 'L': case 'M':	  ret |= PTYPEISO2022CN; break;	}      }    }    break;  case 'l':			/* newline */    (*j)++;    break;  }  return ret;			/* return type of data */}/* File close * Accepts: MAIL stream *	    close options */void phile_close (MAILSTREAM *stream,long options){  if (LOCAL) {			/* only if a file is open */    fs_give ((void **) &mail_elt (stream,1)->private.special.text.data);				/* nuke the local data */    fs_give ((void **) &stream->local);    stream->dtb = NIL;		/* log out the DTB */  }}/* File fetch structure * Accepts: MAIL stream *	    message # to fetch *	    pointer to return body *	    option flags * Returns: envelope of this message, body returned in body value * * Fetches the "fast" information as well */ENVELOPE *phile_structure (MAILSTREAM *stream,unsigned long msgno,BODY **body,			   long flags){  if (body) *body = LOCAL->body;  return LOCAL->env;		/* return the envelope */}/* File fetch message header * Accepts: MAIL stream *	    message # to fetch *	    pointer to returned header text length *	    option flags * Returns: message header in RFC822 format */char *phile_header (MAILSTREAM *stream,unsigned long msgno,		    unsigned long *length,long flags){  rfc822_header (LOCAL->tmp,LOCAL->env,LOCAL->body);  *length = strlen (LOCAL->tmp);  return LOCAL->tmp;}/* File fetch message text (body only) * Accepts: MAIL stream *	    message # to fetch *	    pointer to returned stringstruct *	    option flags * Returns: T, always */long phile_text (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags){  SIZEDTEXT *buf = &mail_elt (stream,msgno)->private.special.text;  if (!(flags &FT_PEEK)) {	/* mark message as seen */    mail_elt (stream,msgno)->seen = T;    mm_flags (stream,msgno);  }  INIT (bs,mail_string,buf->data,buf->size);  return T;}/* File ping mailbox * Accepts: MAIL stream * Returns: T if stream alive, else NIL * No-op for readonly files, since read/writer can expunge it from under us! */long phile_ping (MAILSTREAM *stream){  return T;}/* File check mailbox * Accepts: MAIL stream * No-op for readonly files, since read/writer can expunge it from under us! */void phile_check (MAILSTREAM *stream){  mm_log ("Check completed",NIL);}/* File expunge mailbox * Accepts: MAIL stream *	    sequence to expunge if non-NIL *	    expunge options * Returns: T if success, NIL if failure */long phile_expunge (MAILSTREAM *stream,char *sequence,long options){  if (!stream->silent) mm_log ("Expunge ignored on readonly mailbox",NIL);  return LONGT;}/* File copy message(s) * Accepts: MAIL stream *	    sequence *	    destination mailbox *	    copy options * Returns: T if copy successful, else NIL */long phile_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options){  char tmp[MAILTMPLEN];  mailproxycopy_t pc =    (mailproxycopy_t) mail_parameters (stream,GET_MAILPROXYCOPY,NIL);  if (pc) return (*pc) (stream,sequence,mailbox,options);  sprintf (tmp,"Can't copy - file \"%s\" is not in valid mailbox format",	   stream->mailbox);  mm_log (tmp,ERROR);  return NIL;}/* File append message from stringstruct * Accepts: MAIL stream *	    destination mailbox *	    append callback function *	    data for callback * Returns: T if append successful, else NIL */long phile_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data){  char tmp[MAILTMPLEN],file[MAILTMPLEN];  char *s = mailboxfile (file,mailbox);  if (s && *s)     sprintf (tmp,"Can't append - not in valid mailbox format: %.80s",s);  else sprintf (tmp,"Can't append - invalid name: %.80s",mailbox);  mm_log (tmp,ERROR);  return NIL;}

⌨️ 快捷键说明

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