froth-webdriverio-framework 6.0.34 → 6.0.35
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/froth_common_actions/emailParsing.js +155 -155
- package/package.json +1 -1
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
2
|
-
|
|
3
|
-
const Imap = require('imap');
|
|
4
|
-
const { simpleParser } = require('mailparser');
|
|
5
|
-
const cheerio = require('cheerio');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
async function getEmailLinks(username,app_password, subjectdetails,fromemail) {
|
|
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
|
-
async function findLinks(links,searchText) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Example main function for direct execution
|
|
147
|
-
// if (require.main === module) {
|
|
148
|
-
// (async () => {
|
|
1
|
+
// // process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
2
|
+
|
|
3
|
+
// const Imap = require('imap');
|
|
4
|
+
// const { simpleParser } = require('mailparser');
|
|
5
|
+
// const cheerio = require('cheerio');
|
|
6
|
+
|
|
7
|
+
// /**
|
|
8
|
+
// * Connects to an IMAP inbox, parses emails, and extracts all unique links.
|
|
9
|
+
// * @param {Object} config - IMAP config { user, password, host, port, tls }
|
|
10
|
+
// * @param {Object} [filter] - Optional filter { subject, from }
|
|
11
|
+
// * @returns {Promise<Array<{link: string, text: string}>>}
|
|
12
|
+
// */
|
|
13
|
+
// async function getEmailLinks(username,app_password, subjectdetails,fromemail) {
|
|
14
|
+
// const config = {
|
|
15
|
+
// user: username,
|
|
16
|
+
// password: app_password,
|
|
17
|
+
// host: 'imap.gmail.com',
|
|
18
|
+
// port: 993,
|
|
19
|
+
// tls: true
|
|
20
|
+
// };
|
|
21
|
+
// const filter = {
|
|
22
|
+
// subject: subjectdetails,
|
|
23
|
+
// from: fromemail
|
|
24
|
+
// };
|
|
25
|
+
// const imap = new Imap(config);
|
|
26
|
+
|
|
27
|
+
// function openInbox(cb) {
|
|
28
|
+
// imap.openBox('INBOX', true, cb);
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
// return new Promise((resolve, reject) => {
|
|
32
|
+
// let results = new Map();
|
|
33
|
+
// let allLinks = [];
|
|
34
|
+
// let parseDone;
|
|
35
|
+
// const parsePromise = new Promise(res => { parseDone = res; });
|
|
36
|
+
|
|
37
|
+
// imap.once('ready', function () {
|
|
38
|
+
// openInbox(function (err, box) {
|
|
39
|
+
// if (err) return cleanup(err);
|
|
40
|
+
|
|
41
|
+
// // Build search criteria
|
|
42
|
+
// let searchCriteria = ['ALL'];
|
|
43
|
+
// if (filter.subject) searchCriteria.push(['HEADER', 'SUBJECT', filter.subject]);
|
|
44
|
+
// if (filter.from) searchCriteria.push(['FROM', filter.from]);
|
|
45
|
+
|
|
46
|
+
// imap.search(searchCriteria, function (err, uids) {
|
|
47
|
+
// if (err) return cleanup(err);
|
|
48
|
+
// if (!uids.length) return cleanup(null, []);
|
|
49
|
+
|
|
50
|
+
// // Sort UIDs descending to get the latest email first
|
|
51
|
+
// uids = uids.sort((a, b) => b - a);
|
|
52
|
+
// // Only fetch the latest email
|
|
53
|
+
// const latestUid = uids[0];
|
|
54
|
+
// const fetch = imap.fetch([latestUid], { bodies: '' });
|
|
55
|
+
// fetch.on('message', function (msg) {
|
|
56
|
+
// let buffer = '';
|
|
57
|
+
// msg.on('body', function (stream) {
|
|
58
|
+
// stream.on('data', function (chunk) {
|
|
59
|
+
// buffer += chunk.toString('utf8');
|
|
60
|
+
// });
|
|
61
|
+
// });
|
|
62
|
+
// msg.once('end', async function () {
|
|
63
|
+
// try {
|
|
64
|
+
// const parsed = await simpleParser(buffer);
|
|
65
|
+
// let links = [];
|
|
66
|
+
|
|
67
|
+
// // Extract from HTML with element context
|
|
68
|
+
// if (parsed.html) {
|
|
69
|
+
// const $ = cheerio.load(parsed.html);
|
|
70
|
+
// $('a[href], button[href], [role="button"][href], img[src], area[href]').each((_, el) => {
|
|
71
|
+
// let link = null;
|
|
72
|
+
// let text = '';
|
|
73
|
+
// let elementType = el.tagName;
|
|
74
|
+
// if (elementType === 'a' || elementType === 'area') {
|
|
75
|
+
// link = $(el).attr('href');
|
|
76
|
+
// text = $(el).text().trim() || link;
|
|
77
|
+
// } else if (elementType === 'img') {
|
|
78
|
+
// link = $(el).attr('src');
|
|
79
|
+
// text = $(el).attr('alt') || link;
|
|
80
|
+
// } else if (elementType === 'button' || $(el).attr('role') === 'button') {
|
|
81
|
+
// link = $(el).attr('href');
|
|
82
|
+
// text = $(el).text().trim() || link;
|
|
83
|
+
// }
|
|
84
|
+
// if (link) {
|
|
85
|
+
// links.push({ link, text, element: elementType });
|
|
86
|
+
// }
|
|
87
|
+
// });
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
// // Extract from plaintext
|
|
91
|
+
// if (parsed.text) {
|
|
92
|
+
// const urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
93
|
+
// let match;
|
|
94
|
+
// while ((match = urlRegex.exec(parsed.text))) {
|
|
95
|
+
// links.push({ link: match[1], text: match[1], element: 'text' });
|
|
96
|
+
// }
|
|
97
|
+
// }
|
|
98
|
+
|
|
99
|
+
// // Deduplicate by link and element context
|
|
100
|
+
// for (const l of links) {
|
|
101
|
+
// const key = l.link + '|' + l.element + '|' + l.text;
|
|
102
|
+
// if (!results.has(key)) {
|
|
103
|
+
// results.set(key, { link: l.link, text: l.text, element: l.element });
|
|
104
|
+
// }
|
|
105
|
+
// }
|
|
106
|
+
// allLinks = Array.from(results.values());
|
|
107
|
+
// parseDone();
|
|
108
|
+
// } catch (e) {
|
|
109
|
+
// // Log and continue
|
|
110
|
+
// console.error('Parse error:', e);
|
|
111
|
+
// parseDone();
|
|
112
|
+
// }
|
|
113
|
+
// });
|
|
114
|
+
// });
|
|
115
|
+
// fetch.once('error', cleanup);
|
|
116
|
+
// fetch.once('end', async () => {
|
|
117
|
+
// await parsePromise;
|
|
118
|
+
// cleanup(null, allLinks);
|
|
119
|
+
// });
|
|
120
|
+
// });
|
|
121
|
+
// });
|
|
122
|
+
// });
|
|
123
|
+
|
|
124
|
+
// imap.once('error', cleanup);
|
|
125
|
+
|
|
126
|
+
// function cleanup(err, data) {
|
|
127
|
+
// imap.end();
|
|
128
|
+
// if (err) reject(err);
|
|
129
|
+
// else resolve(data);
|
|
130
|
+
// }
|
|
131
|
+
|
|
132
|
+
// imap.connect();
|
|
133
|
+
// });
|
|
134
|
+
// }
|
|
135
|
+
|
|
136
|
+
// async function findLinks(links,searchText) {
|
|
137
|
+
// const findLinkByText = (links, searchText) => {
|
|
138
|
+
// return links.find(l => l.text && l.text.toLowerCase().includes(searchText.toLowerCase()));
|
|
139
|
+
// };
|
|
140
|
+
// // Example usage:
|
|
141
|
+
// const found = findLinkByText(links, searchText);
|
|
142
|
+
// return found ? found.link : null;
|
|
143
|
+
// }
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// // Example main function for direct execution
|
|
147
|
+
// // if (require.main === module) {
|
|
148
|
+
// // (async () => {
|
|
149
149
|
|
|
150
|
-
// const links = await extractEmailLinks('gfntesting44@gmail.com','wtrd qfee dicr hpba', "GFN Testing, review your Google Account settings","no-reply@google.com");
|
|
151
|
-
// console.log('Extracted links in main:', links);
|
|
152
|
-
// const foundLink = await findLinks(links,"Privacy Policy");
|
|
153
|
-
// console.log('Found Link: ', foundLink);
|
|
150
|
+
// // const links = await extractEmailLinks('gfntesting44@gmail.com','wtrd qfee dicr hpba', "GFN Testing, review your Google Account settings","no-reply@google.com");
|
|
151
|
+
// // console.log('Extracted links in main:', links);
|
|
152
|
+
// // const foundLink = await findLinks(links,"Privacy Policy");
|
|
153
|
+
// // console.log('Found Link: ', foundLink);
|
|
154
154
|
|
|
155
155
|
|
|
156
|
-
// })();
|
|
156
|
+
// // })();
|
|
157
157
|
|
|
158
|
-
// }
|
|
158
|
+
// // }
|
|
159
159
|
|
|
160
|
-
module.exports = { getEmailLinks ,findLinks}
|
|
160
|
+
// module.exports = { getEmailLinks ,findLinks}
|
|
161
161
|
|