From f4b5f42a2cbf6bc1c81b6571fc5b35f055799a23 Mon Sep 17 00:00:00 2001 From: shashikiran-im Date: Fri, 8 Nov 2019 15:55:50 +0530 Subject: [PATCH 001/142] Fix issues with "label" event on new Gmail - Add test case This closes Issue #493. --- src/gmail.js | 13 ++++++++++--- test/test.tools.js | 11 +++++++++++ test/testdata-parser.js | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/gmail.js b/src/gmail.js index c9803f22..85cf0889 100755 --- a/src/gmail.js +++ b/src/gmail.js @@ -1116,6 +1116,7 @@ var Gmail = function(localJQuery) { }; api.tools.check_event_type = function(threadObj) { + const apply_label = "^x_"; const action_map = { // "" : "add_to_tasks", "^a": "archive", @@ -1126,7 +1127,7 @@ var Gmail = function(localJQuery) { // "" : "discard_draft", // "" : "expand_categories", // "" : "filter_messages_like_these", - // "" : "label", + "^x_" : "label", // "^io_im^imi": "mark_as_important", // "^imn": "mark_as_not_important", // "" : "mark_as_not_spam", @@ -1154,8 +1155,14 @@ var Gmail = function(localJQuery) { if (threadData && api.check.data.is_action(threadData)) { const action = api.tools.get_action(threadData); - - return action_map[action]; + + //Check if label is applied to email / existing email is moved to an label + if(action.startsWith(apply_label) && api.check.data.is_first_type_action(threadData)) { + return action_map[apply_label]; + } else { + return action_map[action]; + } + } else { return null; } diff --git a/test/test.tools.js b/test/test.tools.js index 35ad3e7d..53eab59c 100644 --- a/test/test.tools.js +++ b/test/test.tools.js @@ -67,6 +67,7 @@ describe("Test tools for parsing new gmail body_params", () => { assert.deepEqual(threadData, mockThreadData); }); + it("get messages ids", () => { const mockMessageIds = ['msg-f:1603171109786600032', 'msg-f:1603245801543734539', 'msg-f:1603245862071354412', 'msg-f:1603246018478443087', 'msg-f:1603256094012730022', 'msg-f:1603256564311088576', 'msg-f:1603256665279246114', 'msg-f:1603256682384715664', 'msg-f:1603376719891477511', 'msg-f:1603376909485932601', 'msg-f:1603376994923202634', 'msg-f:1603380395240179639']; const messagesIds = gmail.tools.get_message_ids(threadData); @@ -74,4 +75,14 @@ describe("Test tools for parsing new gmail body_params", () => { assert.equal(messagesIds.length, 12); assert.deepEqual(messagesIds, mockMessageIds); }); + + + it("apply label event", () => { + const threads_apply_label_data = JSON.parse(testData.new_gmail_apply_label_action_body_params); + const threads_data = gmail.tools.extract_from_graph(threads_apply_label_data, gmail.check.data.is_thread); + const apply_label_event = "label"; + const actionType = gmail.tools.check_event_type(threads_data[0]); + + assert.equal(actionType, apply_label_event); + }); }); diff --git a/test/testdata-parser.js b/test/testdata-parser.js index 185a6f8a..f71bbda0 100644 --- a/test/testdata-parser.js +++ b/test/testdata-parser.js @@ -31,6 +31,8 @@ var new_gmail_open_email_action_body_params = "{\"2\":{\"1\":[{\"1\":\"5\",\"2\" var new_gmail_new_email_body_params = "{\"1\":\"thread-f:1613947906803228078\",\"2\":{\"7\":{\"2\":[\"^us\"],\"3\":[\"msg-f:1613947906803228078\"]}}}"; +var new_gmail_apply_label_action_body_params = "{\"2\":{\"1\":[{\"1\":\"6\",\"2\":{\"1\":\"thread-f:1644041322536515974|msg-f:1647596654245574633\",\"2\":{\"7\":{\"1\":[\"^x_7680127119979202084\"],\"3\":[\"msg-f:1647596654245574633\"]}}}},{\"1\":\"7\",\"2\":{\"1\":\"thread-f:1647490793383449487|msg-f:1647581105847759434\",\"2\":{\"7\":{\"1\":[\"^x_7680127119979202084\"],\"3\":[\"msg-f:1647581105847759434\"]}}}}]},\"3\":{\"1\":1,\"2\":\"760329\",\"5\":{\"2\":0},\"7\":1},\"4\":{\"2\":2,\"3\":\"1571307981227\",\"4\":0,\"5\":431},\"5\":2}"; + var new_gmail_sent_email_json = "{\"1\":\"msg-a:r1280593055912233690\",\"2\":{\"1\":1,\"2\":\"eric.karlsson1@gmail.com\",\"3\":\"Eric Karlsson1\"},\"3\":[{\"1\":1,\"2\":\"eric.karlsson2@gmail.com\",\"3\":\"Eric Karlsson2\"},{\"1\":1,\"2\":\"eric.karlsson3@gmail.com\"}],\"4\":[{\"1\":1,\"2\":\"eric.karlsson4@gmail.com\"},{\"1\":1,\"2\":\"eric.karlsson5@gmail.com\"}],\"5\":[{\"1\":1,\"2\":\"eric.karlsson6@gmail.com\",\"3\":\"Eric Karlsson6\"},{\"1\":1,\"2\":\"eric.karlsson7@gmail.com\",\"3\":\"Eric Karlsson7\"}],\"7\":\"1562634059674\",\"8\":\"Test Parse Sent\",\"9\":{\"2\":[{\"1\":0,\"2\":\"
Test Link <\/a>Test

