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

📄 phile.c

📁 广泛使用的邮件服务器!同时
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ======================================================================== * Copyright 1988-2006 University of Washington * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * *  * ======================================================================== *//* * Program:	File routines * * Author:	Mark Crispin *		Networks and Distributed Computing *		Computing & Communications *		University of Washington *		Administration Building, AG-44 *		Seattle, WA  98195 *		Internet: MRC@CAC.Washington.EDU * * Date:	25 August 1993 * Last Edited:	9 May 2006 */#include <stdio.h>#include <ctype.h>#include <errno.h>extern int errno;		/* just in case */#include <signal.h>#include "mail.h"#include "osdep.h"#include <pwd.h>#include <sys/stat.h>#include <sys/time.h>#include "rfc822.h"#include "misc.h"#include "dummy.h"/* Types returned from phile_type() */#define PTYPEBINARY 0		/* binary data */#define PTYPETEXT 1		/* textual data */#define PTYPECRTEXT 2		/* textual data with CR */#define PTYPE8 4		/* textual 8bit data */#define PTYPEISO2022JP 8	/* textual Japanese */#define PTYPEISO2022KR 16	/* textual Korean */#define PTYPEISO2022CN 32	/* textual Chinese *//* PHILE I/O stream local data */	typedef struct phile_local {  ENVELOPE *env;		/* file envelope */  BODY *body;			/* file body */  char tmp[MAILTMPLEN];		/* temporary buffer */} PHILELOCAL;/* Convenient access to local data */#define LOCAL ((PHILELOCAL *) stream->local)/* Function prototypes */DRIVER *phile_valid (char *name);int phile_isvalid (char *name,char *tmp);void *phile_parameters (long function,void *value);void phile_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents);void phile_list (MAILSTREAM *stream,char *ref,char *pat);void phile_lsub (MAILSTREAM *stream,char *ref,char *pat);long phile_create (MAILSTREAM *stream,char *mailbox);long phile_delete (MAILSTREAM *stream,char *mailbox);long phile_rename (MAILSTREAM *stream,char *old,char *newname);long phile_status (MAILSTREAM *stream,char *mbx,long flags);MAILSTREAM *phile_open (MAILSTREAM *stream);int phile_type (unsigned char *s,unsigned long i,unsigned long *j);void phile_close (MAILSTREAM *stream,long options);ENVELOPE *phile_structure (MAILSTREAM *stream,unsigned long msgno,BODY **body,			   long flags);char *phile_header (MAILSTREAM *stream,unsigned long msgno,		    unsigned long *length,long flags);long phile_text (MAILSTREAM *stream,unsigned long msgno,STRING *bs,long flags);long phile_ping (MAILSTREAM *stream);void phile_check (MAILSTREAM *stream);long phile_expunge (MAILSTREAM *stream,char *sequence,long options);long phile_copy (MAILSTREAM *stream,char *sequence,char *mailbox,long options);long phile_append (MAILSTREAM *stream,char *mailbox,append_t af,void *data);/* File routines *//* Driver dispatch used by MAIL */DRIVER philedriver = {  "phile",			/* driver name */				/* driver flags */  DR_LOCAL|DR_READONLY|DR_NOSTICKY,  (DRIVER *) NIL,		/* next driver */  phile_valid,			/* mailbox is valid for us */  phile_parameters,		/* manipulate parameters */  phile_scan,			/* scan mailboxes */  phile_list,			/* list mailboxes */  phile_lsub,			/* list subscribed mailboxes */  NIL,				/* subscribe to mailbox */  NIL,				/* unsubscribe from mailbox */  dummy_create,			/* create mailbox */  dummy_delete,			/* delete mailbox */  dummy_rename,			/* rename mailbox */  phile_status,			/* status of mailbox */  phile_open,			/* open mailbox */  phile_close,			/* close mailbox */  NIL,				/* fetch message "fast" attributes */  NIL,				/* fetch message flags */  NIL,				/* fetch overview */  phile_structure,		/* fetch message envelopes */  phile_header,			/* fetch message header only */  phile_text,			/* fetch message body only */  NIL,				/* fetch partial message text */  NIL,				/* unique identifier */  NIL,				/* message number */  NIL,				/* modify flags */  NIL,				/* per-message modify flags */  NIL,				/* search for message based on criteria */  NIL,				/* sort messages */  NIL,				/* thread messages */  phile_ping,			/* ping mailbox to see if still alive */  phile_check,			/* check for new messages */  phile_expunge,		/* expunge deleted messages */  phile_copy,			/* copy messages to another mailbox */  phile_append,			/* append string message to mailbox */  NIL				/* garbage collect stream */};				/* prototype stream */MAILSTREAM phileproto = {&philedriver};/* File validate mailbox * Accepts: mailbox name * Returns: our driver if name is valid, NIL otherwise */DRIVER *phile_valid (char *name){  char tmp[MAILTMPLEN];  return phile_isvalid (name,tmp) ? &philedriver : NIL;}/* File test for valid mailbox * Accepts: mailbox name * Returns: T if valid, NIL otherwise */int phile_isvalid (char *name,char *tmp){  struct stat sbuf;  char *s;				/* INBOX never accepted, any other name is */  return ((s = mailboxfile (tmp,name)) && *s && !stat (s,&sbuf) &&	  !(sbuf.st_mode & S_IFDIR) &&				/* only allow empty files if no empty proto				   or if #ftp */	  (sbuf.st_size || !default_proto (T) ||	   ((*name == '#') && ((name[1] == 'f') || (name[1] == 'F')) &&	    ((name[2] == 't') || (name[2] == 'T')) &&	    ((name[3] == 'p') || (name[3] == 'P')) && (name[4] == '/'))));}/* File manipulate driver parameters * Accepts: function code *	    function-dependent value * Returns: function-dependent return value */void *phile_parameters (long function,void *value){  return NIL;}/* File mail scan mailboxes * Accepts: mail stream *	    reference *	    pattern to search *	    string to scan */void phile_scan (MAILSTREAM *stream,char *ref,char *pat,char *contents){  if (stream) dummy_scan (NIL,ref,pat,contents);}/* File list mailboxes * Accepts: mail stream *	    reference *	    pattern to search */void phile_list (MAILSTREAM *stream,char *ref,char *pat){  if (stream) dummy_list (NIL,ref,pat);}/* File list subscribed mailboxes * Accepts: mail stream *	    reference *	    pattern to search */void phile_lsub (MAILSTREAM *stream,char *ref,char *pat){  if (stream) dummy_lsub (NIL,ref,pat);}/* File status * Accepts: mail stream *	    mailbox name *	    status flags * Returns: T on success, NIL on failure */long phile_status (MAILSTREAM *stream,char *mbx,long flags){  char *s,tmp[MAILTMPLEN];  MAILSTATUS status;  struct stat sbuf;  long ret = NIL;  if ((s = mailboxfile (tmp,mbx)) && *s && !stat (s,&sbuf)) {    status.flags = flags;	/* return status values */    status.unseen = (stream && mail_elt (stream,1)->seen) ? 0 : 1;    status.messages = status.recent = status.uidnext = 1;    status.uidvalidity = sbuf.st_mtime;				/* pass status to main program */    mm_status (stream,mbx,&status);    ret = LONGT;		/* success */  }  return ret;}/* File open * Accepts: Stream to open * Returns: Stream on success, NIL on failure */MAILSTREAM *phile_open (MAILSTREAM *stream){  int i,k,fd;  unsigned long j,m;  char *s,tmp[MAILTMPLEN];  struct passwd *pw;  struct stat sbuf;  struct tm *t;  MESSAGECACHE *elt;  SIZEDTEXT *buf;				/* return prototype for OP_PROTOTYPE call */  if (!stream) return &phileproto;  if (stream->local) fatal ("phile recycle stream");				/* open associated file */  if (!mailboxfile (tmp,stream->mailbox) || !tmp[0] || stat (tmp,&sbuf) ||      (fd = open (tmp,O_RDONLY,NIL)) < 0) {    sprintf (tmp,"Unable to open file %s",stream->mailbox);    mm_log (tmp,ERROR);    return NIL;  }  fs_give ((void **) &stream->mailbox);  stream->mailbox = cpystr (tmp);  stream->local = fs_get (sizeof (PHILELOCAL));  mail_exists (stream,1);	/* make sure upper level knows */  mail_recent (stream,1);

⌨️ 快捷键说明

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