diff --git a/README.md b/README.md
index 2e97ee3..38dc364 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,7 @@ Congratulations! `gmail-tester` is ready to use.
- `include_body`: boolean. Set to `true` to fetch decoded email bodies.
- `before`: Date. Filter messages received _after_ the specified date.
- `after`: Date. Filter messages received _before_ the specified date.
+- `label`: String. The default label is 'INBOX', but can be changed to 'SPAM', 'TRASH' or a custom label. For a full list of built-in labels, see https://developers.google.com/gmail/api/guides/labels?hl=en
**Returns:**
An array of `email` objects with the following fields:
@@ -123,6 +124,8 @@ _Some senders will send you `text/html` content, the others will send you `plain
- `after`: Date. Filter messages received _before_ the specified date.
- `wait_time_sec`: Integer. Interval between inbox checks (in seconds). _Default: 30 seconds_.
- `max_wait_time_sec`: Integer. Maximum wait time (in seconds). When reached and the email was not found, the script exits. _Default: 60 seconds_.
+- `label`: String. The default label is 'INBOX', but can be changed to 'SPAM', 'TRASH' or a custom label. For a full list of built-in labels, see https://developers.google.com/gmail/api/guides/labels?hl=en
+
**Returns:**
An array of `email` objects with the following fields:
diff --git a/gmail-tester.d.ts b/gmail-tester.d.ts
index fe03fbb..22e5884 100644
--- a/gmail-tester.d.ts
+++ b/gmail-tester.d.ts
@@ -19,6 +19,7 @@ declare module "gmail-tester" {
after?: Date;
wait_time_sec?: number;
max_wait_time_sec?: number;
+ label: string;
}
export interface GetMessagesOptions {
@@ -46,4 +47,4 @@ declare module "gmail-tester" {
credentials_json: string,
token_path: string
): Promise;
-}
\ No newline at end of file
+}
diff --git a/gmail-tester.js b/gmail-tester.js
index d4acbc2..0fd0537 100644
--- a/gmail-tester.js
+++ b/gmail-tester.js
@@ -43,7 +43,8 @@ async function _get_recent_email(credentials_json, token_path, options = {}) {
const gmail_emails = await gmail.get_recent_email(
gmail_client,
oAuth2Client,
- query
+ query,
+ options.label
);
for (const gmail_email of gmail_emails) {
const email = {
@@ -146,6 +147,7 @@ async function __check_inbox(credentials_json, token_path, options = {}) {
* @param {Date} [options.after] - Date. Filter messages received _before_ the specified date.
* @param {number} [options.wait_time_sec] - Interval between inbox checks (in seconds). Default: 30 seconds.
* @param {number} [options.max_wait_time_sec] - Maximum wait time (in seconds). When reached and the email was not found, the script exits. Default: 60 seconds.
+ * @param {string} [options.label] - String. The default label is 'INBOX', but can be changed to 'SPAM', 'TRASH' or a custom label. For a full list of built-in labels, see https://developers.google.com/gmail/api/guides/labels?hl=en
*/
async function check_inbox(
credentials_json,
@@ -156,7 +158,8 @@ async function check_inbox(
to: undefined,
wait_time_sec: 30,
max_wait_time_sec: 30,
- include_body: false
+ include_body: false,
+ label: "INBOX"
}
) {
if (typeof options !== "object") {
diff --git a/gmail.js b/gmail.js
index 285957c..229b782 100644
--- a/gmail.js
+++ b/gmail.js
@@ -53,7 +53,7 @@ async function get_new_token(oAuth2Client, token_path) {
return new Promise((resolve, reject) => {
rl.question("Enter the code from that page here: ", async code => {
rl.close();
- oAuth2Client.getToken(code, function(err, token) {
+ oAuth2Client.getToken(code, function (err, token) {
if (err) {
reject(err);
} else {
@@ -82,7 +82,7 @@ async function list_labels(gmail, oauth2Client) {
userId: "me",
auth: oauth2Client
},
- function(err, res) {
+ function (err, res) {
if (err) {
reject(err);
} else {
@@ -115,7 +115,7 @@ async function list_messages(gmail, oauth2Client, query, labelIds) {
auth: oauth2Client,
labelIds: labelIds
},
- async function(err, res) {
+ async function (err, res) {
if (err) {
reject(err);
} else {
@@ -131,7 +131,7 @@ async function list_messages(gmail, oauth2Client, query, labelIds) {
labelIds: labelIds,
pageToken: nextPageToken
},
- function(err, res) {
+ function (err, res) {
if (err) {
reject(err);
} else {
@@ -158,10 +158,10 @@ async function list_messages(gmail, oauth2Client, query, labelIds) {
* @param {google.auth.OAuth2} oauth2Client An authorized OAuth2 client.
* @param {String} query String used to filter the Messages listed.
*/
-async function get_recent_email(gmail, oauth2Client, query = "") {
+async function get_recent_email(gmail, oauth2Client, query = "", label = "INBOX") {
try {
const labels = await list_labels(gmail, oauth2Client);
- const inbox_label_id = [labels.find(l => l.name === "INBOX").id];
+ const inbox_label_id = [labels.find(l => l.name === label).id];
const messages = await list_messages(
gmail,
oauth2Client,
@@ -179,7 +179,7 @@ async function get_recent_email(gmail, oauth2Client, query = "") {
id: message.id,
format: "full"
},
- function(err, res) {
+ function (err, res) {
if (err) {
reject(err);
} else {
diff --git a/init.js b/init.js
index f138521..6e21b4b 100644
--- a/init.js
+++ b/init.js
@@ -1,6 +1,10 @@
const gmail = require("./gmail-tester");
(async () => {
+ if (process.argv.length < 5) {
+ console.error(`Usage: init.js `)
+ process.exit(1)
+ }
await gmail.check_inbox(process.argv[2], process.argv[3], {
subject: "",
from: "",
diff --git a/package-lock.json b/package-lock.json
index 7bbfe00..8e62f37 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "gmail-tester",
- "version": "1.3.1",
+ "version": "1.3.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -40,10 +40,19 @@
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
"integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk="
},
+ "call-bind": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
+ "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "get-intrinsic": "^1.0.2"
+ }
+ },
"debug": {
- "version": "4.3.1",
- "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
- "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
+ "version": "4.3.2",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz",
+ "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==",
"requires": {
"ms": "2.1.2"
}
@@ -71,31 +80,46 @@
"resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz",
"integrity": "sha512-dtm4QZH9nZtcDt8qJiOH9fcQd1NAgi+K1O2DbE6GG1PPCK/BWfOH3idCTRQ4ImXRUOyopDEgDEnVEE7Y/2Wrig=="
},
+ "function-bind": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
+ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A=="
+ },
"gaxios": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.1.0.tgz",
- "integrity": "sha512-vb0to8xzGnA2qcgywAjtshOKKVDf2eQhJoiL6fHhgW5tVN7wNk7egnYIO9zotfn3lQ3De1VPdf7V5/BWfCtCmg==",
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-4.3.1.tgz",
+ "integrity": "sha512-9qXV7yrMCGzTrphl9/YGMVH41oSg0rhn1j3wJWed4Oqk45/hXDD2wBT5J1NjQcqTCcv4g3nFnyQ7reSRHNgBgw==",
"requires": {
"abort-controller": "^3.0.0",
"extend": "^3.0.2",
"https-proxy-agent": "^5.0.0",
"is-stream": "^2.0.0",
- "node-fetch": "^2.3.0"
+ "node-fetch": "^2.6.1"
}
},
"gcp-metadata": {
- "version": "4.2.1",
- "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-4.2.1.tgz",
- "integrity": "sha512-tSk+REe5iq/N+K+SK1XjZJUrFPuDqGZVzCy2vocIHIGmPlTGsa8owXMJwGkrXr73NO0AzhPW4MF2DEHz7P2AVw==",
+ "version": "4.3.1",
+ "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-4.3.1.tgz",
+ "integrity": "sha512-x850LS5N7V1F3UcV7PoupzGsyD6iVwTVvsh3tbXfkctZnBnjW5yu5z1/3k3SehF7TyoTIe78rJs02GMMy+LF+A==",
"requires": {
"gaxios": "^4.0.0",
"json-bigint": "^1.0.0"
}
},
+ "get-intrinsic": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
+ "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==",
+ "requires": {
+ "function-bind": "^1.1.1",
+ "has": "^1.0.3",
+ "has-symbols": "^1.0.1"
+ }
+ },
"google-auth-library": {
- "version": "6.1.3",
- "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-6.1.3.tgz",
- "integrity": "sha512-m9mwvY3GWbr7ZYEbl61isWmk+fvTmOt0YNUfPOUY2VH8K5pZlAIWJjxEi0PqR3OjMretyiQLI6GURMrPSwHQ2g==",
+ "version": "7.9.1",
+ "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-7.9.1.tgz",
+ "integrity": "sha512-cWGykH2WBR+UuYPGRnGVZ6Cjq2ftQiEIFjQWNIRIauZH7hUWoYTr/lkKUqLTYt5dex77nlWWVQ8aPV80mhfp5w==",
"requires": {
"arrify": "^2.0.0",
"base64-js": "^1.3.0",
@@ -109,46 +133,58 @@
}
},
"google-p12-pem": {
- "version": "3.0.3",
- "resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.0.3.tgz",
- "integrity": "sha512-wS0ek4ZtFx/ACKYF3JhyGe5kzH7pgiQ7J5otlumqR9psmWMYc+U9cErKlCYVYHoUaidXHdZ2xbo34kB+S+24hA==",
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/google-p12-pem/-/google-p12-pem-3.1.2.tgz",
+ "integrity": "sha512-tjf3IQIt7tWCDsa0ofDQ1qqSCNzahXDxdAGJDbruWqu3eCg5CKLYKN+hi0s6lfvzYZ1GDVr+oDF9OOWlDSdf0A==",
"requires": {
"node-forge": "^0.10.0"
}
},
"googleapis": {
- "version": "66.0.0",
- "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-66.0.0.tgz",
- "integrity": "sha512-jdEleRoyo/AeJZjKGC7Z2mHgochn2vR2JKqey6kydRkIBmCZxoQKLisRR4H8CRYZeEd6+c8Ns/LzS1S7qUjoFw==",
+ "version": "85.0.0",
+ "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-85.0.0.tgz",
+ "integrity": "sha512-9zFsCbxz/642PROcYJsg/CCm89U1qe15c0Wtv7bmZ8cWYLD1Jszc5z+xTNoXZxnomLbvQaHeKBCPh7RdAccYOA==",
"requires": {
- "google-auth-library": "^6.0.0",
- "googleapis-common": "^4.4.1"
+ "google-auth-library": "^7.0.2",
+ "googleapis-common": "^5.0.2"
}
},
"googleapis-common": {
- "version": "4.4.3",
- "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-4.4.3.tgz",
- "integrity": "sha512-W46WKCk3QtlCCfmZyQIH5zxmDOyeV5Qj+qs7nr2ox08eRkEJMWp6iwv542R/PsokXaGUSrmif4vCC4+rGzRSsQ==",
+ "version": "5.0.5",
+ "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-5.0.5.tgz",
+ "integrity": "sha512-o2dgoW4x4fLIAN+IVAOccz3mEH8Lj1LP9c9BSSvkNJEn+U7UZh0WSr4fdH08x5VH7+sstIpd1lOYFZD0g7j4pw==",
"requires": {
"extend": "^3.0.2",
"gaxios": "^4.0.0",
- "google-auth-library": "^6.0.0",
+ "google-auth-library": "^7.0.2",
"qs": "^6.7.0",
"url-template": "^2.0.8",
"uuid": "^8.0.0"
}
},
"gtoken": {
- "version": "5.1.0",
- "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-5.1.0.tgz",
- "integrity": "sha512-4d8N6Lk8TEAHl9vVoRVMh9BNOKWVgl2DdNtr3428O75r3QFrF/a5MMu851VmK0AA8+iSvbwRv69k5XnMLURGhg==",
+ "version": "5.3.1",
+ "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-5.3.1.tgz",
+ "integrity": "sha512-yqOREjzLHcbzz1UrQoxhBtpk8KjrVhuqPE7od1K2uhyxG2BHjKZetlbLw/SPZak/QqTIQW+addS+EcjqQsZbwQ==",
"requires": {
"gaxios": "^4.0.0",
"google-p12-pem": "^3.0.3",
- "jws": "^4.0.0",
- "mime": "^2.2.0"
+ "jws": "^4.0.0"
}
},
+ "has": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
+ "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==",
+ "requires": {
+ "function-bind": "^1.1.1"
+ }
+ },
+ "has-symbols": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
+ "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw=="
+ },
"https-proxy-agent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
@@ -159,9 +195,9 @@
}
},
"is-stream": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz",
- "integrity": "sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw=="
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",
+ "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg=="
},
"json-bigint": {
"version": "1.0.0",
@@ -198,36 +234,49 @@
"yallist": "^4.0.0"
}
},
- "mime": {
- "version": "2.4.6",
- "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.6.tgz",
- "integrity": "sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA=="
- },
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node-fetch": {
- "version": "2.6.1",
- "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
- "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
+ "version": "2.6.2",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
+ "integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"node-forge": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA=="
},
+ "object-inspect": {
+ "version": "1.11.0",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz",
+ "integrity": "sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg=="
+ },
"qs": {
- "version": "6.9.4",
- "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz",
- "integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ=="
+ "version": "6.10.1",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz",
+ "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==",
+ "requires": {
+ "side-channel": "^1.0.4"
+ }
},
"safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
+ "side-channel": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz",
+ "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==",
+ "requires": {
+ "call-bind": "^1.0.0",
+ "get-intrinsic": "^1.0.2",
+ "object-inspect": "^1.9.0"
+ }
+ },
"url-template": {
"version": "2.0.8",
"resolved": "https://registry.npmjs.org/url-template/-/url-template-2.0.8.tgz",
diff --git a/package.json b/package.json
index 0fb6506..dfa64b6 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "gmail-tester",
- "version": "1.3.2",
+ "version": "1.3.3",
"description": "A simple NodeJS gmail client which checks the inbox for specific message existance",
"main": "gmail-tester.js",
"types": "gmail-tester.d.ts",
@@ -16,7 +16,7 @@
"author": "Lev Gelfenbuim",
"license": "MIT",
"dependencies": {
- "googleapis": "^66.0.0"
+ "googleapis": "^85.0.0"
},
"homepage": "https://github.com/levz0r/gmail-tester"
}