1: /* rmm.c - remove a message */
   2: 
   3: #include "../h/mh.h"
   4: #include <stdio.h>
   5: 
   6: /*  */
   7: 
   8: static struct swit switches[] = {
   9: #define HELPSW  0
  10:     "help", 4,
  11: 
  12:     NULL, NULL
  13: };
  14: 
  15: /*  */
  16: 
  17: /* ARGSUSED */
  18: 
  19: main (argc, argv)
  20: int     argc;
  21: char  **argv;
  22: {
  23:     int     msgp = 0,
  24:             msgnum,
  25:             vecp;
  26:     char   *cp,
  27:            *dp,
  28:            *maildir,
  29:            *folder = NULL,
  30:             buf[100],
  31:           **ap,
  32:           **argp,
  33:           **vec,
  34:            *arguments[MAXARGS],
  35:            *msgs[MAXARGS];
  36:     struct msgs *mp;
  37: 
  38:     invo_name = r1bindex (argv[0], '/');
  39:     if ((cp = m_find (invo_name)) != NULL) {
  40:     ap = brkstring (cp = getcpy (cp), " ", "\n");
  41:     ap = copyip (ap, arguments);
  42:     }
  43:     else
  44:     ap = arguments;
  45:     (void) copyip (argv + 1, ap);
  46:     argp = arguments;
  47: 
  48: /*  */
  49: 
  50:     while (cp = *argp++) {
  51:     if (*cp == '-')
  52:         switch (smatch (++cp, switches)) {
  53:         case AMBIGSW:
  54:             ambigsw (cp, switches);
  55:             done (1);
  56:         case UNKWNSW:
  57:             adios (NULLCP, "-%s unknown\n", cp);
  58:         case HELPSW:
  59:             (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
  60:                 invo_name);
  61:             help (buf, switches);
  62:             done (1);
  63:         }
  64:     if (*cp == '+') {
  65:         if (folder)
  66:         adios (NULLCP, "only one folder at a time!");
  67:         else
  68:         folder = path (cp + 1, TFOLDER);
  69:     }
  70:     else
  71:         msgs[msgp++] = cp;
  72:     }
  73: 
  74: /*  */
  75: 
  76:     if (!m_find ("path"))
  77:     free (path ("./", TFOLDER));
  78:     if (!msgp)
  79:     msgs[msgp++] = "cur";
  80:     if (!folder)
  81:     folder = m_getfolder ();
  82:     maildir = m_maildir (folder);
  83: 
  84:     if (chdir (maildir) == NOTOK)
  85:     adios (maildir, "unable to change directory to");
  86:     if (!(mp = m_gmsg (folder)))
  87:     adios (NULLCP, "unable to read folder %s", folder);
  88:     if (mp -> hghmsg == 0)
  89:     adios (NULLCP, "no messages in %s", folder);
  90: 
  91:     for (msgnum = 0; msgnum < msgp; msgnum++)
  92:     if (!m_convert (mp, msgs[msgnum]))
  93:         done (1);
  94:     m_setseq (mp);
  95: 
  96:     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
  97:     if (mp -> msgstats[msgnum] & SELECTED) {
  98: #ifdef  notdef
  99:         mp -> msgstats[msgnum] |= DELETED;
 100: #endif	notdef
 101:         mp -> msgstats[msgnum] &= ~EXISTS;
 102:     }
 103:     mp -> msgflags |= SEQMOD;
 104: 
 105:     m_replace (pfolder, folder);
 106:     m_sync (mp);
 107:     m_update ();
 108: 
 109:     if (rmmproc) {
 110:     if (mp -> numsel > MAXARGS - 2)
 111:         adios (NULLCP, "more than %d messages for %s exec", MAXARGS - 2,
 112:             rmmproc);
 113:     vec = (char **) calloc ((unsigned) (mp -> numsel + 2), sizeof *vec);
 114:     if (vec == NULL)
 115:         adios (NULLCP, "unable to allocate exec vector");
 116:     vecp = 1;
 117:     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
 118:         if (mp -> msgstats[msgnum] & SELECTED)
 119:         vec[vecp++] = getcpy (m_name (msgnum));
 120:     vec[vecp] = NULL;
 121: 
 122:     (void) fflush (stdout);
 123:     vec[0] = r1bindex (rmmproc, '/');
 124:     execvp (rmmproc, vec);
 125:     adios (rmmproc, "unable to exec");
 126:     }
 127: 
 128:     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
 129:     if (mp -> msgstats[msgnum] & SELECTED) {
 130:         (void) strcpy (buf, m_backup (dp = m_name (msgnum)));
 131:         if (rename (dp, buf) == NOTOK)
 132:         admonish (buf, "unable to rename %s to", dp);
 133:     }
 134: 
 135:     done (0);
 136: }

Defined functions

main defined in line 19; never used

Defined variables

switches defined in line 8; used 3 times

Defined macros

HELPSW defined in line 9; never used
Last modified: 1985-10-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 588
Valid CSS Valid XHTML 1.0 Strict