The mbox variant we use is called `mboxo'.
** prototypes
*/
int mbx_open(char *, uid_t, gid_t, mode_t);
** prototypes
*/
int mbx_open(char *, uid_t, gid_t, mode_t);
-int mbx_copy(char *, int, int, int);
int mbx_close(char *, int);
int mbx_close(char *, int);
.\"
.TH RCVPACK %manext1% "%nmhdate%" MH.6.8 [%nmhversion%]
.SH NAME
.\"
.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
.SH SYNOPSIS
.HP 5
.na
.B rcvpack
.RB [ \-version ]
.RB [ \-help ]
.ad
.SH DESCRIPTION
The
.B rcvpack
.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.
-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.).
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
.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.
-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.
.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
**
** 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
mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
{
/* attempt to open and lock file */
for (count = 4; count > 0; count--) {
/* attempt to open and lock file */
for (count = 4; count > 0; count--) {
case EWOULDBLOCK:
#endif
case ETXTBSY:
case EWOULDBLOCK:
#endif
case ETXTBSY:
/*
** Return if we still failed after 4 attempts,
/*
** Return if we still failed after 4 attempts,
-** Append message to end of file or maildrop.
+** Append message to end of mbox.
-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;
char buffer[BUFSIZ];
FILE *fp;
char buffer[BUFSIZ];
FILE *fp;
- pos = (long) lseek(md, (off_t) 0, SEEK_CUR);
-
- if ((j = dup(fd)) == NOTOK)
+ if ((i = dup(from)) == NOTOK)
- if ((fp = fdopen(j, "r")) == NULL) {
- close(j);
+ if ((fp = fdopen(i, "r")) == NULL) {
+ close(i);
- 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.
*/
/*
** Check the first line, and make some changes.
*/
/*
** Change the "Return-Path:" field
** (if in first line) back to "From ".
/*
** Change the "Return-Path:" field
** (if in first line) back to "From ".
/*
** If this is not first line, and begins with "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;
}
}
fclose(fp);
return NOTOK;
}
}
- if (write(md, "\n", 1) != 1) {
+ if (write(to, "\n", 1) != 1) {
fclose(fp);
return NOTOK;
}
fclose(fp);
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);
- if (mbx_copy(file, md, fd, 1) == NOTOK)
+ if (mbx_copy(md, fd) == NOTOK)
adios(file, "error writing to file");
close(fd);
adios(file, "error writing to file");
close(fd);
- 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()))
/* open and lock the file */
if ((md = mbx_open(file, getuid(), getgid(), m_gmprot()))
done(RCV_MBX);
/* append the message */
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);
}
mbx_close(file, md);
done(RCV_MBX);
}
lseek(fd, (off_t) 0, SEEK_SET);
/* append message to file */
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;
if (verbose)
adorn("", "error writing to:");
return -1;