From 72efc25bb00c303ebb2f85fc8222b9e27c361e17 Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 4 Nov 2011 12:41:49 +0000 Subject: enforce mail box clean up if > 100 x MailboxSize git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5456 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- pttbbs/include/perm.h | 3 ++- pttbbs/include/proto.h | 1 + pttbbs/mbbsd/mail.c | 25 +++++++++++++++++++++---- pttbbs/mbbsd/mbbsd.c | 8 ++++---- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pttbbs/include/perm.h b/pttbbs/include/perm.h index 6cccf2f0..302ed73e 100644 --- a/pttbbs/include/perm.h +++ b/pttbbs/include/perm.h @@ -45,7 +45,8 @@ #define PERM_DEFAULT (PERM_BASIC | PERM_CHAT | PERM_PAGE ) #define PERM_MANAGER (PERM_ACCTREG | PERM_ACTION | PERM_PAINT) -#define PERM_ADMIN (PERM_ACCOUNTS | PERM_SYSOP | PERM_SYSSUBOP | PERM_SYSSUPERSUBOP | PERM_MANAGER) +#define PERM_ADMIN (PERM_ACCOUNTS | PERM_BOARD | PERM_SYSOP | \ + PERM_SYSSUBOP | PERM_SYSSUPERSUBOP | PERM_MANAGER) #define PERM_ALLBOARD (PERM_SYSOP | PERM_BOARD) #define PERM_LOGINCLOAK (PERM_SYSOP | PERM_ACCOUNTS) #define PERM_SEEULEVELS (PERM_SYSOP) diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 5bd1a809..97b481ad 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -363,6 +363,7 @@ int bsmtp(const char *fpath, const char *title, const char *rcpt, const char *fr void hold_mail(const char *fpath, const char *receiver, const char *title); void m_init(void); int chkmailbox(void); +int chkmailbox_hard_limit(void); int mail_man(void); int m_new(void); int m_send(void); diff --git a/pttbbs/mbbsd/mail.c b/pttbbs/mbbsd/mail.c index 82a51e2d..7a5f95a0 100644 --- a/pttbbs/mbbsd/mail.c +++ b/pttbbs/mbbsd/mail.c @@ -315,6 +315,8 @@ setupmailusage(void) #define MAILBOX_LIM_OK 0 #define MAILBOX_LIM_KEEP 1 +#define MAILBOX_LIM_HARD 2 + static int chk_mailbox_limit(void) { @@ -324,9 +326,14 @@ chk_mailbox_limit(void) if (!mailkeep) setupmailusage(); - if (mailkeep > mailmaxkeep) - return MAILBOX_LIM_KEEP; - return MAILBOX_LIM_OK; + if (mailkeep < mailmaxkeep) + return MAILBOX_LIM_OK; + + if ((mailkeep / 100 < mailmaxkeep) + || HasUserPerm(PERM_ADMIN)) + return MAILBOX_LIM_KEEP; + else + return MAILBOX_LIM_HARD; } int @@ -335,8 +342,9 @@ chkmailbox(void) m_init(); switch (chk_mailbox_limit()) { - case MAILBOX_LIM_KEEP: + case MAILBOX_LIM_HARD: bell(); + case MAILBOX_LIM_KEEP: bell(); vmsgf("您保存信件數目 %d 超出上限 %d, 請整理", mailkeep, mailmaxkeep); return mailkeep; @@ -346,6 +354,15 @@ chkmailbox(void) } } +int +chkmailbox_hard_limit() { + if (chk_mailbox_limit() == MAILBOX_LIM_HARD) { + vmsgf("您保存信件數目 %d 遠超出上限 %d, 請整理", mailkeep, mailmaxkeep); + return 1; + } + return 0; +} + static void do_hold_mail(const char *fpath, const char *receiver, const char *holder, const char *save_title) { diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c index 1d6347bb..ca0d4e4b 100644 --- a/pttbbs/mbbsd/mbbsd.c +++ b/pttbbs/mbbsd/mbbsd.c @@ -1137,8 +1137,9 @@ inline static void birthday_make_a_wish(const struct tm *ptime, const struct tm inline static void check_mailbox_quota(void) { - if (chkmailbox()) - m_read(); + if (chkmailbox()) do { + m_read(); + } while (chkmailbox_hard_limit()); } static void init_guest_info(void) @@ -1249,11 +1250,11 @@ user_login(void) append_log_recent_login(); check_bad_login(); - check_mailbox_quota(); check_register(); pwcuLoginSave(); // is_first_login_of_today is only valid after pwcuLoginSave. // cuser.lastlogin 由 pwcuLoginSave 後值就變了,要看 last_login_time restore_backup(); + check_mailbox_quota(); // XXX 這個 check 花不少時間,有點間隔比較好 if (HasUserPerm(PERM_BM) && @@ -1281,7 +1282,6 @@ user_login(void) outs("抱歉,您的帳號資料異常或已被停權。\n"); pressanykey(); exit(1); - // check_mailbox_quota(); } if(ptime.tm_yday!=lasttime.tm_yday) -- cgit v1.2.3