]>
diplodocus.org Git - nmh/blob - uip/mhmisc.c
3 * mhparse.c -- misc routines to process MIME messages
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
15 #include <h/mhparse.h>
21 * limit actions to specified parts or content types
25 char *parts
[NPARTS
+ 1];
26 char *types
[NTYPES
+ 1];
28 int endian
= 0; /* little or big endian */
31 static char *errs
= NULL
;
37 int part_ok (CT
, int);
38 int type_ok (CT
, int);
39 void set_endian (void);
40 int make_intermediates (char *);
41 void content_error (char *, CT
, char *, ...);
42 void flush_errors (void);
46 part_ok (CT ct
, int sP
)
51 if (npart
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
54 for (ap
= parts
; *ap
; ap
++) {
56 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
57 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' ))
66 type_ok (CT ct
, int sP
)
70 CI ci
= &ct
->c_ctinfo
;
72 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
75 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
76 for (ap
= types
; *ap
; ap
++)
77 if (!mh_strcasecmp (*ap
, ci
->ci_type
) || !mh_strcasecmp (*ap
, buffer
))
93 endian
= un
.c
[0] ? -1 : 1;
95 fprintf (stderr
, "%s endian architecture\n",
96 endian
> 0 ? "big" : "little");
101 make_intermediates (char *file
)
105 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
109 if (stat (file
, &st
) == NOTOK
) {
112 if (errno
!= ENOENT
) {
113 advise (file
, "error on directory");
119 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
120 answer
= getanswer (ep
);
124 goto losing_directory
;
125 if (!makedir (file
)) {
126 advise (NULL
, "unable to create directory %s", file
);
127 goto losing_directory
;
139 * Construct error message for content
143 content_error (char *what
, CT ct
, char *fmt
, ...)
147 char *bp
, buffer
[BUFSIZ
];
151 buflen
= sizeof(buffer
);
153 if (userrs
&& invo_name
&& *invo_name
) {
154 snprintf (bp
, buflen
, "%s: ", invo_name
);
160 va_start (arglist
, fmt
);
162 vsnprintf (bp
, buflen
, fmt
, arglist
);
173 snprintf (bp
, buflen
, " %s: ", what
);
179 if ((s
= strerror (errno
)))
180 snprintf (bp
, buflen
, "%s", s
);
182 snprintf (bp
, buflen
, "Error %d", errno
);
189 i
= strlen (invo_name
) + 2;
191 /* Now add content type and subtype */
192 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
193 ci
->ci_type
, ci
->ci_subtype
);
198 /* Now add the message/part number */
200 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
206 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
213 snprintf (bp
, buflen
, ")");
223 errs
= add (buffer
, errs
);
225 advise (NULL
, "%s", buffer
);
235 fprintf (stderr
, "%s", errs
);