@nemorize/korean-banking-email-parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yml +46 -0
- package/LICENSE +8 -0
- package/README.md +114 -0
- package/package.json +16 -0
- package/src/dom.js +22 -0
- package/src/index.js +47 -0
- package/src/parse.js +51 -0
- package/src/presets/nonghyup.js +89 -0
- package/src/vestmail.js +85 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
on:
|
|
2
|
+
workflow_dispatch:
|
|
3
|
+
inputs:
|
|
4
|
+
tags:
|
|
5
|
+
description: 'Semantic version tag (v.x.y.z)'
|
|
6
|
+
required: true
|
|
7
|
+
type: string
|
|
8
|
+
release_body:
|
|
9
|
+
description: 'Description of the release'
|
|
10
|
+
type: string
|
|
11
|
+
jobs:
|
|
12
|
+
release:
|
|
13
|
+
name: Release and publish to NPM registry
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
permissions:
|
|
16
|
+
actions: write
|
|
17
|
+
contents: write
|
|
18
|
+
id-token: write
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout repository
|
|
21
|
+
uses: actions/checkout@v6
|
|
22
|
+
|
|
23
|
+
- name: Set up Node.js
|
|
24
|
+
uses: actions/setup-node@v6
|
|
25
|
+
with:
|
|
26
|
+
node-version: latest
|
|
27
|
+
|
|
28
|
+
- name: Bump version
|
|
29
|
+
uses: ramonpaolo/bump-version@v2.3.1
|
|
30
|
+
with:
|
|
31
|
+
tag: ${{ inputs.tags }}
|
|
32
|
+
commit: true
|
|
33
|
+
branch_to_push: main
|
|
34
|
+
|
|
35
|
+
- name: Publish to NPM
|
|
36
|
+
run: npm ci
|
|
37
|
+
npm publish
|
|
38
|
+
env:
|
|
39
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
40
|
+
|
|
41
|
+
- name: Create GitHub Release
|
|
42
|
+
uses: ncipollo/release-action@v1
|
|
43
|
+
with:
|
|
44
|
+
tag: ${{ inputs.tags }}
|
|
45
|
+
release_name: ${{ inputs.tags }}
|
|
46
|
+
body: ${{ inputs.release_body }}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2026 Ji Yong, Kim.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# korean-banking-email-parser
|
|
2
|
+
|
|
3
|
+
대한민국 은행 입출금 이메일 알림을 복호화하고 파싱합니다.
|
|
4
|
+
|
|
5
|
+
현재 아래의 은행을 지원합니다.
|
|
6
|
+
|
|
7
|
+
* NH농협
|
|
8
|
+
|
|
9
|
+
## 설치하기
|
|
10
|
+
|
|
11
|
+
```shell
|
|
12
|
+
yarn add @nemorize/korean-banking-email-parser
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 예시
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { parse } from '@nemorize/korean-banking-email-parser'
|
|
19
|
+
import { readFile } from 'fs/promises';
|
|
20
|
+
|
|
21
|
+
const encryptedHtml = await readFile('./Message.html', 'utf-8');
|
|
22
|
+
console.log(
|
|
23
|
+
await parse(encryptedHtml, '000-00-00000')
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// Output: {
|
|
27
|
+
// account: {
|
|
28
|
+
// accountNumber: '301-****-1234-56',
|
|
29
|
+
// accountHolder: '네모컴퍼니',
|
|
30
|
+
// accountStatus: '정상',
|
|
31
|
+
// balance: 100000,
|
|
32
|
+
// availableBalance: 100000,
|
|
33
|
+
// },
|
|
34
|
+
// transactions: [
|
|
35
|
+
// {
|
|
36
|
+
// transactionDate: '2026/01/01',
|
|
37
|
+
// type: 'deposit',
|
|
38
|
+
// amount: 30000,
|
|
39
|
+
// balanceAfter: 100000,
|
|
40
|
+
// branch: '자금과',
|
|
41
|
+
// bank: 'SC제일',
|
|
42
|
+
// description: '홍길동'
|
|
43
|
+
// }
|
|
44
|
+
// ]
|
|
45
|
+
// }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
# 보안 주의사항
|
|
49
|
+
|
|
50
|
+
이 라이브러리는 메일을 복호화하기 위해 `new JSDOM(_, { runScripts: 'dangerously' })` 옵션을 사용합니다. 신뢰할 수 없는 HTML 컨텐츠를 전달할 경우 심각한 보안 문제가 발생할 수 있습니다. 입출금 알림을 발송한 이메일 주소가 각 은행의 공식 이메일 주소가 맞는지, 위변조된 이메일이 아닌지 다시 한번 확인해야 합니다.
|
|
51
|
+
|
|
52
|
+
~~쓸데없이 html 파일을 보내며 고객을 위협하는 K-금융에게서 나 자신을 지키기 위해 충분한 노력을 다해야 합니다.~~
|
|
53
|
+
|
|
54
|
+
# API
|
|
55
|
+
|
|
56
|
+
### `parse`
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
parse(html: string, password: string, timeout: number) => Promise<{
|
|
60
|
+
account: {
|
|
61
|
+
accountNumber: string,
|
|
62
|
+
accountHolder: string,
|
|
63
|
+
accountStatus: string,
|
|
64
|
+
balance: number,
|
|
65
|
+
availableBalance: number,
|
|
66
|
+
},
|
|
67
|
+
transactions: {
|
|
68
|
+
transactionDate: string,
|
|
69
|
+
type: 'deposit'|'withdrawal'|'unknown',
|
|
70
|
+
amount: number,
|
|
71
|
+
balanceAfter: number,
|
|
72
|
+
branch: string,
|
|
73
|
+
bank: string,
|
|
74
|
+
description: string,
|
|
75
|
+
}[],
|
|
76
|
+
}>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
암호화된 HTML 컨텐츠를 복호화한 뒤, 복호화된 컨텐츠에서 필요한 데이터만 추출해 반환합니다.
|
|
80
|
+
|
|
81
|
+
* `html`: 암호화된 HTML 컨텐츠.
|
|
82
|
+
* `password`: 복호화를 위한 비밀번호. 일반적으로 생년월일 6자리 또는 사업자번호 10자리.
|
|
83
|
+
* `timeout`: 복호화 작업의 타임아웃. ms 단위.
|
|
84
|
+
* `account`: 계좌 정보.
|
|
85
|
+
* `accountNumber`: 계좌번호. 은행에 따라 일부 번호가 마스킹 되어 있을 수 있음.
|
|
86
|
+
* `accountHolder`: 예금주명.
|
|
87
|
+
* `accountStatus`: 계좌의 상태. 지급정지, 압류 등의 정보를 표기하기 위한 용도로 추측됨.
|
|
88
|
+
* `balance`: 계좌의 잔액. 아래의 트랜잭션이 모두 완료된 이후의 최종 잔액.
|
|
89
|
+
* `availableBalance`: 계좌의 출금 가능 잔액. 잔액에서 압류된 금액을 제외한 금액으로 추측됨.
|
|
90
|
+
* `transactions`: 입출금 트랜잭션. 1개의 항목만 포함될 것으로 추측됨.
|
|
91
|
+
* `transactionDate`: `YYYY/mm/dd` 포맷의 입출금 날짜.
|
|
92
|
+
* `type`: 입금 또는 출금.
|
|
93
|
+
* `'deposit'`: 입금.
|
|
94
|
+
* `'withdrawal'`: 출금.
|
|
95
|
+
* `'unknown'`: 알 수 없음.
|
|
96
|
+
* `amount`: 입출금 액수.
|
|
97
|
+
* `balanceAfter`: 입출금 후 계좌의 잔액.
|
|
98
|
+
* `branch`: 해당 트랜잭션이 이루어진 거래점.
|
|
99
|
+
* `bank`: 해당 트랜잭션이 이루어진 은행명.
|
|
100
|
+
* `description`: 입금자명 또는 출금통장기록.
|
|
101
|
+
|
|
102
|
+
# 기여
|
|
103
|
+
|
|
104
|
+
현재 극소수의 은행만을 지원하고 있습니다. 다른 은행들도 지원할 수 있도록 많은 기여 부탁드립니다.
|
|
105
|
+
|
|
106
|
+
새로운 은행의 파서를 기여하고자 할 경우, 해당 은행에서 수신한 이메일 첨부파일 및 비밀번호를 PR에 함께 동봉하여 정상 작동 여부를 테스트 할 수 있도록 해 주세요.
|
|
107
|
+
|
|
108
|
+
코드 없이 이메일 첨부파일만 기여하시는 것도 환영합니다. 이슈를 통해 이메일 첨부파일과 비밀번호를 동봉해 주시면 검토하여 반영토록 하겠습니다.
|
|
109
|
+
|
|
110
|
+
혹 계좌 정보가 공개적으로 업로드되지 않기를 원하신다면, `jiyong.kim@headercat.com`으로 메일을 발송해 주셔도 좋습니다.
|
|
111
|
+
|
|
112
|
+
# 라이선스
|
|
113
|
+
|
|
114
|
+
MIT 라이선스를 따릅니다.
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nemorize/korean-banking-email-parser",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Decrypt and parse email notification regarding deposits and withdrawals from South Korea banks.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"repository": "https://github.com/nemorize/korean-banking-email-parser",
|
|
11
|
+
"author": "Ji Yong, Kim <jiyong.kim@headercat.com>",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"jsdom": "^29.1.1"
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/dom.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { JSDOM, VirtualConsole } from 'jsdom';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a JSDOM instance from the given HTML and options.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} html
|
|
7
|
+
* @param {import('jsdom').ConstructorOptions} options
|
|
8
|
+
* @returns {JSDOM}
|
|
9
|
+
*/
|
|
10
|
+
export function createDom(html, options) {
|
|
11
|
+
const virtualConsole = new VirtualConsole();
|
|
12
|
+
virtualConsole.on('error', () => { });
|
|
13
|
+
|
|
14
|
+
const dom = new JSDOM(html, {
|
|
15
|
+
...options,
|
|
16
|
+
virtualConsole,
|
|
17
|
+
beforeParse(window) {
|
|
18
|
+
window.alert = function () { };
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return dom;
|
|
22
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { parseContent } from './parse.js';
|
|
2
|
+
import { nonghyupPreset } from './presets/nonghyup.js';
|
|
3
|
+
import { decryptVestMail } from './vestmail.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} html Full encrypted HTML content of the VestMail.
|
|
8
|
+
* @param {string} password Password to decrypt the VestMail.
|
|
9
|
+
* @param {number} [timeout=10000] Maximum time to wait for decryption (in milliseconds).
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<{
|
|
12
|
+
* account: {
|
|
13
|
+
* accountNumber: string,
|
|
14
|
+
* accountHolder: string,
|
|
15
|
+
* accountStatus: string,
|
|
16
|
+
* balance: number,
|
|
17
|
+
* availableBalance: number,
|
|
18
|
+
* },
|
|
19
|
+
* transactions: {
|
|
20
|
+
* transactionDate: string,
|
|
21
|
+
* type: 'deposit'|'withdrawal'|'unknown',
|
|
22
|
+
* amount: number,
|
|
23
|
+
* balanceAfter: number,
|
|
24
|
+
* branch: string,
|
|
25
|
+
* bank: string,
|
|
26
|
+
* description: string,
|
|
27
|
+
* }[]
|
|
28
|
+
* }>}
|
|
29
|
+
*/
|
|
30
|
+
export async function parse(html, password, timeout) {
|
|
31
|
+
const preset = detectPreset(html);
|
|
32
|
+
const decryptedHtml = await decryptVestMail(html, password, preset.verifier, timeout);
|
|
33
|
+
return parseContent(decryptedHtml, preset);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const presets = {
|
|
37
|
+
'농협': nonghyupPreset,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function detectPreset(html) {
|
|
41
|
+
for (const [name, preset] of Object.entries(presets)) {
|
|
42
|
+
if (html.includes(name)) {
|
|
43
|
+
return preset;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
throw new Error('Cannot detect bank from the VestMail content');
|
|
47
|
+
}
|
package/src/parse.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
import { createDom } from './dom.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse the VestMail content and extract account information and transactions using the provided parser functions.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} html
|
|
8
|
+
* @param {{
|
|
9
|
+
* account: (dom: JSDOM) => {
|
|
10
|
+
* accountNumber: string,
|
|
11
|
+
* accountHolder: string,
|
|
12
|
+
* accountStatus: string,
|
|
13
|
+
* balance: number,
|
|
14
|
+
* availableBalance: number,
|
|
15
|
+
* },
|
|
16
|
+
* transactions: (dom: JSDOM) => {
|
|
17
|
+
* transactionDate: string,
|
|
18
|
+
* type: 'deposit'|'withdrawal'|'unknown',
|
|
19
|
+
* amount: number,
|
|
20
|
+
* balanceAfter: number,
|
|
21
|
+
* branch: string,
|
|
22
|
+
* bank: string,
|
|
23
|
+
* description: string,
|
|
24
|
+
* }[]
|
|
25
|
+
* }} parser
|
|
26
|
+
* @returns {{
|
|
27
|
+
* account: {
|
|
28
|
+
* accountNumber: string,
|
|
29
|
+
* accountHolder: string,
|
|
30
|
+
* accountStatus: string,
|
|
31
|
+
* balance: number,
|
|
32
|
+
* availableBalance: number,
|
|
33
|
+
* },
|
|
34
|
+
* transactions: {
|
|
35
|
+
* transactionDate: string,
|
|
36
|
+
* type: 'deposit'|'withdrawal'|'unknown',
|
|
37
|
+
* amount: number,
|
|
38
|
+
* balanceAfter: number,
|
|
39
|
+
* branch: string,
|
|
40
|
+
* bank: string,
|
|
41
|
+
* description: string,
|
|
42
|
+
* }[]
|
|
43
|
+
* }}
|
|
44
|
+
*/
|
|
45
|
+
export function parseContent(html, parser) {
|
|
46
|
+
const dom = createDom(html);
|
|
47
|
+
return {
|
|
48
|
+
account: parser.account(dom),
|
|
49
|
+
transactions: parser.transactions(dom),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
export const nonghyupPreset = {
|
|
3
|
+
verifier: (html) => html.includes('입출금 거래 내역 조회'),
|
|
4
|
+
account: parseNonghyupAccount,
|
|
5
|
+
transactions: parseNonghyupTransactions,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function parseNonghyupAccount(dom) {
|
|
9
|
+
const { document } = dom.window;
|
|
10
|
+
return {
|
|
11
|
+
accountNumber: findValueByLabel(document, '계좌번호'),
|
|
12
|
+
accountHolder: findValueByLabel(document, '예금주명'),
|
|
13
|
+
accountStatus: findValueByLabel(document, '계좌상태'),
|
|
14
|
+
balance: parseMoney(findValueByLabel(document, '통 장 잔 액')),
|
|
15
|
+
availableBalance: parseMoney(findValueByLabel(document, '지급가능잔액')),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseNonghyupTransactions(dom) {
|
|
20
|
+
const { document } = dom.window;
|
|
21
|
+
const rows = [...document.querySelectorAll('tr')];
|
|
22
|
+
const transactions = [];
|
|
23
|
+
for (const row of rows) {
|
|
24
|
+
const cells = [...row.querySelectorAll('td')].map((v) => normalizeText(v.textContent));
|
|
25
|
+
if (!isTransactionRow(cells)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
transactions.push({
|
|
29
|
+
transactionDate: cells[1],
|
|
30
|
+
type: cells[2] === '입금' ? 'deposit' : cells[2] === '출금' ? 'withdrawal' : 'unknown',
|
|
31
|
+
amount: parseMoney(cells[3]),
|
|
32
|
+
balanceAfter: parseMoney(cells[4]),
|
|
33
|
+
branch: cells[5],
|
|
34
|
+
bank: cells[6],
|
|
35
|
+
description: cells[7],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return transactions;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parseMoney(text) {
|
|
42
|
+
text = normalizeText(text);
|
|
43
|
+
if (!text) {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
if (!text.endsWith('원')) {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
const number = Number(text.replace(/[^0-9\-]/g, ''));
|
|
50
|
+
if (!number || isNaN(number)) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
return number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function normalizeText(text) {
|
|
57
|
+
return String(text || '')
|
|
58
|
+
.replace(/\s+/g, ' ')
|
|
59
|
+
.trim();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function findValueByLabel(document, label) {
|
|
63
|
+
const tds = [...document.querySelectorAll('td')];
|
|
64
|
+
for (const td of tds) {
|
|
65
|
+
if (normalizeText(td.textContent) === label) {
|
|
66
|
+
const next = td.nextElementSibling;
|
|
67
|
+
if (next) {
|
|
68
|
+
return normalizeText(next.textContent);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isTransactionRow(cells) {
|
|
76
|
+
if (cells.length < 8) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!/^\d+$/.test(cells[0])) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (!/\d{4}\/\d{2}\/\d{2}/.test(cells[1])) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (!cells[3].includes('원')) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
package/src/vestmail.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createDom } from './dom.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decrypt the VestMail content from the given HTML and password.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} html Full HTML content of the VestMail.
|
|
7
|
+
* @param {string} password Password to decrypt the VestMail.
|
|
8
|
+
* @param {(html:string)=>boolean} [verifier=(html)=>html.length>100] Function to verify if the decrypted content is correct. It receives the decrypted HTML and should return true if it's valid.
|
|
9
|
+
* @param {number} [timeout=10000] Maximum time to wait for decryption (in milliseconds).
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<string>} Decrypted HTML content of the VestMail.
|
|
12
|
+
*
|
|
13
|
+
* @warning This executes the JavaScript code embedded in the HTML. Make sure to use it only with trusted content.
|
|
14
|
+
*/
|
|
15
|
+
export async function decryptVestMail(html, password, verifier, timeout) {
|
|
16
|
+
timeout = timeout || 10000;
|
|
17
|
+
verifier = verifier || ((html) => html.length > 100);
|
|
18
|
+
|
|
19
|
+
const dom = createDom(html, {
|
|
20
|
+
runScripts: 'dangerously',
|
|
21
|
+
resources: 'usable',
|
|
22
|
+
pretendToBeVisual: true,
|
|
23
|
+
url: 'http://localhost/'
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const { window } = dom;
|
|
27
|
+
const { document } = window;
|
|
28
|
+
const documentWrite = document.write.bind(document);
|
|
29
|
+
|
|
30
|
+
let resultHtml = null;
|
|
31
|
+
document.write = function (content) {
|
|
32
|
+
if (typeof content === 'string' && verifier(content)) {
|
|
33
|
+
resultHtml = content;
|
|
34
|
+
}
|
|
35
|
+
return documentWrite(content);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let finished = false;
|
|
39
|
+
window.vestmail_onend = function () {
|
|
40
|
+
finished = true;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const startTime = Date.now();
|
|
44
|
+
await new Promise((resolve) => {
|
|
45
|
+
window.addEventListener('load', () => resolve(), {
|
|
46
|
+
once: true,
|
|
47
|
+
});
|
|
48
|
+
setTimeout(resolve, Math.min(3000, timeout));
|
|
49
|
+
});
|
|
50
|
+
timeout = timeout - (Date.now() - startTime);
|
|
51
|
+
|
|
52
|
+
const inputs = [...document.querySelectorAll('input')];
|
|
53
|
+
const passwordInput = inputs.find((v) => {
|
|
54
|
+
const s = `${v.id} ${v.name} ${v.type}`.toLowerCase();
|
|
55
|
+
return s.includes('pass');
|
|
56
|
+
});
|
|
57
|
+
if (!passwordInput) {
|
|
58
|
+
throw new Error('Cannot find password input');
|
|
59
|
+
}
|
|
60
|
+
passwordInput.value = password;
|
|
61
|
+
|
|
62
|
+
const doAction = window.doAction || window.N;
|
|
63
|
+
if (typeof doAction !== 'function') {
|
|
64
|
+
throw new Error('Cannot find doAction function');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
doAction();
|
|
68
|
+
await new Promise((resolve) => {
|
|
69
|
+
const started = Date.now();
|
|
70
|
+
const t = setInterval(() => {
|
|
71
|
+
if (finished || resultHtml || Date.now() - started > timeout) {
|
|
72
|
+
clearInterval(t);
|
|
73
|
+
resolve();
|
|
74
|
+
}
|
|
75
|
+
}, 50);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
if (!resultHtml) {
|
|
79
|
+
resultHtml = document.documentElement.outerHTML;
|
|
80
|
+
}
|
|
81
|
+
if (!resultHtml || !verifier(resultHtml)) {
|
|
82
|
+
throw new Error('Failed to decrypt VestMail');
|
|
83
|
+
}
|
|
84
|
+
return resultHtml;
|
|
85
|
+
}
|