]>
diplodocus.org Git - nmh/blob - uip/mhmisc.c
3 * mhparse.c -- misc routines to process MIME messages
11 #include <h/mhparse.h>
17 * limit actions to specified parts or content types
21 char *parts
[NPARTS
+ 1];
22 char *types
[NTYPES
+ 1];
24 int endian
= 0; /* little or big endian */
27 static char *errs
= NULL
;
33 int part_ok (CT
, int);
34 int type_ok (CT
, int);
35 void set_endian (void);
36 int make_intermediates (char *);
37 void content_error (char *, CT
, char *, ...);
38 void flush_errors (void);
42 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
++)
50 if (!strcmp (*ap
, ct
->c_partno
))
58 type_ok (CT ct
, int sP
)
62 CI ci
= &ct
->c_ctinfo
;
64 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
67 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
68 for (ap
= types
; *ap
; ap
++)
69 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
85 endian
= un
.c
[0] ? -1 : 1;
87 fprintf (stderr
, "%s endian architecture\n",
88 endian
> 0 ? "big" : "little");
93 make_intermediates (char *file
)
97 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
101 if (stat (file
, &st
) == NOTOK
) {
104 if (errno
!= ENOENT
) {
105 advise (file
, "error on directory");
111 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
112 answer
= getanswer (ep
);
116 goto losing_directory
;
117 if (!makedir (file
)) {
118 advise (NULL
, "unable to create directory %s", file
);
119 goto losing_directory
;
131 * Construct error message for content
135 content_error (char *what
, CT ct
, char *fmt
, ...)
139 char *bp
, buffer
[BUFSIZ
];
143 buflen
= sizeof(buffer
);
145 if (userrs
&& invo_name
&& *invo_name
) {
146 snprintf (bp
, buflen
, "%s: ", invo_name
);
152 va_start (arglist
, fmt
);
154 vsnprintf (bp
, buflen
, fmt
, arglist
);
165 snprintf (bp
, buflen
, " %s: ", what
);
171 if ((s
= strerror (errno
)))
172 snprintf (bp
, buflen
, "%s", s
);
174 snprintf (bp
, buflen
, "Error %d", errno
);
181 i
= strlen (invo_name
) + 2;
183 /* Now add content type and subtype */
184 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
185 ci
->ci_type
, ci
->ci_subtype
);
190 /* Now add the message/part number */
192 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
198 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
205 snprintf (bp
, buflen
, ")");
215 errs
= add (buffer
, errs
);
217 advise (NULL
, "%s", buffer
);
227 fprintf (stderr
, "%s", errs
);