Ejemplo n.º 1
0
void
_mu_sv_instr_nop (mu_sieve_machine_t mach)
{
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: NOP\n",
		 (unsigned long) (mach->pc - 1));
}
Ejemplo n.º 2
0
void
_mu_sv_instr_line (mu_sieve_machine_t mach)
{
  mach->locus.source_line = SIEVE_ARG (mach, 0, line);
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: LINE %lu\n",
		 (unsigned long) (mach->pc - 1),
		 (unsigned long) mach->locus.source_line);
  SIEVE_ADJUST (mach, 1);
}
Ejemplo n.º 3
0
void
_mu_sv_instr_source (mu_sieve_machine_t mach)
{
  mach->locus.source_file = (char*) SIEVE_ARG (mach, 0, string);
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: SOURCE %s\n",
		    (unsigned long) (mach->pc - 1),
		    mach->locus.source_file);
  SIEVE_ADJUST (mach, 1);
}
Ejemplo n.º 4
0
/* Produce diagnostic output. */
static int
diag (mu_sieve_machine_t mach)
{
  if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE)
    {
      mu_sieve_debug (mach, "VACATION");
    }

  mu_sieve_log_action (mach, "VACATION", NULL);
  return mu_sieve_is_dry_run (mach);
}
Ejemplo n.º 5
0
void
_mu_sv_instr_not (mu_sieve_machine_t mach)
{
  if (INSTR_DEBUG (mach))
    {
      mu_sieve_debug (mach, "%4lu: NOT\n", (unsigned long)(mach->pc - 1));
      if (INSTR_DISASS (mach))
	return;
    }
  mach->reg = !mach->reg;
}
Ejemplo n.º 6
0
void
_mu_sv_instr_test (mu_sieve_machine_t mach)
{
  mach->identifier = SIEVE_ARG (mach, 3, string);
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: TEST: %s\n",
		 (unsigned long) (mach->pc - 1),
		 mach->identifier);
  mach->reg = instr_run (mach);
  mach->identifier = NULL;
}
Ejemplo n.º 7
0
void
_mu_sv_instr_action (mu_sieve_machine_t mach)
{
  mach->identifier = SIEVE_ARG (mach, 3, string);
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: ACTION: %s\n",
		 (unsigned long) (mach->pc - 1),
		 mach->identifier);
  mach->action_count++;
  instr_run (mach);
  mach->identifier = NULL;
}
Ejemplo n.º 8
0
static int
instr_run (mu_sieve_machine_t mach)
{
  mu_sieve_handler_t han = SIEVE_ARG (mach, 0, handler);
  mu_list_t arg_list = SIEVE_ARG (mach, 1, list);
  mu_list_t tag_list = SIEVE_ARG (mach, 2, list);
  int rc = 0;
  
  SIEVE_ADJUST(mach, 4);

  if (INSTR_DEBUG (mach))
    {
      mu_sieve_debug (mach, "Arguments: ");
      mu_sv_print_value_list (arg_list, mach->debug_printer, mach->data);
      mu_sieve_debug (mach, "\nTags:");
      mu_sv_print_tag_list (tag_list, mach->debug_printer, mach->data);
      mu_sieve_debug (mach, "\n");
    }

  if (!INSTR_DISASS(mach))
    rc = han (mach, arg_list, tag_list);
  return rc;
}
Ejemplo n.º 9
0
void
_mu_sv_instr_branch (mu_sieve_machine_t mach)
{
  long num = SIEVE_ARG (mach, 0, number);

  SIEVE_ADJUST (mach, 1);
  if (INSTR_DEBUG (mach))
    {
      mu_sieve_debug (mach, "%4lu: BRANCH %lu\n",
		   (unsigned long)(mach->pc-2),
		   (unsigned long)(mach->pc + num));
      if (INSTR_DISASS (mach))
	return;
    }

  mach->pc += num;
}
Ejemplo n.º 10
0
void
_mu_sv_instr_push (mu_sieve_machine_t mach)
{
  if (INSTR_DEBUG (mach))
    {
      mu_sieve_debug (mach, "%4lu: PUSH\n", (unsigned long)(mach->pc - 1));
      if (INSTR_DISASS (mach))
	return;
    }
  
  if (!mach->stack && mu_list_create (&mach->stack))
    {
      mu_sieve_error (mach, _("cannot create stack"));
      mu_sieve_abort (mach);
    }
  mu_list_prepend (mach->stack, (void*) mach->reg);
}
Ejemplo n.º 11
0
void
_mu_sv_instr_pop (mu_sieve_machine_t mach)
{
  if (INSTR_DEBUG (mach))
    {
      mu_sieve_debug (mach, "%4lu: POP\n", (unsigned long)(mach->pc - 1));
      if (INSTR_DISASS (mach))
	return;
    }

  if (!mach->stack || mu_list_is_empty (mach->stack))
    {
      mu_sieve_error (mach, _("stack underflow"));
      mu_sieve_abort (mach);
    }
  mu_list_get (mach->stack, 0, (void **)&mach->reg);
  mu_list_remove (mach->stack, (void *)mach->reg);
}
Ejemplo n.º 12
0
/* Handler for the numaddr test */
static int
numaddr_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
{
  mu_sieve_value_t *h, *v;
  struct val_ctr vc;
  int rc;
  
  if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE)
    {
      mu_sieve_debug (mach, "NUMADDR");
    }

  /* Retrieve required arguments: */
  /* First argument: list of header names */
  h = mu_sieve_value_get (args, 0);
  if (!h)
    {
      mu_sieve_error (mach, "numaddr: can't get argument 1");
      mu_sieve_abort (mach);
    }
  /* Second argument: Limit on the number of addresses */
  v = mu_sieve_value_get (args, 1);
  if (!v)
    {
      mu_sieve_error (mach, "numaddr: can't get argument 2");
      mu_sieve_abort (mach);
    }

  /* Fill in the val_ctr structure */
  mu_message_get_header (mu_sieve_get_message (mach), &vc.hdr);
  vc.count = 0;
  vc.limit = v->v.number;

  /* Count the addresses */
  rc = mu_sieve_vlist_do (h, _count_items, &vc);

  /* Here rc >= 1 iff the counted number of addresses is greater or equal
     to vc.limit. If `:under' tag was given we reverse the return value */
  if (mu_sieve_tag_lookup (tags, "under", NULL))
    rc = !rc;

  return rc;
}
Ejemplo n.º 13
0
int
sieve_run (mu_sieve_machine_t mach)
{
  if (setjmp (mach->errbuf))
    return 1;

  mach->action_count = 0;
  
  for (mach->pc = 1; mach->prog[mach->pc].handler; )
    (*mach->prog[mach->pc++].instr) (mach);

  if (mach->action_count == 0)
    mu_sieve_log_action (mach, "IMPLICIT KEEP", NULL);
  
  if (INSTR_DEBUG (mach))
    mu_sieve_debug (mach, "%4lu: STOP\n", (unsigned long) mach->pc);
  
  return 0;
}
Ejemplo n.º 14
0
static int
moderator_action (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
{
  mu_message_t msg, orig;
  int rc;
  size_t nparts = 0;
  int discard = 0;
  int ismime;
  
  if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE)
    {
      mu_sieve_debug (mach, "moderator_test %lu",
		      (unsigned long) mu_sieve_get_message_num (mach));
    }

  msg = mu_sieve_get_message (mach);
  mu_message_is_multipart (msg, &ismime);

  if (!ismime)
    {
      mu_sieve_error (mach, _("message is not multipart"));
      mu_sieve_abort (mach);
    }

  mu_message_get_num_parts (msg, &nparts);

  if (nparts != 3) /* Mailman moderation requests have three parts */
    {
      mu_sieve_error (mach, _("expected 3 parts, but found %lu"),
		      (unsigned long) nparts);
      mu_sieve_abort (mach);
    }

  if ((rc = moderator_message_get_part (mach, msg, 2, &orig)))
    mu_sieve_abort (mach);

  rc = moderator_filter_message (mach, tags, orig, &discard);
  mu_message_unref (orig);
  if (rc)
    mu_sieve_abort (mach);

  if (discard && !mu_sieve_is_dry_run (mach))
    {
      mu_message_t request;
      char *from = NULL;
      mu_sieve_value_t *arg;
      
      if ((rc = moderator_message_get_part (mach, msg, 3, &request)))
	{
	  mu_sieve_error (mach, _("cannot get message part #3: %s"),
			  mu_strerror (rc));
	  mu_sieve_abort (mach);
	}

      if (mu_sieve_tag_lookup (tags, "address", &arg))
	from = arg->v.string;
      
      if (moderator_discard_message (mach, request, from))
	discard = 0;
      else
	{
	  if (!mu_sieve_tag_lookup (tags, "keep", NULL))
	    {
	      mu_attribute_t attr = 0;

	      if (mu_message_get_attribute (msg, &attr) == 0)
		mu_attribute_set_deleted (attr);
	    }
	  else
	    discard = 0;
	}
      mu_message_unref (request);
    }

  mu_sieve_log_action (mach, "MODERATOR", 
		       discard ? _("discarding message") :
		       _("keeping message"));
  return 0;
}
Ejemplo n.º 15
0
/* Handler for the timestamp test */
static int
timestamp_test (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
{
  mu_sieve_value_t *h, *v;
  mu_header_t hdr;
  char *val;
  time_t now = time (NULL);
  time_t tlimit, tval;
  int rc;
  
  if (mu_sieve_get_debug_level (mach) & MU_SIEVE_DEBUG_TRACE)
    {
      mu_sieve_locus_t locus;
      mu_sieve_get_locus (mach, &locus);
      mu_sieve_debug (mach, "%s:%lu: TIMESTAMP\n",
		   locus.source_file,
		   (unsigned long) locus.source_line);
    }

  /* Retrieve required arguments: */
  /* First argument: header name */
  h = mu_sieve_value_get (args, 0);
  if (!h)
    {
      mu_sieve_arg_error (mach, 1);
      mu_sieve_abort (mach);
    }
  /* Second argument: date displacement */
  v = mu_sieve_value_get (args, 1);
  if (!v)
    {
      mu_sieve_arg_error (mach, 2);
      mu_sieve_abort (mach);
    }

  if (mu_parse_date (v->v.string, &tlimit, &now))
    {
      mu_sieve_error (mach, _("cannot parse date specification (%s)"),
		   v->v.string);
      mu_sieve_abort (mach);
    }

  rc = mu_message_get_header (mu_sieve_get_message (mach), &hdr);
  if (rc)
    {
      mu_sieve_error (mach, "mu_message_get_header: %s", mu_strerror (rc));
      mu_sieve_abort (mach);
    }
  
  if (mu_header_aget_value (hdr, h->v.string, &val))
    return 0;

  if (mu_parse_date (val, &tval, &now))
    {
      mu_sieve_error (mach,
		   "cannot parse header date specification (%s)",
		   val);
      free (val);
      mu_sieve_abort (mach);
    }
  free (val);

  rc = tval > tlimit;
    
  if (mu_sieve_tag_lookup (tags, "before", NULL))
    rc = !rc;  

  return rc;
}