1: /* repl.c - reply to a 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 ANNOSW  0
  12:     "annotate", 0,
  13: #define NANNOSW 1
  14:     "noannotate", 0,
  15: 
  16: #define CCSW    2
  17:     "cc type", 0,
  18: #define NCCSW   3
  19:     "nocc type", 0,
  20: 
  21: #define DFOLDSW 4
  22:     "draftfolder +folder", 0,
  23: #define DMSGSW  5
  24:     "draftmessage msg", 0,
  25: #define NDFLDSW 6
  26:     "nodraftfolder", 0,
  27: 
  28: #define EDITRSW 7
  29:     "editor editor", 0,
  30: #define NEDITSW 8
  31:     "noedit", 0,
  32: 
  33: #define FCCSW   9
  34:     "fcc folder", 0,
  35: 
  36: #define FILTSW  10
  37:     "filter filterfile", 0,
  38: #define FORMSW  11
  39:     "form formfile", 0,
  40: 
  41: #define FRMTSW  12
  42:     "format", 5,
  43: #define NFRMTSW 13
  44:     "noformat", 7,
  45: 
  46: #define INPLSW  14
  47:     "inplace", 0,
  48: #define NINPLSW 15
  49:     "noinplace", 0,
  50: 
  51: #define QURYSW  16
  52:     "query", 0,
  53: #define NQURYSW 17
  54:     "noquery", 0,
  55: 
  56: #define WHATSW  18
  57:     "whatnowproc program", 0,
  58: #define NWHATSW 19
  59:     "nowhatnowproc", 0,
  60: 
  61: #define WIDTHSW 20
  62:     "width columns", 0,
  63: 
  64: #define HELPSW  21
  65:     "help", 4,
  66: 
  67: #define FILESW  22
  68:     "file file", -4,        /* interface from msh */
  69: 
  70: #ifdef  MHE
  71: #define BILDSW  23
  72:     "build", -5,        /* interface from mhe */
  73: #endif	MHE
  74: 
  75:     NULL, NULL
  76: };
  77: 
  78: 
  79: static struct swit ccswitches[] = {
  80: #define CTOSW   0
  81:     "to", 0,
  82: #define CCCSW   1
  83:     "cc", 0,
  84: #define CMESW   2
  85:     "me", 0,
  86: #define CALSW   3
  87:     "all", 0,
  88: 
  89:     NULL, NULL
  90: };
  91: 
  92: /*  */
  93: 
  94: static struct swit aqrnl[] = {
  95: #define NOSW    0
  96:     "quit", 0,
  97: #define YESW    1
  98:     "replace", 0,
  99: #define LISTDSW 2
 100:     "list", 0,
 101: #define REFILSW 3
 102:     "refile +folder", 0,
 103: #define NEWSW   4
 104:     "new", 0,
 105: 
 106:     NULL, NULL
 107: };
 108: 
 109: 
 110: static struct swit aqrl[] = {
 111:     "quit", 0,
 112:     "replace", 0,
 113:     "list", 0,
 114:     "refile +folder", 0,
 115: 
 116:     NULL, NULL
 117: };
 118: 
 119: /*  */
 120: 
 121: #ifndef ATHENA
 122: #define CCDFLT  1
 123: #else   ATHENA
 124: #define CCDFLT  0
 125: #endif	ATHENA
 126: 
 127: short   ccto = CCDFLT;      /* global for replsbr */
 128: short   cccc = CCDFLT;
 129: short   ccme = CCDFLT;
 130: short   format = 1;
 131: short   outputlinelen = OUTPUTLINELEN;
 132: short   querysw = 0;
 133: 
 134: char   *fcc = NULL;     /* global for replsbr */
 135: char   *filter = NULL;
 136: char   *form = NULL;
 137: 
 138: /*  */
 139: 
 140: /* ARGSUSED */
 141: 
 142: main (argc, argv)
 143: int     argc;
 144: char   *argv[];
 145: {
 146:     int     i,
 147:         isdf = 0,
 148:         anot = 0,
 149:         inplace = 0,
 150: #ifdef  MHE
 151:         buildsw = 0,
 152: #endif	MHE
 153:         nedit = 0,
 154:         nwhat = 0;
 155:     char   *cp,
 156:        *cwd,
 157:        *dp,
 158:            *maildir,
 159:            *file = NULL,
 160:            *folder = NULL,
 161:            *msg = NULL,
 162:        *dfolder = NULL,
 163:        *dmsg = NULL,
 164:        *ed = NULL,
 165:         drft[BUFSIZ],
 166:             buf[100],
 167:           **ap,
 168:           **argp,
 169:            *arguments[MAXARGS];
 170:     struct msgs *mp = NULL;
 171:     struct stat st;
 172:     FILE        *in;
 173: 
 174:     invo_name = r1bindex (argv[0], '/');
 175:     if ((cp = m_find (invo_name)) != NULL) {
 176:     ap = brkstring (cp = getcpy (cp), " ", "\n");
 177:     ap = copyip (ap, arguments);
 178:     }
 179:     else
 180:     ap = arguments;
 181:     (void) copyip (argv + 1, ap);
 182:     argp = arguments;
 183: 
 184: /*  */
 185: 
 186:     while (cp = *argp++) {
 187:     if (*cp == '-')
 188:         switch (smatch (++cp, switches)) {
 189:         case AMBIGSW:
 190:             ambigsw (cp, switches);
 191:             done (1);
 192:         case UNKWNSW:
 193:             adios (NULLCP, "-%s unknown", cp);
 194:         case HELPSW:
 195:             (void) sprintf (buf, "%s: [+folder] [msg] [switches]",
 196:             invo_name);
 197:             help (buf, switches);
 198:             done (0);
 199: 
 200:         case ANNOSW:
 201:             anot++;
 202:             continue;
 203:         case NANNOSW:
 204:             anot = 0;
 205:             continue;
 206: 
 207:         case CCSW:
 208:             if (!(cp = *argp++) || *cp == '-')
 209:             adios (NULLCP, "missing argument to %s", argp[-2]);
 210:             docc (cp, 1);
 211:             continue;
 212:         case NCCSW:
 213:             if (!(cp = *argp++) || *cp == '-')
 214:             adios (NULLCP, "missing argument to %s", argp[-2]);
 215:             docc (cp, 0);
 216:             continue;
 217: 
 218:         case EDITRSW:
 219:             if (!(ed = *argp++) || *ed == '-')
 220:             adios (NULLCP, "missing argument to %s", argp[-2]);
 221:             nedit = 0;
 222:             continue;
 223:         case NEDITSW:
 224:             nedit++;
 225:             continue;
 226: 
 227:         case WHATSW:
 228:             if (!(whatnowproc = *argp++) || *whatnowproc == '-')
 229:             adios (NULLCP, "missing argument to %s", argp[-2]);
 230:             nwhat = 0;
 231:             continue;
 232: #ifdef  MHE
 233:         case BILDSW:
 234:             buildsw++;  /* fall... */
 235: #endif	MHE
 236:         case NWHATSW:
 237:             nwhat++;
 238:             continue;
 239: 
 240:         case FCCSW:
 241:             if (!(cp = *argp++) || *cp == '-')
 242:             adios (NULLCP, "missing argument to %s", argp[-2]);
 243:             dp = NULL;
 244:             if (*cp == '@')
 245:             cp = dp = path (cp + 1, TSUBCWF);
 246:             if (fcc)
 247:             fcc = add (", ", fcc);
 248:             fcc = add (cp, fcc);
 249:             if (dp)
 250:             free (dp);
 251:             continue;
 252: 
 253:         case FILESW:
 254:             if (file)
 255:             adios (NULLCP, "only one file at a time!");
 256:             if (!(cp = *argp++) || *cp == '-')
 257:             adios (NULLCP, "missing argument to %s", argp[-2]);
 258:             file = path (cp, TFILE);
 259:             continue;
 260:         case FILTSW:
 261:             if (!(cp = *argp++) || *cp == '-')
 262:             adios (NULLCP, "missing argument to %s", argp[-2]);
 263:             filter = getcpy (m_maildir (cp));
 264:             continue;
 265:         case FORMSW:
 266:             if (!(form = *argp++) || *form == '-')
 267:             adios (NULLCP, "missing argument to %s", argp[-2]);
 268:             continue;
 269: 
 270:         case FRMTSW:
 271:             format++;
 272:             continue;
 273:         case NFRMTSW:
 274:             format = 0;
 275:             continue;
 276: 
 277:         case INPLSW:
 278:             inplace++;
 279:             continue;
 280:         case NINPLSW:
 281:             inplace = 0;
 282:             continue;
 283: 
 284:         case QURYSW:
 285:             querysw++;
 286:             continue;
 287:         case NQURYSW:
 288:             querysw = 0;
 289:             continue;
 290: 
 291:         case WIDTHSW:
 292:             if (!(cp = *argp++) || *cp == '-')
 293:             adios (NULLCP, "missing argument to %s", argp[-2]);
 294:             if ((outputlinelen = atoi (cp)) < 10)
 295:             adios (NULLCP, "impossible width %d", outputlinelen);
 296:             continue;
 297: 
 298:         case DFOLDSW:
 299:             if (dfolder)
 300:             adios (NULLCP, "only one draft folder at a time!");
 301:             if (!(cp = *argp++) || *cp == '-')
 302:             adios (NULLCP, "missing argument to %s", argp[-2]);
 303:             dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
 304:                     *cp != '@' ? TFOLDER : TSUBCWF);
 305:             continue;
 306:         case DMSGSW:
 307:             if (dmsg)
 308:             adios (NULLCP, "only one draft message at a time!");
 309:             if (!(dmsg = *argp++) || *dmsg == '-')
 310:             adios (NULLCP, "missing argument to %s", argp[-2]);
 311:             continue;
 312:         case NDFLDSW:
 313:             dfolder = NULL;
 314:             isdf = NOTOK;
 315:             continue;
 316:         }
 317:     if (*cp == '+' || *cp == '@') {
 318:         if (folder)
 319:         adios (NULLCP, "only one folder at a time!");
 320:         else
 321:         folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
 322:     }
 323:     else
 324:         if (msg)
 325:         adios (NULLCP, "only one message at a time!");
 326:         else
 327:         msg = cp;
 328:     }
 329: 
 330: /*  */
 331: 
 332:     cwd = getcpy (pwd ());
 333: 
 334:     if (!m_find ("path"))
 335:     free (path ("./", TFOLDER));
 336:     if (file && (msg || folder))
 337:     adios (NULLCP, "can't mix files and folders/msgs");
 338: 
 339: try_it_again: ;
 340: #ifndef MHE
 341:     (void) strcpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf));
 342:     if (stat (drft, &st) != NOTOK) {
 343: #else   MHE
 344:     (void) strcpy (drft, buildsw ? m_maildir ("reply")
 345:               : m_draft (dfolder, NULLCP, NOUSE, &isdf));
 346:     if (!buildsw && stat (drft, &st) != NOTOK) {
 347: #endif	MHE
 348:     printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
 349:     for (i = LISTDSW; i != YESW;) {
 350:         if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
 351:         done (1);
 352:         switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
 353:         case NOSW:
 354:             done (0);
 355:         case NEWSW:
 356:             dmsg = NULL;
 357:             goto try_it_again;
 358:         case YESW:
 359:             break;
 360:         case LISTDSW:
 361:             (void) showfile (++argp, drft);
 362:             break;
 363:         case REFILSW:
 364:             if (refile (++argp, drft) == 0)
 365:             i = YESW;
 366:             break;
 367:         default:
 368:             advise (NULLCP, "say what?");
 369:             break;
 370:         }
 371:     }
 372:     }
 373: 
 374: /*  */
 375: 
 376:     if (file) {
 377:     anot = 0;
 378:     goto go_to_it;
 379:     }
 380: 
 381:     if (!msg)
 382:     msg = "cur";
 383:     if (!folder)
 384:     folder = m_getfolder ();
 385:     maildir = m_maildir (folder);
 386: 
 387:     if (chdir (maildir) == NOTOK)
 388:     adios (maildir, "unable to change directory to");
 389:     if (!(mp = m_gmsg (folder)))
 390:     adios (NULLCP, "unable to read folder %s", folder);
 391:     if (mp -> hghmsg == 0)
 392:     adios (NULLCP, "no messages in %s", folder);
 393: 
 394:     if (!m_convert (mp, msg))
 395:     done (1);
 396:     m_setseq (mp);
 397: 
 398:     if (mp -> numsel > 1)
 399:     adios (NULLCP, "only one message at a time!");
 400: 
 401:     m_replace (pfolder, folder);
 402:     if (mp -> lowsel != mp -> curmsg)
 403:     m_setcur (mp, mp -> lowsel);
 404:     m_sync (mp);
 405:     m_update ();
 406: 
 407: go_to_it: ;
 408:     msg = file ? file : getcpy (m_name (mp -> lowsel));
 409: 
 410:     if ((in = fopen (msg, "r")) == NULL)
 411:     adios (msg, "unable to open");
 412: 
 413:     replout (in, msg, drft);
 414:     (void) fclose (in);
 415: 
 416:     if (nwhat)
 417:     done (0);
 418:     (void) m_whatnow (ed, nedit, NOUSE, drft, msg, 0, mp,
 419:         anot ? "Replied" : NULLCP, inplace, cwd);
 420:     done (1);
 421: }
 422: 
 423: /*  */
 424: 
 425: docc (cp, ccflag)
 426: register char   *cp;
 427: int     ccflag;
 428: {
 429:     switch (smatch (cp, ccswitches)) {
 430:     case AMBIGSW:
 431:         ambigsw (cp, ccswitches);
 432:         done (1);
 433:     case UNKWNSW:
 434:         adios (NULLCP, "-%scc %s unknown", ccflag ? "" : "no", cp);
 435: 
 436:     case CTOSW:
 437:         ccto = ccflag;
 438:         break;
 439: 
 440:     case CCCSW:
 441:         cccc = ccflag;
 442:         break;
 443: 
 444:     case CMESW:
 445:         ccme = ccflag;
 446:         break;
 447: 
 448:     case CALSW:
 449:         ccto = cccc = ccme = ccflag;
 450:         break;
 451:     }
 452: }

