]>
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
;
33 int part_ok (CT
, int);
34 int type_ok (CT
, int);
35 void content_error (char *, CT
, char *, ...);
36 void flush_errors (void);
40 part_ok (CT ct
, int sP
)
45 if (npart
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
48 for (ap
= parts
; *ap
; ap
++) {
50 if (!strncmp (*ap
, ct
->c_partno
, len
) &&
51 (!ct
->c_partno
[len
] || ct
->c_partno
[len
] == '.' ))
60 type_ok (CT ct
, int sP
)
64 CI ci
= &ct
->c_ctinfo
;
66 if (ntype
== 0 || (ct
->c_type
== CT_MULTIPART
&& (sP
|| ct
->c_subtype
)))
69 snprintf (buffer
, sizeof(buffer
), "%s/%s", ci
->ci_type
, ci
->ci_subtype
);
70 for (ap
= types
; *ap
; ap
++)
71 if (!strcasecmp (*ap
, ci
->ci_type
) || !strcasecmp (*ap
, buffer
))
79 * Returns true if this content is marked as "inline".
81 * Technically we should check parent content to see if they have
82 * disposition to use as a default, but we don't right now. Maybe
90 * If there isn't any disposition at all, it's "inline". Obviously
91 * if it's "inline", then it's inline. RFC 2183 says if it's an unknown
92 * disposition, treat it as 'attachment'.
95 if (! ct
->c_dispo_type
|| strcasecmp(ct
->c_dispo_type
, "inline") == 0)
102 make_intermediates (char *file
)
106 for (cp
= file
+ 1; (cp
= strchr(cp
, '/')); cp
++) {
110 if (stat (file
, &st
) == NOTOK
) {
113 if (errno
!= ENOENT
) {
114 advise (file
, "error on directory");
120 ep
= concat ("Create directory \"", file
, "\"? ", NULL
);
121 answer
= getanswer (ep
);
125 goto losing_directory
;
126 if (!makedir (file
)) {
127 advise (NULL
, "unable to create directory %s", file
);
128 goto losing_directory
;
140 * Construct error message for content
144 content_error (char *what
, CT ct
, char *fmt
, ...)
148 char *bp
, buffer
[BUFSIZ
];
152 buflen
= sizeof(buffer
);
154 if (userrs
&& invo_name
&& *invo_name
) {
155 snprintf (bp
, buflen
, "%s: ", invo_name
);
161 va_start (arglist
, fmt
);
163 vsnprintf (bp
, buflen
, fmt
, arglist
);
174 snprintf (bp
, buflen
, " %s: ", what
);
180 if ((s
= strerror (errno
)))
181 snprintf (bp
, buflen
, "%s", s
);
183 snprintf (bp
, buflen
, "Error %d", errno
);
190 i
= strlen (invo_name
) + 2;
192 /* Now add content type and subtype */
193 snprintf (bp
, buflen
, "\n%*.*s(content %s/%s", i
, i
, "",
194 ci
->ci_type
, ci
->ci_subtype
);
199 /* Now add the message/part number */
201 snprintf (bp
, buflen
, " in message %s", ct
->c_file
);
207 snprintf (bp
, buflen
, ", part %s", ct
->c_partno
);
214 snprintf (bp
, buflen
, ")");
224 errs
= add (buffer
, errs
);
226 advise (NULL
, "%s", buffer
);
236 fprintf (stderr
, "%s", errs
);