Renamed the mbx_* functions to mbox_*, because mbx is another mail box format.
[mmh] / uip / dropsbr.c
index 62ba424..6a7eb78 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
 ** a file or maildrop.
 */
 int
-mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode)
+mbox_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)
+mbox_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;
 }
@@ -202,7 +194,7 @@ mbx_copy(char *mailbox, int md, int fd, int noisy)
 ** Close and unlock file/maildrop.
 */
 int
-mbx_close(char *mailbox, int md)
+mbox_close(char *mailbox, int md)
 {
        if (lkclose(md, mailbox) == 0)
                return OK;