### Development Setup and Execution (Bash) Source: https://ahochsteger.github.io/gmail-processor/docs/community/contributing This snippet details the steps to set up the development environment for the project. It includes cloning the repository, installing Node.js dependencies using npm, and running pre-commit tasks for code quality checks. ```bash # Pre-requisites: Make sure a recent Node.js LTS version is installed # Clone the repository and navigate to the project folder git clone https://github.com/ahochsteger/gmail-processor.git cd gmail-processor # Install dependencies npm install # Perform changes code . # Run pre-commit tasks to make sure the code is in an acceptable state to be commited # (clean, build, run tests, update docs, do some sanity checks, ...) npm run pre-commit ``` -------------------------------- ### Run GmailProcessor with Dry-Run Mode - Google Apps Script Source: https://ahochsteger.github.io/gmail-processor/docs/getting-started This Google Apps Script function demonstrates how to use the GmailProcessor library to process emails and store attachments. It includes a configuration object specifying matching criteria for threads and attachments, and defines actions to take, such as storing attachments in Google Drive. The example uses the 'dry-run' mode to preview operations without making actual changes. ```javascript function run() { const config = { description: "Use this to get started with Gmail Processor. It stores an attachment to Google Drive.", settings: { markProcessedMethod: "mark-read", }, global: { thread: { match: { query: "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] simple\"", }, }, }, threads: [ { match: { query: "from:${user.email}", }, messages: [ { attachments: [ { match: { name: "^invoice\\.pdf$", }, actions: [ { name: "attachment.store", args: { location: "/GmailProcessor-Tests/e2e/simple/{{message.date|formatDate('yyyy-MM-dd')}}/{{message.subject}}-{{attachment.name}}", conflictStrategy: "keep", }, }, ], }, ], }, ], }, ], } return GmailProcessorLib.run(config, "dry-run") } ``` -------------------------------- ### Gmail2GDrive v1.x Configuration Example Source: https://ahochsteger.github.io/gmail-processor/docs/examples/migrations/migrationMin A minimal configuration file for Gmail2GDrive version 1.x, defining processed labels, runtime settings, and migration rules. ```json { "processedLabel": "gmail2gdrive/client-test", "sleepTime": 100, "maxRuntime": 280, "newerThan": "2m", "timezone": "GMT", "rules": [ { "filter": "to:my.name+scans@gmail.com", "folder": "'Scans'-yyyy-MM-dd" } ] } ``` -------------------------------- ### Global Configuration Example Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema An example of the global configuration for the Gmail processor, including settings for messages, attachments, and variables. ```json { "variables": [ { "key": "reportName", "value": "Monthly Sales" } ], "messages": [ { "name": "process-reports", "match": { "subject": "Sales Report", "from": "reports@company.com" }, "actions": [], "attachments": [ { "name": "extract-csv", "match": { "contentType": "text/csv" }, "actions": [] } ] } ] } ``` -------------------------------- ### Copy Library Code (Advanced) for Gmail Processor Source: https://ahochsteger.github.io/gmail-processor/docs/getting-started This snippet details the advanced method of copying the Gmail Processor library code into your Google Apps Script project. It involves creating a new script file and replacing its contents with the library code from a release asset or a built version. ```Google Apps Script 1. Create a new file using the + icon at "Files" and selecting "Script" 2. Give it a name (e.g. `GmailProcessorLib` resulting in the file `GmailProcessorLib.gs` to be created) 3. Replace the contents of the file with the library code of the release asset `GmailProcessorLib.js` from the latest release or your own built version from `build/gas/lib/GmailProcessorLib.js`. ``` -------------------------------- ### Install Devbox Source: https://ahochsteger.github.io/gmail-processor/docs/development/devbox Installs the Devbox utility using a curl command to download and execute the installation script. ```shell curl -fsSL https://get.jetpack.io/devbox | bash ``` -------------------------------- ### Run LogSheet Logging Example with JavaScript Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/logSheetLogging This JavaScript function sets up the configuration for the logSheetLogging process. It defines the logging settings, including the spreadsheet location and fields, and prepares the structure for processing Gmail threads, messages, and attachments. ```javascript function logSheetLoggingRun() { const config = { description: "Logs data to a Google Spreadsheet.", settings: { markProcessedMethod: "mark-read", logSheetLocation: "/GmailProcessor-Tests/logsheet-{{date.now|formatDate('yyyy-MM')}}", logSheetTracing: true, logFields: [ "log.timestamp", "log.level", "log.location", "log.message", "object.id", "object.date", "object.subject", "object.from", "object.url", "attachment.name", "attachment.size", "attachment.contentType", "stored.location", "stored.url", "stored.downloadUrl", ``` -------------------------------- ### Start Devbox Shell Source: https://ahochsteger.github.io/gmail-processor/docs/development/devbox Enters the Devbox shell environment, providing access to the project's managed dependencies and scripts. ```shell devbox shell ``` -------------------------------- ### Migrate Gmail2GDrive v1.x Config to v2.x in TypeScript Source: https://ahochsteger.github.io/gmail-processor/docs/examples/migrations/migrationMin TypeScript function demonstrating the conversion of a v1.x Gmail2GDrive configuration object to the v2.x Gmail Processor format using GmailProcessorLib.convertV1Config. ```typescript function migrationMinConvert() { const oldConfig = { processedLabel: "gmail2gdrive/client-test", sleepTime: 100, maxRuntime: 280, newerThan: "2m", timezone: "GMT", rules: [ { filter: "to:my.name+scans@gmail.com", folder: "'Scans'-yyyy-MM-dd", }, ], } const migratedConfig = GmailProcessorLib.convertV1Config(oldConfig) console.log(JSON.stringify(migratedConfig, null, 2)) return migratedConfig } ``` -------------------------------- ### Gmail Processor Configuration and Execution (TypeScript) Source: https://ahochsteger.github.io/gmail-processor/docs/examples/basics/simple Defines the configuration for the Gmail Processor, including message queries and attachment actions. It then executes the processor with the defined configuration in dry-run mode. ```typescript const config = { rules: [ { query: "from:${user.email}", }, messages: [ { attachments: [ { match: { name: "^invoice\.pdf$", }, actions: [ { name: "attachment.store", args: { location: "/GmailProcessor-Tests/e2e/simple/{{message.date|formatDate('yyyy-MM-dd')}}/{{message.subject}}-{{attachment.name}}", conflictStrategy: "keep", }, }, ], }, ], }, ], }, ] return GmailProcessorLib.run(config, "dry-run") ``` -------------------------------- ### Gmail Processor Script: Store Attachment Source: https://ahochsteger.github.io/gmail-processor/docs/examples/basics/simple A JavaScript function demonstrating how to define the Gmail Processor configuration programmatically, including settings, global thread matching, and specific rules for matching and storing attachments. ```javascript function simpleRun() { const config = { description: "Use this to get started with Gmail Processor. It stores an attachment to Google Drive.", settings: { markProcessedMethod: "mark-read", }, global: { thread: { match: { query: "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] simple\"", }, }, }, threads: [ { match: { ``` -------------------------------- ### Gmail Processor Configuration: Match Raw Headers Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/headerMatching Configuration to match emails by their raw headers, specifically looking for a 'From:' line matching the user's email. It processes 'invoice.pdf' attachments by storing them in Google Drive. ```json { "description": "This example demonstrates how to match raw message headers.", "settings": { "markProcessedMethod": "mark-read" }, "global": { "thread": { "match": { "query": "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] headerMatching\"" } } }, "threads": [ { "match": { "query": "from:${user.email}" }, "messages": [ { "match": { "rawHeaders": "(?m)^From: ${user.email}$\n" }, "attachments": [ { "match": { "name": "^invoice\\.pdf$" }, "actions": [ { "name": "attachment.store", "args": { "location": "/GmailProcessor-Tests/e2e/headerMatching/{{message.date|formatDate('yyyy-MM-dd')}}/{{message.subject}}-{{attachment.name}}", "conflictStrategy": "keep" } } ] } ] } ] } ] } ``` -------------------------------- ### Gmail Processor Script: Run Header Matching Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/headerMatching A TypeScript function that executes the Gmail Processor configuration for header matching. It uses the GmailProcessorLib to run the provided configuration in a dry-run mode. ```typescript function headerMatchingRun() { const config = { description: "This example demonstrates how to match raw message headers.", settings: { markProcessedMethod: "mark-read", }, global: { thread: { match: { query: "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] headerMatching\"", }, }, }, threads: [ { match: { query: "from:${user.email}", }, messages: [ { match: { rawHeaders: "(?m)^From: ${user.email}$\n", }, attachments: [ { match: { name: "^invoice\\.pdf$", }, actions: [ { name: "attachment.store", args: { location: "/GmailProcessor-Tests/e2e/headerMatching/{{message.date|formatDate('yyyy-MM-dd')}}/{{message.subject}}-{{attachment.name}}", conflictStrategy: "keep", }, }, ], }, ], }, ], }, ], }; return GmailProcessorLib.run(config, "dry-run"); } ``` -------------------------------- ### Gmail Processor v2.x Configuration Example Source: https://ahochsteger.github.io/gmail-processor/docs/examples/migrations/migrationAdvanced This JSON object defines the configuration for Gmail Processor v2.x. It includes global settings like filters, sleep times, and timezone, along with a list of processing rules, each specifying filters, target folders, and filename transformations. ```json { "globalFilter": "has:attachment -in:trash -in:drafts -in:spam", "processedLabel": "gmail2gdrive/client-test", "sleepTime": 100, "maxRuntime": 280, "newerThan": "1d", "timezone": "GMT", "rules": [ { "filter": "to:my.name+scans@gmail.com", "folder": "'Scans'-yyyy-MM-dd" }, { "filter": "from:example1@example.com", "folder": "'Examples/example1'" }, { "filter": "from:example2@example.com", "folder": "'Examples/example2'", "filenameFromRegexp": ".*.pdf$" }, { "filter": "(from:example3a@example.com OR from:example3b@example.com)", "folder": "'Examples/example3ab'", "filenameTo": "'file-'yyyy-MM-dd-'%s.txt'", "archive": true }, { "filter": "label:PDF", "saveThreadPDF": true, "folder": "'PDF Emails'" }, { "filter": "from:example4@example.com", "folder": "'Examples/example4'", "filenameFrom": "file.txt", "filenameTo": "'file-'yyyy-MM-dd-'%s.txt'" } ] } ``` -------------------------------- ### Manage Multiple Gmail Processor Configurations in One Project Source: https://ahochsteger.github.io/gmail-processor/docs/faqs This example shows how to use multiple configurations within a single Google Apps Script project for Gmail Processor. It highlights the importance of unique naming for variables and functions to avoid namespace conflicts. ```Google Apps Script var config1 = {...} function run1() { GmailProcessorLib.run(config1, ...) } var config2 = {...} function run2() { GmailProcessorLib.run(config2, ...) } ``` -------------------------------- ### Execute Custom Actions with GmailProcessorLib Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/customActions A TypeScript function that initializes the Gmail Processor configuration and custom actions, then runs the processor in dry-run mode. It defines a 'mylog' custom action for logging. ```typescript function customActionsRun() { const config = { description: "Define custom logic as actions that can be executed during processing.", settings: { markProcessedMethod: "mark-read", }, global: { thread: { match: { query: "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] customActions\"", }, }, }, threads: [ { match: { query: "from:{{user.email}}", }, messages: [ { actions: [ { name: "custom.mylog", args: { arg1: "value1", arg2: "value2", }, }, ], }, ], }, ], } const customActions = [ { name: "mylog", action: (ctx, args) => ctx.log.info(`Called with args '${JSON.stringify(args)}' ...`), }, ] return GmailProcessorLib.run(config, "dry-run", customActions) } ``` -------------------------------- ### Gmail Processor Configuration for Custom Actions Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/customActions Defines the structure for custom actions in Gmail Processor. It includes global thread matching criteria and specific thread processing logic with custom action execution. ```json { "description": "Define custom logic as actions that can be executed during processing.", "settings": { "markProcessedMethod": "mark-read" }, "global": { "thread": { "match": { "query": "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] customActions\"" } } }, "threads": [ { "match": { "query": "from:{{user.email}}" }, "messages": [ { "actions": [ { "name": "custom.mylog", "args": { "arg1": "value1", "arg2": "value2" } } ] } ] } ] } ``` -------------------------------- ### Gmail Processor Configuration: Store Attachment Source: https://ahochsteger.github.io/gmail-processor/docs/examples/basics/simple A JSON configuration for Gmail Processor to identify emails with specific attachments ('invoice.pdf'), match them based on thread criteria, and store the attachments in Google Drive with dynamic naming and conflict handling. ```json { "description": "Use this to get started with Gmail Processor. It stores an attachment to Google Drive.", "settings": { "markProcessedMethod": "mark-read" }, "global": { "thread": { "match": { "query": "has:attachment -in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} is:unread subject:\"[GmailProcessor-Test] simple\"" } } }, "threads": [ { "match": { "query": "from:${user.email}" }, "messages": [ { "attachments": [ { "match": { "name": "^invoice\\.pdf$" }, "actions": [ { "name": "attachment.store", "args": { "location": "/GmailProcessor-Tests/e2e/simple/{{message.date|formatDate('yyyy-MM-dd')}}/{{message.subject}}-{{attachment.name}}", "conflictStrategy": "keep" } } ] } ] } ] } ] } ``` -------------------------------- ### Processing Placeholders for Gmail Processor Source: https://ahochsteger.github.io/gmail-processor/docs/reference/placeholder These placeholders are valid during any processing phase and allow access to the timer's start time and custom-defined variables. ```javascript console.log(`Processing started at: ${timer.startTime}`); console.log(`Custom variable value: ${variables.customVar}`); ``` -------------------------------- ### Gmail Processor Legacy Expression Configuration (JSON) Source: https://ahochsteger.github.io/gmail-processor/docs/examples/regressions/legacyExpressions This JSON configuration defines settings for Gmail Processor, including thread matching criteria and global variables using legacy date formatting expressions. It specifies how to mark processed emails and includes various date manipulation examples. ```json { "description": "This example uses legacy expressions that are deprecated but still should work until support is finally removed.", "settings": { "markProcessedMethod": "mark-read" }, "global": { "thread": { "match": { "query": "has:attachment -in:trash -in:drafts -in:spam after:${date.now:date::yyyy-MM-dd'} is:unread subject:\"[GmailProcessor-Test] legacyExpressions\"" } }, "variables": [ { "key": "date1", "value": "date1: ${date.now:date:-1d}" }, { "key": "date2", "value": "date2: ${date.now:date:-1d:yyyy-MM-dd}" }, { "key": "date3", "value": "date3: ${date.now:date::yyyy-MM-dd}" }, { "key": "format1", "value": "date1: ${date.now:format}" }, { "key": "format2", "value": "date2: ${date.now:format:yyyy-MM-dd}" }, { "key": "join1", "value": "join1: ${date.now:join}" }, { "key": "join2", "value": "join2: ${date.now:join:-}" }, { "key": "offset-date1", "value": "offset-date1: ${date.now:offset-format:-1d}" }, { "key": "offset-date2", "value": "offset-date2: ${date.now:offset-format:-1d:yyyy-MM-dd}" }, { "key": "offset-date3", "value": "offset-date3: ${date.now:offset-format::yyyy-MM-dd}" } ] }, "threads": [{}] } ``` -------------------------------- ### GmailProcessor logSheetLogging Configuration and Execution Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/logSheetLogging Defines the processing rules for Gmail threads, messages, and attachments. It logs details at different processing stages and stores attachments. The configuration is then executed in dry-run mode. ```typescript const config = { threads: [ { match: { query: "-in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} from:{{user.email}} is:unread subject:\"[GmailProcessor-Test] logSheetLogging\"", }, actions: [ { name: "global.sheetLog", args: { level: "info", message: "Thread log (pre-main): {{thread.id}}", }, processingStage: "pre-main", }, { name: "global.sheetLog", args: { level: "info", message: "Thread log (main): {{thread.id}}", }, processingStage: "main", }, { name: "global.sheetLog", args: { level: "info", message: "Thread log (post-main): {{thread.id}}", }, processingStage: "post-main", }, ], messages: [ { actions: [ { name: "global.sheetLog", args: { level: "warn", message: "Message log (pre-main): {{message.id}}", }, processingStage: "pre-main", }, { name: "global.sheetLog", args: { level: "warn", message: "Message log (main): {{message.id}}", }, processingStage: "main", }, { name: "global.sheetLog", args: { level: "warn", message: "Message log (post-main): {{message.id}}", }, processingStage: "post-main", }, ], attachments: [ { actions: [ { name: "global.sheetLog", args: { level: "error", message: "Attachment log (pre-main): {{attachment.hash}}", }, processingStage: "pre-main", }, { name: "attachment.store", args: { conflictStrategy: "update", location: "/GmailProcessor-Tests/e2e/logSheetLogging/{{attachment.name}}", }, }, { name: "global.sheetLog", args: { level: "error", message: "Attachment log (post-main): {{attachment.hash}}", }, processingStage: "post-main", }, ], }, ], }, ], }, ], }; return GmailProcessorLib.run(config, "dry-run") ``` -------------------------------- ### Define Custom Action Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines a custom action to be executed, identified by a name starting with 'custom.'. The processing stage can be 'post-main'. ```JSON { "name": "custom.processAttachment", "processingStage": "post-main" } ``` -------------------------------- ### Define Custom Action Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines a custom action to be executed, identified by a name starting with 'custom.'. This allows for user-defined processing logic. ```JSON { "name": "custom.myCustomAction", "processingStage": "post-main" } ``` -------------------------------- ### Thread Export as PDF Configuration Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines parameters for exporting a thread as a PDF. Requires a name, description, and processing stage. Supports placeholder substitution in the description. ```text name: string (constant: thread.exportAsPdf) description: string processingStage: string (Possible values: main, post-main, pre-main) ``` -------------------------------- ### Store URL to Google Drive (Configuration) Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines the action to store a URL to Google Drive. It specifies parameters like the destination file name, location, and optional conversion to specific Google Drive MIME types. Placeholder substitution is supported for dynamic values. ```configuration { "name": "message.storeFromURL", "location": "{{message.body.match.url}}", "toMimeType": "application/vnd.google-apps.document" } ``` -------------------------------- ### Migrate Gmail2GDrive v1.x to v2.x Configuration with JavaScript Source: https://ahochsteger.github.io/gmail-processor/docs/examples/migrations/migrationAdvanced This JavaScript function demonstrates how to migrate a Gmail2GDrive v1.x configuration object to the Gmail Processor v2.x format using the `GmailProcessorLib.convertV1Config` method. It logs the migrated configuration to the console. ```javascript function migrationAdvancedConvert() { const oldConfig = { globalFilter: "has:attachment -in:trash -in:drafts -in:spam", processedLabel: "gmail2gdrive/client-test", sleepTime: 100, maxRuntime: 280, newerThan: "1d", timezone: "GMT", rules: [ { filter: "to:my.name+scans@gmail.com", folder: "'Scans'-yyyy-MM-dd", }, { filter: "from:example1@example.com", folder: "'Examples/example1'", }, { filter: "from:example2@example.com", folder: "'Examples/example2'", filenameFromRegexp: ".*.pdf$", }, { filter: "(from:example3a@example.com OR from:example3b@example.com)", folder: "'Examples/example3ab'", filenameTo: "'file-'yyyy-MM-dd-'%s.txt'", archive: true, }, { filter: "label:PDF", saveThreadPDF: true, folder: "'PDF Emails'", }, { filter: "from:example4@example.com", folder: "'Examples/example4'", filenameFrom: "file.txt", filenameTo: "'file-'yyyy-MM-dd-'%s.txt'", }, ], } const migratedConfig = GmailProcessorLib.convertV1Config(oldConfig) console.log(JSON.stringify(migratedConfig, null, 2)) return migratedConfig } ``` -------------------------------- ### Store From URL Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Stores content from a URL to a Google Drive file. Supports placeholder substitution for dynamic configuration. ```APIDOC ## POST /websites/ahochsteger_github_io_gmail-processor/actions/storeFromURL ### Description Stores content from a URL to a Google Drive file. Supports placeholder substitution for dynamic configuration. ### Method POST ### Endpoint /websites/ahochsteger_github_io_gmail-processor/actions/storeFromURL ### Parameters #### Request Body - **name** (string) - Required - Constant value: `message.storeFromURL` - **url** (string) - Required - The URL of the document to be stored. Supports placeholder substitution. - **location** (string) - Required - The location (path + filename) of the Google Drive file. Supports placeholder substitution. - **processingStage** (string) - Optional - The stage of action processing. Possible values: `main`, `post-main`, `pre-main`. - **description** (string) - Optional - The description to be attached to the Google Drive file. Supports placeholder substitution. - **headers** (object) - Optional - Key-value pairs for headers. ### Request Example ```json { "name": "message.storeFromURL", "url": "{{message.body.match.url}}", "location": "/{{message.from.email}}/{{message.subject}}.pdf", "description": "Email content from {{message.subject}}", "processingStage": "main" } ``` ### Response #### Success Response (200) - **message** (string) - A success message indicating the operation completed. #### Response Example ```json { "message": "Successfully stored content from URL to Google Drive." } ``` ``` -------------------------------- ### Environment Placeholders for Gmail Processor Source: https://ahochsteger.github.io/gmail-processor/docs/reference/placeholder These placeholders are globally valid and can be used during adapter initialization or for internal purposes. They provide access to current timestamps, run modes, timezones, and library details. ```javascript console.log(`Current timestamp: ${date.now}`); console.log(`Run mode: ${env.runMode}`); console.log(`Timezone: ${env.timezone}`); console.log(`Library version: ${lib.version}`); console.log(`User email: ${user.email}`); ``` -------------------------------- ### Manual Configuration Conversion Logic (TypeScript) Source: https://ahochsteger.github.io/gmail-processor/docs/migrating This snippet refers to a TypeScript file that contains the logic for converting configurations from the old Gmail2GDrive format to the new Gmail Processor format. It's useful for understanding the transformation process. ```typescript import { GmailProcessorConfigV1 } from './types'; export function convertV1ToV2(configV1: GmailProcessorConfigV1): any { // Conversion logic here const configV2 = { // ... new format properties ... }; return configV2; } ``` -------------------------------- ### Thread Store PDF Configuration Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Configures storing a thread as a PDF in Google Drive. Requires a name, description, and processing stage. Includes arguments for conflict strategy, description, location, skip header, and MIME type conversion. ```text name: string (constant: thread.storePDF) args: ThreadActionArgsStorePDF (object, required) conflictStrategy: ConflictStrategy (string, required; Possible values: backup, error, keep, replace, skip, update) description: string (supports placeholder substitution) location: string (required, path + filename, supports placeholder substitution, prepend with {id:}/ for shared folders/Team Drives) skipHeader: boolean toMimeType: string (Google Drive MIME type) description: string processingStage: string (Possible values: main, post-main, pre-main) ``` -------------------------------- ### Configure Gmail Processor for LogSheet Logging (JSON) Source: https://ahochsteger.github.io/gmail-processor/docs/examples/advanced/logSheetLogging This JSON configuration defines the settings for logging data to a Google Spreadsheet. It specifies the spreadsheet location, fields to log, and tracing behavior. It also outlines the matching criteria for Gmail threads and the actions to perform, including logging at various processing stages for threads, messages, and attachments. ```json { "description": "Logs data to a Google Spreadsheet.", "settings": { "markProcessedMethod": "mark-read", "logSheetLocation": "/GmailProcessor-Tests/logsheet-{{date.now|formatDate('yyyy-MM')}}", "logSheetTracing": true, "logFields": [ "log.timestamp", "log.level", "log.location", "log.message", "object.id", "object.date", "object.subject", "object.from", "object.url", "attachment.name", "attachment.size", "attachment.contentType", "stored.location", "stored.url", "stored.downloadUrl", "context.type" ] }, "threads": [ { "match": { "query": "-in:trash -in:drafts -in:spam after:{{date.now|formatDate('yyyy-MM-dd')}} from:{{user.email}} is:unread subject:\"[GmailProcessor-Test] logSheetLogging\"" }, "actions": [ { "name": "global.sheetLog", "args": { "level": "info", "message": "Thread log (pre-main): {{thread.id}}" }, "processingStage": "pre-main" }, { "name": "global.sheetLog", "args": { "level": "info", "message": "Thread log (main): {{thread.id}}" }, "processingStage": "main" }, { "name": "global.sheetLog", "args": { "level": "info", "message": "Thread log (post-main): {{thread.id}}" }, "processingStage": "post-main" } ], "messages": [ { "actions": [ { "name": "global.sheetLog", "args": { "level": "warn", "message": "Message log (pre-main): {{message.id}}" }, "processingStage": "pre-main" }, { "name": "global.sheetLog", "args": { "level": "warn", "message": "Message log (main): {{message.id}}" }, "processingStage": "main" }, { "name": "global.sheetLog", "args": { "level": "warn", "message": "Message log (post-main): {{message.id}}" }, "processingStage": "post-main" } ], "attachments": [ { "actions": [ { "name": "global.sheetLog", "args": { "level": "error", "message": "Attachment log (pre-main): {{attachment.hash}}" }, "processingStage": "pre-main" }, { "name": "attachment.store", "args": { "conflictStrategy": "update", "location": "/GmailProcessor-Tests/e2e/logSheetLogging/{{attachment.name}}" } }, { "name": "global.sheetLog", "args": { "level": "error", "message": "Attachment log (post-main): {{attachment.hash}}" }, "processingStage": "post-main" } ] } ] } ] } ] } ``` -------------------------------- ### Devbox Shell Init Hook Source: https://ahochsteger.github.io/gmail-processor/docs/development/devbox A script that runs automatically when the Devbox environment is initialized, ensuring corepack is enabled and the PATH is configured correctly for Node.js development. It also provides a welcome message. ```shell test -z $DEVBOX_COREPACK_ENABLED || corepack enable --install-directory "/home/a13870/private/ws/github/ahochsteger/gmail-processor/.devbox/virtenv/nodejs/corepack-bin/" test -z $DEVBOX_COREPACK_ENABLED || export PATH="/home/a13870/private/ws/github/ahochsteger/gmail-processor/.devbox/virtenv/nodejs/corepack-bin/:$PATH" echo 'Welcome to gmail-processor devbox!' > /dev/null ``` -------------------------------- ### Thread Actions Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema API endpoints for performing actions on threads and exporting them to Google Drive. ```APIDOC ## POST /api/threads/noop ### Description Performs a no-operation action on a thread. This can be used for testing or as a placeholder. ### Method POST ### Endpoint /api/threads/noop ### Parameters #### Request Body - **name** (string) - Required - Constant value: `thread.noop` - **processingStage** (string) - Optional - Possible values: `main`, `post-main`, `pre-main`. The stage of action processing. - **args** (object) - Optional - Arguments for the no-operation. - **name** (string) - Required - The name of the no-operation. - **description** (string) - Optional - Description of the action. ### Request Example ```json { "name": "thread.noop", "processingStage": "main", "args": { "name": "NoOpAction" }, "description": "Performing a no-operation on the thread" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success or failure of the operation. #### Response Example ```json { "status": "success" } ``` ``` ```APIDOC ## POST /api/threads/addLabel ### Description Adds a label to a thread. ### Method POST ### Endpoint /api/threads/addLabel ### Parameters #### Request Body - **name** (string) - Required - Constant value: `thread.addLabel` - **processingStage** (string) - Optional - Possible values: `main`, `post-main`, `pre-main`. The stage of action processing. - **args** (ThreadActionExportArgs) - Required - Arguments for adding a label. - **name** (string) - Required - The name of the label. - **description** (string) - Optional - Description of the action. ### Request Example ```json { "name": "thread.addLabel", "processingStage": "main", "args": { "name": "Processed" }, "description": "Adding 'Processed' label to the thread" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success or failure of the operation. #### Response Example ```json { "status": "success" } ``` ``` ```APIDOC ## POST /api/threads/export ### Description Exports a thread to Google Drive with various configuration options. ### Method POST ### Endpoint /api/threads/export ### Parameters #### Request Body - **name** (string) - Required - Constant value: `thread.export` (Assumed based on context, not explicitly stated) - **processingStage** (string) - Optional - Possible values: `main`, `post-main`, `pre-main`. The stage of action processing. - **args** (ThreadActionExportArgs) - Required - Arguments for exporting the thread. - **conflictStrategy** (string) - Required - Possible values: `backup`, `error`, `keep`, `replace`, `skip`, `update`. Strategy for handling conflicts. - **description** (string) - Optional - Description for the Google Drive file. Supports placeholder substitution. - **embedAttachments** (boolean) - Optional - Embed attachments (default: `true`). - **embedAvatar** (boolean) - Optional - Embed sender's avatar (default: `true`). - **embedInlineImages** (boolean) - Optional - Embed inline images (default: `true`). - **embedRemoteImages** (boolean) - Optional - Embed remote images (default: `true`). - **includeAttachments** (boolean) - Optional - Include attachments (default: `true`). - **includeHeader** (boolean) - Optional - Include message header (default: `true`). - **location** (string) - Required - Path and filename for the Google Drive file. Supports placeholder substitution. Prepend with `{id:}/` for shared folders. - **toMimeType** (string) - Optional - MIME type for the exported file. - **description** (string) - Optional - Description of the action. ### Request Example ```json { "name": "thread.export", "processingStage": "main", "args": { "location": "my-drive/exports/email.eml", "conflictStrategy": "replace", "includeAttachments": true, "description": "Exported email with attachments" }, "description": "Exporting thread to Google Drive" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates success or failure of the operation. #### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Star Message Configuration Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines the 'star' action for Gmail messages. This configuration specifies the processing stage and the expected arguments, including description and name. ```json { "processingStage": "main" | "post-main" | "pre-main", "args": { "description": "string", "name": "message.star" } } ``` -------------------------------- ### Message Actions: Move to Trash, Star, Unstar, No Operation Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines the possible actions for individual messages or threads. These include moving messages to the trash, starring or unstarring them, or performing a no-operation action. ```configuration { "type": "object", "args": "args" } ``` ```configuration { "type": "any", "description": "description" } ``` ```configuration { "type": "string", "name": "name", "required": "constant", "constantValue": "message.moveToTrash" } ``` ```configuration { "type": "string", "name": "processingStage", "possibleValues": [ "main", "post-main", "pre-main" ], "description": "The stage of action processing" } ``` ```configuration { "type": "object", "name": "message.star" } ``` ```configuration { "type": "object", "name": "message.unstar" } ``` ```configuration { "type": "object", "name": "thread.noop" } ``` -------------------------------- ### Message Configuration Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Defines how a specific Gmail message should be handled. Includes matching rules and actions to be performed on the message. ```json { "name": "message-config-name", "match": { "from": "sender@example.com", "subject": "Report" }, "orderBy": "date", "orderDirection": "desc" } ``` -------------------------------- ### Thread Actions API Source: https://ahochsteger.github.io/gmail-processor/docs/reference/config-schema Handles actions related to threads, including applying labels and exporting to Google Drive. ```APIDOC ## POST /api/process/thread/noop ### Description Performs a no-operation on a thread. This action does nothing. ### Method POST ### Endpoint /api/process/thread/noop ### Parameters #### Request Body - **args** (any) - Optional - Arguments for the action. Always valid. - **description** (string) - Description of the arguments. - **name** (string) - Required - Constant value: `thread.noop`. - **processingStage** (string) - Required - The stage of action processing. Possible values: `main`, `post-main`, `pre-main`. ### Request Example ```json { "name": "thread.noop", "processingStage": "main" } ``` ### Response #### Success Response (200) - **No specific success response fields documented.** ## POST /api/process/thread/addLabel ### Description Adds a label to a thread. ### Method POST ### Endpoint /api/process/thread/addLabel ### Parameters #### Request Body - **args** (object) - Required - Arguments for the action. - **name** (string) - Required - The name of the label. - **description** (string) - Description of the arguments. - **name** (string) - Required - Constant value: `thread.addLabel`. - **processingStage** (string) - Required - The stage of action processing. Possible values: `main`, `post-main`, `pre-main`. ### Request Example ```json { "name": "thread.addLabel", "args": { "name": "NewLabel" }, "processingStage": "main" } ``` ### Response #### Success Response (200) - **No specific success response fields documented.** ## POST /api/process/thread/export ### Description Exports a thread to Google Drive with various configuration options. ### Method POST ### Endpoint /api/process/thread/export ### Parameters #### Request Body - **args** (object) - Required - Arguments for the export action. - **conflictStrategy** (string) - Required - Strategy for handling conflicts. Possible values: `backup`, `error`, `keep`, `replace`, `skip`, `update`. - **description** (string) - The description for the Google Drive file. Supports placeholder substitution. - **embedAttachments** (boolean) - Embed attachments. Default: `true`. - **embedAvatar** (boolean) - Embed sender's avatar. Default: `true`. - **embedInlineImages** (boolean) - Embed inline images. Default: `true`. - **embedRemoteImages** (boolean) - Embed remote images. Default: `true`. - **includeAttachments** (boolean) - Include attachments. Default: `true`. - **includeHeader** (boolean) - Include message header. Default: `true`. - **location** (string) - Required - The path and filename for the Google Drive file. Supports placeholder substitution. Prepend with `{id:}/...` for shared folders. - **toMimeType** (string) - Converts the file to a specified Google file type (e.g., `application/vnd.google-apps.document`). - **width** (number) - The width of the message in pixels. Default: `700`. - **description** (string) - Description of the arguments. - **name** (string) - Required - Constant value: `thread.export`. - **processingStage** (string) - Required - The stage of action processing. Possible values: `main`, `post-main`, `pre-main`. ### Request Example ```json { "name": "thread.export", "args": { "location": "/MyFolder/MyFile.pdf", "toMimeType": "application/pdf", "description": "Exported thread from Gmail", "conflictStrategy": "replace" }, "processingStage": "main" } ``` ### Response #### Success Response (200) - **No specific success response fields documented.** ```