mmime: allow setting content-disposition and overriding filename

pull/37/head
Leah Neukirchen 7 years ago
parent 9b8ab19a2b
commit cc7ab25814

@ -21,12 +21,18 @@ mail from standard input,
extending, wrapping, and encoding the header as neccessary, extending, wrapping, and encoding the header as neccessary,
and replacing body lines looking like and replacing body lines looking like
.Pp .Pp
.D1 Li # Ns Ar type Pa filename .D1 Li # Ns Ar content Ns Li / Ns Ar type Ns Oo Ns Li # Ns Ar content-disposition Oc Pa path Ns Oo Li > Ns Ar filename Oc
.Pp .Pp
with a MIME part having Content-Type with a MIME part having Content-Type
.Ar type .Ar content/type
consisting of the contents of consisting of the contents of
.Pa filename . .Pa path .
.Ar content-disposition
is optional and defaults to
.Sq attachment .
.Ar filename
is optional and defaults to the basename of
.Ar path .
.Pp .Pp
The options are as follows: The options are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds

@ -115,7 +115,7 @@ basenam(const char *s)
} }
static void static void
gen_attachment(const char *filename) gen_attachment(const char *filename, char *content_disposition)
{ {
const char *s = filename; const char *s = filename;
int quote = 0; int quote = 0;
@ -128,12 +128,12 @@ gen_attachment(const char *filename)
} }
// filename SHOULD be an atom if possible // filename SHOULD be an atom if possible
printf("Content-Disposition: attachment; filename=%s%s%s\n", printf("Content-Disposition: %s; filename=%s%s%s\n", content_disposition,
quote ? "\"" : "", filename, quote ? "\"" : ""); quote ? "\"" : "", filename, quote ? "\"" : "");
return; return;
rfc2231: rfc2231:
printf("Content-Disposition: attachment"); printf("Content-Disposition: %s", content_disposition);
int i = 0; int i = 0;
int d = 0; int d = 0;
@ -162,6 +162,20 @@ gen_file(char *file, char *ct)
uint8_t *content; uint8_t *content;
off_t size; off_t size;
char *cd = "attachment";
char *s = strchr(ct, '#');
if (s) {
*s = 0;
cd = s + 1;
}
const char *filename = basenam(file);
s = strchr(file, '>');
if (s) {
*s = 0;
filename = s + 1;
}
int r = slurp(file, (char **)&content, &size); int r = slurp(file, (char **)&content, &size);
if (r != 0) { if (r != 0) {
fprintf(stderr, "mmime: error attaching file '%s': %s\n", fprintf(stderr, "mmime: error attaching file '%s': %s\n",
@ -191,7 +205,7 @@ gen_file(char *file, char *ct)
bithigh++; bithigh++;
} }
gen_attachment(basenam(file)); gen_attachment(filename, cd);
if (bitlow == 0 && bithigh == 0 && if (bitlow == 0 && bithigh == 0 &&
maxlinelen <= 78 && content[size-1] == '\n') { maxlinelen <= 78 && content[size-1] == '\n') {

Loading…
Cancel
Save