Skip to content

Commit e47451d

Browse files
committed
Added: Gmail Label function
1 parent 659e0ff commit e47451d

File tree

11 files changed

+1005
-892
lines changed

11 files changed

+1005
-892
lines changed

package-lock.json

Lines changed: 966 additions & 854 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apps-script-starter",
3-
"version": "10.13.0",
3+
"version": "11.0.0",
44
"description": "Setup a local development environment for Google Apps Script with Visual Studio Code",
55
"author": "Amit Agarwal <amit@labnol.org> (https://www.labnol.org)",
66
"homepage": "https://digitalinspiration.com/",
@@ -26,33 +26,33 @@
2626
"apps-script-oauth2": "github:googleworkspace/apps-script-oauth2"
2727
},
2828
"devDependencies": {
29-
"@babel/core": "^7.20.12",
30-
"@babel/eslint-parser": "^7.19.1",
29+
"@babel/core": "^7.21.3",
30+
"@babel/eslint-parser": "^7.21.3",
3131
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
3232
"@babel/preset-env": "^7.20.2",
3333
"@google/clasp": "^2.4.2",
34-
"@types/google-apps-script": "^1.0.57",
34+
"@types/google-apps-script": "^1.0.59",
3535
"@types/google-apps-script-oauth2": "^38.0.0",
3636
"@types/google.picker": "^0.0.39",
37-
"@types/jest": "^29.4.0",
37+
"@types/jest": "^29.5.0",
3838
"babel-loader": "^9.1.2",
3939
"copy-webpack-plugin": "^11.0.0",
4040
"cross-env": "^7.0.3",
41-
"eslint": "^8.34.0",
41+
"eslint": "^8.36.0",
4242
"eslint-config-airbnb-base": "^15.0.0",
43-
"eslint-config-prettier": "^8.6.0",
43+
"eslint-config-prettier": "^8.8.0",
4444
"eslint-plugin-googleappsscript": "^1.0.4",
4545
"eslint-plugin-html": "^7.1.0",
4646
"eslint-plugin-import": "^2.27.5",
4747
"eslint-plugin-jest": "^27.2.1",
4848
"eslint-plugin-prettier": "^4.2.1",
4949
"eslint-webpack-plugin": "^4.0.0",
5050
"gas-webpack-plugin": "^2.3.0",
51-
"jest": "^29.4.3",
51+
"jest": "^29.5.0",
5252
"npm-watch": "^0.11.0",
53-
"prettier": "^2.8.4",
54-
"terser-webpack-plugin": "^5.3.6",
55-
"webpack": "^5.75.0",
53+
"prettier": "^2.8.7",
54+
"terser-webpack-plugin": "^5.3.7",
55+
"webpack": "^5.76.3",
5656
"webpack-cli": "^5.0.1"
5757
},
5858
"bugs": {

src/es6/filter-map-reduce.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ const bigNumbers = numbers.filter((number) => number > 10);
1515
Logger.log(bigNumbers);
1616

1717
/* Add the numbers */
18-
const sum = numbers.reduce(
19-
(accumulator, currentValue) => accumulator + currentValue,
20-
0
21-
);
18+
const sum = numbers.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
2219
Logger.log(`The sum of ${numbers.join(', ')} is ${sum}`);
2320

2421
/* Remove duplicates with reduce */

src/es6/spread-rest-operators.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ const emailUpdated = {
2626
};
2727
Logger.log(emailUpdated);
2828

29-
const stack = [
30-
'Google Apps Script',
31-
'JavaScript',
32-
'Firebase',
33-
'Node.js',
34-
'Webpack',
35-
'Babel',
36-
];
29+
const stack = ['Google Apps Script', 'JavaScript', 'Firebase', 'Node.js', 'Webpack', 'Babel'];
3730

3831
const [gas, js, ...others] = stack;
3932

Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/* Returns the Gmail Aliases of the authenticated user */
2-
const getGmailAliases = () => {
2+
export const getGmailAliases = () => {
33
try {
44
const { sendAs = [] } = Gmail.Users.Settings.SendAs.list('me');
55
if (sendAs.length) {
66
return sendAs.map((alias) => alias.sendAsEmail);
77
}
88
} catch (f) {
9-
console.error(f);
9+
Logger.log(f.message);
1010
}
1111
return [Session.getActiveUser().getEmail()];
1212
};
13-
14-
export default getGmailAliases;

src/gmail/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { getGmailAliases } from './alias';
2+
import { getGmailLabels } from './labels';
3+
4+
export { getGmailAliases, getGmailLabels };

src/gmail/labels.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Get a list of Gmail labels */
2+
export const getGmailLabels = () => {
3+
const { labels = [] } = Gmail.Users.Labels.list('me');
4+
const response = labels.filter(({ type }) => type === 'user').map(({ name }) => name);
5+
Logger.log('Labels: %s', response);
6+
return response;
7+
};

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import './server/mail';
2-
import './server/menu';
3-
import './server/webapp';
4-
51
/* Written by Amit Agarwal */
2+
3+
import { getGmailAliases, getGmailLabels } from './gmail';
4+
import { sendmail } from './server/mail';
5+
import { doGet } from './server/webapp';
6+
7+
global.sendmail = sendmail;
8+
global.doGet = doGet;
9+
10+
global.getGmailLabels = getGmailLabels;
11+
global.getGmailAliases = getGmailAliases;

src/server/mail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
global.sendmail = () => {
1+
export const sendmail = () => {
22
const email = Session.getActiveUser().getEmail();
33

44
const TUTORIAL = 'https://www.labnol.org/internet/google-apps-script-developers/32305/';

src/server/utils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ const expBackoff = (func) => {
1111
if (n === MAX_RETRIES) {
1212
throw e;
1313
}
14-
Utilities.sleep(
15-
2 ** n * ONE_SECOND + Math.round(Math.random() * ONE_SECOND)
16-
);
14+
Utilities.sleep(2 ** n * ONE_SECOND + Math.round(Math.random() * ONE_SECOND));
1715
}
1816
}
1917
return null;

0 commit comments

Comments
 (0)