X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fdropsbr.c;h=e1058842669efc37c7928b5d0459d8c7f0cb5712;hp=dd7a2df53cf1ef7137005ea9f68f3582da14056d;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=de448e64862babc8ea92d6ee3f61f68ba3915128 diff --git a/uip/dropsbr.c b/uip/dropsbr.c index dd7a2df..e105884 100644 --- a/uip/dropsbr.c +++ b/uip/dropsbr.c @@ -1,24 +1,20 @@ /* -** 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 ** complete copyright information. */ -#include -#include - #include +#include #include -#include #include - -#ifdef HAVE_ERRNO_H -# include -#endif - +#include #include +#include +#include +#include /* @@ -26,12 +22,12 @@ ** 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--) { @@ -47,9 +43,9 @@ mbx_open(char *file, uid_t uid, gid_t gid, mode_t mode) case EWOULDBLOCK: #endif case ETXTBSY: - j = errno; - sleep(5); - break; + i = errno; + sleep(1); + continue; default: /* just return error */ @@ -61,7 +57,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, @@ -99,34 +95,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 ". @@ -141,7 +131,7 @@ mbx_copy(char *mailbox, int md, int fd, int noisy) fp = strchr(ep + 1, '\n'); tp = dctime(dlocaltimenow()); snprintf(buffer, sizeof(buffer), - "From %.*s %s", + "From %.*s %s", (int)(fp-ep), ep, tp); } else if (strncmp(buffer, "X-Envelope-From:", 16)==0) { @@ -168,32 +158,30 @@ mbx_copy(char *mailbox, int md, int fd, int noisy) ep = "nobody@nowhere"; tp = dctime(dlocaltimenow()); snprintf(buffer, sizeof(buffer), - "From %s %s%s", ep, tp, + "From %s %s%s", ep, tp, tmpbuffer); } } /* ** 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)) != (int)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; } @@ -203,7 +191,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;