sieve/compiler/grammar/actions/action_reject.rs
1/*
2 * Copyright (c) 2020-2023, Stalwart Labs Ltd.
3 *
4 * This file is part of the Stalwart Sieve Interpreter.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 * in the LICENSE file at the top-level directory of this distribution.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * You can be released from the requirements of the AGPLv3 license by
20 * purchasing a commercial license. Please contact licensing@stalw.art
21 * for more details.
22*/
23
24use serde::{Deserialize, Serialize};
25
26use crate::compiler::{
27 grammar::instruction::{CompilerState, Instruction},
28 CompileError, Value,
29};
30
31#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
32pub struct Reject {
33 pub ereject: bool,
34 pub reason: Value,
35}
36
37impl<'x> CompilerState<'x> {
38 pub(crate) fn parse_reject(&mut self, ereject: bool) -> Result<(), CompileError> {
39 let cmd = Instruction::Reject(Reject {
40 ereject,
41 reason: self.parse_string()?,
42 });
43 self.instructions.push(cmd);
44 Ok(())
45 }
46}