]>
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>
16 * limit actions to specified parts or content types
20 char *parts
[NPARTS
+ 1];
21 char *types
[NTYPES
+ 1];
25 static char *errs
= NULL
;
32 int part_exact(CT ct
);
33 int type_ok (CT
, int);
34 void content_error (char *, CT
, char *, ...);
35 void flush_errors (void);
44 /* a part is "ok", i.e., should be processed, if:
45 - there were no -part arguments
46 - this part is a multipart
48 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
53 - this part is a an exact match for any -part option
54 - this part is a sub-part of any -part option
56 for (ap
= parts
; *ap
; ap
++) {
58 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
59 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
75 for (ap
= parts
; *ap
; ap
++) {
76 if (!strcmp (*ap
, ct
->c_partno
)) {
86 type_ok (CT ct
, int sP
)
90 CI ci
= &ct
->c_ctinfo
;
92 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
95 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
96 for (ap
= types
; *ap
; ap
++)
97 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
105 * Returns true if this content is marked as "inline".
107 * Technically we should check parent content to see if they have
108 * disposition to use as a default, but we don't right now. Maybe
116 * If there isn't any disposition at all, it's "inline". Obviously
117 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
118 * disposition, treat it as 'attachment'.
121 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
127 make_intermediates (char *file
)
131 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
135 if (stat (file
, &st
) == NOTOK
) {
138 if (errno
!= ENOENT
) {
139 advise (file
, "error on directory");
145 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
146 answer
= read_yes_or_no_if_tty (ep
);
150 goto losing_directory
;
151 if (!makedir (file
)) {
152 inform("unable to create directory %s", file
);
153 goto losing_directory
;
165 * Construct error message for content
169 content_error (char *what
, CT ct
, char *fmt
, ...)
173 char *bp
, buffer
[BUFSIZ
];
177 buflen
= sizeof(buffer
);
179 if (userrs
&& invo_name
&& *invo_name
) {
180 snprintf (bp
, buflen
, "%s: ", invo_name
);
186 va_start (arglist
, fmt
);
188 vsnprintf (bp
, buflen
, fmt
, arglist
);
199 snprintf (bp
, buflen
, " %s: ", what
);
205 if ((s
= strerror (errno
)))
206 snprintf (bp
, buflen
, "%s", s
);
208 snprintf (bp
, buflen
, "Error %d", errno
);
215 i
= strlen (invo_name
) + 2;
217 /* Now add content type and subtype */
218 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
219 ci
->ci_type
, ci
->ci_subtype
);
224 /* Now add the message/part number */
226 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
232 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
239 snprintf (bp
, buflen
, ")");
249 errs
= add (buffer
, errs
);
251 inform("%s", buffer
);