inc.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,510 行 · 第 1/3 页

C
1,510
字号
    }    real_uid = getuid ();    /* Store real user id in real_uid */    getusr ();    while (all_src != 0) {        (void) seteuid (0);        /* set effective uid to root and real uid */	(void) setruid (real_uid); /* to real users id, so that user can only */			           /* read mail that belongs to him.          */	/* Set this_src to appropriate source - POP, FILE or X400 */        while ((bitposn < sizeof(all_src) * 8) && 	        (this_src = all_src & (1 << bitposn)) == 0)            ++ bitposn;        if (bitposn == sizeof(all_src) * 8)            break;        all_src ^= this_src;	#ifdef	POP        if (pophost && !*pophost)            pophost = NULL;#endif	POP#ifdef  X400        if (x400host && !*x400host)            x400host = NULL;#endif  X400        switch ( this_src ) {        /* PDW: -file or -source file */            case FILESRC:                if ( from ) 	 /* -file */                    newmail = from;                else {                    if (((newmail = getenv ("MAILDROP")) && *newmail)        	        || ((newmail = m_find ("maildrop")) && *newmail))	                newmail = m_mailpath (newmail);	            else {#ifdef	MF	                if (uucp && umincproc && *umincproc)	                    get_uucp_mail ();#endif	MF	                newmail = concat (MAILDIR, "/", MAILFIL, NULLCP); 	            }	        }	        (void) setruid (0);	        (void) seteuid (real_uid);	        if (stat (newmail, &s1) == NOTOK || s1.st_size == 0) {	            if (all_src == 0 && done_inc == 0)		                adios (NULLCP, "no mail to incorporate");	            continue;	        }	        break;#ifdef	POP	    case POPSRC:			/* -[no]rpop or -source pop */	        if ( pophost == NULL) {		    fprintf (stderr, "%s: no pophost\n", invo_name);		    if (all_src == 0)			done (1);		    continue;		}	        if (rpop) {	            if (user == NULL)	                user = getusr ();	            pass = getusr ();	        }	        else {	            fprintf(stderr, "POPhost: ");	            ruserpass (pophost, &user, &pass);  /* -norpop */	        }	        if (pop_init (pophost, user, pass, snoop, rpop) == NOTOK	            || pop_stat (&nmsgs, &nbytes) == NOTOK) {		    fprintf (stderr, "%s: %s\n", invo_name, response);		    if (all_src == 0)			done (1);		    continue;		}	        (void) setruid (0);	        (void) seteuid (real_uid);	        if (nmsgs == 0) {	            (void) pop_quit ();	            if (all_src == 0 && done_inc == 0)	                adios (NULLCP, "no mail to incorporate");	            continue;	        }	        break;#endif	POP#ifdef X400	    case X400SRC:				/* -source x400 */	        if (x400host == NULL) {		    fprintf (stderr, "%s: no x400 host\n", invo_name);		    if (all_src == 0)			done (1);		    continue;		}	        if (rpop) {	            if (x400_user == NULL)		        x400_user = getusr ();	            x400_pass = getusr ();	        }	        else {	            fprintf(stderr, "X400host: ");	            ruserpass (x400host, &x400_user, &x400_pass);  /* -norpop */	        }	        if (x400d_init (x400host, x400_user, x400_pass, x400_snoop,	            rpop) == NOTOK		    || x400d_stat (&x400_nmsgs, &x400_nbytes) == NOTOK) {		    fprintf (stderr, "%s: %s\n", invo_name, x400_response);		    if (all_src == 0)			done (1);		    continue;		}	        (void) setruid(0);	        (void) seteuid (real_uid);	        if (x400_nmsgs == 0) {	            (void) x400d_quit ();	            if (all_src == 0 && done_inc == 0)	                adios (NULLCP, "no mail to incorporate");	            continue;	        }	        break;#endif X400	    default: 	        if (all_src == 0 && done_inc == 0)	            adios (NULLCP, "no mail to incorporate");		continue;		/* done (0); */	        }           #ifdef	POP        if (pophost && file)	    goto go_to_it;#endif	POP#ifdef  X400	if (x400host && file)	    goto go_to_it;#endif  X400        if (!m_find ("path"))            free (path ("./", TFOLDER));        if (!folder)            folder = defalt;        maildir = m_maildir (folder);        if (stat (maildir, &st) == NOTOK) {            if (errno != ENOENT) {	 	if (all_src == 0)                    adios (maildir, "error on folder");		continue;	    }            cp = concat ("Create folder \"", maildir, "\"? ", NULLCP);            if (noisy && !getanswer (cp))                done (1);            free (cp);	    (void) seteuid (0);	    (void) setruid (real_uid);            if (!makedir (maildir)) {		if (all_src == 0)                    adios (NULLCP, "unable to create folder %s", maildir);		continue;	    }	    (void) setruid (0);	    (void) seteuid (real_uid);        }        if (chdir (maildir) == NOTOK) {	    if (all_src == 0)                adios (maildir, "unable to change directory to");	    continue;	}        if (!(mp = m_gmsg (folder))) {	    if (all_src == 0)                adios (NULLCP, "unable to read folder %s", folder);	    continue;	}	(void) setruid (0);	(void) seteuid (real_uid);/*  */#if defined (POP) || defined (X400)go_to_it: ;#endif defined (POP) || defined (X400)	(void) setruid (0);	(void) seteuid (real_uid);        if ( this_src == FILESRC ) {            if (access (newmail, 02) == NOTOK) {                trnflag = 0;                if ((in = fopen (newmail, "r")) == NULL) {		    fprintf (stderr, "unable to read %s\n", newmail);		    if (all_src == 0)			done (1);		    continue;		}            }            else {                locked++;                if (trnflag) {                    (void) signal (SIGHUP, SIG_IGN);                    (void) signal (SIGINT, SIG_IGN);                    (void) signal (SIGQUIT, SIG_IGN);                    (void) signal (SIGTERM, SIG_IGN);                }/* PDW: old version :				 *//* #ifndef NFSFLOCK				 *//*   	else {					 */		/* Make sure no stale lock files are		 * left lying about..		 *//*		(void) signal(SIGHUP, onhup);	 *//*		(void) signal(SIGINT, onintr);	 *//*		(void) signal(SIGQUIT, onquit);  *//*		(void) signal(SIGTERM, onterm);	 *//*	}					 *//* #endif NFSFLOCK				 */                if ((in = lkfopen (newmail, "r")) == NULL) {		    if (all_src == 0)                        adios (NULLCP, "unable to lock and fopen %s", newmail);		    continue;		}                (void) fstat (fileno(in), &s1);            }        }        if (audfile) {            if ((i = stat (audfile, &st)) == NOTOK)                advise (NULLCP, "Creating Receive-Audit: %s", audfile);            if ((aud = fopen (audfile, "a")) == NULL) {		if (all_src == 0)                    adios (audfile, "unable to append to");		continue;	    }            else                if (i == NOTOK)    	            (void) chmod (audfile, m_gmprot ());#if !(defined (POP)) && !(defined (X400))	    fprintf (aud, from ? "<<inc>> %s  -ms %s\n" : "<<inc>> %s\n",	            dtimenow (), from);#endif !(defined (POP)) && !(defined (X400))#ifdef X400	    if (this_src == X400SRC) {	        fprintf (aud, from ? "<<inc>> %s -ms %s\n"		            : x400host ? "<<inc>> %s -host %s -user %s%s\n"		            : "<<inc>> %s\n",	                dtimenow (), from ? from : x400host, x400_user,                        rpop ? " -rpop" : "");            }#endif X400#ifdef POP	    if (this_src == POPSRC) {	       fprintf (aud, from ? "<<inc>> %s -ms %s\n"		           : pophost ? "<<inc>> %s -host %s -user %s%s\n"		           : "<<inc>> %s\n",	               dtimenow (), from ? from : pophost, user,                       rpop ? " -rpop" : "");  	    }#endif POP        }#ifdef	MHE        if (m_find ("mhe")) {            cp = concat (maildir, "/++", NULLCP);            i = stat (cp, &st);            if ((mhe = fopen (cp, "a")) == NULL)                admonish (cp, "unable to append to");            else                if (i == NOTOK)    	            (void) chmod (cp, m_gmprot ());	    free (cp);        }#endif	MHE        nfs = new_fs (form, format, FORMAT);        if (noisy && done_inc == 0) {      	    done_inc++ ;	    printf ("Incorporating new mail into %s...\n\n", folder);	    (void) fflush (stdout);        }/*  */#ifdef	POP        if (this_src == POPSRC) {            if (file) {	/* -packf option. */                file = path (file, TFILE);                if (stat (file, &st) == NOTOK) {   	            if (errno != ENOENT) {			if (all_src == 0)	                    adios (file, "error on file");		 	continue;		    }	            cp = concat ("Create file \"", file, "\"? ", NULLCP);	            if (noisy && !getanswer (cp))	                done (1);	            free (cp);	        }	        msgnum = map_count ();	        if ((pd = mbx_open (file, getuid (), getgid (), m_gmprot ()))	                == NOTOK) {		    if (all_src == 0)	                adios (file, "unable to open");		    continue;		}	        if ((pf = fdopen (pd, "w+")) == NULL) {		    if (all_src == 0)	                adios (NULLCP, "unable to fdopen %s", file);		    continue;		}	    }	    else {	        hghnum = msgnum = mp -> hghmsg;	        if ((mp = m_remsg (mp, 0, mp -> hghmsg + nmsgs)) == NULL) {		    if (all_src == 0)	                adios (NULLCP, "unable to allocate folder storage");		    continue;		}	    }	    for (i = 1; i <= nmsgs; i++) {	        msgnum++;	        if (file) {	/* -packf option. */	            (void) fseek (pf, 0L, 1);	            pos = ftell (pf);	            size = 0;	            (void) fwrite (mmdlm1, 1, strlen (mmdlm1), pf);	            start = ftell (pf);	            if (pop_retr (i, pop_pack) == NOTOK) {			fprintf (stderr, "%s: %s\n", invo_name, response);			if (all_src == 0)			    done (1);			continue;		    }	            (void) fseek (pf, 0L, 1);	            stop = ftell (pf);	            if (fflush (pf)) {			fprintf (stderr, "write error on %s\n", file);			if (all_src == 0)			    done (1);			continue;		    }	            (void) fseek (pf, start, 0);	        }	        else {	            cp = getcpy (m_name (msgnum));	            if ((pf = fopen (cp, "w+")) == NULL) {			fprintf (stderr, "unable to write %s\n", cp);			if (all_src == 0)			    done (1);			continue;		    }	            (void) chmod (cp, m_gmprot ());	            start = stop = 0L;	            if (pop_retr (i, pop_action) == NOTOK) {			fprintf (stderr, "%s: %s\n", invo_name, response);			if (all_src == 0)			    done (1);			continue;		    }        	            if (fflush (pf)) {			fprintf (stderr, "write error on %s\n", cp);			if (all_src == 0)			    done (1);			continue;		    }	            (void) fseek (pf, 0L, 0);	        }	        switch (p = scan (pf, msgnum, 0, nfs, width,	  	           file ? 0 : msgnum == mp -> hghmsg + 1 && chgflag &&			   !cur_updtd,		           0, stop - start, noisy)) {		    case SCNEOF: 		        fprintf (stderr, "%*d  empty\n", DMAXFOLDER, msgnum);		        break;		    case SCNERR: 		    case SCNNUM: 		        break;		    case SCNMSG: 		    case SCNENC:		    default: 		        if (aud)		            fputs (scanl, aud);#ifdef	MHE		        if (mhe)		            fputs (scanl, mhe);#endif	MHE		        if (noisy)		            (void) fflush (stdout);		        if (!file) {		            mp -> msgstats[msgnum] = EXISTS;#ifdef	TMA		            if (p == SCNENC) {		                if (mp -> lowsel == 0 ||                                         msgnum < mp -> lowsel)			            mp -> lowsel = msgnum;		                if (mp -> hghsel == 0 ||                                        msgnum > mp -> hghsel)			            mp -> hghsel = msgnum;		                mp -> numsel++;		                mp -> msgstats[msgnum] |= SELECTED;		            }#endif	TMA		            mp -> msgstats[msgnum] |= UNSEEN;			    mp -> msgflags |= SEQMOD;		        }		        break;		    }	        if (file) {	/* -packf option. */	            (void) fseek (pf, stop, 0);	            (void) fwrite (mmdlm2, 1, strlen (mmdlm2), pf);	            if (fflush (pf)) {			fprintf (stderr, "write error on %s\n",file);			if (all_src == 0)			    done (1);			continue;		    }/* PDW: old version :							*//*	(void) map_write (file, pd, 0, start, stop, pos, size, noisy);  */	            (void) map_write (file, pd, 0, 0L, start, stop, pos,	    		 	      size, noisy);	        }	        else {	            (void) fclose (pf);	            free (cp);	        }	        if (trnflag && pop_dele (i) == NOTOK) {		    fprintf (stderr, "%s: %s\n", invo_name, response);		    if (all_src == 0)			done (1);		    continue;		}	    }	    if (pop_quit () == NOTOK) {		fprintf (stderr, "%s: %s\n", invo_name, response);		if (all_src == 0)		    done (1);		continue;	    }	    if (file) {	        (void) mbx_close (file, pd);	        pd = NOTOK;	    }        }#endif	POP/*  */#ifdef X400        if (this_src == X400SRC) {            if (file) {  /* -packf option. */                file = path (file, TFILE);                if (stat (file, &st) == NOTOK) {  	            if (errno != ENOENT) {			fprintf (stderr, "error on file %s\n", file);			if (all_src == 0)			    done(1);			continue;		    }	            cp = concat ("Create file \"", file, "\"? ", NULLCP);	            if (noisy && !getanswer (cp))	                done (1);	            free (cp);	        }	        msgnum = x400_map_count ();	        if ((x400_pd = mbx_open (file, getuid (), getgid (), 		        m_gmprot ())) == NOTOK) {		    fprintf (stderr, "unable to open %s\n", file);		    if (all_src == 0)			done (1);		    continue;		}	        if ((x400_pf = fdopen (x400_pd, "w+")) == NULL) {		    if (all_src == 0)		        adios (NULLCP, "unable to fdopen %s", file);		    continue;		}	    }	    else {	        hghnum = msgnum = mp -> hghmsg;	        if ((mp = m_remsg (mp, 0, mp -> hghmsg + x400_nmsgs)) == NULL) {		    if (all_src == 0)	                adios (NULLCP, "unable to allocate folder storage");		    continue;		}	    }	    for (i = 1; i <= x400_nmsgs; i++) {

⌨️ 快捷键说明

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