]>
diplodocus.org Git - nmh/blob - uip/show.c
3 * show.c -- show/list messages
11 static struct swit switches
[] = {
14 #define NOCHECKMIMESW 1
21 { "form formfile", 0 },
23 { "moreproc program", 0 },
27 { "length lines", 0 },
29 { "width columns", 0 },
31 { "showproc program", 0 },
33 { "showmimeproc program", 0 },
39 { "file file", -4 }, /* interface from showfile */
50 static int is_nontext(char *);
52 /* prototype from mhlsbr.c */
53 int mhl (int, char **);
61 main (int argc
, char **argv
)
63 int draftsw
= 0, headersw
= 1, msgp
= 0;
64 int nshow
= 0, checkmime
= 1, mime
;
65 int vecp
= 1, procp
= 1, isdf
= 0, mode
= SHOW
, msgnum
;
66 char *cp
, *maildir
, *file
= NULL
, *folder
= NULL
, *proc
;
67 char buf
[BUFSIZ
], **argp
, **arguments
;
68 char *msgs
[MAXARGS
], *vec
[MAXARGS
];
72 setlocale(LC_ALL
, "");
74 invo_name
= r1bindex (argv
[0], '/');
76 /* read user profile/context */
79 if (!strcasecmp (invo_name
, "next")) {
81 } else if (!strcasecmp (invo_name
, "prev")) {
84 arguments
= getarguments (invo_name
, argc
, argv
, 1);
87 while ((cp
= *argp
++)) {
89 switch (smatch (++cp
, switches
)) {
91 ambigsw (cp
, switches
);
99 snprintf (buf
, sizeof(buf
),
100 "%s [+folder] %s[switches] [switches for showproc]",
101 invo_name
, mode
== SHOW
? "[msgs] ": "");
102 print_help (buf
, switches
, 1);
105 print_version(invo_name
);
110 adios (NULL
, "only one file at a time!");
116 "usage: %s [+folder] [switches] [switches for showproc]",
122 adios (NULL
, "only one file at a time!");
123 if (!(cp
= *argp
++) || *cp
== '-')
124 adios (NULL
, "missing argument to %s", argp
[-2]);
125 file
= path (cp
, TFILE
);
137 if (!(cp
= *argp
++) || *cp
== '-')
138 adios (NULL
, "missing argument to %s", argp
[-2]);
139 vec
[vecp
++] = getcpy (etcpath(cp
));
146 if (!(cp
= *argp
++) || *cp
== '-')
147 adios (NULL
, "missing argument to %s", argp
[-2]);
152 if (!(showproc
= *argp
++) || *showproc
== '-')
153 adios (NULL
, "missing argument to %s", argp
[-2]);
161 if (!(showmimeproc
= *argp
++) || *showmimeproc
== '-')
162 adios (NULL
, "missing argument to %s", argp
[-2]);
173 if (*cp
== '+' || *cp
== '@') {
175 adios (NULL
, "only one folder at a time!");
177 folder
= path (cp
+ 1, *cp
== '+' ? TFOLDER
: TSUBCWF
);
187 if (!context_find ("path"))
188 free (path ("./", TFOLDER
));
190 if (draftsw
|| file
) {
192 adios (NULL
, "only one file at a time!");
193 vec
[vecp
++] = draftsw
194 ? getcpy (m_draft (folder
, msgp
? msgs
[0] : NULL
, 1, &isdf
))
200 if (!msgp
&& !folder
&& mode
== SHOW
&& (cp
= getenv ("mhdraft")) && *cp
) {
210 msgs
[msgp
++] = "next";
213 msgs
[msgp
++] = "prev";
216 msgs
[msgp
++] = "cur";
222 folder
= getfolder (1);
223 maildir
= m_maildir (folder
);
225 if (chdir (maildir
) == NOTOK
)
226 adios (maildir
, "unable to change directory to");
228 /* read folder and create message structure */
229 if (!(mp
= folder_read (folder
)))
230 adios (NULL
, "unable to read folder %s", folder
);
232 /* check for empty folder */
234 adios (NULL
, "no messages in %s", folder
);
236 /* parse all the message ranges/sequences and set SELECTED */
237 for (msgnum
= 0; msgnum
< msgp
; msgnum
++)
238 if (!m_convert (mp
, msgs
[msgnum
]))
242 * Set the SELECT_UNSEEN bit for all the SELECTED messages,
243 * since we will use that as a tag to know which messages
244 * to remove from the "unseen" sequence.
246 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
247 if (is_selected(mp
, msgnum
))
248 set_unseen (mp
, msgnum
);
250 seq_setprev (mp
); /* set the Previous-Sequence */
251 seq_setunseen (mp
, 1); /* unset the Unseen-Sequence */
253 if (mp
->numsel
> MAXARGS
- 2)
254 adios (NULL
, "more than %d messages for show exec", MAXARGS
- 2);
256 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
257 if (is_selected(mp
, msgnum
))
258 vec
[vecp
++] = getcpy (m_name (msgnum
));
260 seq_setcur (mp
, mp
->hghsel
); /* update current message */
261 seq_save (mp
); /* synchronize sequences */
262 context_replace (pfolder
, folder
); /* update current folder */
263 context_save (); /* save the context file */
265 if (headersw
&& vecp
== 2)
266 printf ("(Message %s:%s)\n", folder
, vec
[1]);
274 * Decide which "proc" to use
280 /* check if any messages are non-text MIME messages */
281 if (checkmime
&& !getenv ("NOMHNPROC")) {
282 if (!draftsw
&& !file
) {
283 /* loop through selected messages and check for MIME */
284 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++)
285 if (is_selected (mp
, msgnum
) && is_nontext (m_name (msgnum
))) {
290 /* check the file or draft for MIME */
291 if (is_nontext (vec
[vecp
- 1]))
303 if (folder
&& !draftsw
&& !file
)
304 m_putenv ("mhfolder", folder
);
307 * For backward compatibility, if the "proc" is mhn,
308 * then add "-show" option. Add "-file" if showing
311 if (strcmp (r1bindex (proc
, '/'), "mhn") == 0) {
312 if (draftsw
|| file
) {
313 vec
[vecp
] = vec
[vecp
- 1];
314 vec
[vecp
- 1] = "-file";
317 vec
[vecp
++] = "-show";
321 /* If the "proc" is "mhshow", add "-file" if showing file or draft.
323 if (strcmp (r1bindex (proc
, '/'), "mhshow") == 0 && (draftsw
|| file
) ) {
324 vec
[vecp
] = vec
[vecp
- 1];
325 vec
[vecp
- 1] = "-file";
330 * If "proc" is mhl, then run it internally
331 * rather than exec'ing it.
333 if (strcmp (r1bindex (proc
, '/'), "mhl") == 0) {
340 * If you are not using a nmh command as your "proc", then
341 * add the path to the message names. Currently, we are just
342 * checking for mhn here, since we've already taken care of mhl.
344 if (!strcmp (r1bindex (proc
, '/'), "mhl")
347 && chdir (maildir
= concat (m_maildir (""), "/", NULL
)) != NOTOK
) {
348 mp
->foldpath
= concat (mp
->foldpath
, "/", NULL
);
349 cp
= ssequal (maildir
, mp
->foldpath
)
350 ? mp
->foldpath
+ strlen (maildir
)
352 for (msgnum
= procp
; msgnum
< vecp
; msgnum
++)
353 vec
[msgnum
] = concat (cp
, vec
[msgnum
], NULL
);
356 vec
[0] = r1bindex (proc
, '/');
358 adios (proc
, "unable to exec");
359 return 0; /* dead code to satisfy the compiler */
363 * Cheat: we are loaded with adrparse, which wants a routine called
364 * OfficialName(). We call adrparse:getm() with the correct arguments
365 * to prevent OfficialName() from being called. Hence, the following
366 * is to keep the loader happy.
370 OfficialName (char *name
)
377 * Check if a message or file contains any non-text parts
380 is_nontext (char *msgnam
)
384 char buf
[BUFSIZ
], name
[NAMESZ
];
387 if ((fp
= fopen (msgnam
, "r")) == NULL
)
390 for (state
= FLD
;;) {
391 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
)) {
396 * Check Content-Type field
398 if (!strcasecmp (name
, TYPE_FIELD
)) {
402 cp
= add (buf
, NULL
);
403 while (state
== FLDPLUS
) {
404 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
411 for (; isspace (*bp
); bp
++)
416 for (bp
++, i
= 0;;) {
446 for (dp
= bp
; istoken (*dp
); dp
++)
453 if ((result
= (strcasecmp (bp
, "plain") != 0)))
456 for (dp
++; isspace (*dp
); dp
++)
459 if ((result
= !uprf (dp
, "charset")))
461 dp
+= sizeof("charset") - 1;
462 while (isspace (*dp
))
466 while (isspace (*dp
))
469 if ((bp
= strchr(++dp
, '"')))
472 for (bp
= dp
; *bp
; bp
++)
479 /* Default character set */
482 /* Check the character set */
483 result
= !check_charset (dp
, strlen (dp
));
485 if (!(result
= (strcasecmp (bp
, "text") != 0))) {
502 * Check Content-Transfer-Encoding field
504 if (!strcasecmp (name
, ENCODING_FIELD
)) {
505 cp
= add (buf
, NULL
);
506 while (state
== FLDPLUS
) {
507 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
510 for (bp
= cp
; isspace (*bp
); bp
++)
512 for (dp
= bp
; istoken (*dp
); dp
++)
515 result
= (strcasecmp (bp
, "7bit")
516 && strcasecmp (bp
, "8bit")
517 && strcasecmp (bp
, "binary"));
528 * Just skip the rest of this header
529 * field and go to next one.
531 while (state
== FLDPLUS
)
532 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
536 * We've passed the message header,
537 * so message is just text.