feat: add 126 mail provider routing

This commit is contained in:
Ryan Liu
2026-04-19 11:36:31 +08:00
parent 914dd8f2a5
commit 508fbdc50a
8 changed files with 214 additions and 7 deletions
+66
View File
@@ -0,0 +1,66 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const source = fs.readFileSync('content/utils.js', 'utf8');
function extractFunction(name) {
const start = source.indexOf(`function ${name}(`);
if (start < 0) {
throw new Error(`missing function ${name}`);
}
let parenDepth = 0;
let signatureEnded = false;
let braceStart = -1;
for (let index = start; index < source.length; index += 1) {
const ch = source[index];
if (ch === '(') {
parenDepth += 1;
} else if (ch === ')') {
parenDepth -= 1;
if (parenDepth === 0) {
signatureEnded = true;
}
} else if (ch === '{' && signatureEnded) {
braceStart = index;
break;
}
}
if (braceStart < 0) {
throw new Error(`missing body for function ${name}`);
}
let depth = 0;
let end = braceStart;
for (; end < source.length; end += 1) {
const ch = source[end];
if (ch === '{') depth += 1;
if (ch === '}') {
depth -= 1;
if (depth === 0) {
end += 1;
break;
}
}
}
return source.slice(start, end);
}
test('detectScriptSource maps 126 mail hosts to the shared 163 mail source', () => {
const bundle = [extractFunction('detectScriptSource')].join('\n');
const api = new Function(`
${bundle}
return { detectScriptSource };
`)();
assert.equal(
api.detectScriptSource({
url: 'https://mail.126.com/js6/main.jsp',
hostname: 'mail.126.com',
}),
'mail-163'
);
});
+35
View File
@@ -0,0 +1,35 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const {
HOTMAIL_PROVIDER,
getMailProviderConfig,
normalizeMailProvider,
} = require('../mail-provider-utils.js');
test('normalizeMailProvider accepts 126 and falls back to 163', () => {
assert.equal(normalizeMailProvider('126'), '126');
assert.equal(normalizeMailProvider('163-vip'), '163-vip');
assert.equal(normalizeMailProvider('unknown-provider'), '163');
});
test('getMailProviderConfig returns the shared NetEase source for 126 mail', () => {
assert.deepEqual(
getMailProviderConfig({ mailProvider: '126' }),
{
source: 'mail-163',
url: 'https://mail.126.com/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',
label: '126 邮箱',
}
);
});
test('getMailProviderConfig preserves the hotmail provider sentinel', () => {
assert.deepEqual(
getMailProviderConfig({ mailProvider: HOTMAIL_PROVIDER }),
{
provider: HOTMAIL_PROVIDER,
label: 'Hotmail(微软 Graph',
}
);
});