Annotation of researchv10no/cmd/upas/smtp/to822addr.c, revision 1.1

1.1     ! root        1: #include "string.h"
        !             2: #include "addrformat.h"
        !             3: #include <stdio.h>
        !             4: 
        !             5: /*
        !             6:  *     Convert from `bang' to `%@' format or `source routing' format
        !             7:  *     or `mixed rfc976' format.
        !             8:  *     Let a!b!c!d be addr with host prepended if not gatewaying:
        !             9:  *
        !            10:  *        a!b!c!d ->   d%c%[email protected]          (format==PERCENT)
        !            11:  *                ->   @a.domain,@b:d@c        (format==SOURCEROUTE)
        !            12:  *                ->   [email protected]          (format==RFC976)
        !            13:  *
        !            14:  *     where the .domain is added only if domain!=0 and 'a' has no '.'s
        !            15:  *     
        !            16:  *        a!b!uucp!c!d -> c!d%[email protected] or @a.domain:c!d@b
        !            17:  *
        !            18:  *     Or, if addr has one component only:
        !            19:  *
        !            20:  *        a    ->      [email protected]    if host!=0
        !            21:  */
        !            22: extern char *
        !            23: convertaddr(addr, domain, format)
        !            24:        char *addr;
        !            25:        char *domain;
        !            26: {
        !            27:        static string *buf;
        !            28:        register int i=0;
        !            29:        register char *sp;
        !            30:        int j, d;
        !            31:        char *field[128];
        !            32: 
        !            33:        /* parse the '!' format address */
        !            34:        buf = s_reset(buf);
        !            35:        field[i] = addr;
        !            36:        sp = addr;
        !            37:        while (*sp) {
        !            38:                if (*sp == '!') {
        !            39:                        *sp = '\0';
        !            40:                        if (strcmp(field[i], "uucp") == 0) {
        !            41:                                /* the token 'uucp' stops the parsing */
        !            42:                                field[i] = ++sp;
        !            43:                                break;
        !            44:                        }
        !            45:                        field[++i] = ++sp;
        !            46:                        if(format==RFC976)
        !            47:                                break;
        !            48:                } else
        !            49:                        ++sp;
        !            50:        }
        !            51:        if (buf==NULL)
        !            52:                buf= s_new();
        !            53:        s_restart(buf);
        !            54:        if (i==0) {
        !            55:                s_append(buf, field[0]);
        !            56:        } else {
        !            57:                if (format!=SOURCEROUTE) {
        !            58:                        s_append(buf, field[i--]);
        !            59:                        while (i>=1) {
        !            60:                                s_append(buf, "%");
        !            61:                                s_append(buf, field[i--]);
        !            62:                        }
        !            63:                        addhostdom(buf, field[0], domain);
        !            64:                } else {
        !            65:                        /*
        !            66:                         *  count leading domain fields (non-domains don't count)
        !            67:                         */
        !            68:                        d = 0;
        !            69:                        if(domain || strchr(field[0], '.'))
        !            70:                                d++;
        !            71:                        for( ; d<i; d++)
        !            72:                                if(strchr(field[d], '.')==0)
        !            73:                                        break;
        !            74:                        /*
        !            75:                         *  if there are more than 1 leading domain elements,
        !            76:                         *  put them in as source routing
        !            77:                         */
        !            78:                        if(d > 1){
        !            79:                                addhostdom(buf, field[0], domain);
        !            80:                                for(j=1; j<d-1; j++){
        !            81:                                        s_append(buf, ",");
        !            82:                                        s_append(buf, "@");
        !            83:                                        s_append(buf, field[j]);
        !            84:                                }
        !            85:                                s_append(buf, ":");
        !            86:                        }
        !            87: 
        !            88:                        /*
        !            89:                         *  throw in the non-domain elements separated by '!'s
        !            90:                         */
        !            91:                        s_append(buf, field[d]);
        !            92:                        for(j=d+1; j<=i; j++) {
        !            93:                                s_append(buf, "!");
        !            94:                                s_append(buf, field[j]);
        !            95:                        }
        !            96:                        if(d)
        !            97:                                addhostdom(buf, field[d-1], domain);
        !            98:                }
        !            99:        }
        !           100:        return s_to_c(s_copy(s_to_c(buf)));
        !           101: }
        !           102: 
        !           103: addhostdom(buf, host, dom)
        !           104:        string *buf;
        !           105:        char *host;
        !           106:        char *dom;
        !           107: {
        !           108:        char *cp;
        !           109: 
        !           110:        s_append(buf, "@");
        !           111:        s_append(buf, host);
        !           112:        if(dom && !strchr(host, '.')){
        !           113:                cp = strchr(dom, '.');
        !           114:                if(cp!=NULL)
        !           115:                        s_append(buf, cp);
        !           116:        }
        !           117: }

unix.superglobalmegacorp.com

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