Coverage Report

Created: 2026-05-16 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/lib-sieve/cmd-discard.c
Line
Count
Source
1
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
2
 */
3
4
#include "lib.h"
5
#include "str-sanitize.h"
6
7
#include "sieve-common.h"
8
#include "sieve-commands.h"
9
#include "sieve-code.h"
10
#include "sieve-dump.h"
11
#include "sieve-actions.h"
12
#include "sieve-validator.h"
13
#include "sieve-generator.h"
14
#include "sieve-interpreter.h"
15
#include "sieve-result.h"
16
17
/*
18
 * Discard command
19
 *
20
 * Syntax
21
 *   discard
22
 */
23
24
static bool
25
cmd_discard_generate(const struct sieve_codegen_env *cgenv,
26
         struct sieve_command *ctx ATTR_UNUSED);
27
28
const struct sieve_command_def cmd_discard = {
29
  .identifier = "discard",
30
  .type = SCT_COMMAND,
31
  .positional_args = 0,
32
  .subtests = 0,
33
  .block_allowed = FALSE,
34
  .block_required = FALSE,
35
  .generate = cmd_discard_generate
36
};
37
38
/*
39
 * Discard operation
40
 */
41
42
static bool
43
cmd_discard_operation_dump(const struct sieve_dumptime_env *denv,
44
         sieve_size_t *address);
45
static int
46
cmd_discard_operation_execute(const struct sieve_runtime_env *renv,
47
            sieve_size_t *address);
48
49
const struct sieve_operation_def cmd_discard_operation = {
50
  .mnemonic = "DISCARD",
51
  .code = SIEVE_OPERATION_DISCARD,
52
  .dump = cmd_discard_operation_dump,
53
  .execute = cmd_discard_operation_execute
54
};
55
56
/*
57
 * Discard actions
58
 */
59
60
static bool
61
act_discard_equals(const struct sieve_script_env *senv,
62
       const struct sieve_action *act1,
63
       const struct sieve_action *act2);
64
static int
65
act_discard_check_duplicate(const struct sieve_runtime_env *renv,
66
          const struct sieve_action *act,
67
          const struct sieve_action *act_other);
68
static void
69
act_discard_print(const struct sieve_action *action,
70
      const struct sieve_result_print_env *rpenv, bool *keep);
71
static int
72
act_discard_execute(const struct sieve_action_exec_env *aenv, void *tr_context,
73
        bool *keep);
74
75
const struct sieve_action_def act_discard = {
76
  .name = "discard",
77
  .equals = act_discard_equals,
78
  .check_duplicate = act_discard_check_duplicate,
79
  .print = act_discard_print,
80
  .execute = act_discard_execute,
81
};
82
83
/*
84
 * Code generation
85
 */
86
87
static bool
88
cmd_discard_generate(const struct sieve_codegen_env *cgenv,
89
         struct sieve_command *cmd ATTR_UNUSED)
90
0
{
91
0
  sieve_operation_emit(cgenv->sblock, NULL, &cmd_discard_operation);
92
93
0
  return TRUE;
94
0
}
95
96
/*
97
 * Code dump
98
 */
99
100
static bool
101
cmd_discard_operation_dump(const struct sieve_dumptime_env *denv,
102
         sieve_size_t *address)
103
0
{
104
0
  sieve_code_dumpf(denv, "DISCARD");
105
0
  sieve_code_descend(denv);
106
107
0
  return (sieve_action_opr_optional_dump(denv, address, NULL) == 0);
108
0
}
109
110
/*
111
 * Interpretation
112
 */
113
114
static int
115
cmd_discard_operation_execute(const struct sieve_runtime_env *renv ATTR_UNUSED,
116
            sieve_size_t *address ATTR_UNUSED)
117
0
{
118
0
  sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS,
119
0
    "discard action; cancel implicit keep");
120
121
0
  if (sieve_result_add_action(renv, NULL, "discard", &act_discard,
122
0
            NULL, NULL, 0, FALSE) < 0)
123
0
    return SIEVE_EXEC_FAILURE;
124
0
  return SIEVE_EXEC_OK;
125
0
}
126
127
/*
128
 * Action implementation
129
 */
130
131
static bool
132
act_discard_equals(const struct sieve_script_env *senv ATTR_UNUSED,
133
       const struct sieve_action *act1 ATTR_UNUSED,
134
       const struct sieve_action *act2 ATTR_UNUSED)
135
0
{
136
0
  return TRUE;
137
0
}
138
139
static int
140
act_discard_check_duplicate(const struct sieve_runtime_env *renv ATTR_UNUSED,
141
          const struct sieve_action *act ATTR_UNUSED,
142
          const struct sieve_action *act_other ATTR_UNUSED)
143
0
{
144
0
  return 1;
145
0
}
146
147
static void
148
act_discard_print(const struct sieve_action *action ATTR_UNUSED,
149
      const struct sieve_result_print_env *rpenv, bool *keep)
150
0
{
151
0
  sieve_result_action_printf(rpenv, "discard");
152
153
0
  *keep = FALSE;
154
0
}
155
156
static int
157
act_discard_execute(const struct sieve_action_exec_env *aenv,
158
        void *tr_context ATTR_UNUSED, bool *keep)
159
0
{
160
0
  const struct sieve_execute_env *eenv = aenv->exec_env;
161
162
0
  eenv->exec_status->significant_action_executed = TRUE;
163
164
0
  struct event_passthrough *e = sieve_action_create_finish_event(aenv);
165
166
0
  sieve_result_event_log(aenv, e->event(),
167
0
    "Marked message to be discarded if not explicitly delivered "
168
0
    "(discard action)");
169
0
  *keep = FALSE;
170
171
0
  return SIEVE_EXEC_OK;
172
0
}
173