summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h1
-rw-r--r--mbbsd/record.c31
-rw-r--r--util/bbsmail.c11
3 files changed, 35 insertions, 8 deletions
diff --git a/include/proto.h b/include/proto.h
index c6731ad1..206593cb 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -425,6 +425,7 @@ int get_record_keep(char *fpath, void *rptr, int size, int id, int *fd);
void prints(char *fmt, ...) GCC_CHECK_FORMAT(1,2);
int append_record(char *fpath, fileheader_t *record, int size);
int stampfile(char *fpath, fileheader_t *fh);
+int stampfilefd(char *fpath, fileheader_t *fh);
void stampdir(char *fpath, fileheader_t *fh);
int get_num_records(char *fpath, int size);
int get_records(char *fpath, void *rptr, int size, int id, int number);
diff --git a/mbbsd/record.c b/mbbsd/record.c
index c8393f6f..d50fb611 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -474,6 +474,37 @@ stampfile(char *fpath, fileheader_t * fh)
return 0;
}
+int
+stampfilefd(char *fpath, fileheader_t * fh)
+{
+ char *ip = fpath;
+ time_t dtime = COMMON_TIME;
+ struct tm *ptime;
+ int fd;
+
+ if (access(fpath, X_OK | R_OK | W_OK))
+ mkdir(fpath, 0755);
+
+ while (*(++ip))
+ ;
+ *ip++ = '/';
+
+ while( 1 ) {
+ sprintf(ip, "M.%d.A.%3.3X", (int)++dtime, rand() & 0xFFF);
+ if( (fd = open(fpath, O_CREAT | O_EXCL | O_WRONLY, 0644)) != -1 )
+ break;
+ if( errno != EEXIST )
+ return -1;
+ }
+
+ memset(fh, 0, sizeof(fileheader_t));
+ strlcpy(fh->filename, ip, sizeof(fh->filename));
+ ptime = localtime(&dtime);
+ snprintf(fh->date, sizeof(fh->date),
+ "%2d/%02d", ptime->tm_mon + 1, ptime->tm_mday);
+ return fd;
+}
+
void
stampdir(char *fpath, fileheader_t * fh)
{
diff --git a/util/bbsmail.c b/util/bbsmail.c
index a58d5763..2ca997b8 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -78,7 +78,7 @@ void str_decode_M3(unsigned char *str);
int mail2bbs(char *userid)
{
- int uid;
+ int uid, fd;
fileheader_t mymail;
char genbuf[512], title[512], sender[512], filename[512], *ip, *ptr;
time_t tmp_time;
@@ -156,9 +156,6 @@ int mail2bbs(char *userid)
if( strchr(sender, '@') == NULL ) /* ¥Ñ local host ±H«H */
strcat(sender, "@" MYHOSTNAME);
-/* allocate a file for the new mail */
- stampfile(filename, &mymail);
-
#ifdef HMM_USE_ANTI_SPAM
for (n = 0; notitle[n]; n++)
if (strstr(title, notitle[n]))
@@ -178,11 +175,9 @@ int mail2bbs(char *userid)
}
#endif
- if ((fout = fopen(filename, "w")) == NULL)
- {
- printf("Cannot open %s\n", filename);
+ if( (fd = stampfilefd(filename, &mymail)) == -1 ||
+ (fout = fdopen(fd, "wt")) == NULL )
return -1;
- }
if (!title[0])
sprintf(title, "¨Ó¦Û %.64s", sender);