Annotation of 43BSDReno/contrib/mh/uip/send.c, revision 1.1

1.1     ! root        1: /* send.c - send a composed message */
        !             2: 
        !             3: #include "../h/mh.h"
        !             4: #include <stdio.h>
        !             5: #include <sys/types.h>
        !             6: #include <sys/stat.h>
        !             7: 
        !             8: /*  */
        !             9: 
        !            10: static struct swit switches[] = {
        !            11: #define        ALIASW  0
        !            12:     "alias aliasfile", 0,
        !            13: 
        !            14: #define        DEBUGSW 1
        !            15:     "debug", -5,
        !            16: 
        !            17: #define        DRAFTSW 2
        !            18:     "draft", 0,
        !            19: 
        !            20: #define        DFOLDSW 3
        !            21:     "draftfolder +folder", 6,
        !            22: #define        DMSGSW  4
        !            23:     "draftmessage msg", 6,
        !            24: #define        NDFLDSW 5
        !            25:     "nodraftfolder", 0,
        !            26: 
        !            27: #define        ENCRSW  6
        !            28:     "encrypt",
        !            29: #ifndef        TMA
        !            30:        -7,
        !            31: #else  TMA
        !            32:        0,
        !            33: #endif TMA
        !            34: #define        NENCRSW 7
        !            35:     "noencrypt",
        !            36: #ifndef        TMA
        !            37:        -9,
        !            38: #else  TMA
        !            39:        0,
        !            40: #endif TMA
        !            41: 
        !            42: #define        FILTSW  8
        !            43:     "filter filterfile", 0,
        !            44: #define        NFILTSW 9
        !            45:     "nofilter", 0,
        !            46: 
        !            47: #define        FRMTSW  10
        !            48:     "format", 0,
        !            49: #define        NFRMTSW 11
        !            50:     "noformat", 0,
        !            51: 
        !            52: #define        FORWSW  12
        !            53:     "forward", 0,
        !            54: #define        NFORWSW 13
        !            55:     "noforward", 0,
        !            56: 
        !            57: #define        MSGDSW  14
        !            58:     "msgid", 0,
        !            59: #define        NMSGDSW 15
        !            60:     "nomsgid", 0,
        !            61: 
        !            62: #define        PUSHSW  16
        !            63:     "push", 0,
        !            64: #define        NPUSHSW 17
        !            65:     "nopush", 0,
        !            66: 
        !            67: #define        UNIQSW  18
        !            68:     "unique", -6,
        !            69: #define        NUNIQSW 19
        !            70:     "nounique", -8,
        !            71: 
        !            72: #define        VERBSW  20
        !            73:     "verbose", 0,
        !            74: #define        NVERBSW 21
        !            75:     "noverbose", 0,
        !            76: 
        !            77: #define        WATCSW  22
        !            78:     "watch", 0,
        !            79: #define        NWATCSW 23
        !            80:     "nowatch", 0,
        !            81: 
        !            82: #define        WIDTHSW 24
        !            83:     "width columns", 0,
        !            84: 
        !            85: #define        HELPSW  25
        !            86:     "help", 4,
        !            87: 
        !            88: #define        MAILSW  26
        !            89:     "mail", -4,
        !            90: #define        SAMLSW  27
        !            91:     "saml", -4,
        !            92: #define        SENDSW  28
        !            93:     "send", -4,
        !            94: #define        SOMLSW  29
        !            95:     "soml", -4,
        !            96: 
        !            97: #define        CLIESW  30
        !            98:     "client host", -6,
        !            99: #define        SERVSW  31
        !           100:     "server host", -6,
        !           101: #define        SNOOPSW 32
        !           102:     "snoop", -5,
        !           103: 
        !           104:     NULL, NULL
        !           105: };
        !           106: 
        !           107: static struct swit anyl[] = {
        !           108: #define        NOSW    0
        !           109:     "no", 0,
        !           110: #define        YESW    1
        !           111:     "yes", 0,
        !           112: #define        LISTDSW 2
        !           113:     "list", 0,
        !           114: 
        !           115:     NULL, NULL
        !           116: };
        !           117: 
        !           118: /*  */
        !           119: 
        !           120: extern int debugsw;            /* from sendsbr.c */
        !           121: extern int forwsw;
        !           122: extern int inplace;
        !           123: extern int pushsw;
        !           124: extern int unique;
        !           125: 
        !           126: extern char *altmsg;           /*  .. */
        !           127: extern char *annotext;
        !           128: extern char *distfile;
        !           129: 
        !           130: /*  */
        !           131: 
        !           132: /* ARGSUSED */
        !           133: 
        !           134: main (argc, argv)
        !           135: int     argc;
        !           136: char   *argv[];
        !           137: {
        !           138:     int     msgp = 0,
        !           139:            distsw = 0,
        !           140:             vecp = 1,
        !           141:             isdf = 0,
        !           142:             msgnum,
        !           143:             status;
        !           144:     char   *cp,
        !           145:            *dfolder = NULL,
        !           146:            *maildir,
        !           147:             buf[100],
        !           148:           **ap,
        !           149:           **argp,
        !           150:            *arguments[MAXARGS],
        !           151:            *msgs[MAXARGS],
        !           152:            *vec[MAXARGS];
        !           153:     struct msgs *mp;
        !           154:     struct stat st;
        !           155: #ifdef UCI
        !           156:     FILE   *fp;
        !           157: #endif UCI
        !           158: 
        !           159:     invo_name = r1bindex (argv[0], '/');
        !           160:     if ((cp = m_find (invo_name)) != NULL) {
        !           161:        ap = brkstring (cp = getcpy (cp), " ", "\n");
        !           162:        ap = copyip (ap, arguments);
        !           163:     }
        !           164:     else
        !           165:        ap = arguments;
        !           166:     (void) copyip (argv + 1, ap);
        !           167:     argp = arguments;
        !           168: 
        !           169:     vec[vecp++] = "-library";
        !           170:     vec[vecp++] = getcpy (m_maildir (""));
        !           171: 
        !           172: /*  */
        !           173: 
        !           174:     while (cp = *argp++) {
        !           175:        if (*cp == '-')
        !           176:            switch (smatch (++cp, switches)) {
        !           177:                case AMBIGSW: 
        !           178:                    ambigsw (cp, switches);
        !           179:                    senddone (1);
        !           180:                case UNKWNSW: 
        !           181:                    adios (NULLCP, "-%s unknown\n", cp);
        !           182:                case HELPSW: 
        !           183:                    (void) sprintf (buf, "%s [file] [switches]", invo_name);
        !           184:                    help (buf, switches);
        !           185:                    senddone (1);       /* thanks, phyl */
        !           186: 
        !           187:                case DRAFTSW: 
        !           188:                    msgs[msgp++] = draft;
        !           189:                    continue;
        !           190: 
        !           191:                case DFOLDSW: 
        !           192:                    if (dfolder)
        !           193:                        adios (NULLCP, "only one draft folder at a time!");
        !           194:                    if (!(cp = *argp++) || *cp == '-')
        !           195:                        adios (NULLCP, "missing argument to %s", argp[-2]);
        !           196:                    dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
        !           197:                            *cp != '@' ? TFOLDER : TSUBCWF);
        !           198:                    continue;
        !           199:                case DMSGSW: 
        !           200:                    if (!(cp = *argp++) || *cp == '-')
        !           201:                        adios (NULLCP, "missing argument to %s", argp[-2]);
        !           202:                    msgs[msgp++] = cp;
        !           203:                    continue;
        !           204:                case NDFLDSW: 
        !           205:                    dfolder = NULL;
        !           206:                    isdf = NOTOK;
        !           207:                    continue;
        !           208: 
        !           209:                case PUSHSW: 
        !           210:                    pushsw++;
        !           211:                    continue;
        !           212:                case NPUSHSW: 
        !           213:                    pushsw = 0;
        !           214:                    continue;
        !           215: 
        !           216:                case UNIQSW: 
        !           217:                    unique++;
        !           218:                    continue;
        !           219:                case NUNIQSW: 
        !           220:                    unique = 0;
        !           221:                    continue;
        !           222: 
        !           223:                case FORWSW:
        !           224:                    forwsw++;
        !           225:                    continue;
        !           226:                case NFORWSW:
        !           227:                    forwsw = 0;
        !           228:                    continue;
        !           229: 
        !           230:                case DEBUGSW: 
        !           231:                    debugsw++;  /* fall */
        !           232:                case NFILTSW: 
        !           233:                case FRMTSW: 
        !           234:                case NFRMTSW: 
        !           235:                case MSGDSW: 
        !           236:                case NMSGDSW: 
        !           237:                case VERBSW: 
        !           238:                case NVERBSW: 
        !           239:                case WATCSW: 
        !           240:                case NWATCSW: 
        !           241:                case MAILSW: 
        !           242:                case SAMLSW: 
        !           243:                case SENDSW: 
        !           244:                case SOMLSW: 
        !           245:                case ENCRSW:
        !           246:                case NENCRSW:
        !           247:                case SNOOPSW: 
        !           248:                    vec[vecp++] = --cp;
        !           249:                    continue;
        !           250: 
        !           251:                case ALIASW: 
        !           252:                case FILTSW: 
        !           253:                case WIDTHSW: 
        !           254:                case CLIESW: 
        !           255:                case SERVSW: 
        !           256:                    vec[vecp++] = --cp;
        !           257:                    if (!(cp = *argp++) || *cp == '-')
        !           258:                        adios (NULLCP, "missing argument to %s", argp[-2]);
        !           259:                    vec[vecp++] = cp;
        !           260:                    continue;
        !           261:            }
        !           262:        else
        !           263:            msgs[msgp++] = cp;
        !           264:     }
        !           265: 
        !           266: /*  */
        !           267: 
        !           268:     if (dfolder == NULL) {
        !           269:        if (msgp == 0) {
        !           270: #ifdef WHATNOW
        !           271:            if ((cp = getenv ("mhdraft")) && *cp) {
        !           272:                msgs[msgp++] = cp;
        !           273:                goto go_to_it;
        !           274:            }
        !           275: #endif WHATNOW
        !           276:            msgs[msgp++] = getcpy (m_draft (NULLCP, NULLCP, 1, &isdf));
        !           277:            if (stat (msgs[0], &st) == NOTOK)
        !           278:                adios (msgs[0], "unable to stat draft file");
        !           279:            cp = concat ("Use \"", msgs[0], "\"? ", NULLCP);
        !           280:            for (status = LISTDSW; status != YESW;) {
        !           281:                if (!(argp = getans (cp, anyl)))
        !           282:                    senddone (1);
        !           283:                switch (status = smatch (*argp, anyl)) {
        !           284:                    case NOSW: 
        !           285:                        senddone (0);
        !           286:                    case YESW: 
        !           287:                        break;
        !           288:                    case LISTDSW: 
        !           289:                        (void) showfile (++argp, msgs[0]);
        !           290:                        break;
        !           291:                    default:
        !           292:                        advise (NULLCP, "say what?");
        !           293:                        break;
        !           294:                }
        !           295:            }
        !           296:        }
        !           297:        else
        !           298:            for (msgnum = 0; msgnum < msgp; msgnum++)
        !           299:                msgs[msgnum] = getcpy (m_maildir (msgs[msgnum]));
        !           300:     }
        !           301:     else {
        !           302:        if (!m_find ("path"))
        !           303:            free (path ("./", TFOLDER));
        !           304: 
        !           305:        if (!msgp)
        !           306:            msgs[msgp++] = "cur";
        !           307:        maildir = m_maildir (dfolder);
        !           308: 
        !           309:        if (chdir (maildir) == NOTOK)
        !           310:            adios (maildir, "unable to change directory to");
        !           311:        if (!(mp = m_gmsg (dfolder)))
        !           312:            adios (NULLCP, "unable to read folder %s", dfolder);
        !           313:        if (mp -> hghmsg == 0)
        !           314:            adios (NULLCP, "no messages in %s", dfolder);
        !           315: 
        !           316:        for (msgnum = 0; msgnum < msgp; msgnum++)
        !           317:            if (!m_convert (mp, msgs[msgnum]))
        !           318:                senddone (1);
        !           319:        m_setseq (mp);
        !           320: 
        !           321:        for (msgp = 0, msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
        !           322:            if (mp -> msgstats[msgnum] & SELECTED) {
        !           323:                msgs[msgp++] = getcpy (m_name (msgnum));
        !           324: #ifdef notdef
        !           325:                mp -> msgstats[msgnum] |= DELETED;
        !           326: #endif notdef
        !           327:                mp -> msgstats[msgnum] &= ~EXISTS;
        !           328:            }
        !           329:        mp -> msgflags |= SEQMOD;
        !           330: 
        !           331:        m_sync (mp);
        !           332:     }
        !           333: #ifdef WHATNOW
        !           334: go_to_it: ;
        !           335: #endif WHATNOW
        !           336: 
        !           337: /*  */
        !           338: 
        !           339: #ifdef TMA
        !           340:     if ((cp = getenv ("KDS")) == NULL || *cp == NULL)
        !           341:        if ((cp = m_find ("kdsproc")) && *cp)
        !           342:            (void) putenv ("KDS", cp);
        !           343:     if ((cp = getenv ("TMADB")) == NULL || *cp == NULL)
        !           344:        if ((cp = m_find ("tmadb")) && *cp)
        !           345:            (void) putenv ("TMADB", m_maildir (cp));
        !           346: #endif TMA
        !           347: 
        !           348:     if ((cp = getenv ("SIGNATURE")) == NULL || *cp == NULL)
        !           349:        if ((cp = m_find ("signature")) && *cp)
        !           350:            (void) putenv ("SIGNATURE", cp);
        !           351: #ifdef UCI
        !           352:        else {
        !           353:            (void) sprintf (buf, "%s/.signature", mypath);
        !           354:            if ((fp = fopen (buf, "r")) != NULL
        !           355:                && fgets (buf, sizeof buf, fp) != NULL) {
        !           356:                    (void) fclose (fp);
        !           357:                    if (cp = index (buf, '\n'))
        !           358:                        *cp = NULL;
        !           359:                    (void) putenv ("SIGNATURE", buf);
        !           360:            }
        !           361:        }
        !           362: #endif UCI
        !           363: 
        !           364:     for (msgnum = 0; msgnum < msgp; msgnum++)
        !           365:        if (stat (msgs[msgnum], &st) == NOTOK)
        !           366:            adios (msgs[msgnum], "unable to stat draft file");
        !           367: 
        !           368:     if ((annotext = getenv ("mhannotate")) == NULL || *annotext == NULL)
        !           369:        annotext = NULL;
        !           370:     if (annotext
        !           371:            && ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == NULL))
        !           372:        altmsg = NULL;
        !           373:     if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != NULL))
        !           374:        inplace = atoi (cp);
        !           375: 
        !           376:     if ((cp = getenv ("mhdist"))
        !           377:            && *cp
        !           378:            && (distsw = atoi (cp))
        !           379:            && altmsg) {
        !           380:        vec[vecp++] = "-dist";
        !           381:        distfile = getcpy (m_scratch (altmsg, invo_name));
        !           382:        if (link (altmsg, distfile) == NOTOK)
        !           383:            adios (distfile, "unable to link %s to", altmsg);
        !           384:     }
        !           385:     else
        !           386:        distfile = NULL;
        !           387: 
        !           388:     if (altmsg == NULL || stat (altmsg, &st) == NOTOK)
        !           389:        st.st_mtime = 0, st.st_dev = 0, st.st_ino = 0;
        !           390:     if (pushsw)
        !           391:        push ();
        !           392: 
        !           393:     status = 0;
        !           394:     vec[0] = r1bindex (postproc, '/');
        !           395:     closefds (3);
        !           396: 
        !           397:     for (msgnum = 0; msgnum < msgp; msgnum++)
        !           398:        switch (sendsbr (vec, vecp, msgs[msgnum], &st)) {
        !           399:            case DONE: 
        !           400:                senddone (++status);
        !           401: 
        !           402:            case NOTOK: 
        !           403:                status++;       /* fall */
        !           404:            case OK:
        !           405:                break;
        !           406:        }
        !           407: 
        !           408:     m_update ();
        !           409: 
        !           410:     senddone (status);
        !           411: }

unix.superglobalmegacorp.com

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