The mbox variant we use is called `mboxo'.
** prototypes
*/
int mbx_open(char *, uid_t, gid_t, mode_t);
-int mbx_copy(char *, int, int, int);
+int mbx_copy(int, int);
int mbx_close(char *, int);
.\"
.TH RCVPACK %manext1% "%nmhdate%" MH.6.8 [%nmhversion%]
.SH NAME
-rcvpack \- append message to file
+rcvpack \- append message to mbox file
.SH SYNOPSIS
.HP 5
.na
.B rcvpack
-.I file
+.RI [ file ]
.RB [ \-version ]
.RB [ \-help ]
.ad
.SH DESCRIPTION
The
.B rcvpack
-program will append a copy of the message to the file
-listed on its command line.
+program will read a message on standard in, convert it and
+append it to the mbox file listed on the command line.
.PP
-The messages are separated using mbox (uucp) style delimiters.
+The RFC 822 message is converted to the mbox format.
This is the format used by most mail clients (elm, mailx, etc.).
+For the nitpickers: It's the mboxo format.
.PP
.B rcvpack
will correctly lock and unlock the file to serialize
access to the file, when running multiple copies of
.B rcvpack .
.PP
-In general, its use is obsoleted by the
-.B file
-action of
-.BR slocal ,
-although it might still have occasional uses in various
-shell scripts.
+If no
+.I file
+argument is given, the converted message is printed to standard out.
+No locking will be done in this case.
.SH FILES
.fc ^ ~
.fi
.SH "SEE ALSO"
-rcvdist(1), rcvstore(1), slocal(1)
+rcvdist(1), rcvstore(1), slocal(1), packf(1)
+
+.SH HISTORY
+Some people say that this tool would be obsoleted by the
+.B file
+action of
+.BR slocal ,
+although it might still have occasional uses in various
+shell scripts.
.SH BUGS
Only two return codes are meaningful, others should be.
/*
-** dropsbr.c -- create/read/manipulate mail drops
+** dropsbr.c -- append to mbox files
**
** This code is Copyright (c) 2002, by the authors of nmh. See the
** COPYRIGHT file in the root directory of the nmh distribution for
int
mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
{
- int j, count, fd;
+ int i, count, fd;
struct stat st;
- j = 0;
+ i = 0;
/* attempt to open and lock file */
for (count = 4; count > 0; count--) {
case EWOULDBLOCK:
#endif
case ETXTBSY:
- j = errno;
+ i = errno;
sleep(5);
break;
break;
}
- errno = j;
+ errno = i;
/*
** Return if we still failed after 4 attempts,
}
-
/*
-** Append message to end of file or maildrop.
+** Append message to end of mbox.
*/
int
-mbx_copy(char *mailbox, int md, int fd, int noisy)
+mbx_copy(int to, int from)
{
- int i, j;
- off_t start, stop;
- long pos;
+ int i;
char buffer[BUFSIZ];
FILE *fp;
- pos = (long) lseek(md, (off_t) 0, SEEK_CUR);
-
- if ((j = dup(fd)) == NOTOK)
+ if ((i = dup(from)) == NOTOK)
return NOTOK;
- if ((fp = fdopen(j, "r")) == NULL) {
- close(j);
+ if ((fp = fdopen(i, "r")) == NULL) {
+ close(i);
return NOTOK;
}
- start = lseek(md, (off_t) 0, SEEK_CUR);
- for (j = 0; fgets(buffer, sizeof(buffer), fp) != NULL; j++) {
+ for (i = 0; fgets(buffer, sizeof(buffer), fp) != NULL; i++) {
/*
** Check the first line, and make some changes.
*/
- if (j == 0) {
+ if (i == 0) {
/*
** Change the "Return-Path:" field
** (if in first line) back to "From ".
/*
** If this is not first line, and begins with "From ",
- ** then prepend line with ">".
+ ** then prepend line with ">". (`mboxo' format is used.)
*/
- if (j != 0 && strncmp(buffer, "From ", 5) == 0) {
- write(md, ">", 1);
+ if (i != 0 && strncmp(buffer, "From ", 5) == 0) {
+ write(to, ">", 1);
}
- i = strlen(buffer);
- if (write(md, buffer, i) != i) {
+ if (write(to, buffer, strlen(buffer)) != strlen(buffer)) {
fclose(fp);
return NOTOK;
}
}
- if (write(md, "\n", 1) != 1) {
+ if (write(to, "\n", 1) != 1) {
fclose(fp);
return NOTOK;
}
fclose(fp);
- lseek(fd, (off_t) 0, SEEK_END);
- stop = lseek(md, (off_t) 0, SEEK_CUR);
+ lseek(from, (off_t) 0, SEEK_END);
return OK;
}
break;
}
- if (mbx_copy(file, md, fd, 1) == NOTOK)
+ if (mbx_copy(md, fd) == NOTOK)
adios(file, "error writing to file");
close(fd);
file = cp;
}
- if (!file)
- adios(NULL, "%s [switches] file", invo_name);
-
- rewind(stdin);
+ /* copy stdin to stdout, converting rfc822 message to mbox */
+ if (!file) {
+ if (mbx_copy(fileno(stdout), fileno(stdin)) == NOTOK) {
+ done(RCV_MBX);
+ }
+ done(RCV_MOK);
+ return 1;
+ }
/* open and lock the file */
if ((md = mbx_open(file, getuid(), getgid(), m_gmprot()))
done(RCV_MBX);
/* append the message */
- if (mbx_copy(file, md, fileno(stdin), 0) == NOTOK) {
+ if (mbx_copy(md, fileno(stdin)) == NOTOK) {
mbx_close(file, md);
done(RCV_MBX);
}
lseek(fd, (off_t) 0, SEEK_SET);
/* append message to file */
- if (mbx_copy(mailbox, md, fd, verbose) == -1) {
+ if (mbx_copy(md, fd) == -1) {
if (verbose)
adorn("", "error writing to:");
return -1;