]>
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)
130 make_intermediates (char *file
)
134 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
138 if (stat (file
, &st
) == NOTOK
) {
141 if (errno
!= ENOENT
) {
142 advise (file
, "error on directory");
148 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
149 answer
= getanswer (ep
);
153 goto losing_directory
;
154 if (!makedir (file
)) {
155 advise (NULL
, "unable to create directory %s", file
);
156 goto losing_directory
;
168 * Construct error message for content
172 content_error (char *what
, CT ct
, char *fmt
, ...)
176 char *bp
, buffer
[BUFSIZ
];
180 buflen
= sizeof(buffer
);
182 if (userrs
&& invo_name
&& *invo_name
) {
183 snprintf (bp
, buflen
, "%s: ", invo_name
);
189 va_start (arglist
, fmt
);
191 vsnprintf (bp
, buflen
, fmt
, arglist
);
202 snprintf (bp
, buflen
, " %s: ", what
);
208 if ((s
= strerror (errno
)))
209 snprintf (bp
, buflen
, "%s", s
);
211 snprintf (bp
, buflen
, "Error %d", errno
);
218 i
= strlen (invo_name
) + 2;
220 /* Now add content type and subtype */
221 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
222 ci
->ci_type
, ci
->ci_subtype
);
227 /* Now add the message/part number */
229 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
235 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
242 snprintf (bp
, buflen
, ")");
252 errs
= add (buffer
, errs
);
254 advise (NULL
, "%s", buffer
);
264 fprintf (stderr
, "%s", errs
);