If rcvpack missed file argument, it prints to stdout; Removed unused code.
authormarkus schnalke <meillo@marmaro.de>
Wed, 21 Mar 2012 10:19:50 +0000 (11:19 +0100)
committermarkus schnalke <meillo@marmaro.de>
Wed, 21 Mar 2012 10:19:50 +0000 (11:19 +0100)
The mbox variant we use is called `mboxo'.

h/dropsbr.h
man/rcvpack.man1
uip/dropsbr.c
uip/packf.c
uip/rcvpack.c
uip/slocal.c

index 2b21f10..c80770a 100644 (file)
@@ -6,5 +6,5 @@
 ** 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_copy(int, int);
 int mbx_close(char *, int);
 int mbx_close(char *, int);
index 366b0d5..290f5cc 100644 (file)
@@ -3,35 +3,34 @@
 .\"
 .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
-.I file
+.RI [ file ]
 .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.
 .PP
 .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.).
 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.
 
 .SH FILES
 .fc ^ ~
 
 .SH FILES
 .fc ^ ~
@@ -40,7 +39,15 @@ shell scripts.
 .fi
 
 .SH "SEE ALSO"
 .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.
 
 .SH BUGS
 Only two return codes are meaningful, others should be.
index 62ba424..f093c2f 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-** 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)
 {
-       int j, count, fd;
+       int i, count, fd;
        struct stat st;
 
        struct stat st;
 
-       j = 0;
+       i = 0;
 
        /* attempt to open and lock file */
        for (count = 4; count > 0; count--) {
 
        /* attempt to open and lock file */
        for (count = 4; count > 0; count--) {
@@ -46,7 +46,7 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
                        case EWOULDBLOCK:
 #endif
                        case ETXTBSY:
                        case EWOULDBLOCK:
 #endif
                        case ETXTBSY:
-                               j = errno;
+                               i = errno;
                                sleep(5);
                                break;
 
                                sleep(5);
                                break;
 
@@ -60,7 +60,7 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
                break;
        }
 
                break;
        }
 
-       errno = j;
+       errno = i;
 
        /*
        ** Return if we still failed after 4 attempts,
 
        /*
        ** Return if we still failed after 4 attempts,
@@ -98,34 +98,28 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
 }
 
 
 }
 
 
-
 /*
 /*
-** Append message to end of file or maildrop.
+** Append message to end of mbox.
 */
 int
 */
 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;
 
        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;
                return NOTOK;
-       if ((fp = fdopen(j, "r")) == NULL) {
-               close(j);
+       if ((fp = fdopen(i, "r")) == NULL) {
+               close(i);
                return NOTOK;
        }
                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.
                */
                /*
                ** 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 ".
                        /*
                        ** Change the "Return-Path:" field
                        ** (if in first line) back to "From ".
@@ -174,25 +168,23 @@ mbx_copy(char *mailbox, int md, int fd, int noisy)
 
                /*
                ** 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);
 
        return OK;
 }
 
        return OK;
 }
index 62c09da..fc7fcba 100644 (file)
@@ -145,7 +145,7 @@ main(int argc, char **argv)
                                break;
                        }
 
                                break;
                        }
 
-                       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);
index d6e1025..827373f 100644 (file)
@@ -65,10 +65,14 @@ main(int argc, char **argv)
                        file = cp;
        }
 
                        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()))
 
        /* open and lock the file */
        if ((md = mbx_open(file, getuid(), getgid(), m_gmprot()))
@@ -76,7 +80,7 @@ main(int argc, char **argv)
                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);
        }
index ae71c1b..6b78c1e 100644 (file)
@@ -1043,7 +1043,7 @@ usr_file(int fd, char *mailbox)
        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;