]>
diplodocus.org Git - nmh/blob - uip/mhmisc.c
fcec3c3eb7609feda8c672f550ddb0c435afef77
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.
9 #include "sbr/concat.h"
10 #include "sbr/error.h"
12 #include "h/mhparse.h"
14 #include "sbr/makedir.h"
20 * limit actions to specified parts or content types
24 char *parts
[NPARTS
+ 1];
25 char *types
[NTYPES
+ 1];
29 static char *errs
= NULL
;
38 /* a part is "ok", i.e., should be processed, if:
39 - there were no -part arguments
40 - this part is a multipart
42 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
47 - this part is a an exact match for any -part option
48 - this part is a sub-part of any -part option
50 for (ap
= parts
; *ap
; ap
++) {
52 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
53 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
69 for (ap
= parts
; *ap
; ap
++) {
70 if (!strcmp (*ap
, ct
->c_partno
)) {
80 type_ok (CT ct
, int sP
)
84 CI ci
= &ct
->c_ctinfo
;
86 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
89 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
90 for (ap
= types
; *ap
; ap
++)
91 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
99 * Returns true if the content has a disposition of "inline".
101 * Technically we should check parent content to see if they have
102 * disposition to use as a default, but we don't right now. Maybe
110 * If there isn't any disposition at all, it's "inline". Obviously
111 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
112 * disposition, treat it as 'attachment'.
115 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
121 make_intermediates (char *file
)
125 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
129 if (stat (file
, &st
) == NOTOK
) {
132 if (errno
!= ENOENT
) {
133 advise (file
, "error on directory");
139 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
140 answer
= read_yes_or_no_if_tty (ep
);
144 goto losing_directory
;
145 if (!makedir (file
)) {
146 inform("unable to create directory %s", file
);
147 goto losing_directory
;
159 * Construct error message for content
163 content_error (char *what
, CT ct
, char *fmt
, ...)
167 char *bp
, buffer
[BUFSIZ
];
171 buflen
= sizeof(buffer
);
173 if (userrs
&& invo_name
&& *invo_name
) {
174 snprintf (bp
, buflen
, "%s: ", invo_name
);
180 va_start (arglist
, fmt
);
182 vsnprintf (bp
, buflen
, fmt
, arglist
);
193 snprintf (bp
, buflen
, " %s: ", what
);
199 if ((s
= strerror (errno
)))
200 snprintf (bp
, buflen
, "%s", s
);
202 snprintf (bp
, buflen
, "Error %d", errno
);
209 /* Now add content type and subtype */
210 snprintf (bp
, buflen
, "\n (content %s/%s",
211 ci
->ci_type
, ci
->ci_subtype
);
216 /* Now add the message/part number */
218 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
224 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
231 snprintf (bp
, buflen
, ")");
241 errs
= add (buffer
, errs
);
243 inform("%s", buffer
);