summaryrefslogtreecommitdiffstats
path: root/mh.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1998-11-23 10:08:07 +0000
committerThomas Roessler <roessler@does-not-exist.org>1998-11-23 10:08:07 +0000
commit9f61713ddeea783bddc259b2ecfe8a1dcd7481f4 (patch)
tree21ae2b1636b0306db4a6be277e22c9002f92deb5 /mh.c
parente0943692edf7d7970fddd908d9fa4846d6e1fcdf (diff)
Introduce a new option $reply_self. From Vikas.
Diffstat (limited to 'mh.c')
-rw-r--r--mh.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/mh.c b/mh.c
index 0e65fbb9..be9f30cf 100644
--- a/mh.c
+++ b/mh.c
@@ -29,12 +29,16 @@ static const char rcsid[]="$Id$";
#include "sort.h"
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include <dirent.h>
#include <limits.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
+#include <fcntl.h>
struct maildir
{
@@ -168,10 +172,18 @@ static int maildir_parse_entry(CONTEXT *ctx, struct maildir ***last,
HEADER *h;
char buf[_POSIX_PATH_MAX];
+#ifndef HAVE_FCHDIR
+
if(subdir)
snprintf(buf, sizeof(buf), "%s/%s/%s", ctx->path, subdir, fname);
else
snprintf(buf, sizeof(buf), "%s/%s", ctx->path, fname);
+
+#else
+
+ strfcpy(buf, fname, sizeof(buf));
+
+#endif
if((h = maildir_parse_message(ctx->magic, buf, is_old)) != NULL)
{
@@ -223,7 +235,10 @@ static int maildir_parse_dir(CONTEXT *ctx, struct maildir ***last,
struct dirent *de;
char buf[_POSIX_PATH_MAX];
int is_old = 0;
-
+#ifdef HAVE_FCHDIR
+ int fd;
+#endif
+
if(subdir)
{
snprintf(buf, sizeof(buf), "%s/%s", ctx->path, subdir);
@@ -231,10 +246,26 @@ static int maildir_parse_dir(CONTEXT *ctx, struct maildir ***last,
}
else
strfcpy(buf, ctx->path, sizeof(buf));
+
+#ifdef HAVE_FCHDIR
+
+ if((fd = open(".", 0)) == -1)
+ return -1;
+
+ if((chdir(buf) == -1) || ((dirp = opendir(".")) == NULL))
+ {
+ fchdir(fd);
+ close(fd);
+ return -1;
+ }
+#else
+
if((dirp = opendir(buf)) == NULL)
return -1;
+#endif
+
while ((de = readdir (dirp)) != NULL)
{
if ((ctx->magic == M_MH && !mh_valid_message(de->d_name)) || (ctx->magic == M_MAILDIR && *de->d_name == '.'))
@@ -246,6 +277,8 @@ static int maildir_parse_dir(CONTEXT *ctx, struct maildir ***last,
}
closedir(dirp);
+ fchdir(fd);
+ close(fd);
return 0;
}