Beispiel #1
0
/* Same as is_valid_mailbox (see below) but operates on non-nul
   terminated buffer.  */
int
is_valid_mailbox_mem (const void *name_arg, size_t namelen)
{
  const char *name = name_arg;

  return !( !name
            || !namelen
            || has_invalid_email_chars (name, namelen)
            || mem_count_chr (name, '@', namelen) != 1
            || *name == '@'
            || name[namelen-1] == '@'
            || name[namelen-1] == '.'
            || my_memstr (name, namelen, ".."));
}
Beispiel #2
0
/* Return true if the record RECORD has been selected.  The GETVAL
 * function is called with COOKIE and the NAME of a property used in
 * the expression.  */
int
recsel_select (recsel_expr_t selector,
               const char *(*getval)(void *cookie, const char *propname),
               void *cookie)
{
  recsel_expr_t se;
  const char *value;
  size_t selen, valuelen;
  long numvalue;
  int result = 1;

  se = selector;
  while (se)
    {
      value = getval? getval (cookie, se->name) : NULL;
      if (!value)
        value = "";

      if (!*value)
        {
          /* Field is empty.  */
          result = 0;
        }
      else /* Field has a value.  */
        {
          valuelen = strlen (value);
          numvalue = strtol (value, NULL, 0);
          selen = strlen (se->value);

          switch (se->op)
            {
            case SELECT_SAME:
              if (se->xcase)
                result = (valuelen==selen && !memcmp (value,se->value,selen));
              else
                result = (valuelen==selen && !memicmp (value,se->value,selen));
              break;
            case SELECT_SUB:
              if (se->xcase)
                result = !!my_memstr (value, valuelen, se->value);
              else
                result = !!memistr (value, valuelen, se->value);
              break;
            case SELECT_NONEMPTY:
              result = !!valuelen;
              break;
            case SELECT_ISTRUE:
              result = !!numvalue;
              break;
            case SELECT_EQ:
              result = (numvalue == se->numvalue);
              break;
            case SELECT_GT:
              result = (numvalue > se->numvalue);
              break;
            case SELECT_GE:
              result = (numvalue >= se->numvalue);
              break;
            case SELECT_LT:
              result = (numvalue < se->numvalue);
              break;
            case SELECT_LE:
              result = (numvalue <= se->numvalue);
              break;
            }
        }

      if (se->not)
        result = !result;

      if (result)
        {
          /* This expression evaluated to true.  See wether there are
             remaining expressions in this conjunction.  */
          if (!se->next || se->next->disjun)
            break; /* All expressions are true.  Return True.  */
          se = se->next;  /* Test the next.  */
        }
      else
        {
          /* This expression evaluated to false and thus the
           * conjuction evaluates to false.  We skip over the
           * remaining expressions of this conjunction and continue
           * with the next disjunction if any.  */
          do
            se = se->next;
          while (se && !se->disjun);
        }
    }

  return result;
}