1 import type { SIEVE_VERSION, SieveBranch } from '@proton/sieve/src/interface';
7 IncomingAddressForwarding,
8 OutgoingAddressForwarding,
9 } from '../interfaces';
10 import queryPages from './helpers/queryPages';
12 interface ProxyInstance {
14 ForwarderKeyFingerprint: string;
15 ForwardeeKeyFingerprint: string;
18 interface QueryProps {
24 export const queryOutgoingForwardings = ({ AddressID, Page, PageSize }: QueryProps) => ({
26 url: 'mail/v4/forwardings/outgoing',
27 params: { Page, PageSize, AddressID },
30 export const queryAllOutgoingForwardings = (api: Api) => {
31 return queryPages((Page, PageSize) => {
32 return api<{ OutgoingAddressForwardings: OutgoingAddressForwarding[]; Total: number }>(
33 queryOutgoingForwardings({
39 return pages.flatMap(({ OutgoingAddressForwardings }) => OutgoingAddressForwardings);
43 export const queryIncomingForwardings = ({ AddressID, Page, PageSize }: QueryProps) => ({
45 url: 'mail/v4/forwardings/incoming',
46 params: { Page, PageSize, AddressID },
49 export const queryAllIncomingForwardings = (api: Api) => {
50 return queryPages((Page, PageSize) => {
51 return api<{ IncomingAddressForwardings: IncomingAddressForwarding[]; Total: number }>(
52 queryIncomingForwardings({
58 return pages.flatMap(({ IncomingAddressForwardings }) => IncomingAddressForwardings);
62 export interface SetupForwardingParameters {
64 ForwarderAddressID: string;
65 ForwardeeEmail: string;
66 ForwardeePrivateKey?: string; // Only for internal E2EE forwarding
67 ActivationToken?: string; // Only for internal E2EE forwarding
68 ProxyInstances?: ProxyInstance[]; // Only for E2EE forwarding
69 Tree: SieveBranch[] | null;
70 Version: SIEVE_VERSION;
73 export const setupForwarding = ({
82 }: SetupForwardingParameters) => ({
84 url: 'mail/v4/forwardings',
97 interface UpdateForwardingParameters {
99 ForwardeePrivateKey: string;
100 ActivationToken: string;
101 ProxyInstances: ProxyInstance[];
104 export const updateForwarding = ({
109 }: UpdateForwardingParameters) => ({
111 url: `mail/v4/forwardings/${ID}`,
119 export const deleteForwarding = (ID: string) => ({
121 url: `mail/v4/forwardings/${ID}`,
124 export const rejectForwarding = (ID: string) => ({
126 url: `mail/v4/forwardings/${ID}`,
129 export const acceptExternalForwarding = (jwt: string) => ({
131 url: `mail/v4/forwardings/external/${jwt}`,
134 export const rejectExternalForwarding = (jwt: string) => ({
136 url: `mail/v4/forwardings/external/${jwt}`,
139 export interface ExternalForwardingResult {
141 Type: ForwardingType;
142 State: ForwardingState;
143 ForwarderEmail: string;
144 ForwardeeEmail: string;
147 export const getExternalForwarding = (jwt: string) => ({
149 url: `mail/v4/forwardings/external/${jwt}`,
152 export const pauseForwarding = (ID: string) => ({
154 url: `mail/v4/forwardings/${ID}/pause`,
157 export const resumeForwarding = (ID: string) => ({
159 url: `mail/v4/forwardings/${ID}/resume`,
162 export const resendForwardingInvitation = (ID: string) => ({
164 url: `mail/v4/forwardings/${ID}/reinvite`,
167 export const updateForwardingFilter = (ID: string, Tree: SieveBranch[] | null, Version: SIEVE_VERSION) => ({
169 url: `mail/v4/forwardings/${ID}/filter`,
170 data: { Tree, Version },