1: /* mark.c - mark messages */ 2: 3: #include "../h/mh.h" 4: #include <stdio.h> 5: 6: /* */ 7: 8: static struct swit switches[] = { 9: #define ADDSW 0 10: "add", 0, 11: #define DELSW 1 12: "delete", 0, 13: #define LSTSW 2 14: "list", 0, 15: 16: #define SEQSW 3 17: "sequence name", 0, 18: 19: #define PUBLSW 4 20: "public", 0, 21: #define NPUBLSW 5 22: "nopublic", 0, 23: 24: #define ZEROSW 6 25: "zero", 0, 26: #define NZEROSW 7 27: "nozero", 0, 28: 29: #define HELPSW 8 30: "help", 4, 31: 32: #define DEBUGSW 9 33: "debug", -5, 34: 35: NULL, NULL 36: }; 37: 38: /* */ 39: 40: /* ARGSUSED */ 41: 42: main (argc, argv) 43: int argc; 44: char **argv; 45: { 46: int addsw = 0, 47: deletesw = 0, 48: debugsw = 0, 49: listsw = 0, 50: publicsw = -1, 51: zerosw = 0, 52: seqp = 0, 53: msgp = 0, 54: i, 55: msgnum; 56: char *cp, 57: *maildir, 58: *folder = NULL, 59: buf[100], 60: **ap, 61: **argp, 62: *arguments[MAXARGS], 63: *seqs[NATTRS + 1], 64: *msgs[MAXARGS]; 65: struct msgs *mp; 66: 67: invo_name = r1bindex (argv[0], '/'); 68: if ((cp = m_find (invo_name)) != NULL) { 69: ap = brkstring (cp = getcpy (cp), " ", "\n"); 70: ap = copyip (ap, arguments); 71: } 72: else 73: ap = arguments; 74: (void) copyip (argv + 1, ap); 75: argp = arguments; 76: 77: /* */ 78: 79: while (cp = *argp++) { 80: if (*cp == '-') 81: switch (smatch (++cp, switches)) { 82: case AMBIGSW: 83: ambigsw (cp, switches); 84: done (1); 85: case UNKWNSW: 86: adios (NULLCP, "-%s unknown\n", cp); 87: case HELPSW: 88: (void) sprintf (buf, "%s [+folder] [msgs] [switches]", 89: invo_name); 90: help (buf, switches); 91: done (1); 92: 93: case ADDSW: 94: addsw++; 95: deletesw = listsw = 0; 96: continue; 97: case DELSW: 98: deletesw++; 99: addsw = listsw = 0; 100: continue; 101: case LSTSW: 102: listsw++; 103: addsw = deletesw = 0; 104: continue; 105: 106: case SEQSW: 107: if (!(cp = *argp++) || *cp == '-') 108: adios (NULLCP, "missing argument to %s", argp[-2]); 109: if (seqp < NATTRS) 110: seqs[seqp++] = cp; 111: else 112: adios (NULLCP, "only %d sequences allowed!", NATTRS); 113: continue; 114: 115: case PUBLSW: 116: publicsw = 1; 117: continue; 118: case NPUBLSW: 119: publicsw = 0; 120: continue; 121: 122: case DEBUGSW: 123: debugsw++; 124: continue; 125: 126: case ZEROSW: 127: zerosw++; 128: continue; 129: case NZEROSW: 130: zerosw = 0; 131: continue; 132: } 133: if (*cp == '+' || *cp == '@') { 134: if (folder) 135: adios (NULLCP, "only one folder at a time!"); 136: else 137: folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); 138: } 139: else 140: msgs[msgp++] = cp; 141: } 142: 143: /* */ 144: 145: if (!addsw && !deletesw && !listsw) 146: if (seqp) 147: addsw++; 148: else 149: listsw++; 150: 151: if (!m_find ("path")) 152: free (path ("./", TFOLDER)); 153: if (!msgp) 154: msgs[msgp++] = listsw ? "all" :"cur"; 155: if (!folder) 156: folder = m_getfolder (); 157: maildir = m_maildir (folder); 158: 159: if (chdir (maildir) == NOTOK) 160: adios (maildir, "unable to change directory to"); 161: if (!(mp = m_gmsg (folder))) 162: adios (NULLCP, "unable to read folder %s", folder); 163: if (mp -> hghmsg == 0) 164: adios (NULLCP, "no messages in %s", folder); 165: 166: for (msgnum = 0; msgnum < msgp; msgnum++) 167: if (!m_convert (mp, msgs[msgnum])) 168: done (1); 169: 170: if (publicsw == -1) 171: publicsw = mp -> msgflags & READONLY ? 0 : 1; 172: if (publicsw && (mp -> msgflags & READONLY)) 173: adios (NULLCP, "folder %s is read-only, so -public not allowed", 174: folder); 175: 176: /* */ 177: 178: if (debugsw) { 179: printf ("invo_name=%s mypath=%s defpath=%s\n", 180: invo_name, mypath, defpath); 181: printf ("ctxpath=%s context flags=%s\n", 182: ctxpath, sprintb (buf, (unsigned) ctxflags, DBITS)); 183: printf ("foldpath=%s flags=%s\n", 184: mp -> foldpath, 185: sprintb (buf, (unsigned) mp -> msgflags, FBITS)); 186: printf ("lowmsg=%d hghmsg=%d nummsg=%d curmsg=%d\n", 187: mp -> lowmsg, mp -> hghmsg, mp -> nummsg, mp -> curmsg); 188: printf ("lowsel=%d hghsel=%d numsel=%d\n", 189: mp -> lowsel, mp -> hghsel, mp -> numsel); 190: #ifndef MTR 191: printf ("lowoff=%d hghoff=%d\n", 192: mp -> lowoff, mp -> hghoff); 193: #else MTR 194: printf ("lowoff=%d hghoff=%d msgbase=0x%x msgstats=0x%x\n", 195: mp -> lowoff, mp -> hghoff, mp -> msgbase, mp -> msgstats); 196: #endif MTR 197: } 198: 199: if (seqp == 0 && (addsw || deletesw)) 200: adios (NULLCP, "-%s requires at least one -sequence argument", 201: addsw ? "add" : "delete"); 202: seqs[seqp] = NULL; 203: 204: if (addsw) 205: for (seqp = 0; seqs[seqp]; seqp++) { 206: if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw)) 207: done (1); 208: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) 209: if (mp -> msgstats[msgnum] & SELECTED) 210: if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw)) 211: done (1); 212: } 213: 214: if (deletesw) 215: for (seqp = 0; seqs[seqp]; seqp++) { 216: if (zerosw) 217: for (msgnum = mp -> lowmsg; msgnum <= mp -> hghmsg; msgnum++) 218: if (mp -> msgstats[msgnum] & EXISTS) 219: if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw)) 220: done (1); 221: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) 222: if (mp -> msgstats[msgnum] & SELECTED) 223: if (!m_seqdel (mp, seqs[seqp], msgnum)) 224: done (1); 225: } 226: 227: if (listsw) { 228: int bits = FFATTRSLOT; 229: 230: if (seqp == 0) 231: for (i = 0; mp -> msgattrs[i]; i++) 232: printf ("%s%s: %s\n", mp -> msgattrs[i], 233: mp -> attrstats & (1 << (bits + i)) 234: ? " (private)" : "", 235: m_seq (mp, mp -> msgattrs[i])); 236: else 237: for (seqp = 0; seqs[seqp]; seqp++) 238: printf ("%s: %s\n", seqs[seqp], m_seq (mp, seqs[seqp])); 239: 240: if (debugsw) 241: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) 242: if (mp -> msgstats[msgnum] & SELECTED) 243: printf ("%*d: %s\n", DMAXFOLDER, msgnum, 244: sprintb (buf, (unsigned) mp -> msgstats[msgnum], 245: m_seqbits (mp))); 246: } 247: 248: m_replace (pfolder, folder); 249: m_sync (mp); 250: m_update (); 251: 252: done (0); 253: }