- int fd;
- FILE *out;
-
-#ifdef HAVE_MKSTEMP
- fd = mkstemp(bccfil);
- if (fd == -1 || (out = fdopen(fd, "w")) == NULL)
- adios(bccfil, "unable to create");
-#else
- mktemp(bccfil);
- if ((out = fopen(bccfil, "w")) == NULL)
- adios(bccfil, "unable to create");
-#endif
- chmod(bccfil, 0600);
-
- if (subject) {
- fprintf(out, "Subject: BCC: %s", subject);
- } else {
- fprintf(out, "Subject: BCC: message without subject");
+ char *bccdraft = NULL;
+ char buf[BUFSIZ];
+ struct mailname *mp = NULL;
+ FILE *out = NULL;
+
+ for (mp=bccs; mp; mp=mp->m_next) {
+ /*
+ ** Note: This draft file will be left existing by send(1),
+ ** although renamed with backup prefix.
+ ** TODO: We should have it removed eventually.
+ */
+ bccdraft = getcpy(m_mktemp2("/tmp/", invo_name, NULL, &out));
+ fprintf(out, "To: %s\n", mp->m_text);
+ fprintf(out, "Subject: [BCC] %s", subject ? subject : "");
+ fprintf(out, "%s: %s\n", attach_hdr, origmsg);
+ fprintf(out, "------------\n");
+ fclose(out);
+
+ snprintf(buf, sizeof buf, "send%s %s",
+ pushflg ? " -push" : "", bccdraft);
+ if (system(buf) != 0) {
+ admonish(invo_name, "Problems to send Bcc to %s",
+ mp->m_text);
+ unlink(bccdraft);
+ }
+ /* TODO: unlink renamed bcc draft after send(1) */