]>
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.
13 #include <h/mhparse.h>
19 * limit actions to specified parts or content types
23 char *parts
[NPARTS
+ 1];
24 char *types
[NTYPES
+ 1];
28 static char *errs
= NULL
;
34 int part_ok (CT
, int);
35 int type_ok (CT
, int);
36 void content_error (char *, CT
, char *, ...);
37 void flush_errors (void);
41 part_ok (CT ct
, int sP
)
46 if (npart
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
49 for (ap
= parts
; *ap
; ap
++) {
51 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
52 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' ))
61 type_ok (CT ct
, int sP
)
65 CI ci
= &ct
->c_ctinfo
;
67 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
70 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
71 for (ap
= types
; *ap
; ap
++)
72 if (!mh_strcasecmp (*ap
, ci
->ci_type
) || !mh_strcasecmp (*ap
, buffer
))
80 make_intermediates (char *file
)
84 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
88 if (stat (file
, &st
) == NOTOK
) {
91 if (errno
!= ENOENT
) {
92 advise (file
, "error on directory");
98 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
99 answer
= getanswer (ep
);
103 goto losing_directory
;
104 if (!makedir (file
)) {
105 advise (NULL
, "unable to create directory %s", file
);
106 goto losing_directory
;
118 * Construct error message for content
122 content_error (char *what
, CT ct
, char *fmt
, ...)
126 char *bp
, buffer
[BUFSIZ
];
130 buflen
= sizeof(buffer
);
132 if (userrs
&& invo_name
&& *invo_name
) {
133 snprintf (bp
, buflen
, "%s: ", invo_name
);
139 va_start (arglist
, fmt
);
141 vsnprintf (bp
, buflen
, fmt
, arglist
);
152 snprintf (bp
, buflen
, " %s: ", what
);
158 if ((s
= strerror (errno
)))
159 snprintf (bp
, buflen
, "%s", s
);
161 snprintf (bp
, buflen
, "Error %d", errno
);
168 i
= strlen (invo_name
) + 2;
170 /* Now add content type and subtype */
171 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
172 ci
->ci_type
, ci
->ci_subtype
);
177 /* Now add the message/part number */
179 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
185 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
192 snprintf (bp
, buflen
, ")");
202 errs
= add (buffer
, errs
);
204 advise (NULL
, "%s", buffer
);
214 fprintf (stderr
, "%s", errs
);