X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0c50c6698d3fee84b18f11b3affdffbe59011c2c..351a74de3e5d3cd2048d2ec4444b090c6b7e00ac:/uip/attach.c?ds=sidebyside diff --git a/uip/attach.c b/uip/attach.c index 333cda66..9ff7d095 100644 --- a/uip/attach.c +++ b/uip/attach.c @@ -28,7 +28,6 @@ attach(char *attachment_header_field_name, char *draft_file_name, int length; /* of attachment header field name */ char *p; /* miscellaneous string pointer */ struct stat st; /* file status buffer */ - FILE *fp; /* pointer for mhn.defaults */ FILE *body_file = NULL; /* body file pointer */ FILE *draft_file; /* draft file pointer */ int field_size; /* size of header field buffer */ @@ -101,12 +100,15 @@ attach(char *attachment_header_field_name, char *draft_file_name, * Make names for the temporary files. */ - (void)strncpy(body_file_name, - m_mktemp(m_maildir(invo_name), NULL, NULL), - body_file_name_len); - (void)strncpy(composition_file_name, - m_mktemp(m_maildir(invo_name), NULL, NULL), - composition_file_name_len); + if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + (void)strncpy(body_file_name, p, body_file_name_len); + if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + unlink(body_file_name); + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } + (void)strncpy(composition_file_name, p, composition_file_name_len); if (has_body) body_file = fopen(body_file_name, "w"); @@ -177,11 +179,6 @@ attach(char *attachment_header_field_name, char *draft_file_name, * composition file for each. */ - if ((fp = fopen (p = etcpath ("mhn.defaults"), "r"))) { - readconfig ((struct node **) NULL, fp, p, 0); - fclose(fp); - } - rewind(draft_file); while (get_line(draft_file, field, field_size) != EOF && *field != '\0' && @@ -404,7 +401,6 @@ construct_build_directive (char *file_name, const char *default_content_type, char cmd[PATH_MAX + 8]; /* file command buffer */ struct stat st; /* file status buffer */ char *p; /* miscellaneous temporary variables */ - FILE *fp; int c; /* current character */ if ((content_type = mime_type (file_name)) == NULL) { @@ -417,6 +413,12 @@ construct_build_directive (char *file_name, const char *default_content_type, * have the suffix in the field, including the dot. */ struct node *np; /* context scan node pointer */ + static FILE *fp = NULL; /* pointer for mhn.defaults */ + + if (fp == NULL && (fp = fopen (p = etcpath ("mhn.defaults"), "r"))) { + readconfig ((struct node **) NULL, fp, p, 0); + fclose(fp); + } if ((p = strrchr(file_name, '.')) != NULL) { for (np = m_defs; np; np = np->n_next) { @@ -441,6 +443,7 @@ construct_build_directive (char *file_name, const char *default_content_type, */ if (content_type == NULL) { int binary; /* binary character found flag */ + FILE *fp; if ((fp = fopen(file_name, "r")) == (FILE *)0) { advise(NULL, "unable to access file \"%s\"", file_name); @@ -465,6 +468,7 @@ construct_build_directive (char *file_name, const char *default_content_type, switch (attachformat) { case 0: { struct stat st; + FILE *fp; char m[4]; /* Insert name, file mode, and Content-Id. */