]>
diplodocus.org Git - nmh/blob - uip/mhmisc.c
1 /* mhmisc.c -- misc routines to process MIME messages
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
11 #include "h/mhparse.h"
13 #include "sbr/makedir.h"
19 * limit actions to specified parts or content types
23 char *parts
[NPARTS
+ 1];
24 char *types
[NTYPES
+ 1];
28 static char *errs
= NULL
;
37 /* a part is "ok", i.e., should be processed, if:
38 - there were no -part arguments
39 - this part is a multipart
41 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
46 - this part is a an exact match for any -part option
47 - this part is a sub-part of any -part option
49 for (ap
= parts
; *ap
; ap
++) {
51 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
52 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
68 for (ap
= parts
; *ap
; ap
++) {
69 if (!strcmp (*ap
, ct
->c_partno
)) {
79 type_ok (CT ct
, int sP
)
83 CI ci
= &ct
->c_ctinfo
;
85 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
88 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
89 for (ap
= types
; *ap
; ap
++)
90 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
98 * Returns true if the content has a disposition of "inline".
100 * Technically we should check parent content to see if they have
101 * disposition to use as a default, but we don't right now. Maybe
109 * If there isn't any disposition at all, it's "inline". Obviously
110 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
111 * disposition, treat it as 'attachment'.
114 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
120 make_intermediates (char *file
)
124 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
128 if (stat (file
, &st
) == NOTOK
) {
131 if (errno
!= ENOENT
) {
132 advise (file
, "error on directory");
138 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
139 answer
= read_yes_or_no_if_tty (ep
);
143 goto losing_directory
;
144 if (!makedir (file
)) {
145 inform("unable to create directory %s", file
);
146 goto losing_directory
;
158 * Construct error message for content
162 content_error (char *what
, CT ct
, char *fmt
, ...)
166 char *bp
, buffer
[BUFSIZ
];
170 buflen
= sizeof(buffer
);
172 if (userrs
&& invo_name
&& *invo_name
) {
173 snprintf (bp
, buflen
, "%s: ", invo_name
);
179 va_start (arglist
, fmt
);
181 vsnprintf (bp
, buflen
, fmt
, arglist
);
192 snprintf (bp
, buflen
, " %s: ", what
);
198 if ((s
= strerror (errno
)))
199 snprintf (bp
, buflen
, "%s", s
);
201 snprintf (bp
, buflen
, "Error %d", errno
);
208 /* Now add content type and subtype */
209 snprintf (bp
, buflen
, "\n (content %s/%s",
210 ci
->ci_type
, ci
->ci_subtype
);
215 /* Now add the message/part number */
217 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
223 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
230 snprintf (bp
, buflen
, ")");
240 errs
= add (buffer
, errs
);
242 inform("%s", buffer
);