#include <h/mime.h>
#include <h/tws.h>
#include <h/utils.h>
+#include <h/mts.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
static jmp_buf env;
-/*
- * external prototypes
- */
-int sendsbr (char **, int, char *, char *, struct stat *, int, char *, int);
-char *getusername (void);
-
/*
* static prototypes
*/
*/
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 */
+ char **buildvec, *buildprogram;
+ char *volatile drft = draft;
/*
- * 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.
+ * Run the mimebuildproc (which is by default mhbuild) on the message
+ * with the addition of the "-auto" flag
*/
- original_draft = drft;
-
- /*
- * 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.
- */
-
- 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;
* rename the draft file. I'm not quite sure why.
*/
if (pushsw && unique) {
- char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
- if (cp == NULL) {
- adios ("sendsbr", "unable to create temporary file");
- }
+ char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+ if (cp == NULL) {
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
+ }
if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
adios (file, "unable to rename %s to", drft);
drft = file;
* 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;
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;
}
* of message/partials. For the "Subject" header
* field, we also record it, so that a modified
* version of it, can be copied to the header
- * of each messsage/partial in the collection.
+ * of each message/partial in the collection.
*/
if (!strcasecmp (name, "Subject")) {
size_t sublen;
char *cp = m_mktemp2(drft, invo_name, NULL, &out);
if (cp == NULL) {
- adios (drft, "unable to create temporary file for");
+ adios(NULL, "unable to create temporary file in %s",
+ get_temp_dir());
}
strncpy(tmpdrf, cp, sizeof(tmpdrf));
- chmod (tmpdrf, 0600);
/*
* Output the header fields
snprintf (partnum, sizeof(partnum), "%d", partno);
status = sendaux (vec, vecp, program, tmpdrf, st);
- unlink (tmpdrf);
+ (void) m_unlink (tmpdrf);
if (status != OK)
break;
fd = pushsw ? tmp_fd () : NOTOK;
fd2 = NOTOK;
- vec[vecp++] = drft;
if (annotext) {
if ((fd2 = tmp_fd ()) != NOTOK) {
vec[vecp++] = "-idanno";
snprintf (buf, sizeof(buf), "%d", fd2);
vec[vecp++] = buf;
} else {
- admonish (NULL, "unable to create file for annotation list");
+ admonish (NULL, "unable to create temporary file in %s "
+ "for annotation list", get_temp_dir());
}
}
+ vec[vecp++] = drft;
if (distfile && distout (drft, distfile, backup) == NOTOK)
done (1);
vec[vecp] = NULL;
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);
}
} 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);
}
tmp_fd (void)
{
int fd;
- char *tfile = NULL;
+ char *tfile;
- tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
- if (tfile == NULL) return NOTOK;
- fchmod(fd, 0600);
+ if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK;
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;
sigaddset (&set, SIGTERM);
sigprocmask (SIG_BLOCK, &set, &oset);
+ unregister_for_removal(0);
+
annoaux (fd);
if (child_id == OK)
_exit (0);
/* reset the signal mask */
sigprocmask (SIG_SETMASK, &oset, &set);
- chdir (cwd);
+ if (chdir (cwd) < 0) {
+ advise (cwd, "chdir");
+ }
break;
default: /* no waiting... */