]>
diplodocus.org Git - nmh/blob - uip/mhmisc.c
3 * mhparse.c -- misc routines to process MIME messages
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 #include <h/mhparse.h>
18 * limit actions to specified parts or content types
22 char *parts
[NPARTS
+ 1];
23 char *types
[NTYPES
+ 1];
27 static char *errs
= NULL
;
34 int part_exact(CT ct
);
35 int type_ok (CT
, int);
36 void content_error (char *, CT
, char *, ...);
37 void flush_errors (void);
46 /* a part is "ok", i.e., should be processed, if:
47 - there were no -part arguments
48 - this part is a multipart
50 if (npart
== 0 || ct
->c_type
== CT_MULTIPART
) {
55 - this part is a an exact match for any -part option
56 - this part is a sub-part of any -part option
58 for (ap
= parts
; *ap
; ap
++) {
60 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
61 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' )) {
77 for (ap
= parts
; *ap
; ap
++) {
78 if (!strcmp (*ap
, ct
->c_partno
)) {
88 type_ok (CT ct
, int sP
)
92 CI ci
= &ct
->c_ctinfo
;
94 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
97 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
98 for (ap
= types
; *ap
; ap
++)
99 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
107 * Returns true if this content is marked as "inline".
109 * Technically we should check parent content to see if they have
110 * disposition to use as a default, but we don't right now. Maybe
118 * If there isn't any disposition at all, it's "inline". Obviously
119 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
120 * disposition, treat it as 'attachment'.
123 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
129 make_intermediates (char *file
)
133 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
137 if (stat (file
, &st
) == NOTOK
) {
140 if (errno
!= ENOENT
) {
141 advise (file
, "error on directory");
147 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
148 answer
= read_yes_or_no_if_tty (ep
);
152 goto losing_directory
;
153 if (!makedir (file
)) {
154 advise (NULL
, "unable to create directory %s", file
);
155 goto losing_directory
;
167 * Construct error message for content
171 content_error (char *what
, CT ct
, char *fmt
, ...)
175 char *bp
, buffer
[BUFSIZ
];
179 buflen
= sizeof(buffer
);
181 if (userrs
&& invo_name
&& *invo_name
) {
182 snprintf (bp
, buflen
, "%s: ", invo_name
);
188 va_start (arglist
, fmt
);
190 vsnprintf (bp
, buflen
, fmt
, arglist
);
201 snprintf (bp
, buflen
, " %s: ", what
);
207 if ((s
= strerror (errno
)))
208 snprintf (bp
, buflen
, "%s", s
);
210 snprintf (bp
, buflen
, "Error %d", errno
);
217 i
= strlen (invo_name
) + 2;
219 /* Now add content type and subtype */
220 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
221 ci
->ci_type
, ci
->ci_subtype
);
226 /* Now add the message/part number */
228 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
234 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
241 snprintf (bp
, buflen
, ")");
251 errs
= add (buffer
, errs
);
253 advise (NULL
, "%s", buffer
);