src.warn-filecount
changeset 29 89ea60e88edf
equal deleted inserted replaced
28:10d2d38cf564 29:89ea60e88edf
       
     1 # HG changeset patch
       
     2 # Parent 8d6f7028bb88356841de22bf3dd6190d20537ce3
       
     3 
       
     4 diff -r 8d6f7028bb88 doc/spec.txt
       
     5 --- a/doc/spec.txt	Thu Jun 02 23:26:40 2011 +0200
       
     6 +++ b/doc/spec.txt	Wed Jun 08 23:30:53 2011 +0200
       
     7 @@ -18932,7 +18932,7 @@
       
     8  changed by setting quota_is_inclusive false. When this is done, the check for
       
     9  exceeding the quota does not include the current message. Thus, deliveries
       
    10  continue until the quota has been exceeded; thereafter, no further messages are
       
    11 -delivered. See also quota_warn_threshold.
       
    12 +delivered. See also quota_warn_threshold and quota_filecount_warn_threshold.
       
    13  
       
    14  +---------------+---------------+-------------+--------------+
       
    15  |quota_directory|Use: appendfile|Type: string*|Default: unset|
       
    16 @@ -18995,14 +18995,15 @@
       
    17  +------------------+---------------+-------------+------------------+
       
    18  
       
    19  See below for the use of this option. If it is not set when 
       
    20 -quota_warn_threshold is set, it defaults to
       
    21 +quota_warn_threshold or quota_filecount_warn_threshold is set, 
       
    22 +it defaults to
       
    23  
       
    24  quota_warn_message = "\
       
    25    To: $local_part@$domain\n\
       
    26    Subject: Your mailbox\n\n\
       
    27    This message is automatically created \
       
    28    by mail delivery software.\n\n\
       
    29 -  The size of your mailbox has exceeded \
       
    30 +  The size or filecount of your mailbox has exceeded \
       
    31    a warning threshold that is\n\
       
    32    set by the system administrator.\n"
       
    33  
       
    34 @@ -19037,6 +19038,14 @@
       
    35  independent of one another except when the threshold is specified as a
       
    36  percentage.
       
    37  
       
    38 ++------------------------------+---------------+-------------+----------+
       
    39 +|quota_filecount_warn_threshold|Use: appendfile|Type: string*|Default: 0|
       
    40 ++------------------------------+---------------+-------------+----------+
       
    41 +
       
    42 +See quota_warn_threshold. The only difference is that the
       
    43 +quota_filecount_warn_threshold applies to the number of messages and not to the
       
    44 +size of the mailbox.
       
    45 +
       
    46  +---------+---------------+-------------+--------------+
       
    47  |use_bsmtp|Use: appendfile|Type: boolean|Default: false|
       
    48  +---------+---------------+-------------+--------------+
       
    49 diff -r 8d6f7028bb88 src/transports/appendfile.c
       
    50 --- a/src/transports/appendfile.c	Thu Jun 02 23:26:40 2011 +0200
       
    51 +++ b/src/transports/appendfile.c	Wed Jun 08 23:30:53 2011 +0200
       
    52 @@ -29,8 +29,17 @@
       
    53  /* Check warn threshold only if quota size set or not a percentage threshold
       
    54     percentage check should only be done if quota > 0 */
       
    55  
       
    56 -#define THRESHOLD_CHECK  (ob->quota_warn_threshold_value > 0 && \
       
    57 -  (!ob->quota_warn_threshold_is_percent || ob->quota_value > 0))
       
    58 +#define _THRESHOLD_CHECK(threshold, is_percent, quota) (threshold > 0 && (!is_percent || quota > 0))
       
    59 +
       
    60 +#define THRESHOLD_CHECK1 _THRESHOLD_CHECK(ob->quota_warn_threshold_value, \
       
    61 +                                          ob->quota_warn_threshold_is_percent, \
       
    62 +                                          ob->quota_value)  
       
    63 +
       
    64 +#define THRESHOLD_CHECK2 _THRESHOLD_CHECK(ob->quota_filecount_warn_threshold_value, \
       
    65 +                                          ob->quota_filecount_warn_threshold_is_percent, \
       
    66 +                                          ob->quota_filecount_value)  
       
    67 +
       
    68 +#define THRESHOLD_CHECK (THRESHOLD_CHECK1 || THRESHOLD_CHECK2)
       
    69  
       
    70  
       
    71  /* Options specific to the appendfile transport. They must be in alphabetic
       
    72 @@ -145,6 +154,8 @@
       
    73        (void *)offsetof(appendfile_transport_options_block, quota_directory) },
       
    74    { "quota_filecount",   opt_stringptr,
       
    75        (void *)offsetof(appendfile_transport_options_block, quota_filecount) },
       
    76 +  { "quota_filecount_warn_threshold",   opt_stringptr,
       
    77 +      (void *)offsetof(appendfile_transport_options_block, quota_filecount_warn_threshold) },
       
    78    { "quota_is_inclusive", opt_bool,
       
    79        (void *)offsetof(appendfile_transport_options_block, quota_is_inclusive) },
       
    80    { "quota_size_regex",   opt_stringptr,
       
    81 @@ -189,6 +200,7 @@
       
    82    NULL,           /* quota_filecount */
       
    83    NULL,           /* quota_size_regex */
       
    84    NULL,           /* quota_warn_threshold */
       
    85 +  NULL,           /* quota_filecount_warn_threshold */
       
    86    NULL,           /* mailbox_size_string */
       
    87    NULL,           /* mailbox_filecount_string */
       
    88    NULL,           /* expand_maildir_use_size_file */ 
       
    89 @@ -206,6 +218,7 @@
       
    90    -1,             /* mailbox_size_value */
       
    91    -1,             /* mailbox_filecount_value */
       
    92    0,              /* quota_filecount_value */
       
    93 +  0,              /* quota_filecount_warn_threshold_value */
       
    94    APPENDFILE_MODE,           /* mode */
       
    95    APPENDFILE_DIRECTORY_MODE, /* dirmode */
       
    96    APPENDFILE_LOCKFILE_MODE,  /* lockfile_mode */
       
    97 @@ -240,6 +253,7 @@
       
    98    FALSE,          /* mailstore_format */
       
    99    FALSE,          /* mbx_format */
       
   100    FALSE,          /* quota_warn_threshold_is_percent */
       
   101 +  FALSE,          /* quota_filecount_warn_threshold_is_percent */
       
   102    TRUE,           /* quota_is_inclusive */
       
   103    FALSE,          /* quota_no_check */
       
   104    FALSE           /* quota_filecount_no_check */
       
   105 @@ -311,10 +325,10 @@
       
   106    ob->maildir_use_size_file = expand_check_condition(ob->expand_maildir_use_size_file, 
       
   107      US"`maildir_use_size_file` in transport", tblock->name);
       
   108  
       
   109 -/* Loop for quota, quota_filecount, quota_warn_threshold, mailbox_size,
       
   110 +/* Loop for quota, quota_filecount, quota_warn_threshold, quota_filecount_warn_threshold, mailbox_size,
       
   111  mailbox_filecount */
       
   112  
       
   113 -for (i = 0; i < 5; i++)
       
   114 +for (i = 0; i < 6; i++)
       
   115    {
       
   116    double d;
       
   117    int no_check = 0;
       
   118 @@ -353,6 +367,18 @@
       
   119        ob->quota_warn_threshold_is_percent = TRUE;
       
   120        rest++;
       
   121        }
       
   122 +    else if (*rest == '%' && i == 3)
       
   123 +      {
       
   124 +      if (ob->quota_filecount_value <= 0 && !ob->maildir_use_size_file) d = 0;
       
   125 +      else if ((int)d < 0 || (int)d > 100)
       
   126 +        {
       
   127 +        *errmsg = string_sprintf("Invalid quota_filecount_warn_threshold percentage (%d)"
       
   128 +          " for %s transport", (int)d, tblock->name);
       
   129 +        return FAIL;
       
   130 +        }
       
   131 +      ob->quota_filecount_warn_threshold_is_percent = TRUE;
       
   132 +      rest++;
       
   133 +      }
       
   134  
       
   135  
       
   136      /* For quota and quota_filecount there may be options
       
   137 @@ -395,18 +421,26 @@
       
   138      if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4)
       
   139        which = US"quota_warn_threshold";
       
   140      ob->quota_warn_threshold_value = (off_t)d;
       
   141 +    q = ob->quota_filecount_warn_threshold;
       
   142 +    default_value = -1.0;
       
   143 +    break;
       
   144 +
       
   145 +    case 3:
       
   146 +    if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4)
       
   147 +      which = US"quota_filecount_warn_threshold";
       
   148 +    ob->quota_filecount_warn_threshold_value = (off_t)d;
       
   149      q = ob->mailbox_size_string;
       
   150      default_value = -1.0;
       
   151      break;
       
   152  
       
   153 -    case 3:
       
   154 +    case 4:
       
   155      if (d >= 2.0*1024.0*1024.0*1024.0 && sizeof(off_t) <= 4)
       
   156        which = US"mailbox_size";;
       
   157      ob->mailbox_size_value = (off_t)d;
       
   158      q = ob->mailbox_filecount_string;
       
   159      break;
       
   160  
       
   161 -    case 4:
       
   162 +    case 5:
       
   163      if (d >= 2.0*1024.0*1024.0*1024.0) which = US"mailbox_filecount";
       
   164      ob->mailbox_filecount_value = (int)d;
       
   165      break;
       
   166 @@ -557,13 +591,13 @@
       
   167  not be used if the actual threshold for a given delivery ends up as zero,
       
   168  of if it's given as a percentage and there's no quota setting. */
       
   169  
       
   170 -if (ob->quota_warn_threshold != NULL)
       
   171 +if (ob->quota_warn_threshold != NULL || ob->quota_filecount_warn_threshold != NULL)
       
   172    {
       
   173    if (tblock->warn_message == NULL) tblock->warn_message = US
       
   174      "To: $local_part@$domain\n"
       
   175      "Subject: Your mailbox\n\n"
       
   176      "This message is automatically created by mail delivery software (Exim).\n\n"
       
   177 -    "The size of your mailbox has exceeded a warning threshold that is\n"
       
   178 +    "The size or message count of your mailbox has exceeded a warning threshold that is\n"
       
   179      "set by the system administrator.\n";
       
   180    }
       
   181  
       
   182 @@ -1424,13 +1458,15 @@
       
   183    {
       
   184    debug_printf("appendfile: mode=%o notify_comsat=%d quota=" OFF_T_FMT
       
   185      "%s"
       
   186 -    " warning=" OFF_T_FMT "%s\n"
       
   187 +    " warning=" OFF_T_FMT "%s / %d%s\n"
       
   188      "  %s=%s format=%s\n  message_prefix=%s\n  message_suffix=%s\n  "
       
   189      "maildir_use_size_file=%s\n",
       
   190      mode, ob->notify_comsat, ob->quota_value,
       
   191      ob->quota_no_check? " (no_check)" : "",
       
   192      ob->quota_warn_threshold_value,
       
   193      ob->quota_warn_threshold_is_percent? "%" : "",
       
   194 +    ob->quota_filecount_warn_threshold_value,
       
   195 +    ob->quota_filecount_warn_threshold_is_percent? "%" : "",
       
   196      isdirectory? "directory" : "file",
       
   197      path, mailbox_formats[mbformat],
       
   198      (ob->message_prefix == NULL)? US"null" : string_printing(ob->message_prefix),
       
   199 @@ -3031,16 +3067,21 @@
       
   200  if (!disable_quota && THRESHOLD_CHECK)
       
   201    {
       
   202    off_t threshold = ob->quota_warn_threshold_value;
       
   203 +  int filecount_threshold = ob->quota_filecount_warn_threshold_value;
       
   204    if (ob->quota_warn_threshold_is_percent)
       
   205      threshold = (off_t)(((double)ob->quota_value * threshold) / 100);
       
   206 +  if (ob->quota_filecount_warn_threshold_is_percent)
       
   207 +    filecount_threshold = (int)(((double)ob->quota_filecount_value * filecount_threshold) / 100);
       
   208    DEBUG(D_transport)
       
   209      debug_printf("quota = " OFF_T_FMT
       
   210 -      " threshold = " OFF_T_FMT
       
   211 +      " threshold = " OFF_T_FMT "/%d"
       
   212        " old size = " OFF_T_FMT
       
   213 -      " message size = %d\n",
       
   214 -      ob->quota_value, threshold, mailbox_size,
       
   215 -      message_size);
       
   216 -  if (mailbox_size <= threshold && mailbox_size + message_size > threshold)
       
   217 +      " message size = %d"
       
   218 +      " filecount = %d\n",
       
   219 +      ob->quota_value, threshold, filecount_threshold, mailbox_size,
       
   220 +      message_size, mailbox_filecount);
       
   221 +  if ((mailbox_size <= threshold && mailbox_size + message_size > threshold)
       
   222 +    ||(mailbox_filecount + 1 == filecount_threshold))
       
   223      addr->special_action = SPECIAL_WARN;
       
   224  
       
   225    /******* You might think that the test ought to be this:
       
   226 diff -r 8d6f7028bb88 src/transports/appendfile.h
       
   227 --- a/src/transports/appendfile.h	Thu Jun 02 23:26:40 2011 +0200
       
   228 +++ b/src/transports/appendfile.h	Wed Jun 08 23:30:53 2011 +0200
       
   229 @@ -21,6 +21,7 @@
       
   230    uschar *quota_filecount;
       
   231    uschar *quota_size_regex;
       
   232    uschar *quota_warn_threshold;
       
   233 +  uschar *quota_filecount_warn_threshold;
       
   234    uschar *mailbox_size_string;
       
   235    uschar *mailbox_filecount_string;
       
   236    uschar *expand_maildir_use_size_file;
       
   237 @@ -38,6 +39,7 @@
       
   238    off_t mailbox_size_value;
       
   239    int   mailbox_filecount_value;
       
   240    int   quota_filecount_value;
       
   241 +  int   quota_filecount_warn_threshold_value;
       
   242    int   mode;
       
   243    int   dirmode;
       
   244    int   lockfile_mode;
       
   245 @@ -72,6 +74,7 @@
       
   246    BOOL  mailstore_format;
       
   247    BOOL  mbx_format;
       
   248    BOOL  quota_warn_threshold_is_percent;
       
   249 +  BOOL  quota_filecount_warn_threshold_is_percent;
       
   250    BOOL  quota_is_inclusive;
       
   251    BOOL  quota_no_check;
       
   252    BOOL  quota_filecount_no_check;