^Current\-Folder:~^To find the default current folder
^Draft\-Folder:~^To set the default draft\-folder
^Editor:~^To override the default editor
-^fileproc:~^Program to refile the message
^whatnowproc:~^Program to ask the \*(lqWhat now?\*(rq questions
.fi
In order to conform with the ARPA Internet standard, RFC\-822, the
.RI \*(lq Resent\-xxx: \*(rq
form is now used.
-.B Dist
-will recognize
+Since
+.B mmh
+.B dist
+will no longer recognize and convert
.RI \*(lq Distribute\-xxx: \*(rq
-type headers and automatically convert them to
-.RI \*(lq Resent\-xxx: \*(rq.
+type headers.
.SH BUGS
.B Dist
program will balk (and rightly so) at poorly formatted messages, and
.B dist
won't correct things for you.
-.PP
-If your current working directory is not writable, the link named
-\*(lq@\*(rq is not available.
.IR formfile ]
[switches\ for
.IR postproc ]
-.I address1
-\&...
+.IR RECIPIENT ...
.RB [ \-version ]
.RB [ \-help ]
.ad
.ta \w'%etcdir%/ExtraBigFileName 'u
^%etcdir%/rcvdistcomps~^Default message skeleton
^or $HOME/.mmh/rcvdistcomps~^Rather than standard message skeleton
-^$HOME/\&.maildelivery~^The file controlling local delivery
-^%etcdir%/maildelivery~^Rather than the standard file
.fi
.SH "SEE ALSO"
{ "version", 0 },
#define HELPSW 8
{ "help", 0 },
-#define FILESW 9
- { "file file", -4 }, /* interface from msh */
{ NULL, 0 }
};
int anot = 0, nedit = 0;
int nwhat = 0, in, out;
char *cp, *cwd, *maildir, *msgnam;
- char *ed = NULL, *file = NULL, *folder = NULL;
+ char *ed = NULL, *folder = NULL;
char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ];
char **argp, **arguments;
struct msgs *mp = NULL;
nwhat++;
continue;
- case FILESW:
- if (file)
- adios(NULL, "only one file at a time!");
- if (!(cp = *argp++) || *cp == '-')
- adios(NULL, "missing argument to %s",
- argp[-2]);
- file = getcpy(expanddir(cp));
- continue;
case FORMSW:
if (!(form = *argp++) || *form == '-')
adios(NULL, "missing argument to %s",
cwd = getcpy(pwd());
- if (file && (msg || folder))
- adios(NULL, "can't mix files and folders/msgs");
-
strncpy(drft, m_draft(seq_beyond), sizeof(drft));
if ((out = creat(drft, m_gmprot())) == NOTOK)
adios(drft, "unable to create");
}
close(out);
- if (file) {
- /*
- ** Dist a file
- */
- anot = 0; /* don't want to annotate a file */
- } else {
- /*
- ** Dist a message
- */
- if (!msg)
- msg = seq_cur;
- if (!folder)
- folder = getcurfol();
- maildir = toabsdir(folder);
-
- 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);
-
- /* check for empty folder */
- if (mp->nummsg == 0)
- adios(NULL, "no messages in %s", folder);
-
- /* parse the message range/sequence/name and set SELECTED */
- if (!m_convert(mp, msg))
- done(1);
- seq_setprev(mp); /* set the previous-sequence */
-
- if (mp->numsel > 1)
- adios(NULL, "only one message at a time!");
- }
+ if (!msg)
+ msg = seq_cur;
+ if (!folder)
+ folder = getcurfol();
+ maildir = toabsdir(folder);
+
+ if (chdir(maildir) == NOTOK)
+ adios(maildir, "unable to change directory to");
- msgnam = file ? file : getcpy(m_name(mp->lowsel));
+ 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);
+
+ /* parse the message range/sequence/name and set SELECTED */
+ if (!m_convert(mp, msg))
+ done(1);
+ seq_setprev(mp);
+
+ if (mp->numsel > 1)
+ adios(NULL, "only one message at a time!");
+
+ msgnam = getcpy(m_name(mp->lowsel));
if ((in = open(msgnam, O_RDONLY)) == NOTOK)
adios(msgnam, "unable to open message");
- if (!file) {
- context_replace(curfolder, 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(curfolder, folder);
+ seq_setcur(mp, mp->lowsel);
+ seq_save(mp); /* synchronize sequences */
+ context_save();
if (nwhat)
done(0);
- what_now(ed, nedit, NOUSE, drft, msgnam, 1, mp, anot ? "Resent" : NULL,
- cwd);
+ what_now(ed, nedit, NOUSE, drft, msgnam, 1, mp,
+ anot ? "Resent" : NULL, cwd);
done(1);
return 1;
}
static int hdrfd = NOTOK;
static int txtfd = NOTOK;
-#define BADHDR "please re-edit %s to remove the ``%s'' header!"
-#define BADTXT "please re-edit %s to consist of headers only!"
-#define BADMSG "please re-edit %s to include a ``Resent-To:''!"
-#define BADRFT "please re-edit %s and fix that header!"
-
/*
** static prototypes
*/
char name[NAMESZ], buffer[BUFSIZ];
register FILE *ifp, *ofp;
- if (rename(drft, strcpy(backup, m_backup(drft))) == NOTOK)
+ if (rename(drft, strcpy(backup, m_backup(drft))) == NOTOK) {
adios(backup, "unable to rename %s to",drft);
- if ((ifp = fopen(backup, "r")) == NULL)
+ }
+ if (!(ifp = fopen(backup, "r"))) {
adios(backup, "unable to read");
+ }
- if ((ofp = fopen(drft, "w")) == NULL)
+ if (!(ofp = fopen(drft, "w"))) {
adios(drft, "unable to create temporary file");
+ }
chmod(drft, m_gmprot());
ready_msg(msgnam);
lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(hdrfd, fileno(ofp), msgnam, drft);
- for (state = FLD, resent = NULL;;)
- switch (state = m_getfld (state, name, buffer,
- sizeof buffer, ifp)) {
+ state = FLD;
+ resent = NULL;
+ while (1) {
+ switch (state = m_getfld(state, name, buffer, sizeof buffer,
+ ifp)) {
case FLD:
case FLDPLUS:
case FLDEOF:
- if (uprf(name, "distribute-"))
- snprintf(name, sizeof(name), "%s%s",
- "Resent", &name[10]);
- if (uprf(name, "distribution-"))
- snprintf(name, sizeof(name), "%s%s",
- "Resent", &name[12]);
if (!uprf(name, "resent")) {
- advise(NULL, BADHDR, "draft", name);
+ advise(NULL, "Please re-edit draft to remove the ``%s'' header.", name);
goto leave_bad;
}
- if (state == FLD)
+ if (state == FLD) {
resent = add(":", add(name, resent));
+ }
resent = add(buffer, resent);
fprintf(ofp, "%s: %s", name, buffer);
while (state == FLDPLUS) {
resent = add(buffer, resent);
fputs(buffer, ofp);
}
- if (state == FLDEOF)
+ if (state == FLDEOF) {
goto process;
+ }
break;
case BODY:
case BODYEOF:
- for (dp = buffer; *dp; dp++)
+ for (dp = buffer; *dp; dp++) {
if (!isspace(*dp)) {
- advise(NULL, BADTXT, "draft");
+ advise(NULL, "Please re-edit draft to consist of headers only.");
goto leave_bad;
}
+ }
case FILEEOF:
goto process;
case LENERR:
case FMTERR:
- advise(NULL, BADRFT, "draft");
+ advise(NULL, "Please re-edit draft and fix that header.");
leave_bad: ;
fclose(ifp);
fclose(ofp);
unlink(drft);
- if (rename(backup, drft) == NOTOK)
+ if (rename(backup, drft) == NOTOK) {
adios(drft, "unable to rename %s to", backup);
+ }
return NOTOK;
default:
adios(NULL, "getfld() returned %d", state);
}
+ }
+
process: ;
fclose(ifp);
fflush(ofp);
if (!resent) {
- advise(NULL, BADMSG, "draft");
+ advise(NULL, "Please re-edit draft to include a ``Resent-To:'' header.");
fclose(ofp);
unlink(drft);
- if (rename(backup, drft) == NOTOK)
+ if (rename(backup, drft) == NOTOK) {
adios(drft, "unable to rename %s to", backup);
+ }
return NOTOK;
}
free(resent);
if (txtfd != NOTOK) {
- lseek(txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
+ lseek(txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(txtfd, fileno(ofp), msgnam, drft);
}
register FILE *ifp, *ofp;
char *cp = NULL;
- if (hdrfd != NOTOK)
- close(hdrfd), hdrfd = NOTOK;
- if (txtfd != NOTOK)
- close(txtfd), txtfd = NOTOK;
-
- if ((ifp = fopen(msgnam, "r")) == NULL)
+ if (hdrfd != NOTOK) {
+ close(hdrfd);
+ hdrfd = NOTOK;
+ }
+ if (txtfd != NOTOK) {
+ close(txtfd);
+ txtfd = NOTOK;
+ }
+ if (!(ifp = fopen(msgnam, "r"))) {
adios(msgnam, "unable to open message");
+ }
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
- if (cp == NULL) {
+ if (!cp) {
adios("distsbr", "unable to create temporary file");
}
fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
- if ((out = dup(hdrfd)) == NOTOK
- || (ofp = fdopen(out, "w")) == NULL)
+ if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) {
adios(NULL, "no file descriptors -- you lose big");
+ }
unlink(tmpfil);
- for (state = FLD;;) {
+ state = FLD;
+ while (1) {
state = m_getfld(state, name, buffer, sizeof buffer, ifp);
switch (state) {
case FLD:
case FLDPLUS:
case FLDEOF:
- if (uprf(name, "resent"))
+ if (uprf(name, "resent")) {
fprintf(ofp, "Prev-");
+ }
fprintf(ofp, "%s: %s", name, buffer);
while (state == FLDPLUS) {
state = m_getfld(state, name, buffer,
sizeof buffer, ifp);
fputs(buffer, ofp);
}
- if (state == FLDEOF)
+ if (state == FLDEOF) {
goto process;
+ }
break;
case BODY:
fclose(ofp);
cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
- if (cp == NULL) {
- adios("distsbr", "unable to create temporary file");
+ if (!cp) {
+ adios("distsbr", "unable to create temp file");
}
fchmod(txtfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
- if ((out = dup(txtfd)) == NOTOK
- || (ofp = fdopen(out, "w")) == NULL)
- adios(NULL, "no file descriptors -- you lose big");
+ if ((out = dup(txtfd)) == NOTOK ||
+ !(ofp = fdopen(out, "w"))) {
+ adios(NULL, "no file descriptors -- you lose");
+ }
unlink(tmpfil);
fprintf(ofp, "\n%s", buffer);
while (state == BODY) {
int
main(int argc, char **argv)
{
- pid_t child_id;
- int i, vecp = 1;
+ int vecp = 1;
char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
char **argp, **arguments, *vec[MAXARGS];
FILE *fp;
done(1);
case FORMSW:
- if (!(form = *argp++) || *form == '-')
+ if (!(form = *argp++) || *form == '-') {
adios(NULL, "missing argument to %s",
argp[-2]);
+ }
continue;
}
}
addrs = addrs ? add(cp, add(", ", addrs)) : getcpy(cp);
}
- if (addrs == NULL)
+ if (!addrs) {
adios(NULL, "usage: %s [switches] [switches for postproc] address ...", invo_name);
+ }
umask(~m_gmprot());
rcvdistout(fp, form, addrs);
fclose(fp);
- if (distout(drft, tmpfil, backup) == NOTOK)
+ if (distout(drft, tmpfil, backup) == NOTOK) {
done(1);
+ }
vec[0] = mhbasename(postproc);
vec[vecp++] = "-dist";
vec[vecp++] = drft;
vec[vecp] = NULL;
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep(5);
- switch (child_id) {
- case NOTOK:
- admonish(NULL, "unable to fork");/* fall */
- case OK:
- execvp(postproc, vec);
- fprintf(stderr, "unable to exec ");
- perror(postproc);
- _exit(1);
-
- default:
- done(pidXwait(child_id, postproc));
- }
-
+ execvp(postproc, vec);
+ fprintf(stderr, "unable to exec ");
+ perror(postproc);
+ _exit(1);
return 0; /* dead code to satisfy the compiler */
}
register struct comp *cptr, **savecomp;
FILE *out;
- if (!(out = fopen(drft, "w")))
+ if (!(out = fopen(drft, "w"))) {
adios(drft, "unable to create");
+ }
/* get new format string */
cp = new_fs(form ? form : rcvdistcomps, NULL);
format_len = strlen(cp);
ncomps = fmt_compile(cp, &fmt) + 1;
if (!(nxtbuf = compbuffers =
- (char **) calloc((size_t) ncomps, sizeof(char *))))
+ (char **) calloc((size_t) ncomps, sizeof(char *)))) {
adios(NULL, "unable to allocate component buffers");
+ }
if (!(savecomp = used_buf =
(struct comp **) calloc((size_t) (ncomps + 1),
- sizeof(struct comp *))))
+ sizeof(struct comp *)))) {
adios(NULL, "unable to allocate component buffer stack");
+ }
savecomp += ncomps + 1;
*--savecomp = 0;
- for (i = ncomps; i--;)
+ for (i = ncomps; i--;) {
*nxtbuf++ = mh_xmalloc(SBUFSIZ);
+ }
nxtbuf = compbuffers;
tmpbuf = *nxtbuf++;
for (ap = addrcomps; *ap; ap++) {
FINDCOMP(cptr, *ap);
- if (cptr)
+ if (cptr) {
cptr->c_type |= CT_ADDR;
+ }
}
FINDCOMP(cptr, "addresses");
- if (cptr)
+ if (cptr) {
cptr->c_text = addrs;
-
- for (state = FLD;;) {
- switch (state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb)) {
+ }
+ state = FLD;
+ while (1) {
+ state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
+ switch (state) {
case FLD:
case FLDPLUS:
- if ((cptr = wantcomp[CHASH(name)]))
+ if ((cptr = wantcomp[CHASH(name)])) {
do {
- if (!mh_strcasecmp(name, cptr->c_name)) {
- char_read += msg_count;
- if (!cptr->c_text) {
- cptr->c_text = tmpbuf;
- *--savecomp = cptr;
- tmpbuf = *nxtbuf++;
- } else {
- i = strlen(cp = cptr->c_text) - 1;
- if (cp[i] == '\n') {
- if (cptr->c_type & CT_ADDR) {
- cp[i] = 0;
- cp = add(",\n\t", cp);
- } else
- cp = add("\t", cp);
+ if (mh_strcasecmp(name, cptr->c_name)!=0) {
+ continue;
+ }
+ char_read += msg_count;
+ if (!cptr->c_text) {
+ cptr->c_text = tmpbuf;
+ *--savecomp = cptr;
+ tmpbuf = *nxtbuf++;
+ } else {
+ cp = cptr->c_text;
+ i = strlen(cp) - 1;
+ if (cp[i] == '\n') {
+ if (cptr->c_type & CT_ADDR) {
+ cp[i] = 0;
+ cp = add(",\n\t", cp);
+ } else {
+ cp = add("\t", cp);
}
- cptr->c_text = add(tmpbuf, cp);
}
- while (state == FLDPLUS) {
- state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
- cptr->c_text = add(tmpbuf, cptr->c_text);
- char_read += msg_count;
- }
- break;
+ cptr->c_text = add(tmpbuf, cp);
+ }
+ while (state == FLDPLUS) {
+ state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
+ cptr->c_text = add(tmpbuf, cptr->c_text);
+ char_read += msg_count;
}
+ break;
} while ((cptr = cptr->c_next));
+ }
- while (state == FLDPLUS)
- state = m_getfld(state, name, tmpbuf, SBUFSIZ, inb);
+ while (state == FLDPLUS) {
+ state = m_getfld(state, name, tmpbuf,
+ SBUFSIZ, inb);
+ }
break;
case LENERR:
fmt_scan(fmt, scanl, i, dat);
fputs(scanl, out);
- if (ferror(out))
+ if (ferror(out)) {
adios(drft, "error writing");
+ }
fclose(out);
free(scanl);
for (nxtbuf = compbuffers, i = ncomps; (cptr = *savecomp++);
- nxtbuf++, i--)
+ nxtbuf++, i--) {
free(cptr->c_text);
- while (i-- > 0)
+ }
+ while (i-- > 0) {
free(*nxtbuf++);
- free((char *) compbuffers);
- free((char *) used_buf);
+ }
+ free(compbuffers);
+ free(used_buf);
}
static void
unlink_done(int status)
{
- if (backup[0])
+ if (*backup) {
unlink(backup);
- if (drft[0])
+ }
+ if (*drft) {
unlink(drft);
- if (tmpfil[0])
+ }
+ if (*tmpfil) {
unlink(tmpfil);
-
+ }
exit(status ? RCV_MBX : RCV_MOK);
}