]>
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];
26 int endian
= 0; /* little or big endian */
29 static char *errs
= NULL
;
35 int part_ok (CT
, int);
36 int type_ok (CT
, int);
37 void content_error (char *, CT
, char *, ...);
38 void flush_errors (void);
42 part_ok (CT ct
, int sP
)
47 if (npart
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
50 for (ap
= parts
; *ap
; ap
++) {
52 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
53 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' ))
62 type_ok (CT ct
, int sP
)
66 CI ci
= &ct
->c_ctinfo
;
68 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
71 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
72 for (ap
= types
; *ap
; ap
++)
73 if (!mh_strcasecmp (*ap
, ci
->ci_type
) || !mh_strcasecmp (*ap
, buffer
))
89 endian
= un
.c
[0] ? -1 : 1;
91 fprintf (stderr
, "%s endian architecture\n",
92 endian
> 0 ? "big" : "little");
97 make_intermediates (char *file
)
101 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
105 if (stat (file
, &st
) == NOTOK
) {
108 if (errno
!= ENOENT
) {
109 advise (file
, "error on directory");
115 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
116 answer
= getanswer (ep
);
120 goto losing_directory
;
121 if (!makedir (file
)) {
122 advise (NULL
, "unable to create directory %s", file
);
123 goto losing_directory
;
135 * Construct error message for content
139 content_error (char *what
, CT ct
, char *fmt
, ...)
143 char *bp
, buffer
[BUFSIZ
];
147 buflen
= sizeof(buffer
);
149 if (userrs
&& invo_name
&& *invo_name
) {
150 snprintf (bp
, buflen
, "%s: ", invo_name
);
156 va_start (arglist
, fmt
);
158 vsnprintf (bp
, buflen
, fmt
, arglist
);
169 snprintf (bp
, buflen
, " %s: ", what
);
175 if ((s
= strerror (errno
)))
176 snprintf (bp
, buflen
, "%s", s
);
178 snprintf (bp
, buflen
, "Error %d", errno
);
185 i
= strlen (invo_name
) + 2;
187 /* Now add content type and subtype */
188 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
189 ci
->ci_type
, ci
->ci_subtype
);
194 /* Now add the message/part number */
196 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
202 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
209 snprintf (bp
, buflen
, ")");
219 errs
= add (buffer
, errs
);
221 advise (NULL
, "%s", buffer
);
231 fprintf (stderr
, "%s", errs
);