/*
-** 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
#include <h/mh.h>
#include <h/dropsbr.h>
-#include <h/mts.h>
#include <h/tws.h>
#ifdef HAVE_ERRNO_H
** 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--) {
case EWOULDBLOCK:
#endif
case ETXTBSY:
- j = errno;
+ i = errno;
sleep(5);
break;
break;
}
- errno = j;
+ errno = i;
/*
** Return if we still failed after 4 attempts,
}
-
/*
-** 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 ".
/*
** 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;
}
** 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;