]>
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.
9 #include "sbr/read_yes_or_no_if_tty.h"
10 #include "sbr/concat.h"
11 #include "sbr/error.h"
13 #include "h/mhparse.h"
15 #include "sbr/makedir.h"
21 * limit actions to specified parts or content types
25 char *parts
[NPARTS
+ 1];
26 char *types
[NTYPES
+ 1];
30 static char *errs
= NULL
;
39 /* a part is "ok", i.e., should be processed, if:
40 - there were no -part arguments
41 - this part is a multipart
43 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
48 - this part is a an exact match for any -part option
49 - this part is a sub-part of any -part option
51 for (ap
= parts
; *ap
; ap
++) {
53 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
54 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
70 for (ap
= parts
; *ap
; ap
++) {
71 if (!strcmp (*ap
, ct
->c_partno
)) {
81 type_ok (CT ct
, int sP
)
85 CI ci
= &ct
->c_ctinfo
;
87 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
90 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
91 for (ap
= types
; *ap
; ap
++)
92 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
100 * Returns true if the content has a disposition of "inline".
102 * Technically we should check parent content to see if they have
103 * disposition to use as a default, but we don't right now. Maybe
111 * If there isn't any disposition at all, it's "inline". Obviously
112 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
113 * disposition, treat it as 'attachment'.
116 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
122 make_intermediates (char *file
)
126 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
130 if (stat (file
, &st
) == NOTOK
) {
133 if (errno
!= ENOENT
) {
134 advise (file
, "error on directory");
140 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
141 answer
= read_yes_or_no_if_tty (ep
);
145 goto losing_directory
;
146 if (!makedir (file
)) {
147 inform("unable to create directory %s", file
);
148 goto losing_directory
;
160 * Construct error message for content
164 content_error (char *what
, CT ct
, char *fmt
, ...)
168 char *bp
, buffer
[BUFSIZ
];
172 buflen
= sizeof(buffer
);
174 if (userrs
&& invo_name
&& *invo_name
) {
175 snprintf (bp
, buflen
, "%s: ", invo_name
);
181 va_start (arglist
, fmt
);
183 vsnprintf (bp
, buflen
, fmt
, arglist
);
194 snprintf (bp
, buflen
, " %s: ", what
);
200 if ((s
= strerror (errno
)))
201 snprintf (bp
, buflen
, "%s", s
);
203 snprintf (bp
, buflen
, "Error %d", errno
);
210 /* Now add content type and subtype */
211 snprintf (bp
, buflen
, "\n (content %s/%s",
212 ci
->ci_type
, ci
->ci_subtype
);
217 /* Now add the message/part number */
219 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
225 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
232 snprintf (bp
, buflen
, ")");
242 errs
= add (buffer
, errs
);
244 inform("%s", buffer
);