回精華區
作者itoc.bbs@xeon.tfcis.org (核心動力) 看板: plan
標題Re: [問題] 限制個人信箱容量
時間動力核心 (Tue, 04 Nov 2003 09:16:36 +0800 (CST)) Updated: 2005/05/17
※ 引述《cpd.bbs@pitch.twbbs.org (Seasons)》之銘言:
> 就是我想要限制每個使用者的信箱使用容量(原本只有限制篇數)...
> 要是信箱使用超過上限,就限制只能到郵件選單,除非刪除一些信才能離開郵件選單..

: config.h

#define MAX_BBSMAIL     500             /* PERM_MBOX 收信上限(封) */
#define MAX_VALIDMAIL   300             /* 認證 user 收信上限(封) */
#define MAX_NOVALIDMAIL 100             /* 未認證 user 收信上限(封) */

+ #define MAX_BBSMAILSIZE     1024000       /* PERM_MBOX 容量上限(byte) */
+ #define MAX_VALIDMAILSIZE   512000        /* 認證 user 容量上限(byte) */
+ #define MAX_NOVALIDMAILSIZE 204800        /* 未認證 user 容量上限(byte) */

: bbsd.c:m_overflow() 加在 tn_motd() 前面

static int          /* 1:過大 */
m_overflow()
{
  int total_size, limit;
  char fpath[64], *ptr, *str;
  struct stat st;
  struct dirent *de;
  DIR *dirp;

  usr_fpath(fpath, cuser.userid, fn_dir);

  if (stat(fpath, &st))
    return 0;

  /* 上限幾篇 */
  if (HAS_PERM(PERM_MBOX))
    limit = MAX_BBSMAIL;
  else if (HAS_PERM(PERM_VALID))
    limit = MAX_VALIDMAIL;
  else
    limit = MAX_NOVALIDMAIL;
  if (st.st_size > sizeof(HDR) * limit)
    return 1;

  ptr = (char *) strchr(fpath, '.');
  *ptr++ = '@';
  *ptr = '\0';

  if (dirp = opendir(fpath))
  {
    /* 容量幾 byte */
    if (HAS_PERM(PERM_MBOX))
      limit = MAX_BBSMAILSIZE;
    else if (HAS_PERM(PERM_VALID))
      limit = MAX_VALIDMAILSIZE;
    else
      limit = MAX_NOVALIDMAILSIZE;

    *ptr++ = '/';
    total_size = 0;
    while (de = readdir(dirp))
    {
      str = de->d_name;
      if (*str <= ' ' || *str == '.')
        continue;
      strcpy(ptr, str);
      if (!stat(fpath, &st))
      {
        total_size += st.st_size;
        if (total_size > limit)
        {
          closedir(dirp);
          return 1;
        }
      }
    }
    closedir(dirp);
  }

  return 0;
}

: bbsd:tn_motd()

static void
tn_motd()
{
  ...
  ...

+ while (m_overflow())
+ {
+   vmsg("您的信件過多,請打包回家或刪除部分信件");
+   m_zip();
+   xover(XZ_MBOX);
+ }
}

--
  這功能很吃 I/O

--
  Origin:  Maple-itoc˙動力核心  processor.tfcis.org 
  Author: itoc itoc.dorm11.nctu.edu.tw 發表
精華選讀←離開[主題上]主題下(k)上篇(j)下篇S/a搜尋 G串列 TAB精華 ↑↓捲 Pg/Space翻