1 /* show.c - list messages */
3 static char ident[] = "@(#)$Id: show.c,v 1.15 1995/12/06 21:07:46 jromine Exp $";
15 static struct swit switches[] = {
22 "moreproc program", 4,
31 "showproc program", 4,
41 "file file", -4, /* interface from showfile */
88 setlocale(LC_ALL, "");
90 invo_name = r1bindex (argv[0], '/');
91 if (uleq (invo_name, "next"))
94 if (uleq (invo_name, "prev"))
96 if ((cp = m_find (invo_name)) != NULL) {
97 ap = brkstring (cp = getcpy (cp), " ", "\n");
98 ap = copyip (ap, arguments);
102 (void) copyip (argv + 1, ap);
107 while (cp = *argp++) {
109 switch (smatch (++cp, switches)) {
111 ambigsw (cp, switches);
119 "%s [+folder] %s[switches] [switches for showproc]",
120 invo_name, mode == SHOW ? "[msgs] ": "");
121 help (buf, switches);
126 adios (NULLCP, "only one file at a time!");
132 "usage: %s [+folder] [switches] [switches for showproc]",
138 adios (NULLCP, "only one file at a time!");
139 if (!(cp = *argp++) || *cp == '-')
140 adios (NULLCP, "missing argument to %s", argp[-2]);
141 file = path (cp, TFILE);
153 if (!(cp = *argp++) || *cp == '-')
154 adios (NULLCP, "missing argument to %s", argp[-2]);
155 vec[vecp++] = getcpy (libpath(cp));
162 if (!(cp = *argp++) || *cp == '-')
163 adios (NULLCP, "missing argument to %s", argp[-2]);
168 if (!(showproc = *argp++) || *showproc == '-')
169 adios (NULLCP, "missing argument to %s", argp[-2]);
176 if (*cp == '+' || *cp == '@') {
178 adios (NULLCP, "only one folder at a time!");
180 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
192 if (!m_find ("path"))
193 free (path ("./", TFOLDER));
195 if (draftsw || file) {
197 adios (NULLCP, "only one file at a time!");
198 vec[vecp++] = draftsw
199 ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf))
205 if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) {
213 msgs[msgp++] = mode == NEXT ? "next" : mode == PREV ? "prev" : "cur";
215 folder = m_getfolder ();
216 maildir = m_maildir (folder);
218 if (chdir (maildir) == NOTOK)
219 adios (maildir, "unable to change directory to");
220 if (!(mp = m_gmsg (folder)))
221 adios (NULLCP, "unable to read folder %s", folder);
222 if (mp -> hghmsg == 0)
223 adios (NULLCP, "no messages in %s", folder);
225 for (msgnum = 0; msgnum < msgp; msgnum++)
226 if (!m_convert (mp, msgs[msgnum]))
228 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
229 if (mp -> msgstats[msgnum] & SELECTED)
230 mp -> msgstats[msgnum] |= UNSEEN;
234 if (mp -> numsel > MAXARGS - 2)
235 adios (NULLCP, "more than %d messages for show exec", MAXARGS - 2);
236 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
237 if (mp -> msgstats[msgnum] & SELECTED)
238 vec[vecp++] = getcpy (m_name (msgnum));
240 m_replace (pfolder, folder);
241 if (mp -> hghsel != mp -> curmsg)
242 m_setcur (mp, mp -> hghsel);
246 if (vecp == 2 && headersw)
247 printf ("(Message %s:%s)\n", folder, vec[1]);
252 (void) fflush (stdout);
257 if (!nshow && !getenv ("NOMHNPROC")) {
258 if (!(cp = m_find ("mhnproc")))
261 if (draftsw || file) {
262 if (nontext (vec[vecp - 1])) {
263 vec[vecp] = vec[vecp - 1];
264 vec[vecp - 1] = "-file";
270 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
271 if ((mp -> msgstats[msgnum] & SELECTED)
272 && nontext (m_name (msgnum))) {
275 vec[vecp++] = "-show";
284 if (folder && !draftsw && !file)
285 (void) m_putenv ("mhfolder", folder);
286 if (strcmp (r1bindex (showproc, '/'), "mhl") == 0) {
288 (void) mhl (vecp, vec);
296 && chdir (maildir = concat (m_maildir (""), "/", NULLCP))
298 mp -> foldpath = concat (mp -> foldpath, "/", NULLCP);
299 cp = ssequal (maildir, mp -> foldpath)
300 ? mp -> foldpath + strlen (maildir)
302 for (msgnum = procp; msgnum < vecp; msgnum++)
303 vec[msgnum] = concat (cp, vec[msgnum], NULLCP);
307 vec[0] = r1bindex (proc, '/');
309 adios (proc, "unable to exec");
314 /* Cheat: we are loaded with adrparse, which wants a routine called
315 OfficialName(). We call adrparse:getm() with the correct arguments
316 to prevent OfficialName() from being called. Hence, the following
317 is to keep the loader happy.
320 char *OfficialName (name)
329 #include "../h/mhn.h"
332 static int nontext (msgnam)
345 if ((fp = fopen (msgnam, "r")) == NULL)
348 if (!(chset = getenv ("MM_CHARSET")))
352 switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
356 if (uleq (name, TYPE_FIELD)) {
360 cp = add (buf, NULLCP);
361 while (state == FLDPLUS) {
362 state = m_getfld (state, name, buf, sizeof buf, fp);
369 for (; isspace (*bp); bp++)
374 for (bp++, i = 0;;) {
404 for (dp = bp; istoken (*dp); dp++)
410 if (result = !uleq (bp, "plain"))
413 for (dp++; isspace (*dp); dp++)
415 if (result = !uprf (dp, "charset"))
417 dp += sizeof "charset" - 1;
418 while (isspace (*dp))
422 while (isspace (*dp))
425 if (bp = index (++dp, '"'))
429 for (bp = dp; *bp; bp++)
434 if ((result = !uleq (dp, chset))
435 && uleq (dp, "us-ascii")
436 && uleq (chset, "iso-8859-1"))
440 if (!(result = !uleq (bp, "text"))) {
455 if (uleq (name, ENCODING_FIELD)) {
456 cp = add (buf, NULLCP);
457 while (state == FLDPLUS) {
458 state = m_getfld (state, name, buf, sizeof buf, fp);
461 for (bp = cp; isspace (*bp); bp++)
463 for (dp = bp; istoken (*dp); dp++)
466 result = !uleq (bp, "7bit")
467 && !uleq (bp, "8bit")
468 && !uleq (bp, "binary");
477 while (state == FLDPLUS)
478 state = m_getfld (state, name, buf, sizeof buf, fp);