-
Notifications
You must be signed in to change notification settings - Fork 935
Expand file tree
/
Copy pathmail-provider-utils.js
More file actions
137 lines (126 loc) · 4.49 KB
/
mail-provider-utils.js
File metadata and controls
137 lines (126 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
(function attachMailProviderUtils(root, factory) {
const api = factory();
if (typeof module !== 'undefined' && module.exports) {
module.exports = api;
}
if (root) {
root.MailProviderUtils = api;
}
})(typeof self !== 'undefined' ? self : globalThis, function createMailProviderUtils() {
const HOTMAIL_PROVIDER = 'hotmail-api';
const GMAIL_PROVIDER = 'gmail';
const YYDS_MAIL_PROVIDER = 'yyds-mail';
const NETEASE_LIST_PATH = '/js6/main.jsp?df=mail163_letter#module=mbox.ListModule%7C%7B%22fid%22%3A1%2C%22order%22%3A%22date%22%2C%22desc%22%3Atrue%7D';
const ICLOUD_TARGET_MAILBOX_TYPE_INBOX = 'icloud-inbox';
const ICLOUD_TARGET_MAILBOX_TYPE_FORWARD = 'forward-mailbox';
const ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS = [
{ value: 'qq', label: 'QQ 邮箱' },
{ value: '163', label: '163 邮箱' },
{ value: '163-vip', label: '163 VIP 邮箱' },
{ value: '126', label: '126 邮箱' },
{ value: GMAIL_PROVIDER, label: 'Gmail 邮箱' },
];
function normalizeMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
switch (normalized) {
case HOTMAIL_PROVIDER:
case YYDS_MAIL_PROVIDER:
case '163':
case '163-vip':
case '126':
case 'qq':
case 'inbucket':
return normalized;
default:
return '163';
}
}
function normalizeIcloudTargetMailboxType(value = '') {
return String(value || '').trim().toLowerCase() === ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
? ICLOUD_TARGET_MAILBOX_TYPE_FORWARD
: ICLOUD_TARGET_MAILBOX_TYPE_INBOX;
}
function normalizeIcloudForwardMailProvider(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.some((option) => option.value === normalized)
? normalized
: 'qq';
}
function getIcloudForwardMailProviderOptions() {
return ICLOUD_FORWARD_MAIL_PROVIDER_OPTIONS.map((option) => ({ ...option }));
}
function getIcloudForwardMailConfig(provider = 'qq') {
const normalizedProvider = normalizeIcloudForwardMailProvider(provider);
if (normalizedProvider === GMAIL_PROVIDER) {
return {
source: 'gmail-mail',
url: 'https://mail.google.com/mail/u/0/#inbox',
label: 'Gmail 邮箱',
inject: ['content/activation-utils.js', 'content/utils.js', 'content/gmail-mail.js'],
injectSource: 'gmail-mail',
};
}
return getMailProviderConfig({ mailProvider: normalizedProvider });
}
function getMailProviderConfig(state = {}, options = {}) {
const provider = normalizeMailProvider(state.mailProvider);
const normalizeInbucketOrigin = options.normalizeInbucketOrigin || (() => '');
if (provider === HOTMAIL_PROVIDER) {
return { provider: HOTMAIL_PROVIDER, label: 'Hotmail(微软 Graph)' };
}
if (provider === YYDS_MAIL_PROVIDER) {
return { provider: YYDS_MAIL_PROVIDER, label: 'YYDS Mail' };
}
if (provider === '163') {
return {
source: 'mail-163',
url: `https://mail.163.com${NETEASE_LIST_PATH}`,
label: '163 邮箱',
};
}
if (provider === '163-vip') {
return {
source: 'mail-163',
url: `https://webmail.vip.163.com${NETEASE_LIST_PATH}`,
label: '163 VIP 邮箱',
};
}
if (provider === '126') {
return {
source: 'mail-163',
url: `https://mail.126.com${NETEASE_LIST_PATH}`,
label: '126 邮箱',
};
}
if (provider === 'inbucket') {
const host = normalizeInbucketOrigin(state.inbucketHost);
const mailbox = String(state.inbucketMailbox || '').trim();
if (!host) {
return { error: 'Inbucket 主机地址为空或无效。' };
}
if (!mailbox) {
return { error: 'Inbucket 邮箱名称为空。' };
}
return {
source: 'inbucket-mail',
url: `${host}/m/${encodeURIComponent(mailbox)}/`,
label: `Inbucket 邮箱(${mailbox})`,
navigateOnReuse: true,
inject: ['content/activation-utils.js', 'content/utils.js', 'content/inbucket-mail.js'],
injectSource: 'inbucket-mail',
};
}
return { source: 'qq-mail', url: 'https://wx.mail.qq.com/', label: 'QQ 邮箱' };
}
return {
GMAIL_PROVIDER,
HOTMAIL_PROVIDER,
YYDS_MAIL_PROVIDER,
getIcloudForwardMailConfig,
getIcloudForwardMailProviderOptions,
getMailProviderConfig,
normalizeIcloudForwardMailProvider,
normalizeIcloudTargetMailboxType,
normalizeMailProvider,
};
});