You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a Google Apps Script project that helps you delete old emails in Gmail that match your custom regex filters. This can help you save space and keep your inbox organized.
9
+
A Google Apps Script that helps you delete old emails in Gmail that match your custom regex filters. This can help you save space and keep your inbox organized.
8
10
9
-
## Features
11
+
## Table of Contents
10
12
11
-
- Delete old emails in Gmail that match a regular expression
12
-
- Specify the number of days to keep the emails
13
-
- Exclude starred, important, or labeled emails from deletion
14
-
- Run the script manually or on a schedule
15
-
- Log the deleted emails and errors
13
+
*[About The Project](#about-the-project)
14
+
*[Getting Started](#getting-started)
15
+
*[Usage](#usage)
16
+
*[Development](#development)
17
+
*[Contributing](#contributing)
18
+
*[License](#license)
19
+
*[Disclaimer](#disclaimer)
16
20
17
-
## How to use
21
+
## About The Project
22
+
23
+
This project provides a flexible way to automatically clean up your Gmail inbox by deleting old emails that match specific criteria defined by regular expressions. It's perfect for managing recurring emails like newsletters, notifications, and alerts that you don't need to keep forever.
24
+
25
+
### Features
26
+
27
+
* Delete old emails in Gmail that match a regular expression
28
+
* Specify the number of days to keep the emails
29
+
* Exclude starred, important, or labeled emails from deletion
30
+
* Run the script manually or on a schedule
31
+
* Log the deleted emails and errors
32
+
33
+
## Getting Started
34
+
35
+
> [!WARNING]
36
+
> This script will delete your emails permanently, without moving them to the trash. Please use it with caution and make sure you have a backup of your important emails. You can run the script with the `isDryRun` option set to `true` first to see what emails will be deleted.
37
+
38
+
This section will guide you through the process of setting up and running the script.
39
+
40
+
### Prerequisites
41
+
42
+
* A Google account with access to Gmail and Google Drive.
43
+
44
+
### Installation
45
+
46
+
1. Create a new Google Apps Script project in Google Drive.
47
+
2. Copy and paste the code from `dist/code.js` and `dist/examples.js` into the script editor.
48
+
3. From the `examples.js` file, choose a function that matches your needs, or create a new one. You can then run this function from the Apps Script editor.
49
+
50
+
For example, to run one of the pre-made functions, you would select it in the editor's function list and click **Run**.
51
+
52
+
> [!IMPORTANT]
53
+
> When running the script for the first time, you may need to authorize it to access your Gmail account.
54
+
55
+
4. Optionally, set up a trigger to run a function periodically. You can do this by clicking the **Triggers** icon in the left sidebar, then clicking the **Add a trigger** button, and choosing the options you want. For example, you can set the script to run every day, week, or month.
56
+
57
+
## Usage
18
58
19
59
For detailed instructions on how to set up and use this script, please see the [**Usage Guide**](./docs/usage.md).
20
60
21
61
## Development
22
62
23
63
This project uses ESLint for linting, Prettier for formatting, Jest for testing, and Rollup for building. For more details on the development setup and build process, please see the [**Development Guide**](./docs/development.md).
24
64
25
-
## Disclaimer
65
+
## Contributing
26
66
27
-
This script is provided as is, without any warranty or liability. Use it at your own risk. Make sure to test the script before using it on your Gmail account. The script may delete emails that you want to keep, or fail to delete emails that you want to remove. The script may also exceed the quota limits of Google Apps Script or Gmail API, resulting in errors or partial execution. The author is not responsible for any loss or damage caused by the use of this script.
67
+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
68
+
69
+
1. Fork the Project
70
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
71
+
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
72
+
4. Push to the Branch (`git push origin feature/AmazingFeature`)
73
+
5. Open a Pull Request
74
+
75
+
Please read the [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) before contributing.
76
+
77
+
If you have a bug report or a feature request, please open an issue on the [GitHub Issues page](https://github.com/chriskyfung/gmail-regex-cleaner-apps-script/issues).
28
78
29
79
## License
30
80
31
81
This project is distributed under the AGPL-3.0 license. You can use, modify, and distribute this project, as long as you comply with the terms and conditions in the [LICENSE](/LICENSE) file.
82
+
83
+
## Disclaimer
84
+
85
+
This script is provided as is, without any warranty or liability. Use it at your own risk. Make sure to test the script before using it on your Gmail account. The script may delete emails that you want to keep, or fail to delete emails that you want to remove. The script may also exceed the quota limits of Google Apps Script or Gmail API, resulting in errors or partial execution. The author is not responsible for any loss or damage caused by the use of this script.
Copy file name to clipboardExpand all lines: docs/development.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,3 +62,22 @@ To update the timezone, run the following command **after** the build command:
62
62
```bash
63
63
npm run update-timezone
64
64
```
65
+
66
+
### `dateFormatterFactory`
67
+
68
+
The `dateFormatterFactory` function is a helper function that creates a `dateFormatter` function for you. It takes a regular expression pattern and an optional boolean `useLastMessageYear` as arguments.
69
+
70
+
The pattern should contain named capture groups for `year`, `month1`, `month2` (optional), and `enddate`. The factory will then generate a function that extracts these parts from a date string and returns a formatted date string.
Copy file name to clipboardExpand all lines: docs/usage.md
+3-17Lines changed: 3 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,4 @@
1
-
# How to Use
2
-
3
-
1. Create a new Google Apps Script project in Google Drive.
4
-
2. Copy and paste the code from `dist/code.js` and `dist/examples.js` into the script editor.
5
-
3. From the `examples.js` file, choose a function that matches your needs, or create a new one. You can then run this function from the Apps Script editor.
6
-
7
-
For example, to run one of the pre-made functions, you would select it in the editor's function list and click **Run**.
8
-
9
-
The `main` function, which does the core work, has been updated to be more flexible. Here is how you would call it inside a custom function:
1
+
The `main` function, which does the core work, has been updated to be more flexible. Here is how you would call it inside a custom function:
10
2
11
3
```js
12
4
function removeOldGoogleAlerts() {
@@ -41,13 +33,7 @@
41
33
> -**`isDryRun`**: A boolean value that indicates whether to run the script in test mode or not. If `true` (the default), the script will only log the emails that match the query and the regex, but will not delete them. If `false`, the script will delete the emails permanently. It is recommended to run the script with `isDryRun` set to `true` first to make sure it works as expected.
42
34
> -**`mode`**: A string that specifies whether to process the email body as plain text or HTML. Can be either `'plain'` (default) or `'html'`. If set to `'html'`, the script will strip all HTML tags from the email body before searching for the regex pattern.
43
35
> -**`dateFormatter`**: A function that takes two parameters: `textWithDate` and `lastMessageDate`. The `textWithDate` is a string that contains the date part extracted from the email body. The `lastMessageDate` is a date object that represents the latest date of the email thread. The function should return a date string like `yyyy-MM-dd` that can be parsed by `new Date()`.
36
+
> > [!TIP]
37
+
> > For common date formats, you can use the `dateFormatterFactory` function to create a `dateFormatter` for you. See the [Development Guide](./development.md#dateformatterfactory) for more details.
44
38
45
39
4. Save and run the desired function from the script editor. You can use the **Run** menu or the **Run** button in the toolbar.
46
-
47
-
> [!IMPORTANT]
48
-
> When running the script for the first time, you may need to authorize it to access your Gmail account.
49
-
50
-
5. Optionally, set up a trigger to run a function periodically. You can do this by clicking the **Triggers** icon in the left sidebar, then clicking the **Add a trigger** button, and choosing the options you want. For example, you can set the script to run every day, week, or month.
51
-
52
-
> [!WARNING]
53
-
> This script will delete your emails permanently, without moving them to the trash. Please use it with caution and make sure you have a backup of your important emails. You can run the script with the `isDryRun` option set to `true` first to see what emails will be deleted.
0 commit comments