1 import type { SimpleObject } from '@proton/components/containers/filters/interfaces';
3 import { V1 } from '../constants';
4 import type { SIEVE_VERSION } from '../interface';
12 validateSimpleRepresentation,
13 } from './toSieveTree.helpers';
16 * Transforms a simple representation to a filter tree.
18 export const toSieveTree = (simple: SimpleObject, version: SIEVE_VERSION = V1) => {
20 validateSimpleRepresentation(simple);
22 const condition = buildCondition(simple.Conditions);
23 const fileInto = buildFileInto(simple.Actions.FileInto);
24 const mark = buildMark(simple.Actions.Mark);
25 const vacation = buildVacation(simple.Actions.Vacation, version);
26 const redirects = buildRedirects(simple.Actions.Redirects);
28 return buildBasicTree(
30 type: simple.Operator.value,
31 requires: vacation.blocks.length ? ['vacation'] : [],
32 tests: condition.tests,
33 comparators: condition.comparators,
34 dollarNeeded: condition.dollarNeeded || fileInto.dollarNeeded || vacation.dollarNeeded,
35 thens: [...fileInto.blocks, ...mark.blocks, ...vacation.blocks, ...redirects.blocks],