<\/div>--
Thanks,

<\/font><\/div>
Eric Karlsson<\/b><\/font><\/div>
Product Development<\/font><\/div>
+1 240.688.9219 <\/span><\/span><\/font><\/div>

<\/font><\/div>

<\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div>\"}],\"7\":1},\"11\":[\"^all\",\"^pfg\",\"^f_bt\",\"^f_btns\",\"^f_cl\",\"^a\"],\"12\":[{\"1\":\"image\/png\",\"2\":\"Socket Error.PNG\",\"3\":\"108256\",\"5\":\"f_jxv3xqgb1\",\"6\":\"https:\/\/mail.google.com\/mail\/?ui=2&ik=5a14ab333d&attid=0.1&permmsgid=msg-a:r1280593055912233690&view=att&realattid=f_jxv3xqgb1&zw\",\"7\":0,\"8\":{\"1\":\"\/gmail\/att\/166604492527\/AAWNNRTJX9IJ7ZaSARt87A.4\/1747\",\"2\":\"108256\",\"3\":\"bb9be3f3_feddda5b_ced3b555_987aef4d_a2be44fc\",\"4\":1934455450,\"5\":\"148142\",\"7\":\"b64magic:NK,f,76\",\"9\":\"ANGjdJ-QStOwYEIO1RZFXbrqEojK2WgFoZ0V1Kz3vpz9UOHjUgrZQgA1-rl7VZQpCNuUaHp9TybcxV3TnVJ1i_jXREotXNE89ubF0BiJZ7m9CzZjhz8POOrOBDoNS4A\"},\"10\":\"GkEvYmxvYnN0b3JlL3Byb2QvZ21haWwtdXBsb2FkLzliZDcwM2JhLTY4ZjQtNGU2ZC05MmU0LTMwYjRhNmQ5ZDYzYijgzQYyLGJiOWJlM2YzX2ZlZGRkYTViX2NlZDNiNTU1Xzk4N2FlZjRkX2EyYmU0NGZjOJrltZoHSK6FCVgDYhBiNjRtYWdpYzpOSyxmLDc2aACaAUAxYzdlNDY2ZjYzYTkyYjI3ZDU0NzliNzYxNzMwZmRhNDQ4OGExMjU1NDA2Mjg4YzZjYjQ5OTU5NmM1NDJiNjJmqgECCAE=\",\"11\":1},{\"1\":\"image\/jpeg\",\"2\":\"8002291_3.jpg\",\"3\":\"2312479\",\"5\":\"f_jxv3xqg00\",\"6\":\"https:\/\/mail.google.com\/mail\/?ui=2&ik=5a14ab333d&attid=0.2&permmsgid=msg-a:r1280593055912233690&view=att&realattid=f_jxv3xqg00&zw\",\"7\":0,\"8\":{\"1\":\"\/gmail\/att\/166604492527\/AAWNNRTJX9IJ7ZaSARt87A.4\/150129\",\"2\":\"2312479\",\"3\":\"96e83a05_62c000c1_c37358d5_63616d16_491c844c\",\"4\":-2058827829,\"5\":\"3164446\",\"7\":\"b64magic:NK,f,76\",\"9\":\"ANGjdJ8mqimbXxk2JQsqD1dmjMeuyinFaMmrWf0uVxPkkwdFZMmefFDSi2KNiKkz-rjWt0VpUt3tluGL_2WLTrLTSoW_D1ULhXcIhzf03F64TyWZk5kaGTz8Yb13Ysk\"},\"10\":\"GkEvYmxvYnN0b3JlL3Byb2QvZ21haWwtdXBsb2FkLzM3N2Y4MjUxLTJjYjMtNGE1Yi04NjdmLTU0MDU3MGIxYWU3Yiifko0BMiw5NmU4M2EwNV82MmMwMDBjMV9jMzczNThkNV82MzYxNmQxNl80OTFjODQ0YzjLj6OqCEieksEBWANiEGI2NG1hZ2ljOk5LLGYsNzZoAJoBQDc2OWUyNTNmMzZlMzFjZTZlZjgyODFjZTdjZTE4YjBmYTYzZTc0NDQ1MDlmNzhhMDdhZmRkMjcxYmRkMzllZGSqAQIIAQ==\",\"11\":1}],\"18\":\"1562634059674\",\"42\":0,\"43\":{\"1\":0,\"2\":0,\"3\":14,\"4\":0},\"52\":\"s:7b25e2896356085b|#msg-a:r1280593055912233690|0\"}"; module.exports = { @@ -44,5 +46,6 @@ module.exports = { new_gmail_delete_action_body_params: new_gmail_delete_action_body_params, new_gmail_open_email_action_body_params: new_gmail_open_email_action_body_params, new_gmail_new_email_body_params: new_gmail_new_email_body_params, + new_gmail_apply_label_action_body_params: new_gmail_apply_label_action_body_params, new_gmail_sent_email_json: new_gmail_sent_email_json }; From 1734a866bce45c7ea2205cc0a6db14c39588883c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Nov 2019 11:33:28 +0100 Subject: [PATCH 002/142] Bump eslint from 3.19.0 to 6.6.0 (#595) Bumps [eslint](https://github.com/eslint/eslint) from 3.19.0 to 6.6.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v3.19.0...v6.6.0) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 54730d10..90921afe 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "devDependencies": { "@types/jquery": "^1.10.27", - "eslint": "^3.10.2", + "eslint": "^6.6.0", "jsdom": "^15.1.1", "mocha": "^3.1.2", "typescript": "^2.0.7" From f5f547442ab05b3bce4d273a4f29b9a717586a6a Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 14 Nov 2019 12:00:17 +0200 Subject: [PATCH 003/142] Use top window as xhr window (#597) * Use top window as xhr window in the new gmail UI, in the case of window_opener as xhr window, some events do not work, for example before_send event --- src/gmail.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gmail.js b/src/gmail.js index 85cf0889..5c9555eb 100755 --- a/src/gmail.js +++ b/src/gmail.js @@ -1709,13 +1709,19 @@ var Gmail = function(localJQuery) { }; api.helper.get_xhr_window = function() { - var js_frame = null; + // in the new gmail UI, in the case of window_opener as xhr window, + // some events do not work, for example before_send event + if (api.check.is_new_gui()) { + return top; + } + var js_frame = null; if (top.document.getElementById("js_frame")){ js_frame = top.document.getElementById("js_frame"); } else if (window_opener) { js_frame = window_opener.top.document.getElementById("js_frame"); } + if (!js_frame){ if (window_opener) { js_frame = window_opener.top; @@ -1723,12 +1729,14 @@ var Gmail = function(localJQuery) { js_frame = top; } } + var win; if (js_frame.contentDocument) { win = js_frame.contentDocument.defaultView; } else { win = js_frame; } + return win; }; From 833ef95abd3326751da7e461468b8de2a6427cb7 Mon Sep 17 00:00:00 2001 From: mikob Date: Thu, 9 Apr 2020 11:40:57 -0500 Subject: [PATCH 004/142] visible_messages fix --- src/gmail.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gmail.js b/src/gmail.js index 5c9555eb..d70d65a7 100755 --- a/src/gmail.js +++ b/src/gmail.js @@ -1155,14 +1155,14 @@ var Gmail = function(localJQuery) { if (threadData && api.check.data.is_action(threadData)) { const action = api.tools.get_action(threadData); - + //Check if label is applied to email / existing email is moved to an label if(action.startsWith(apply_label) && api.check.data.is_first_type_action(threadData)) { return action_map[apply_label]; } else { return action_map[action]; } - + } else { return null; } @@ -1721,7 +1721,7 @@ var Gmail = function(localJQuery) { } else if (window_opener) { js_frame = window_opener.top.document.getElementById("js_frame"); } - + if (!js_frame){ if (window_opener) { js_frame = window_opener.top; @@ -1729,14 +1729,14 @@ var Gmail = function(localJQuery) { js_frame = top; } } - + var win; if (js_frame.contentDocument) { win = js_frame.contentDocument.defaultView; } else { win = js_frame; } - + return win; }; @@ -2844,7 +2844,7 @@ var Gmail = function(localJQuery) { thread_id = thread_id.substring(1); } - return thread_id; + return thread_id; }; api.helper.get.email_source_pre = function(identifier) { @@ -3330,7 +3330,8 @@ var Gmail = function(localJQuery) { */ api.dom.visible_messages = function() { const ret = []; - $('tbody>tr.zA[draggable="true"]:visible', api.dom.inbox_content()) + // [draggable="true"] is not always on the rows for some unknown reason + $('tbody>tr.zA[role="row"]:visible', api.dom.inbox_content()) .each((index, msgEle) => { const nameAndEmail = $('*[email][name]', msgEle); const linkAndSubject = $('*[role=link]', msgEle); From b68fe4d48d79fd9337d57be72f12d4e538a0d241 Mon Sep 17 00:00:00 2001 From: Fabi1Sc Date: Fri, 10 Apr 2020 10:27:58 +0200 Subject: [PATCH 005/142] fix #589, parsing xhr bv request and embedded data --- src/changes_notes.txt | 137 +++++++++++++++++ src/gmail.js | 348 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 470 insertions(+), 15 deletions(-) create mode 100644 src/changes_notes.txt mode change 100755 => 100644 src/gmail.js diff --git a/src/changes_notes.txt b/src/changes_notes.txt new file mode 100644 index 00000000..5d6b698d --- /dev/null +++ b/src/changes_notes.txt @@ -0,0 +1,137 @@ + +Content of this pull request : +------------------------------ + + - Fix issue #589 with a parsing of embedded JSON data (see more details below) + - Extend XHR parsing data with a parsing of /bv request + - Extend email cache : update cache and not only append new email in cache + - Refactoring function name (parse_fd_email2, parse_fd_email) + + +Changes : +--------- + + + Fix issue #589 + -------------- + + Important : content-script which launch injected script must be configured with "run_at": "document_start" + It's recommand to split injected script to have only gmail.js to load in first because size of injected script impact the loadind time. + Gmail.js must be injected and loaded before Gmail load embedded data. + + api.tools.embedded_data_watcher override Gmail JS function "_GM_setData" + There is 2 different parsing (like XHR) : parse_fd_embedded_json and parse_bv_embedded_json + + + Extend XHR parsing data with a parsing of /bv request + ----------------------------------------------------- + + Like /fd request parsing, implement of /bv request parsing. + + Extend email cache : update cache and not only append new email in cache + ------------------------------------------------------------------------ + + Update function api.tools.cache_email_data + + +More details : +------------- + +In Gmail, there are 2 methods to load thread and email data. + 1) embedded data + 2) XHR + +When you load Gmail UI with default URL (like https://mail.google.com or https://mail.google.com) the default view displayed +is the inbox view, in this case, sequence is STEP 1 and STEP 2A + +If you load Gmail UI with personnalized URL (like https://mail.google.com/mail/u/0/#sent), the wiew display depend on the URL. +in this case, sequence is STEP 1 and STEP 2B. + + +STEP 1 : +-------- + +This step is mandatory because it's automatic when loading Gmail UI. + +Thread and email data for INBOX (BUT NOT ONLY these datas) can partially be read in JSON embedded data from text/html content request. +IT IS NOT an XHR... + +First Http request is on https://mail.google.com/mail/u/0/, the response is a document text/html. +In the body of HTML content, we can find an iframe. +Example : + + + +When iframe is loaded, the document is text/html and contain javascript function and JSON embedded data +Example : +