X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/b4f2851d40874160fbe4c5ce288ae2e7fd8fbb4b..351a74de3e5d3cd2048d2ec4444b090c6b7e00ac:/uip/attach.c?ds=sidebyside diff --git a/uip/attach.c b/uip/attach.c index b1a4f441..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' && @@ -327,10 +324,8 @@ mime_type(const char *file_name) { */ static char * get_file_info(const char *proc, const char *file_name) { - char buf[BUFSIZ >= 2048 ? BUFSIZ : 2048]; char *cmd, *cp; char *quotec = "'"; - FILE *fp; if ((cp = strchr(file_name, '\''))) { /* file_name contains a single quote. */ @@ -345,7 +340,12 @@ get_file_info(const char *proc, const char *file_name) { cmd = concat(proc, " ", quotec, file_name, quotec, NULL); if ((cmd = concat(proc, " ", quotec, file_name, quotec, NULL))) { + FILE *fp; + if ((fp = popen(cmd, "r")) != NULL) { + char buf[BUFSIZ >= 2048 ? BUFSIZ : 2048]; + + buf[0] = '\0'; if (fgets(buf, sizeof buf, fp)) { char *eol; @@ -363,8 +363,12 @@ get_file_info(const char *proc, const char *file_name) { if ((eol = strpbrk(cp, "\n\r")) != NULL) { *eol = '\0'; } - } else { - advise(NULL, "unable to read mime type"); + } else if (buf[0] == '\0') { + /* This can happen on Cygwin if the popen() + mysteriously fails. Return NULL so that the caller + will use another method to determine the info. */ + free (cp); + cp = NULL; } (void) pclose(fp); @@ -397,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) { @@ -410,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) { @@ -434,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); @@ -458,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. */