New experimental full mail scan

This commit is contained in:
Andrew Pamment 2017-10-12 20:24:55 +10:00
parent 1d7d4d4f9a
commit ce65048a98
4 changed files with 162 additions and 26 deletions

View File

@ -283,6 +283,8 @@ extern void post_message(struct user_record *user);
extern void msg_conf_sub_bases();
extern void msgbase_reset_pointers(int conference, int msgarea);
extern void msgbase_reset_all_pointers();
extern void full_mail_scan(struct user_record *user);
extern void read_new_msgs(struct user_record *user, struct msg_headers *msghs);
extern void rundoor(struct user_record *user, char *cmd, int stdio, char *codepage);
extern void runexternal(struct user_record *user, char *cmd, int stdio, char **argv, char *cwd, int raw, char *codepage);

View File

@ -105,6 +105,11 @@ int l_bbsGetEmailCount(lua_State *L) {
return 1;
}
int l_bbsFullMailScan(lua_State *L) {
full_mail_scan(gUser);
return 0;
}
int l_bbsMailScan(lua_State *L) {
mail_scan(gUser);
return 0;
@ -201,6 +206,8 @@ void lua_push_cfunctions(lua_State *L) {
lua_setglobal(L, "bbs_get_info");
lua_pushcfunction(L, l_bbsFileScan);
lua_setglobal(L, "bbs_file_scan");
lua_pushcfunction(L, l_bbsFullMailScan);
lua_setglobal(L, "bbs_full_mail_scan");
}
void do_lua_script(char *script) {

View File

@ -1899,6 +1899,49 @@ void read_message(struct user_record *user, struct msg_headers *msghs, int mailn
}
}
void read_new_msgs(struct user_record *user, struct msg_headers *msghs) {
s_JamBase *jb;
s_JamLastRead jlr;
int all_unread;
int i;
int k;
char buffer[7];
// list mail in message base
if (msghs != NULL && msghs->msg_count > 0) {
jb = open_jam_base(conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
if (!jb) {
dolog("Error opening JAM base.. %s", conf.mail_conferences[user->cur_mail_conf]->mail_areas[user->cur_mail_area]->path);
return;
} else {
all_unread = 0;
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
jlr.LastReadMsg = 0;
jlr.HighReadMsg = 0;
all_unread = 1;
} else if (jlr.LastReadMsg == 0 && jlr.HighReadMsg == 0) {
all_unread = 1;
}
JAM_CloseMB(jb);
if (all_unread == 0) {
k = jlr.HighReadMsg;
for (i=0;i<msghs->msg_count;i++) {
if (msghs->msgs[i]->msg_h->MsgNum == k) {
break;
}
}
i += 2;
} else {
i = 1;
}
if (i > 0 && i <= msghs->msg_count) {
read_message(user, msghs, i - 1);
}
}
}
}
void read_mail(struct user_record *user) {
struct msg_headers *msghs;
s_JamBase *jb;
@ -2577,7 +2620,9 @@ void prev_mail_area(struct user_record *user) {
}
}
void mail_scan(struct user_record *user) {
void do_mail_scan(struct user_record *user, int oldscan) {
s_JamBase *jb;
s_JamBaseHeader jbh;
s_JamLastRead jlr;
@ -2586,6 +2631,8 @@ void mail_scan(struct user_record *user) {
int i;
int j;
int lines = 0;
int orig_conf;
int orig_area;
s_printf(get_string(139));
c = s_getc();
@ -2616,10 +2663,12 @@ void mail_scan(struct user_record *user) {
dolog("Unable to open message base");
continue;
}
if (JAM_ReadMBHeader(jb, &jbh) != 0) {
JAM_CloseMB(jb);
continue;
}
if (JAM_ReadLastRead(jb, user->id, &jlr) == JAM_NO_USER) {
if (jbh.ActiveMsgs == 0) {
JAM_CloseMB(jb);
@ -2629,6 +2678,7 @@ void mail_scan(struct user_record *user) {
msghs = read_message_headers(i, j, user);
if (msghs != NULL) {
if (msghs->msg_count > 0) {
if (oldscan) {
s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count);
lines++;
if (lines == 22) {
@ -2636,10 +2686,23 @@ void mail_scan(struct user_record *user) {
s_getc();
lines = 0;
}
} else {
orig_conf = user->cur_mail_conf;
orig_area = user->cur_mail_area;
user->cur_mail_conf = i;
user->cur_mail_area = j;
read_new_msgs(user, msghs);
user->cur_mail_conf = orig_conf;
user->cur_mail_area = orig_area;
}
}
free_message_headers(msghs);
}
} else {
if (oldscan) {
s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs);
lines++;
if (lines == 22) {
@ -2647,6 +2710,24 @@ void mail_scan(struct user_record *user) {
s_getc();
lines = 0;
}
} else {
msghs = read_message_headers(i, j, user);
if (msghs != NULL) {
if (msghs->msg_count > 0) {
orig_conf = user->cur_mail_conf;
orig_area = user->cur_mail_area;
user->cur_mail_conf = i;
user->cur_mail_area = j;
read_new_msgs(user, msghs);
user->cur_mail_conf = orig_conf;
user->cur_mail_area = orig_area;
}
free_message_headers(msghs);
}
}
}
} else {
if (jlr.HighReadMsg < jbh.ActiveMsgs) {
@ -2655,6 +2736,7 @@ void mail_scan(struct user_record *user) {
if (msghs != NULL) {
if (msghs->msg_count > 0) {
if (msghs->msgs[msghs->msg_count-1]->msg_no > jlr.HighReadMsg) {
if (oldscan) {
s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msgs[msghs->msg_count-1]->msg_h->MsgNum - jlr.HighReadMsg);
lines++;
if (lines == 22) {
@ -2662,11 +2744,24 @@ void mail_scan(struct user_record *user) {
s_getc();
lines = 0;
}
} else {
orig_conf = user->cur_mail_conf;
orig_area = user->cur_mail_area;
user->cur_mail_conf = i;
user->cur_mail_area = j;
read_new_msgs(user, msghs);
user->cur_mail_conf = orig_conf;
user->cur_mail_area = orig_area;
}
}
}
free_message_headers(msghs);
}
} else {
if (oldscan) {
s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs - jlr.HighReadMsg);
lines++;
if (lines == 22) {
@ -2674,6 +2769,24 @@ void mail_scan(struct user_record *user) {
s_getc();
lines = 0;
}
} else {
msghs = read_message_headers(i, j, user);
if (msghs != NULL) {
if (msghs->msg_count > 0) {
orig_conf = user->cur_mail_conf;
orig_area = user->cur_mail_area;
user->cur_mail_conf = i;
user->cur_mail_area = j;
read_new_msgs(user, msghs);
user->cur_mail_conf = orig_conf;
user->cur_mail_area = orig_area;
}
free_message_headers(msghs);
}
}
}
} else {
JAM_CloseMB(jb);
@ -2688,6 +2801,14 @@ void mail_scan(struct user_record *user) {
}
}
void full_mail_scan(struct user_record *user) {
do_mail_scan(user, 0);
}
void mail_scan(struct user_record *user) {
do_mail_scan(user, 1);
}
void msg_conf_sub_bases() {
int i;

View File

@ -50,6 +50,7 @@
#define MENU_RESETPOINTERS 40
#define MENU_RESETALLPOINTERS 41
#define MENU_FILESCAN 42
#define MENU_FULLMAILSCAN 43
extern struct bbs_config conf;
extern struct user_record *gUser;
@ -200,6 +201,8 @@ int menu_system(char *menufile) {
menu[menu_items-1]->command = MENU_RESETALLPOINTERS;
} else if (strncasecmp(&buffer[8], "FILESCAN", 8) == 0) {
menu[menu_items-1]->command = MENU_FILESCAN;
} else if (strncasecmp(&buffer[8], "FULLMAILSCAN", 12) == 0) {
menu[menu_items-1]->command = MENU_FULLMAILSCAN;
}
} else if (strncasecmp(buffer, "SECLEVEL", 8) == 0) {
menu[menu_items-1]->seclevel = atoi(&buffer[9]);
@ -501,6 +504,9 @@ int menu_system(char *menufile) {
case MENU_FILESCAN:
file_scan();
break;
case MENU_FULLMAILSCAN:
full_mail_scan(gUser);
break;
default:
break;
}