Defined functions

docc defined in line 425; used 2 times
main defined in line 142; never used

Defined variables

aqrl defined in line 110; used 2 times
aqrnl defined in line 94; used 2 times
cccc defined in line 128; used 3 times
ccme defined in line 129; used 5 times
ccswitches defined in line 79; used 2 times
ccto defined in line 127; used 3 times
fcc defined in line 134; used 7 times
filter defined in line 135; used 1 times
form defined in line 136; used 4 times
format defined in line 130; used 2 times
outputlinelen defined in line 131; used 3 times
querysw defined in line 132; used 3 times
switches defined in line 10; used 3 times

Defined macros

ANNOSW defined in line 11; never used
BILDSW defined in line 71; never used
CALSW defined in line 86; never used
CCCSW defined in line 82; never used
CCDFLT defined in line 124; used 3 times
CCSW defined in line 16; never used
CMESW defined in line 84; never used
CTOSW defined in line 80; never used
DFOLDSW defined in line 21; never used
DMSGSW defined in line 23; never used
EDITRSW defined in line 28; never used
FCCSW defined in line 33; never used
FILESW defined in line 67; never used
FILTSW defined in line 36; never used
FORMSW defined in line 38; never used
FRMTSW defined in line 41; never used
HELPSW defined in line 64; never used
INPLSW defined in line 46; never used
LISTDSW defined in line 99; used 1 times
NANNOSW defined in line 13; never used
NCCSW defined in line 18; never used
NDFLDSW defined in line 25; never used
NEDITSW defined in line 30; never used
NEWSW defined in line 103; never used
NFRMTSW defined in line 43; never used
NINPLSW defined in line 48; never used
NOSW defined in line 95; never used
NQURYSW defined in line 53; never used
NWHATSW defined in line 58; never used
QURYSW defined in line 51; never used
REFILSW defined in line 101; never used
WHATSW defined in line 56; never used
WIDTHSW defined in line 61; never used
YESW defined in line 97; used 2 times
Last modified: 1986-02-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1299
Valid CSS Valid XHTML 1.0 Strict