1: /* show.c - list messages */ 2: 3: #include "../h/mh.h" 4: #include <stdio.h> 5: 6: /* */ 7: 8: static struct swit switches[] = { 9: #define DRFTSW 0 10: "draft", 5, 11: 12: #define FORMSW 1 13: "form formfile", 4, 14: #define PROGSW 2 15: "moreproc program", 4, 16: #define NPROGSW 3 17: "nomoreproc", 3, 18: #define LENSW 4 19: "length lines", 4, 20: #define WIDSW 5 21: "width columns", 4, 22: 23: #define SHOWSW 6 24: "showproc program", 4, 25: #define NSHOWSW 7 26: "noshowproc", 3, 27: 28: #define HEADSW 8 29: "header", 4, 30: #define NHEADSW 9 31: "noheader", 3, 32: 33: #define FILESW 10 34: "file file", -4, /* interface from showfile */ 35: 36: #define HELPSW 11 37: "help", 4, 38: 39: NULL, NULL 40: }; 41: 42: 43: #define SHOW 0 44: #define NEXT 1 45: #define PREV 2 46: 47: /* */ 48: 49: /* ARGSUSED */ 50: 51: main (argc, argv) 52: int argc; 53: char **argv; 54: { 55: int draftsw = 0, 56: headersw = 1, 57: nshow = 0, 58: msgp = 0, 59: vecp = 1, 60: procp = 1, 61: isdf = 0, 62: mode = SHOW, 63: msgnum; 64: char *cp, 65: *maildir, 66: *file = NULL, 67: *folder = NULL, 68: *proc, 69: buf[100], 70: **ap, 71: **argp, 72: *arguments[MAXARGS], 73: *msgs[MAXARGS], 74: *vec[MAXARGS]; 75: struct msgs *mp; 76: 77: invo_name = r1bindex (argv[0], '/'); 78: if (uleq (invo_name, "next")) 79: mode = NEXT; 80: else 81: if (uleq (invo_name, "prev")) 82: mode = PREV; 83: if ((cp = m_find (invo_name)) != NULL) { 84: ap = brkstring (cp = getcpy (cp), " ", "\n"); 85: ap = copyip (ap, arguments); 86: } 87: else 88: ap = arguments; 89: (void) copyip (argv + 1, ap); 90: argp = arguments; 91: 92: /* */ 93: 94: while (cp = *argp++) { 95: if (*cp == '-') 96: switch (smatch (++cp, switches)) { 97: case AMBIGSW: 98: ambigsw (cp, switches); 99: done (1); 100: case UNKWNSW: 101: case NPROGSW: 102: vec[vecp++] = --cp; 103: continue; 104: case HELPSW: 105: (void) sprintf (buf, 106: "%s [+folder] %s[switches] [switches for showproc]", 107: invo_name, mode == SHOW ? "[msgs] ": ""); 108: help (buf, switches); 109: done (1); 110: 111: case DRFTSW: 112: if (file) 113: adios (NULLCP, "only one file at a time!"); 114: draftsw++; 115: if (mode == SHOW) 116: continue; 117: usage: ; 118: adios (NULLCP, 119: "usage: %s [+folder] [switches] [switches for showproc]", 120: invo_name); 121: case FILESW: 122: if (mode != SHOW) 123: goto usage; 124: if (draftsw || file) 125: adios (NULLCP, "only one file at a time!"); 126: if (!(cp = *argp++) || *cp == '-') 127: adios (NULLCP, "missing argument to %s", argp[-2]); 128: file = path (cp, TFILE); 129: continue; 130: 131: case HEADSW: 132: headersw++; 133: continue; 134: case NHEADSW: 135: headersw = 0; 136: continue; 137: 138: case FORMSW: 139: case PROGSW: 140: case LENSW: 141: case WIDSW: 142: vec[vecp++] = --cp; 143: if (!(cp = *argp++) || *cp == '-') 144: adios (NULLCP, "missing argument to %s", argp[-2]); 145: vec[vecp++] = cp; 146: continue; 147: 148: case SHOWSW: 149: if (!(showproc = *argp++) || *showproc == '-') 150: adios (NULLCP, "missing argument to %s", argp[-2]); 151: nshow = 0; 152: continue; 153: case NSHOWSW: 154: nshow++; 155: continue; 156: } 157: if (*cp == '+' || *cp == '@') { 158: if (folder) 159: adios (NULLCP, "only one folder at a time!"); 160: else 161: folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); 162: } 163: else 164: if (mode != SHOW) 165: goto usage; 166: else 167: msgs[msgp++] = cp; 168: } 169: procp = vecp; 170: 171: /* */ 172: 173: if (!m_find ("path")) 174: free (path ("./", TFOLDER)); 175: 176: if (draftsw || file) { 177: if (msgp > 1) 178: adios (NULLCP, "only one file at a time!"); 179: vec[vecp++] = draftsw 180: ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf)) 181: : file; 182: goto go_to_it; 183: } 184: 185: #ifdef WHATNOW 186: if (!msgp && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { 187: vec[vecp++] = cp; 188: goto go_to_it; 189: } 190: #endif WHATNOW 191: 192: if (!msgp) 193: msgs[msgp++] = mode == NEXT ? "next" : mode == PREV ? "prev" : "cur"; 194: if (!folder) 195: folder = m_getfolder (); 196: maildir = m_maildir (folder); 197: 198: if (chdir (maildir) == NOTOK) 199: adios (maildir, "unable to change directory to"); 200: if (!(mp = m_gmsg (folder))) 201: adios (NULLCP, "unable to read folder %s", folder); 202: if (mp -> hghmsg == 0) 203: adios (NULLCP, "no messages in %s", folder); 204: 205: for (msgnum = 0; msgnum < msgp; msgnum++) 206: if (!m_convert (mp, msgs[msgnum])) 207: done (1); 208: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) 209: if (mp -> msgstats[msgnum] & SELECTED) 210: mp -> msgstats[msgnum] |= UNSEEN; 211: m_setseq (mp); 212: m_setvis (mp, 1); 213: 214: if (mp -> numsel > MAXARGS - 2) 215: adios (NULLCP, "more than %d messages for show exec", MAXARGS - 2); 216: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++) 217: if (mp -> msgstats[msgnum] & SELECTED) 218: vec[vecp++] = getcpy (m_name (msgnum)); 219: 220: m_replace (pfolder, folder); 221: if (mp -> hghsel != mp -> curmsg) 222: m_setcur (mp, mp -> hghsel); 223: m_sync (mp); 224: m_update (); 225: 226: if (vecp == 2 && headersw) 227: printf ("(Message %s:%s)\n", folder, vec[1]); 228: 229: /* */ 230: 231: go_to_it: ; 232: (void) fflush (stdout); 233: 234: if (nshow) 235: proc = "/bin/cat"; 236: else { 237: (void) putenv ("mhfolder", folder); 238: if (strcmp (r1bindex (showproc, '/'), "mhl") == 0) { 239: vec[0] = "mhl"; 240: (void) mhl (vecp, vec); 241: done (0); 242: } 243: proc = showproc; 244: } 245: 246: if (!draftsw 247: && chdir (maildir = concat (m_maildir (""), "/", NULLCP)) 248: != NOTOK) { 249: mp -> foldpath = concat (mp -> foldpath, "/", NULLCP); 250: cp = ssequal (maildir, mp -> foldpath) 251: ? mp -> foldpath + strlen (maildir) 252: : mp -> foldpath; 253: for (msgnum = procp; msgnum < vecp; msgnum++) 254: vec[msgnum] = concat (cp, vec[msgnum], NULLCP); 255: } 256: 257: vec[0] = r1bindex (proc, '/'); 258: execvp (proc, vec); 259: adios (proc, "unable to exec"); 260: } 261: 262: /* */ 263: 264: /* Cheat: we are loaded with adrparse, which wants a routine called 265: OfficialName(). We call adrparse:getm() with the correct arguments 266: to prevent OfficialName() from being called. Hence, the following 267: is to keep the loader happy. 268: */ 269: 270: char *OfficialName (name) 271: register char *name; 272: { 273: return name; 274: }