X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/4a78cbcd4fa986d9c1e7bd0a5a4bdb619faeb7cb..7711f3fc00259e55f630cfe6104eff3083dc9d77:/uip/sendsbr.c diff --git a/uip/sendsbr.c b/uip/sendsbr.c index c1914aa1..af9412df 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef HAVE_SYS_TIME_H # include @@ -34,12 +35,6 @@ char *distfile = NULL; static jmp_buf env; -/* - * external prototypes - */ -int sendsbr (char **, int, char *, char *, struct stat *, int, char *, int); -char *getusername (void); - /* * static prototypes */ @@ -57,48 +52,43 @@ static int sendaux (char **, int, char *, char *, struct stat *); */ int -sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st, - int rename_drft, char *attachment_header_field_name, int attachformat) +sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st, + int rename_drft) { - int status; + int status, i; + pid_t child; char buffer[BUFSIZ], file[BUFSIZ]; struct stat sts; - char *original_draft; /* name of original draft file */ - char *p; /* string pointer for building file name */ - char composition_file_name[PATH_MAX + 1]; /* name of mhbuild composition temporary file */ - char body_file_name[PATH_MAX + 1]; /* name of temporary file for body content */ - - /* - * Save the original name of the draft file. The name of the draft file is changed - * to a temporary file containing the built MIME message if there are attachments. - * We need the original name so that it can be renamed after the message is sent. - */ - - original_draft = drft; + char **buildvec, *buildprogram; + char *volatile drft = draft; /* - * There might be attachments if a header field name for attachments is supplied. - * Convert the draft to a MIME message. Use the mhbuild composition file for the - * draft if there was a successful conversion because that now contains the MIME - * message. A nice side effect of this is that it leaves the original draft file - * untouched so that it can be retrieved and modified if desired. + * Run the mimebuildproc (which is by default mhbuild) on the message + * with the addition of the "-auto" flag */ - if (attachment_header_field_name != (char *)0) { - switch (attach(attachment_header_field_name, drft, - body_file_name, sizeof body_file_name, - composition_file_name, sizeof composition_file_name, - attachformat)) { - case OK: - drft = composition_file_name; - break; + switch (child = fork()) { + case NOTOK: + adios("fork", "unable to"); + break; - case NOTOK: - return (NOTOK); + case OK: + buildvec = argsplit(buildmimeproc, &buildprogram, &i); + buildvec[i++] = "-auto"; + if (distfile) + buildvec[i++] = "-dist"; + buildvec[i++] = (char *) drft; + buildvec[i] = NULL; + execvp(buildprogram, buildvec); + fprintf(stderr, "unable to exec "); + perror(buildmimeproc); + _exit(-1); + break; - case DONE: - break; - } + default: + if (pidXwait(child, buildmimeproc)) + return NOTOK; + break; } done=armed_done; @@ -123,16 +113,18 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st, * Check if we need to split the message into * multiple messages of type "message/partial". */ - if (splitsw >= 0 && !distfile && stat (drft, &sts) != NOTOK + if (splitsw >= 0 && !distfile && stat ((char *) drft, &sts) != NOTOK && sts.st_size >= CPERMSG) { - status = splitmsg (vec, vecp, program, drft, st, splitsw) ? NOTOK : OK; + status = splitmsg (vec, vecp, program, drft, + st, splitsw) ? NOTOK : OK; } else { status = sendaux (vec, vecp, program, drft, st) ? NOTOK : OK; } /* rename the original draft */ if (rename_drft && status == OK && - rename (original_draft, strncpy (buffer, m_backup (original_draft), sizeof(buffer))) == NOTOK) + rename (drft, strncpy (buffer, m_backup (drft), + sizeof(buffer))) == NOTOK) advise (buffer, "unable to rename %s to", drft); break; @@ -143,34 +135,7 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st, done=exit; if (distfile) - unlink (distfile); - - /* - * Get rid of any temporary files that we created for attachments. Also get rid of - * the renamed composition file that mhbuild leaves as a turd. It looks confusing, - * but we use the body file name to help build the renamed composition file name. - */ - - if (drft == composition_file_name) { - clean_up_temporary_files(body_file_name, composition_file_name); - - if (strlen(composition_file_name) >= sizeof (composition_file_name) - 6) - advise((char *)0, "unable to remove original composition file."); - - else { - if ((p = strrchr(composition_file_name, '/')) == (char *)0) - p = composition_file_name; - else - p++; - - (void)strcpy(body_file_name, p); - *p++ = ','; - (void)strcpy(p, body_file_name); - (void)strcat(p, ".orig"); - - (void)unlink(composition_file_name); - } - } + (void) m_unlink (distfile); return status; } @@ -389,7 +354,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft, snprintf (partnum, sizeof(partnum), "%d", partno); status = sendaux (vec, vecp, program, tmpdrf, st); - unlink (tmpdrf); + (void) m_unlink (tmpdrf); if (status != OK) break; @@ -487,7 +452,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st) if (annotext && fd2 != NOTOK) close (fd2); if (distfile) { - unlink (drft); + (void) m_unlink (drft); if (rename (backup, drft) == NOTOK) advise (drft, "unable to rename %s to", backup); } @@ -533,13 +498,19 @@ alert (char *file, int out) } else { lseek (out, (off_t) 0, SEEK_END); strncpy (buf, "\nMessage not delivered to anyone.\n", sizeof(buf)); - write (out, buf, strlen (buf)); + if (write (out, buf, strlen (buf)) < 0) { + advise (file, "write"); + } strncpy (buf, "\n------- Unsent Draft\n\n", sizeof(buf)); - write (out, buf, strlen (buf)); + if (write (out, buf, strlen (buf)) < 0) { + advise (file, "write"); + } cpydgst (in, out, file, "temporary file"); close (in); strncpy (buf, "\n------- End of Unsent Draft\n", sizeof(buf)); - write (out, buf, strlen (buf)); + if (write (out, buf, strlen (buf)) < 0) { + advise (file, "write"); + } if (rename (file, strncpy (buf, m_backup (file), sizeof(buf))) == NOTOK) admonish (buf, "unable to rename %s to", file); } @@ -580,7 +551,7 @@ tmp_fd (void) if (debugsw) advise (NULL, "temporary file %s selected", tfile); else - if (unlink (tfile) == NOTOK) + if (m_unlink (tfile) == NOTOK) advise (tfile, "unable to remove"); return fd; @@ -623,6 +594,8 @@ anno (int fd, struct stat *st) sigaddset (&set, SIGTERM); sigprocmask (SIG_BLOCK, &set, &oset); + unregister_for_removal(0); + annoaux (fd); if (child_id == OK) _exit (0); @@ -630,7 +603,9 @@ anno (int fd, struct stat *st) /* reset the signal mask */ sigprocmask (SIG_SETMASK, &oset, &set); - chdir (cwd); + if (chdir (cwd) < 0) { + advise (cwd, "chdir"); + } break; default: /* no waiting... */