Skip to content

Commit

Permalink
Check recipient mailbox limit when forwarding inner mail
Browse files Browse the repository at this point in the history
  • Loading branch information
robertabcd committed Jan 18, 2021
1 parent 86f1574 commit 4d56e77
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
34 changes: 29 additions & 5 deletions mbbsd/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ loadmailusage(void)
mailkeep = get_num_records(currmaildir,sizeof(fileheader_t));
}

int
static int
get_max_keepmail(const userec_t *u) {
int lvl = u->userlevel;
int keep = MAX_KEEPMAIL; // default: 200
Expand Down Expand Up @@ -302,12 +302,31 @@ setupmailusage(void)
loadmailusage();
}

static int
get_user_mailbox_usage(const char *userid)
{
char fpath[PATHLEN];
sethomedir(fpath, userid);
return get_num_records(fpath, sizeof(fileheader_t));
}

static int
get_user_mailbox_limit(const char *userid)
{
int limit = -1;
userec_t u = {};
if (passwd_load_user(userid, &u) > 0)
limit = get_max_keepmail(&u);
memset(&u, 0, sizeof(u));
return limit;
}

#define MAILBOX_LIM_OK 0
#define MAILBOX_LIM_KEEP 1
#define MAILBOX_LIM_HARD 2

static int
chk_mailbox_limit(void)
chk_cuser_mailbox_limit(void)
{
if (HasUserPerm(PERM_SYSOP) || HasUserPerm(PERM_MAILLIMIT))
return MAILBOX_LIM_OK;
Expand Down Expand Up @@ -411,7 +430,12 @@ send_inner_mail(const char *fpath, const char *title, const char *receiver) {
/* to avoid DDOS of disk */
sethomedir(fname, rightid);
if (strcmp(rightid, cuser.userid) == 0) {
if (chk_mailbox_limit())
if (chk_cuser_mailbox_limit())
return -4;
} else {
int limit = get_user_mailbox_limit(rightid);
/* okay for failure: limit < 0 */
if (limit && get_user_mailbox_usage(rightid) >= limit)
return -4;
}

Expand Down Expand Up @@ -686,7 +710,7 @@ chkmailbox(void)
{
m_init();

switch (chk_mailbox_limit()) {
switch (chk_cuser_mailbox_limit()) {
case MAILBOX_LIM_HARD:
bell();
case MAILBOX_LIM_KEEP:
Expand All @@ -701,7 +725,7 @@ chkmailbox(void)

int
chkmailbox_hard_limit() {
if (chk_mailbox_limit() == MAILBOX_LIM_HARD) {
if (chk_cuser_mailbox_limit() == MAILBOX_LIM_HARD) {
vmsgf("您保存信件數目 %d 遠超出上限 %d, 請整理", mailkeep, mailmaxkeep);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion mbbsd/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ forward_file(const fileheader_t * fhdr, const char *direct)
#endif
break;
case -4:
vmsg("信箱已滿");
vmsg("對方信箱已滿");
break;
default:
break;
Expand Down

0 comments on commit 4d56e77

Please sign in to comment.