X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fspost.c;h=369f03e24341150d731ff0df1700bf4ede912597;hp=4a8ffdc5693d7e2132eb15d88e913e5b63bc4d0c;hb=412b2e54251ff6e20537f83b95c8ee76ea8c5c40;hpb=4c513fd6ebd0f1b08b8f9504b6d6c8aef2351d4a diff --git a/uip/spost.c b/uip/spost.c index 4a8ffdc..369f03e 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -18,7 +18,6 @@ #include #define MAX_SM_FIELD 1476 /* < largest hdr field sendmail will accept */ -#define FCCS 10 /* max number of fccs allowed */ struct swit switches[] = { #define VERBSW 0 @@ -75,7 +74,6 @@ struct headers { unsigned int set; }; - static struct headers NHeaders[] = { { "Return-Path", HBAD, 0 }, { "Received", HBAD, 0 }, @@ -89,6 +87,7 @@ static struct headers NHeaders[] = { { "Bcc", HADR|HTRY|HBCC, MINV }, { "Message-Id", HBAD, 0 }, { "Fcc", HFCC, 0 }, + { "Envelope-From", HIGN, 0 }, { NULL, 0, 0 } }; @@ -105,6 +104,7 @@ static struct headers RHeaders[] = { { "Resent-Fcc", HFCC, 0 }, { "Reply-To", HADR, 0 }, { "Fcc", HIGN, 0 }, + { "Envelope-From", HIGN, 0 }, { NULL, 0, 0 } }; @@ -122,18 +122,15 @@ static enum { normal, resent } msgstate = normal; -static char tmpfil[] = "/tmp/spost-XXXXXX"; -static char bccfil[] = "/tmp/spost-bcc-XXXXXX"; +static char *tmpfil; static char *subject = NULL; /* the subject field for BCC'ing */ static char fccs[BUFSIZ] = ""; -struct mailname *bccs = NULL; +struct mailname *bccs = NULL; /* list of the bcc recipients */ static struct headers *hdrtab; /* table for the message we're doing */ static FILE *out; /* output (temp) file */ -extern char *sendmail; - /* ** static prototypes */ @@ -144,13 +141,13 @@ static void putadr(char *, struct mailname *); static int putone(char *, int, int); static void process_fcc(char *); static void fcc(char *, char *); -static void make_bcc_draft(char *); +static void process_bccs(char *); int main(int argc, char **argv) { - int state, i, pid, compnum; + int state, compnum; char *cp, *msg = NULL, **argp, **arguments; char *sargv[16], buf[BUFSIZ], name[NAMESZ]; FILE *in; @@ -253,15 +250,7 @@ main(int argc, char **argv) verbose++; out = stdout; } else { -#ifdef HAVE_MKSTEMP - if ((out = fdopen(mkstemp(tmpfil), "w")) == NULL) - adios(tmpfil, "unable to create"); -#else - mktemp(tmpfil); - if ((out = fopen(tmpfil, "w")) == NULL) - adios(tmpfil, "unable to create"); - chmod(tmpfil, 0600); -#endif + tmpfil = getcpy(m_mktemp2("/tmp/", invo_name, NULL, &out)); } hdrtab = (msgstate == normal) ? NHeaders : RHeaders; @@ -323,20 +312,6 @@ main(int argc, char **argv) fcc(tmpfil, fccs); } - /* process Bcc */ - if (bccs) { - make_bcc_draft(tmpfil); - } - - /* - ** re-open the temp file, unlink it and exec sendmail, giving it - ** the msg temp file as std in. - */ - if (!freopen(tmpfil, "r", stdin)) { - adios(tmpfil, "can't reopen for sendmail"); - } - unlink(tmpfil); - argp = sargv; *argp++ = "send-mail"; *argp++ = "-m"; /* send to me too */ @@ -348,29 +323,27 @@ main(int argc, char **argv) } *argp = NULL; - if (pushflg) { - /* fork to a child to run sendmail */ - for (i=0; (pid = fork()) == NOTOK && i < 5; i++) - sleep(5); - switch (pid) { - case NOTOK: - fprintf(verbose ? stdout : stderr, - "%s: can't fork to %s\n", - invo_name, sendmail); - exit(-1); - case OK: - /* we're the child .. */ - break; - default: + if (bccs) { + process_bccs(tmpfil); + if (!(msgflags & MVIS)) { + /* only Bcc rcpts: we're finished here */ + unlink(tmpfil); exit(0); } } - if (0 /*bccs*/) { + /* + ** re-open the temp file, unlink it and exec sendmail, giving it + ** the msg temp file as std in. + */ + if (!freopen(tmpfil, "r", stdin)) { + adios(tmpfil, "can't reopen for sendmail"); + } + unlink(tmpfil); + + if (pushflg) { /* fork to a child to run sendmail */ - for (i=0; (pid = fork()) == NOTOK && i < 5; i++) - sleep(5); - switch (pid) { + switch (fork()) { case NOTOK: fprintf(verbose ? stdout : stderr, "%s: can't fork to %s\n", @@ -378,17 +351,17 @@ main(int argc, char **argv) exit(-1); case OK: /* we're the child .. */ - exit(0); + break; default: exit(0); } } - execv(sendmail, sargv); adios(sendmail, "can't exec"); - return 0; /* dead code to satisfy the compiler */ + return -1; } + /* DRAFT GENERATION */ static void @@ -506,7 +479,7 @@ finish_headers(FILE *out) char *resentstr = (msgstate == resent) ? "Resent-" : ""; if (!(msgflags & MDAT)) { - fprintf(out, "%sDate: %s\n", resentstr, dtimenow(0)); + fprintf(out, "%sDate: %s\n", resentstr, dtimenow()); } strncpy(from, getusername(), sizeof(from)); @@ -525,6 +498,7 @@ finish_headers(FILE *out) fprintf(out, "%sBcc: Blind Distribution List: ;\n", resentstr); } if (badmsg) { + unlink(tmpfil); adios(NULL, "re-format message and try again"); } } @@ -680,12 +654,12 @@ fcc(char *file, char *folders) folders); fflush(stdout); } - if (strlen(fileproc)+strlen(file)+strlen(folders)+100 > sizeof cmd) { + if (100+strlen(file)+strlen(folders) > sizeof cmd) { adios(NULL, "Too much Fcc data"); } /* hack: read from /dev/null and refile(1) won't question us */ - snprintf(cmd, sizeof cmd, "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) */ } - fprintf(out, "%s: %s\n", attach_hdr, draft); - fprintf(out, "------------\n"); - fclose(out); }