]>
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.
10 #include <h/mhparse.h>
12 #include "../sbr/makedir.h"
17 * limit actions to specified parts or content types
21 char *parts
[NPARTS
+ 1];
22 char *types
[NTYPES
+ 1];
26 static char *errs
= NULL
;
33 int part_exact(CT ct
);
34 int type_ok (CT
, int);
35 void content_error (char *, CT
, char *, ...);
36 void flush_errors (void);
45 /* a part is "ok", i.e., should be processed, if:
46 - there were no -part arguments
47 - this part is a multipart
49 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
54 - this part is a an exact match for any -part option
55 - this part is a sub-part of any -part option
57 for (ap
= parts
; *ap
; ap
++) {
59 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
60 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
76 for (ap
= parts
; *ap
; ap
++) {
77 if (!strcmp (*ap
, ct
->c_partno
)) {
87 type_ok (CT ct
, int sP
)
91 CI ci
= &ct
->c_ctinfo
;
93 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
96 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
97 for (ap
= types
; *ap
; ap
++)
98 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
106 * Returns true if this content is marked as "inline".
108 * Technically we should check parent content to see if they have
109 * disposition to use as a default, but we don't right now. Maybe
117 * If there isn't any disposition at all, it's "inline". Obviously
118 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
119 * disposition, treat it as 'attachment'.
122 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
128 make_intermediates (char *file
)
132 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
136 if (stat (file
, &st
) == NOTOK
) {
139 if (errno
!= ENOENT
) {
140 advise (file
, "error on directory");
146 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
147 answer
= read_yes_or_no_if_tty (ep
);
151 goto losing_directory
;
152 if (!makedir (file
)) {
153 inform("unable to create directory %s", file
);
154 goto losing_directory
;
166 * Construct error message for content
170 content_error (char *what
, CT ct
, char *fmt
, ...)
174 char *bp
, buffer
[BUFSIZ
];
178 buflen
= sizeof(buffer
);
180 if (userrs
&& invo_name
&& *invo_name
) {
181 snprintf (bp
, buflen
, "%s: ", invo_name
);
187 va_start (arglist
, fmt
);
189 vsnprintf (bp
, buflen
, fmt
, arglist
);
200 snprintf (bp
, buflen
, " %s: ", what
);
206 if ((s
= strerror (errno
)))
207 snprintf (bp
, buflen
, "%s", s
);
209 snprintf (bp
, buflen
, "Error %d", errno
);
216 i
= strlen (invo_name
) + 2;
218 /* Now add content type and subtype */
219 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
220 ci
->ci_type
, ci
->ci_subtype
);
225 /* Now add the message/part number */
227 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
233 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
240 snprintf (bp
, buflen
, ")");
250 errs
= add (buffer
, errs
);
252 inform("%s", buffer
);