From ce65048a982c8da6d69e0255df2d52416efafe39 Mon Sep 17 00:00:00 2001 From: Andrew Pamment Date: Thu, 12 Oct 2017 20:24:55 +1000 Subject: [PATCH] New experimental full mail scan --- src/bbs.h | 2 + src/lua_glue.c | 7 ++ src/mail_menu.c | 173 ++++++++++++++++++++++++++++++++++++++++-------- src/menus.c | 6 ++ 4 files changed, 162 insertions(+), 26 deletions(-) diff --git a/src/bbs.h b/src/bbs.h index 60ed07a..b652540 100644 --- a/src/bbs.h +++ b/src/bbs.h @@ -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); diff --git a/src/lua_glue.c b/src/lua_glue.c index 7db851e..d560aca 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -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) { diff --git a/src/mail_menu.c b/src/mail_menu.c index 0e3eb9e..79a516a 100644 --- a/src/mail_menu.c +++ b/src/mail_menu.c @@ -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;imsg_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,7 +2631,9 @@ 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,23 +2678,55 @@ void mail_scan(struct user_record *user) { msghs = read_message_headers(i, j, user); if (msghs != NULL) { if (msghs->msg_count > 0) { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); - lines++; - if (lines == 22) { - s_printf(get_string(6)); - s_getc(); - lines = 0; + if (oldscan) { + s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, msghs->msg_count); + lines++; + if (lines == 22) { + s_printf(get_string(6)); + 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 { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); - lines++; - if (lines == 22) { - s_printf(get_string(6)); - s_getc(); - lines = 0; + if (oldscan) { + s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs); + lines++; + if (lines == 22) { + s_printf(get_string(6)); + 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 { @@ -2655,24 +2736,56 @@ 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) { - 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) { - s_printf(get_string(6)); - s_getc(); - lines = 0; + 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) { + s_printf(get_string(6)); + 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 { - s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs - jlr.HighReadMsg); - lines++; - if (lines == 22) { - s_printf(get_string(6)); - s_getc(); - lines = 0; + if (oldscan) { + s_printf(get_string(141), j, conf.mail_conferences[i]->mail_areas[j]->name, jbh.ActiveMsgs - jlr.HighReadMsg); + lines++; + if (lines == 22) { + s_printf(get_string(6)); + 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 { @@ -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; diff --git a/src/menus.c b/src/menus.c index 9dbdd04..5f7af12 100644 --- a/src/menus.c +++ b/src/menus.c @@ -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; }