1 import type { Filter } from '@proton/components/containers/filters/interfaces';
2 import type { MailSearchContext } from '@proton/shared/lib/api/messages';
3 import type { Nullable } from '@proton/shared/lib/interfaces';
5 type AddSieveFilterParams = Required<Pick<Filter, 'Name' | 'Sieve' | 'Version'>>;
6 export const addSieveFilter = ({ Name, Sieve, Version }: AddSieveFilterParams) => ({
8 url: 'mail/v4/filters',
9 data: { Name, Sieve, Version },
12 export const addTreeFilter = (
21 }: Pick<Filter, 'ID' | 'Name' | 'Status' | 'Version' | 'Simple' | 'Tree' | 'Sieve'>,
22 Source?: 'AutoLabel' | 'AutoFolder'
25 url: 'mail/v4/filters',
26 data: { ID, Name, Status, Version, Simple, Tree, Sieve },
30 export const queryFilters = () => ({
32 url: 'mail/v4/filters',
35 export const clearFilters = () => ({
37 url: 'mail/v4/filters',
40 export const updateFilter = (
49 }: Pick<Filter, 'ID' | 'Name' | 'Status' | 'Version' | 'Simple' | 'Tree' | 'Sieve'>
52 url: `mail/v4/filters/${filterID}`,
63 export const checkSieveFilter = (
64 { Sieve, Version }: Partial<Pick<Filter, 'Sieve' | 'Version'>> = { Sieve: undefined, Version: undefined }
67 url: 'mail/v4/filters/check',
68 data: { Sieve, Version },
71 export const enableFilter = (filterID: string) => ({
73 url: `mail/v4/filters/${filterID}/enable`,
76 export const disableFilter = (filterID: string) => ({
78 url: `mail/v4/filters/${filterID}/disable`,
81 export const toggleEnable = (ID: string, enable = true) => (enable ? enableFilter : disableFilter)(ID);
83 export const deleteFilter = (filterID: string) => ({
85 url: `mail/v4/filters/${filterID}`,
88 export const updateFilterOrder = (FilterIDs: string[]) => ({
90 url: 'mail/v4/filters/order',
94 interface ApplyFiltersParams {
95 SearchContext?: Nullable<MailSearchContext>;
96 Version?: Nullable<string>;
97 Sieve?: Nullable<string>;
105 export const applyFilters = ({
106 SearchContext = null,
114 }: ApplyFiltersParams) => ({
116 url: 'mail/v4/messages/apply-filters',