X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fforw.c;h=91ce04a8a29f074191885e060bfc753fea883745;hp=b84632bd1a5c4347cb85191a0538e54e13c67e70;hb=2abb9a7cfb0930e27062088734d306e7d78e4cc2;hpb=6e271608b7b9c23771523f88d23a4d3593010cf1 diff --git a/uip/forw.c b/uip/forw.c index b84632b..91ce04a 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -11,7 +11,8 @@ #include #include #include - +#include +#include #define IFORMAT "digest-issue-%s" #define VFORMAT "digest-volume-%s" @@ -20,33 +21,25 @@ static struct swit switches[] = { #define ANNOSW 0 { "annotate", 0 }, #define NANNOSW 1 - { "noannotate", 0 }, + { "noannotate", 2 }, #define EDITRSW 2 { "editor editor", 0 }, -#define NEDITSW 3 - { "noedit", 0 }, -#define FORMSW 4 +#define FORMSW 3 { "form formfile", 0 }, -#define DGSTSW 5 +#define DGSTSW 4 { "digest list", 0 }, -#define ISSUESW 6 +#define ISSUESW 5 { "issue number", 0 }, -#define VOLUMSW 7 +#define VOLUMSW 6 { "volume number", 0 }, -#define WHATSW 8 +#define WHATSW 7 { "whatnowproc program", 0 }, -#define NWHATSW 9 - { "nowhatnowproc", 0 }, -#define VERSIONSW 10 - { "version", 0 }, -#define HELPSW 11 +#define VERSIONSW 8 + { "Version", 0 }, +#define HELPSW 9 { "help", 0 }, - -#ifdef MHE -#define BILDSW 12 +#define BILDSW 10 { "build", 5 }, /* interface from mhe */ -#endif /* MHE */ - { NULL, 0 } }; @@ -66,21 +59,17 @@ main(int argc, char **argv) { int msgp = 0, anot = 0; int issue = 0, volume = 0; - int nedit = 0, nwhat = 0, in; + int in; int out, msgnum; char *cp, *cwd, *maildir; char *digest = NULL, *ed = NULL; char *folder = NULL; char *form = NULL, buf[BUFSIZ], value[10]; char **argp, **arguments, *msgs[MAXARGS]; - -#ifdef MHE + char *fmtstr; int buildsw = 0; -#endif /* MHE */ -#ifdef LOCALE setlocale(LC_ALL, ""); -#endif invo_name = mhbasename(argv[0]); /* read user profile/context */ @@ -94,17 +83,18 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(1); + /* sysexits.h EX_USAGE */ + exit(1); case UNKWNSW: adios(NULL, "-%s unknown", cp); case HELPSW: snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); print_help(buf, switches, 1); - done(1); + exit(0); case VERSIONSW: print_version(invo_name); - done(1); + exit(0); case ANNOSW: anot++; @@ -117,10 +107,6 @@ main(int argc, char **argv) if (!(ed = *argp++) || *ed == '-') adios(NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; continue; case WHATSW: @@ -128,14 +114,10 @@ main(int argc, char **argv) *whatnowproc == '-') adios(NULL, "missing argument to %s", argp[-2]); - nwhat = 0; continue; -#ifdef MHE + case BILDSW: - buildsw++; /* fall... */ -#endif /* MHE */ - case NWHATSW: - nwhat++; + buildsw++; continue; case FORMSW: @@ -179,13 +161,14 @@ main(int argc, char **argv) } cwd = getcpy(pwd()); - -#ifdef MHE - strncpy(drft, buildsw ? toabsdir("draft") - : m_draft(seq_beyond), sizeof(drft)); -#else - strncpy(drft, m_draft(seq_beyond), sizeof(drft)); -#endif /* MHE */ + strncpy(drft, buildsw ? toabsdir("draft") : m_draft(seq_beyond), + sizeof(drft)); + /* + ** FIXME: (concerning MHE support (buildsw) only) + ** There's no check if the draft already exists. mmh has removed + ** this case by having the draft folder. I won't add code only to + ** handle this legacy issue for MHE. -- meillo@marmaro.de 2012-05 + */ /* ** Forwarding a message. @@ -208,11 +191,17 @@ main(int argc, char **argv) adios(NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert(mp, msgs[msgnum])) - done(1); + for (msgnum = 0; msgnum < msgp; msgnum++) { + if (!m_convert(mp, msgs[msgnum])) { + /* sysexits.h EX_USAGE */ + exit(1); + } + } seq_setprev(mp); /* set the previous sequence */ + if ((out = creat(drft, m_gmprot())) == NOTOK) + adios(drft, "unable to create"); + /* Open form (component) file. */ if (digest) { if (issue == 0) { @@ -222,26 +211,25 @@ main(int argc, char **argv) issue = 0; issue++; } - if (volume == 0) + if (volume == 0) { snprintf(buf, sizeof(buf), VFORMAT, digest); - if ((cp = context_find(buf)) == NULL || - (volume = atoi(cp)) <= 0) - volume = 1; + if ((cp = context_find(buf)) == NULL || + (volume = atoi(cp)) <= 0) + volume = 1; + } if (!form) form = digestcomps; in = build_form(form, digest, volume, issue); - } else - in = open_form(&form, forwcomps); - - if ((out = creat(drft, m_gmprot())) == NOTOK) - adios(drft, "unable to create"); - - /* - ** copy the components into the draft - */ - cpydata(in, out, form, drft); - close(in); + cpydata(in, out, form, drft); + close(in); + } else { + fmtstr = new_fs(form, forwcomps); + if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) { + adios(drft, "error writing"); + } + } close(out); + add_forw_hdr(drft); if (digest) { @@ -258,11 +246,11 @@ main(int argc, char **argv) seq_save(mp); /* synchronize sequences */ context_save(); /* save the context file */ - if (nwhat) - done(0); - what_now(ed, nedit, NOUSE, drft, NULL, 0, mp, + if (buildsw) + exit(0); + what_now(ed, NOUSE, drft, NULL, 0, mp, anot ? "Forwarded" : NULL, cwd); - done(1); + /* sysexits.h EX_SOFTWARE */ return 1; } @@ -274,19 +262,35 @@ static void add_forw_hdr(char *draft) { int msgnum; - char buffer[BUFSIZ]; - - snprintf(buffer, sizeof(buffer), "+%s", mp->foldpath); + char buf[BUFSIZ]; + char *vec[MAXARGS]; + int vecp = 0; + + vec[vecp++] = "anno"; + vec[vecp++] = "-append"; + vec[vecp++] = "-nodate"; + vec[vecp++] = draft; + vec[vecp++] = "-comp"; + vec[vecp++] = attach_hdr; + vec[vecp++] = "-text"; + snprintf(buf, sizeof buf, "+%s", mp->foldpath); for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (!is_selected(mp, msgnum)) { continue; } - /* TODO: improve the code */ - strncat(buffer, " ", sizeof(buffer)-strlen(buffer)-1); - strncat(buffer, m_name(msgnum), - sizeof(buffer)-strlen(buffer)-1); + if (strlen(buf) + 1 + strlen(m_name(msgnum)) + 1 + > sizeof buf) { + adios(NULL, "Attachment header line too long. " + "Forward less messages."); + } + strcat(buf, " "); + strcat(buf, m_name(msgnum)); + } + vec[vecp++] = buf; + vec[vecp] = NULL; + if (execprog(*vec, vec) != 0) { + advise(NULL, "unable to add attachment header"); } - annotate(draft, attach_hdr, buffer, 0, -2, 1); } @@ -295,7 +299,7 @@ build_form(char *form, char *digest, int volume, int issue) { int in; int fmtsize; - register char *nfs; + register char *fmtstr; char *line, tmpfil[BUFSIZ]; FILE *tmp; register struct comp *cptr; @@ -304,18 +308,18 @@ build_form(char *form, char *digest, int volume, int issue) char *cp = NULL; /* Get new format string */ - nfs = new_fs(form, NULL, NULL); - fmtsize = strlen(nfs) + 256; + fmtstr = new_fs(form, NULL); + fmtsize = strlen(fmtstr) + 256; /* Compile format string */ - fmt_compile(nfs, &fmt); + fmt_compile(fmtstr, &fmt); FINDCOMP(cptr, "digest"); if (cptr) cptr->c_text = digest; FINDCOMP(cptr, "date"); if (cptr) - cptr->c_text = getcpy(dtimenow(0)); + cptr->c_text = getcpy(dtimenow()); dat[0] = issue; dat[1] = volume;