Annotation of researchv10no/lbin/mailx/is.c, revision 1.1

1.1     ! root        1: #ident "@(#)is.c       1.3 'attmail mail(1) command'"
        !             2: #ident "@(#)mailx:is.c 1.1"
        !             3: #ident "@(#)is.c       2.6 'attmail mail(1) command'"
        !             4: #include "rcv.h"
        !             5: #include <pwd.h>
        !             6: 
        !             7: static int isit();
        !             8: 
        !             9: /*
        !            10:  * isheader(lp, ctf) - check if lp is header line and return type
        !            11:  *     lp      ->      pointer to line
        !            12:  *     ctfp    ->      continuation flag (should be FALSE the first time
        !            13:  *                     isheader() is called on a message.  isheader() sets
        !            14:  *                     it for the remaining calls to that message)
        !            15:  * returns
        !            16:  *     FALSE   ->      not header line
        !            17:  *     H_*     ->      type of header line found.
        !            18:  */
        !            19: int
        !            20: isheader(lp, ctfp)
        !            21: char   *lp;
        !            22: int    *ctfp;
        !            23: {
        !            24:        register char   *p, *q;
        !            25:        register int    i;
        !            26: 
        !            27:        p = lp;
        !            28:        while((*p) && (*p != '\n') && (isspace(*p))) {
        !            29:                p++;
        !            30:        }
        !            31:        if((*p == NULL) || (*p == '\n')) {
        !            32:                /* blank line */
        !            33:                return (FALSE);
        !            34:        }
        !            35: 
        !            36:        if ((*ctfp) && ((*lp == ' ') || (*lp == '\t'))) {
        !            37:                return(H_CONT);
        !            38:        }
        !            39: 
        !            40:        *ctfp = FALSE;
        !            41:        for (i = 1; i < H_CONT; i++) {
        !            42:                if (!isit(lp, i)) {
        !            43:                        continue;
        !            44:                }
        !            45:                if ((i == H_FROM) || (i == H_FROM1)) {
        !            46:                        /*
        !            47:                         * Should NEVER get 'From ' or '>From ' line on stdin
        !            48:                         * if invoked as mail (rather than rmail) since
        !            49:                         * 'From ' and/or '>From ' lines are generated by
        !            50:                         * program itself. Therefore, if it DOES match and
        !            51:                         * ismail == TRUE, it must be part of the content.
        !            52:                         */
        !            53:                        if (sending && ismail) {
        !            54:                                return (FALSE);
        !            55:                        }
        !            56:                        /* 
        !            57:                         * I'm sorry, but as far as I can tell, a "From " line should
        !            58:                         * _never_ be "from " or "FROM ".  Case matters in this case
        !            59:                         *     --- adb
        !            60:                         */
        !            61:                        if( i == H_FROM && strncmp(lp,"From",4) != 0)           /* adb */
        !            62:                                return(FALSE);                                  /* adb */
        !            63:                }
        !            64:                *ctfp = TRUE;
        !            65:                return (i);
        !            66:        }
        !            67:        /*
        !            68:         * Check if name: value pair
        !            69:         */
        !            70:        if ((p = strpbrk(lp, ":")) != NULL ) {
        !            71:                for(q = lp; q < p; q++)  {
        !            72:                        if ( (!isalnum(*q)) && (*q != '-') && (*q != '>'))  {
        !            73:                                return(FALSE);
        !            74:                        }
        !            75:                }
        !            76:                *ctfp = TRUE;
        !            77:                return(H_NAMEVALUE);
        !            78:        }
        !            79:        return(FALSE);
        !            80: }
        !            81: 
        !            82: /*
        !            83:  * isit(lp, type) -- case independent match of "name" portion of 
        !            84:  *             "name: value" pair
        !            85:  *     lp      ->      pointer to line to check
        !            86:  *     type    ->      type of header line to match
        !            87:  * returns
        !            88:  *     TRUE    ->      lp matches header type (case independent)
        !            89:  *     FALSE   ->      no match
        !            90:  */
        !            91: static int
        !            92: isit(lp, type)
        !            93: register char  *lp;
        !            94: register int   type;
        !            95: {
        !            96:        register char   *p;
        !            97: 
        !            98:        for (p = header[type].tag; *lp && *p; lp++, p++) {
        !            99:                if (toupper(*p) != toupper(*lp))  {
        !           100:                        return(FALSE);
        !           101:                }
        !           102:        }
        !           103:        if (*p == NULL) {
        !           104:                return(TRUE);
        !           105:        }
        !           106:        return(FALSE);
        !           107: }
        !           108: 
        !           109: /*
        !           110:  * istext(line, size) - check for text characters
        !           111:  */
        !           112: int
        !           113: istext(lp, size)
        !           114:        char    *lp;
        !           115:        long    size;
        !           116: {
        !           117:        register unsigned char *line = (unsigned char*)lp;
        !           118:        register unsigned char *ep;
        !           119:        
        !           120:        for (ep = line+size; --ep >= line; ) {
        !           121:                if( *ep > 0177) return(FALSE);
        !           122:        }
        !           123:        return(TRUE);
        !           124: }
        !           125: 
        !           126: /*
        !           127:  * linecount (line, size) - determine the number of lines in a printable
        !           128:  *                          file.
        !           129:  */
        !           130: int
        !           131: linecount(lp, size)
        !           132:        char    *lp;
        !           133:        int     size;
        !           134: {
        !           135:        register unsigned char  *line = (unsigned char*)lp;
        !           136:        register unsigned char *ch;
        !           137:        register c;
        !           138:        register int count;
        !           139: 
        !           140:        count = 0;
        !           141:        for (ch = line+size; --ch >= line;)
        !           142:        {
        !           143:                c = *ch;
        !           144:                if (c == '\n')
        !           145:                        count++;
        !           146:                continue;
        !           147:        }
        !           148:        return (count); 
        !           149: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.