X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fforw.c;h=9ad2877119e9105686f07c350952fa539fb5bfb1;hp=5c71c5522e41801d0442e522a4d95f35361bbb6c;hb=714b5c530ece27ea2835a313013f5b770163403c;hpb=ced6090a330d3d83d0bce709f756aa3d7d65fea4 diff --git a/uip/forw.c b/uip/forw.c index 5c71c55..9ad2877 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -83,14 +83,14 @@ static struct msgs *mp = NULL; /* used a lot */ /* ** static prototypes */ -static void mhl_draft (int, char *, int, int, char *, char *, int); -static void copy_draft (int, char *, char *, int, int, int); -static void copy_mime_draft (int); -static int build_form (char *, char *, int, int); +static void mhl_draft(int, char *, int, int, char *, char *, int); +static void copy_draft(int, char *, char *, int, int, int); +static void copy_mime_draft(int); +static int build_form(char *, char *, int, int); int -main (int argc, char **argv) +main(int argc, char **argv) { int msgp = 0, anot = 0, inplace = 1, mime = 0; int issue = 0, volume = 0, dashstuff = 0; @@ -109,31 +109,30 @@ main (int argc, char **argv) #ifdef LOCALE setlocale(LC_ALL, ""); #endif - invo_name = r1bindex (argv[0], '/'); + invo_name = r1bindex(argv[0], '/'); /* read user profile/context */ context_read(); - arguments = getarguments (invo_name, argc, argv, 1); + arguments = getarguments(invo_name, argc, argv, 1); argp = arguments; while ((cp = *argp++)) { if (*cp == '-') { - switch (smatch (++cp, switches)) { + switch (smatch(++cp, switches)) { case AMBIGSW: - ambigsw (cp, switches); - done (1); + ambigsw(cp, switches); + done(1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + adios(NULL, "-%s unknown", cp); case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); + snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); + print_help(buf, switches, 1); + done(1); case VERSIONSW: print_version(invo_name); - done (1); + done(1); case ANNOSW: anot++; @@ -144,7 +143,7 @@ main (int argc, char **argv) case EDITRSW: if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); + adios(NULL, "missing argument to %s", argp[-2]); nedit = 0; continue; case NEDITSW: @@ -153,7 +152,7 @@ main (int argc, char **argv) case WHATSW: if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); + adios(NULL, "missing argument to %s", argp[-2]); nwhat = 0; continue; #ifdef MHE @@ -166,24 +165,24 @@ main (int argc, char **argv) case FILESW: if (file) - adios (NULL, "only one file at a time!"); + adios(NULL, "only one file at a time!"); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); + adios(NULL, "missing argument to %s", argp[-2]); + file = path(cp, TFILE); continue; case FILTSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); + adios(NULL, "missing argument to %s", argp[-2]); + filter = getcpy(etcpath(cp)); mime = 0; continue; case FORMSW: if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); + adios(NULL, "missing argument to %s", argp[-2]); continue; case FRMTSW: - filter = getcpy (etcpath (mhlforward)); + filter = getcpy(etcpath(mhlforward)); continue; case NFRMTSW: filter = NULL; @@ -206,20 +205,20 @@ main (int argc, char **argv) case DGSTSW: if (!(digest = *argp++) || *digest == '-') - adios (NULL, "missing argument to %s", argp[-2]); + adios(NULL, "missing argument to %s", argp[-2]); mime = 0; continue; case ISSUESW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((issue = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); + adios(NULL, "missing argument to %s", argp[-2]); + if ((issue = atoi(cp)) < 1) + adios(NULL, "bad argument %s %s", argp[-2], cp); continue; case VOLUMSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((volume = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); + adios(NULL, "missing argument to %s", argp[-2]); + if ((volume = atoi(cp)) < 1) + adios(NULL, "bad argument %s %s", argp[-2], cp); continue; case BITSTUFFSW: @@ -232,26 +231,26 @@ main (int argc, char **argv) } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); + adios(NULL, "only one folder at a time!"); else - folder = pluspath (cp); + folder = pluspath(cp); } else { msgs[msgp++] = cp; } } - cwd = getcpy (pwd ()); + cwd = getcpy(pwd()); - if (!context_find ("path")) - free (path ("./", TFOLDER)); + if (!context_find("path")) + free(path("./", TFOLDER)); if (file && (msgp || folder)) - adios (NULL, "can't mix files and folders/msgs"); + adios(NULL, "can't mix files and folders/msgs"); #ifdef MHE - strncpy (drft, buildsw ? m_maildir ("draft") + strncpy(drft, buildsw ? m_maildir("draft") : m_draft("new"), sizeof(drft)); #else - strncpy (drft, m_draft("new"), sizeof(drft)); + strncpy(drft, m_draft("new"), sizeof(drft)); #endif /* MHE */ if (file) { @@ -266,101 +265,103 @@ main (int argc, char **argv) if (!msgp) msgs[msgp++] = "cur"; if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); + folder = getfolder(1); + maildir = m_maildir(folder); - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); + if (chdir(maildir) == NOTOK) + adios(maildir, "unable to change directory to"); /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); + if (!(mp = folder_read(folder))) + adios(NULL, "unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + 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); - seq_setprev (mp); /* set the previous sequence */ + if (!m_convert(mp, msgs[msgnum])) + done(1); + seq_setprev(mp); /* set the previous sequence */ } - if (filter && access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); + if (filter && access(filter, R_OK) == NOTOK) + adios(filter, "unable to read"); /* ** Open form (component) file. */ if (digest) { if (issue == 0) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - if (volume == 0 - && (cp = context_find (buf)) - && ((issue = atoi (cp)) < 0)) + snprintf(buf, sizeof(buf), IFORMAT, digest); + if (volume == 0 && (cp = context_find(buf)) + && ((issue = atoi(cp)) < 0)) issue = 0; issue++; } if (volume == 0) - snprintf (buf, sizeof(buf), VFORMAT, digest); - if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) + snprintf(buf, sizeof(buf), VFORMAT, digest); + if ((cp = context_find(buf)) == NULL || + (volume = atoi(cp)) <= 0) volume = 1; if (!form) form = digestcomps; - in = build_form (form, digest, volume, issue); + 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"); + 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); if (file) { /* just copy the file into the draft */ - if ((in = open (file, O_RDONLY)) == NOTOK) - adios (file, "unable to open"); - cpydata (in, out, file, drft); - close (in); - close (out); + if ((in = open(file, O_RDONLY)) == NOTOK) + adios(file, "unable to open"); + cpydata(in, out, file, drft); + close(in); + close(out); } else { /* ** If filter file is defined, then format the ** messages into the draft using mhlproc. */ if (filter) - mhl_draft (out, digest, volume, issue, drft, filter, dashstuff); + mhl_draft(out, digest, volume, issue, drft, filter, + dashstuff); else if (mime) - copy_mime_draft (out); + copy_mime_draft(out); else - copy_draft (out, digest, drft, volume, issue, dashstuff); - close (out); + copy_draft(out, digest, drft, volume, issue, + dashstuff); + close(out); if (digest) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - snprintf (value, sizeof(value), "%d", issue); - context_replace (buf, getcpy (value)); - snprintf (buf, sizeof(buf), VFORMAT, digest); - snprintf (value, sizeof(value), "%d", volume); - context_replace (buf, getcpy (value)); + snprintf(buf, sizeof(buf), IFORMAT, digest); + snprintf(value, sizeof(value), "%d", issue); + context_replace(buf, getcpy(value)); + snprintf(buf, sizeof(buf), VFORMAT, digest); + snprintf(value, sizeof(value), "%d", volume); + context_replace(buf, getcpy(value)); } - context_replace (pfolder, folder); /* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ + context_replace(pfolder, folder); /* update current folder */ + seq_setcur(mp, mp->lowsel); /* update current message */ + seq_save(mp); /* synchronize sequences */ + context_save(); /* save the context file */ } if (nwhat) - done (0); - what_now (ed, nedit, NOUSE, drft, NULL, 0, mp, + done(0); + what_now(ed, nedit, NOUSE, drft, NULL, 0, mp, anot ? "Forwarded" : NULL, inplace, cwd); - done (1); + done(1); return 1; } @@ -372,7 +373,7 @@ main (int argc, char **argv) */ static void -mhl_draft (int out, char *digest, int volume, int issue, +mhl_draft(int out, char *digest, int volume, int issue, char *file, char *filter, int dashstuff) { pid_t child_id; @@ -381,21 +382,21 @@ mhl_draft (int out, char *digest, int volume, int issue, char buf1[BUFSIZ]; char buf2[BUFSIZ]; - if (pipe (pd) == NOTOK) - adios ("pipe", "unable to create"); + if (pipe(pd) == NOTOK) + adios("pipe", "unable to create"); - vec[0] = r1bindex (mhlproc, '/'); + vec[0] = r1bindex(mhlproc, '/'); for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); + sleep(5); switch (child_id) { case NOTOK: - adios ("fork", "unable to"); + adios("fork", "unable to"); case OK: - close (pd[0]); - dup2 (pd[1], 1); - close (pd[1]); + close(pd[0]); + dup2(pd[1], 1); + close(pd[1]); i = 1; vec[i++] = "-forwall"; @@ -406,10 +407,10 @@ mhl_draft (int out, char *digest, int volume, int issue, vec[i++] = "-digest"; vec[i++] = digest; vec[i++] = "-issue"; - snprintf (buf1, sizeof(buf1), "%d", issue); + snprintf(buf1, sizeof(buf1), "%d", issue); vec[i++] = buf1; vec[i++] = "-volume"; - snprintf (buf2, sizeof(buf2), "%d", volume); + snprintf(buf2, sizeof(buf2), "%d", volume); vec[i++] = buf2; } @@ -424,8 +425,7 @@ mhl_draft (int out, char *digest, int volume, int issue, vec[i++] = "-nodashstuffing"; if (mp->numsel >= MAXARGS - i) - adios (NULL, "more than %d messages for %s exec", - MAXARGS - i, vec[0]); + adios(NULL, "more than %d messages for %s exec", MAXARGS - i, vec[0]); /* ** Now add the message names to filter. We can only @@ -435,19 +435,19 @@ mhl_draft (int out, char *digest, int volume, int issue, for (msgnum = mp->lowsel; msgnum <= mp->hghsel && i < sizeof(vec) - 1; msgnum++) - if (is_selected (mp, msgnum)) - vec[i++] = getcpy (m_name (msgnum)); + if (is_selected(mp, msgnum)) + vec[i++] = getcpy(m_name(msgnum)); vec[i] = NULL; - execvp (mhlproc, vec); - fprintf (stderr, "unable to exec "); - perror (mhlproc); - _exit (-1); + execvp(mhlproc, vec); + fprintf(stderr, "unable to exec "); + perror(mhlproc); + _exit(-1); default: - close (pd[1]); - cpydata (pd[0], out, vec[0], file); - close (pd[0]); + close(pd[1]); + cpydata(pd[0], out, vec[0], file); + close(pd[0]); pidXwait(child_id, mhlproc); break; } @@ -461,7 +461,7 @@ mhl_draft (int out, char *digest, int volume, int issue, */ static void -copy_draft (int out, char *digest, char *file, int volume, int issue, +copy_draft(int out, char *digest, char *file, int volume, int issue, int dashstuff) { int fd,i, msgcnt, msgnum; @@ -471,36 +471,36 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, msgcnt = 1; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { + if (is_selected(mp, msgnum)) { if (digest) { - strncpy (buffer, msgnum == mp->lowsel ? + strncpy(buffer, msgnum == mp->lowsel ? delim3 : delim4, sizeof(buffer)); } else { /* Get buffer ready to go */ bp = buffer; buflen = sizeof(buffer); - strncpy (bp, "\n-------", buflen); - len = strlen (bp); + strncpy(bp, "\n-------", buflen); + len = strlen(bp); bp += len; buflen -= len; if (msgnum == mp->lowsel) { - snprintf (bp, buflen, " Forwarded Message%s", - mp->numsel > 1 ? "s" : ""); + snprintf(bp, buflen, " Forwarded Message%s", mp->numsel > 1 ? "s" : ""); } else { - snprintf (bp, buflen, " Message %d", msgcnt); + snprintf(bp, buflen, " Message %d", msgcnt); } - len = strlen (bp); + len = strlen(bp); bp += len; buflen -= len; - strncpy (bp, "\n\n", buflen); + strncpy(bp, "\n\n", buflen); } - write (out, buffer, strlen (buffer)); + write(out, buffer, strlen(buffer)); - if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { - admonish (msgnam, "unable to read message"); + if ((fd = open(msgnam = m_name (msgnum), O_RDONLY)) + == NOTOK) { + admonish(msgnam, "unable to read message"); continue; } @@ -509,32 +509,34 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, ** unless given the -nodashstuffing flag. */ if (dashstuff >= 0) - cpydgst (fd, out, msgnam, file); + cpydgst(fd, out, msgnam, file); else - cpydata (fd, out, msgnam, file); + cpydata(fd, out, msgnam, file); - close (fd); + close(fd); msgcnt++; } } if (digest) { - strncpy (buffer, delim4, sizeof(buffer)); + strncpy(buffer, delim4, sizeof(buffer)); } else { - snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n\n", + snprintf(buffer, sizeof(buffer), + "\n------- End of Forwarded Message%s\n\n", mp->numsel > 1 ? "s" : ""); } - write (out, buffer, strlen (buffer)); + write(out, buffer, strlen(buffer)); if (digest) { - snprintf (buffer, sizeof(buffer), "End of %s Digest [Volume %d Issue %d]\n", + snprintf(buffer, sizeof(buffer), + "End of %s Digest [Volume %d Issue %d]\n", digest, volume, issue); - i = strlen (buffer); + i = strlen(buffer); for (bp = buffer + i; i > 1; i--) *bp++ = '*'; *bp++ = '\n'; *bp = 0; - write (out, buffer, strlen (buffer)); + write(out, buffer, strlen(buffer)); } } @@ -544,25 +546,26 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, */ static void -copy_mime_draft (int out) +copy_mime_draft(int out) { int msgnum; char buffer[BUFSIZ]; - snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s", - mp->numsel == 1 ? "" : "s", mp->foldpath); - write (out, buffer, strlen (buffer)); + snprintf(buffer, sizeof(buffer), "#forw [forwarded message%s] +%s", + mp->numsel == 1 ? "" : "s", mp->foldpath); + write(out, buffer, strlen(buffer)); for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) { - snprintf (buffer, sizeof(buffer), " %s", m_name (msgnum)); - write (out, buffer, strlen (buffer)); + if (is_selected(mp, msgnum)) { + snprintf(buffer, sizeof(buffer), " %s", + m_name(msgnum)); + write(out, buffer, strlen(buffer)); } - write (out, "\n", 1); + write(out, "\n", 1); } static int -build_form (char *form, char *digest, int volume, int issue) +build_form(char *form, char *digest, int volume, int issue) { int in; int fmtsize; @@ -575,18 +578,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; + nfs = new_fs(form, NULL, NULL); + fmtsize = strlen(nfs) + 256; /* Compile format string */ - fmt_compile (nfs, &fmt); + fmt_compile(nfs, &fmt); - FINDCOMP (cptr, "digest"); + FINDCOMP(cptr, "digest"); if (cptr) cptr->c_text = digest; - FINDCOMP (cptr, "date"); + FINDCOMP(cptr, "date"); if (cptr) - cptr->c_text = getcpy(dtimenow (0)); + cptr->c_text = getcpy(dtimenow(0)); dat[0] = issue; dat[1] = volume; @@ -596,18 +599,18 @@ build_form (char *form, char *digest, int volume, int issue) cp = m_mktemp2(NULL, invo_name, NULL, &tmp); if (cp == NULL) adios("forw", "unable to create temporary file"); - strncpy (tmpfil, cp, sizeof(tmpfil)); - unlink (tmpfil); - if ((in = dup (fileno (tmp))) == NOTOK) - adios ("dup", "unable to"); - - line = mh_xmalloc ((unsigned) fmtsize); - fmt_scan (fmt, line, fmtsize, dat); - fputs (line, tmp); - free (line); - if (fclose (tmp)) - adios (tmpfil, "error writing"); - - lseek (in, (off_t) 0, SEEK_SET); + strncpy(tmpfil, cp, sizeof(tmpfil)); + unlink(tmpfil); + if ((in = dup(fileno(tmp))) == NOTOK) + adios("dup", "unable to"); + + line = mh_xmalloc((unsigned) fmtsize); + fmt_scan(fmt, line, fmtsize, dat); + fputs(line, tmp); + free(line); + if (fclose(tmp)) + adios(tmpfil, "error writing"); + + lseek(in, (off_t) 0, SEEK_SET); return in; }