From: markus schnalke Date: Wed, 21 Mar 2012 10:19:50 +0000 (+0100) Subject: If rcvpack missed file argument, it prints to stdout; Removed unused code. X-Git-Tag: mmh-thesis-end~279 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=ef1216bc36bd48ceb7549ae76aa7c26e3be4d9e4;p=mmh If rcvpack missed file argument, it prints to stdout; Removed unused code. The mbox variant we use is called `mboxo'. --- diff --git a/h/dropsbr.h b/h/dropsbr.h index 2b21f10..c80770a 100644 --- a/h/dropsbr.h +++ b/h/dropsbr.h @@ -6,5 +6,5 @@ ** 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); diff --git a/man/rcvpack.man1 b/man/rcvpack.man1 index 366b0d5..290f5cc 100644 --- a/man/rcvpack.man1 +++ b/man/rcvpack.man1 @@ -3,35 +3,34 @@ .\" .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 ^ ~ @@ -40,7 +39,15 @@ shell scripts. .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. diff --git a/uip/dropsbr.c b/uip/dropsbr.c index 62ba424..f093c2f 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -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 @@ -27,10 +27,10 @@ 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--) { @@ -46,7 +46,7 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode) case EWOULDBLOCK: #endif case ETXTBSY: - j = errno; + i = errno; sleep(5); break; @@ -60,7 +60,7 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode) break; } - errno = j; + errno = i; /* ** 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 -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 ". @@ -174,25 +168,23 @@ mbx_copy(char *mailbox, int md, int fd, int noisy) /* ** 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; } diff --git a/uip/packf.c b/uip/packf.c index 62c09da..fc7fcba 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -145,7 +145,7 @@ main(int argc, char **argv) break; } - if (mbx_copy(file, md, fd, 1) == NOTOK) + if (mbx_copy(md, fd) == NOTOK) adios(file, "error writing to file"); close(fd); diff --git a/uip/rcvpack.c b/uip/rcvpack.c index d6e1025..827373f 100644 --- a/uip/rcvpack.c +++ b/uip/rcvpack.c @@ -65,10 +65,14 @@ main(int argc, char **argv) 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())) @@ -76,7 +80,7 @@ main(int argc, char **argv) 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); } diff --git a/uip/slocal.c b/uip/slocal.c index ae71c1b..6b78c1e 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -1043,7 +1043,7 @@ usr_file(int fd, char *mailbox) 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;