-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpage.js
More file actions
executable file
·28 lines (25 loc) · 911 Bytes
/
page.js
File metadata and controls
executable file
·28 lines (25 loc) · 911 Bytes
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
/**
* Fetching the actual email headers requires the user's cookies, so we need to execute this in the page contents.
*
* This script simply waits for a message from the content script, executes the HTTP request
* (and regex to avoid passing the entire body as JSON) and returns the resulting message id.
*/
const regex = /Message-ID: <(.*)>/i;
window.addEventListener("message", function(event) {
if (event.source != window) {
return;
}
if (event.data.type != 'FETCH_ATTACHMENT') {
return;
}
fetch('https://mail.google.com/mail/u/' + event.data.user + '/?ui=2&ik=' + GLOBALS[9] + '&view=om&th=' + event.data.id, {credentials: 'include'}).then(function (r) {
return r.text();
}).then(function (r) {
var m = regex.exec(r);
if (m) {
window.postMessage({type: 'FETCH_RESULT', result: m[1]}, "*");
} else {
window.postMessage({type: 'FETCH_ERROR'}, "*");
}
});
}, false);