|
|
1.1 root 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: vec[vecp++] = --cp;
140: if (!(cp = *argp++) || *cp == '-')
141: adios (NULLCP, "missing argument to %s", argp[-2]);
142: vec[vecp++] = getcpy (libpath(cp));
143: continue;
144:
145: case PROGSW:
146: case LENSW:
147: case WIDSW:
148: vec[vecp++] = --cp;
149: if (!(cp = *argp++) || *cp == '-')
150: adios (NULLCP, "missing argument to %s", argp[-2]);
151: vec[vecp++] = cp;
152: continue;
153:
154: case SHOWSW:
155: if (!(showproc = *argp++) || *showproc == '-')
156: adios (NULLCP, "missing argument to %s", argp[-2]);
157: nshow = 0;
158: continue;
159: case NSHOWSW:
160: nshow++;
161: continue;
162: }
163: if (*cp == '+' || *cp == '@') {
164: if (folder)
165: adios (NULLCP, "only one folder at a time!");
166: else
167: folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
168: }
169: else
170: if (mode != SHOW)
171: goto usage;
172: else
173: msgs[msgp++] = cp;
174: }
175: procp = vecp;
176:
177: /* */
178:
179: if (!m_find ("path"))
180: free (path ("./", TFOLDER));
181:
182: if (draftsw || file) {
183: if (msgp > 1)
184: adios (NULLCP, "only one file at a time!");
185: vec[vecp++] = draftsw
186: ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf))
187: : file;
188: goto go_to_it;
189: }
190:
191: #ifdef WHATNOW
192: if (!msgp && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) {
193: draftsw++;
194: vec[vecp++] = cp;
195: goto go_to_it;
196: }
197: #endif WHATNOW
198:
199: if (!msgp)
200: msgs[msgp++] = mode == NEXT ? "next" : mode == PREV ? "prev" : "cur";
201: if (!folder)
202: folder = m_getfolder ();
203: maildir = m_maildir (folder);
204:
205: if (chdir (maildir) == NOTOK)
206: adios (maildir, "unable to change directory to");
207: if (!(mp = m_gmsg (folder)))
208: adios (NULLCP, "unable to read folder %s", folder);
209: if (mp -> hghmsg == 0)
210: adios (NULLCP, "no messages in %s", folder);
211:
212: for (msgnum = 0; msgnum < msgp; msgnum++)
213: if (!m_convert (mp, msgs[msgnum]))
214: done (1);
215: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
216: if (mp -> msgstats[msgnum] & SELECTED)
217: mp -> msgstats[msgnum] |= UNSEEN;
218: m_setseq (mp);
219: m_setvis (mp, 1);
220:
221: if (mp -> numsel > MAXARGS - 2)
222: adios (NULLCP, "more than %d messages for show exec", MAXARGS - 2);
223: for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
224: if (mp -> msgstats[msgnum] & SELECTED)
225: vec[vecp++] = getcpy (m_name (msgnum));
226:
227: m_replace (pfolder, folder);
228: if (mp -> hghsel != mp -> curmsg)
229: m_setcur (mp, mp -> hghsel);
230: m_sync (mp);
231: m_update ();
232:
233: if (vecp == 2 && headersw)
234: printf ("(Message %s:%s)\n", folder, vec[1]);
235:
236: /* */
237:
238: go_to_it: ;
239: (void) fflush (stdout);
240:
241: vec[vecp] = NULL;
242:
243: if (nshow)
244: proc = "/bin/cat";
245: else {
246: (void) putenv ("mhfolder", folder);
247: if (strcmp (r1bindex (showproc, '/'), "mhl") == 0) {
248: vec[0] = "mhl";
249: (void) mhl (vecp, vec);
250: done (0);
251: }
252: proc = showproc;
253: }
254:
255: if (!draftsw
256: && !file
257: && chdir (maildir = concat (m_maildir (""), "/", NULLCP))
258: != NOTOK) {
259: mp -> foldpath = concat (mp -> foldpath, "/", NULLCP);
260: cp = ssequal (maildir, mp -> foldpath)
261: ? mp -> foldpath + strlen (maildir)
262: : mp -> foldpath;
263: for (msgnum = procp; msgnum < vecp; msgnum++)
264: vec[msgnum] = concat (cp, vec[msgnum], NULLCP);
265: }
266:
267: vec[0] = r1bindex (proc, '/');
268: execvp (proc, vec);
269: adios (proc, "unable to exec");
270: }
271:
272: /* */
273:
274: /* Cheat: we are loaded with adrparse, which wants a routine called
275: OfficialName(). We call adrparse:getm() with the correct arguments
276: to prevent OfficialName() from being called. Hence, the following
277: is to keep the loader happy.
278: */
279:
280: char *OfficialName (name)
281: register char *name;
282: {
283: return name;
284: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.