summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/proto.h2
-rw-r--r--mbbsd/bbs.c34
-rw-r--r--mbbsd/mail.c64
-rw-r--r--mbbsd/record.c4
4 files changed, 60 insertions, 44 deletions
diff --git a/include/proto.h b/include/proto.h
index 78acebbc..76a24cac 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -491,7 +491,7 @@ int safe_article_delete_range(char *direct, int from, int to);
#endif
int delete_file(char *dirname, int size, int ent, int (*filecheck)());
int delete_range(char *fpath, int id1, int id2);
-int apply_record(char *fpath, int (*fptr)(), int size);
+int apply_record(char *fpath, int (*fptr)(void*,void*), int size,void *arg);
int search_rec(char* dirname, int (*filecheck)());
int append_record_forward(char *fpath, fileheader_t *record, int size);
int get_sum_records(char* fpath, int size);
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index ba2c52d4..e4062050 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -2080,28 +2080,29 @@ tar_addqueue(int ent, fileheader_t * fhdr, char *direct)
}
#endif
-static int sequent_ent;
-static int continue_flag;
+struct SeqReadArg {
+ int idc;
+ int sequent_ent;
+ int continue_flag;
+};
/* ----------------------------------------------------- */
/* 依序讀新文章 */
/* ----------------------------------------------------- */
static int
-sequent_messages(fileheader_t * fptr)
+sequent_messages(void * voidfptr, void *optarg)
{
- static int idc;
+ fileheader_t *fptr=(fileheader_t*)voidfptr;
+ struct SeqReadArg *arg=(struct SeqReadArg*)optarg;
char genbuf[200];
- if (fptr == NULL)
- return (idc = 0);
-
- if (++idc < sequent_ent)
+ if (++arg->idc < arg->sequent_ent)
return 0;
if (!brc_unread(fptr->filename, brc_num, brc_list))
return 0;
- if (continue_flag)
+ if (arg->continue_flag)
genbuf[0] = 'y';
else {
prints("讀取文章於:[%s] 作者:[%s]\n標題:[%s]",
@@ -2119,7 +2120,7 @@ sequent_messages(fileheader_t * fptr)
if (more(genbuf, YEA) == 0)
outmsg("\033[31;47m \033[31m(R)\033[30m回信 \033[31m(↓,n)"
"\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m");
- continue_flag = 0;
+ arg->continue_flag = 0;
switch (igetch()) {
case KEY_LEFT:
@@ -2143,7 +2144,7 @@ sequent_messages(fileheader_t * fptr)
case KEY_DOWN:
case '\n':
case 'n':
- continue_flag = 1;
+ arg->continue_flag = 1;
}
clear();
@@ -2154,13 +2155,16 @@ static int
sequential_read(int ent, fileheader_t * fhdr, char *direct)
{
char buf[40];
+ struct SeqReadArg arg;
clear();
- sequent_messages((fileheader_t *) NULL);
- sequent_ent = ent;
- continue_flag = 0;
+
+ arg.idc=0;
+ arg.sequent_ent = ent;
+ arg.continue_flag = 0;
+
setbdir(buf, currboard);
- apply_record(buf, sequent_messages, sizeof(fileheader_t));
+ apply_record(buf, sequent_messages, sizeof(fileheader_t), &arg);
return FULLUPDATE;
}
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 7d953388..1a195b75 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -667,24 +667,23 @@ m_forward(int ent, fileheader_t * fhdr, char *direct)
return FULLUPDATE;
}
-static int delmsgs[128];
-static int delcnt;
-static int mrd;
+struct ReadNewMailArg {
+ int idc;
+ int *delmsgs;
+ int delcnt;
+ int mrd;
+};
static int
-read_new_mail(fileheader_t * fptr)
+read_new_mail(void * voidfptr, void *optarg)
{
- static int idc;
+ fileheader_t *fptr=(fileheader_t*)voidfptr;
+ struct ReadNewMailArg *arg=(struct ReadNewMailArg*)optarg;
char done = NA, delete_it;
char fname[256];
char genbuf[4];
- if (fptr == NULL) {
- delcnt = 0;
- idc = 0;
- return 0;
- }
- idc++;
+ arg->idc++;
if (fptr->filemode)
return 0;
clear();
@@ -698,17 +697,17 @@ read_new_mail(fileheader_t * fptr)
setuserfile(fname, fptr->filename);
fptr->filemode |= FILE_READ;
- if (substitute_record(currmaildir, fptr, sizeof(*fptr), idc))
+ if (substitute_record(currmaildir, fptr, sizeof(*fptr), arg->idc))
return -1;
- mrd = 1;
+ arg->mrd = 1;
delete_it = NA;
while (!done) {
int more_result = more(fname, YEA);
switch (more_result) {
case 999:
- mail_reply(idc, fptr, currmaildir);
+ mail_reply(arg->idc, fptr, currmaildir);
return FULLUPDATE;
case -1:
return READ_SKIP;
@@ -723,13 +722,13 @@ read_new_mail(fileheader_t * fptr)
switch (igetch()) {
case 'r':
case 'R':
- mail_reply(idc, fptr, currmaildir);
+ mail_reply(arg->idc, fptr, currmaildir);
break;
case 'x':
- m_forward(idc, fptr, currmaildir);
+ m_forward(arg->idc, fptr, currmaildir);
break;
case 'y':
- multi_reply(idc, fptr, currmaildir);
+ multi_reply(arg->idc, fptr, currmaildir);
break;
case 'd':
case 'D':
@@ -739,12 +738,23 @@ read_new_mail(fileheader_t * fptr)
}
}
if (delete_it) {
+ if(arg->delcnt==1000) {
+ vmsg("一次最多刪 1000 封信");
+ return 0;
+ }
clear();
prints("刪除信件《%s》", fptr->title);
getdata(1, 0, msg_sure_ny, genbuf, 2, LCECHO);
if (genbuf[0] == 'y') {
+ if(arg->delmsgs==NULL) {
+ arg->delmsgs=(int*)malloc(sizeof(int)*1000);
+ if(arg->delmsgs==NULL) {
+ vmsg("失敗, 請洽站長");
+ return 0;
+ }
+ }
unlink(fname);
- delmsgs[delcnt++] = idc; // FIXME 一次刪太多信 out of array boundary
+ arg->delmsgs[arg->delcnt++] = arg->idc;
mailsum = mailkeep = 0;
}
}
@@ -755,24 +765,26 @@ read_new_mail(fileheader_t * fptr)
int
m_new()
{
+ struct ReadNewMailArg arg;
clear();
- mrd = 0;
setutmpmode(RMAIL);
- read_new_mail(NULL);
+ memset(&arg, 0, sizeof(arg));
clear();
curredit |= EDIT_MAIL;
curredit &= ~EDIT_ITEM;
- if (apply_record(currmaildir, read_new_mail, sizeof(fileheader_t)) == -1) {
+ if (apply_record(currmaildir, read_new_mail, sizeof(fileheader_t), &arg) == -1) {
+ if(arg.delmsgs)
+ free(arg.delmsgs);
vmsg("沒有新信件了");
return -1;
}
curredit = 0;
currutmp->mailalert = load_mailalert(cuser.userid);
- if (delcnt) {
- while (delcnt--)
- delete_record(currmaildir, sizeof(fileheader_t), delmsgs[delcnt]);
- }
- vmsg(mrd ? "信已閱\畢" : "沒有新信件了");
+ while (arg.delcnt--)
+ delete_record(currmaildir, sizeof(fileheader_t), arg.delmsgs[arg.delcnt]);
+ if(arg.delmsgs)
+ free(arg.delmsgs);
+ vmsg(arg.mrd ? "信已閱\畢" : "沒有新信件了");
return -1;
}
diff --git a/mbbsd/record.c b/mbbsd/record.c
index 28e6dee9..7de68780 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -443,7 +443,7 @@ safe_article_delete_range(char *direct, int from, int to)
#endif
int
-apply_record(char *fpath, int (*fptr) (), int size){
+apply_record(char *fpath, int (*fptr) (void *item, void *optarg), int size, void *arg){
char abuf[BUFSIZE];
int fp;
@@ -451,7 +451,7 @@ apply_record(char *fpath, int (*fptr) (), int size){
return -1;
while (read(fp, abuf, size) == (size_t)size)
- if ((*fptr) (abuf) == QUIT) {
+ if ((*fptr) (abuf, arg) == QUIT) {
close(fp);
return QUIT;
}