Skip to content

Conversation

@hugobiais
Copy link
Contributor

@hugobiais hugobiais commented Jun 3, 2025

Summary

Resolves #16932 and another problem where, with withTextPayload enabled, the payload could end up empty.

Changes

  • find-email.mjs

    • Bumped version to 0.1.1
    • Removed inline Base64 decoding and per-part logic; replaced with imports from newly created utils.mjs.
    • Updated run logic so that:
      • When withTextPayload = false, each part’s decoded text is attached to part.body.text (preserving the original MIME structure).
      • When withTextPayload = true, all decoded text is concatenated and set to message.payload (avoiding empty payloads).
  • utils.mjs

    • New helper file exporting:
      • decodeBase64Url(data): Converts Gmail’s base64url strings into UTF-8.
      • extractTextFromParts(parts): Recursively walks nested parts, decodes text/plain and converts text/html to plain text.
      • attachTextToParts(parts): Recursively traverses and attaches decoded text to part.body.text for each text/plain or text/html part.

Why

  • Correct Base64 decoding: Gmail returns message bodies as base64url; using standard "base64" decoding could produce garbled content. Converting -+ and _/ ensures reliable results.

  • Nested MIME handling: Previously, deeply nested parts could be skipped, leading to missing or empty payloads when withTextPayload = true. The new recursive helpers guarantee no text is lost.

  • Readability and maintainability: Extracting decoding and part traversal into utils.mjs separates concerns, making it easier to reason about payload mutation versus text extraction.

How to test

1. Publish the component:

pd publish components/gmail/actions/find-email/find-email.mjs

2. Test without withTextPayload:

  • Trigger the action on a variety of emails (single-part, multipart, HTML and plain-text).
  • Verify that message.payload.parts[i].body.text exists for each part and contains the decoded content.
  • Confirm that no other fields in message.payload are overwritten.

3. Test with withTextPayload = true:

  • Rerun the action with the same test emails, setting withTextPayload to true.
  • Verify that message.payload is a single string containing all decoded text (HTML converted to plain text) and is never empty.
  • Confirm that nested MIME parts’ content appears in the concatenated string.

4. Verify Message-ID extraction:

  • For each test email, check that message.message_id matches the Message-ID header in Gmail.

5. Potential edge cases:

  • Test an email with deep nesting (e.g., multipart/mixedmultipart/alternativetext/plain & text/html).
  • Test an email without any payload.body.data (attachment-only); ensure no runtime errors occur and payload remains unchanged if withTextPayload = false.

Ressources

Summary by CodeRabbit

  • New Features

    • Improved extraction and display of plain text from Gmail messages, including better handling of multi-part emails and attachments.
    • Added support for retrieving the "message-id" from email headers.
  • Bug Fixes

    • Enhanced decoding of email content for more accurate text representation in various email formats.
  • Chores

    • Updated package version to 0.3.4.
    • Incremented versions of "Create Draft" and "Send Email" actions.

@vercel
Copy link

vercel bot commented Jun 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jun 5, 2025 6:01am

@vercel
Copy link

vercel bot commented Jun 3, 2025

@hugobiais is attempting to deploy a commit to the Pipedreamers Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce new utility functions for decoding and extracting plain text from Gmail message payloads, update the logic for processing message parts in the Gmail Search Email action, and ensure the "message-id" header is extracted and included in the returned payload. Package versions are incremented accordingly.

Changes

File(s) Change Summary
components/gmail/actions/find-email/find-email.mjs Refactored message payload processing; added extraction of "message-id" header; updated text extraction logic; bumped version.
components/gmail/common/utils.mjs Added decodeBase64Url, extractTextFromParts, and attachTextToParts utility functions for decoding and text extraction.
components/gmail/package.json Incremented package version from 0.3.3 to 0.3.4.
components/gmail/actions/create-draft/create-draft.mjs, components/gmail/actions/send-email/send-email.mjs Version bumps only for create-draft (0.1.2 → 0.1.3) and send-email (0.1.10 → 0.1.11) actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FindEmailAction
    participant GmailAPI
    participant Utils

    User->>FindEmailAction: Trigger search email action
    FindEmailAction->>GmailAPI: Fetch message payload
    GmailAPI-->>FindEmailAction: Return message data
    FindEmailAction->>Utils: decodeBase64Url / extractTextFromParts / attachTextToParts
    Utils-->>FindEmailAction: Decoded and extracted text, message-id
    FindEmailAction-->>User: Return processed payload with message_id and plain text
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure messageId is returned in the plain text payload for Gmail Search Email action (#16932)

Poem

In the warren where emails dwell,
A message-id now hops in as well!
With utils that decode and extract,
Plain text emerges, neat and exact.
Version bumped, the code feels bright—
The Gmail bunny got it right!
🐇📧


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@adolfo-pd adolfo-pd added the User submitted Submitted by a user label Jun 3, 2025
@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
components/gmail/actions/find-email/utils.mjs (1)

1-1: Add JSDoc documentation for the module.

Following the Pipedream component guidelines, add module-level documentation.

+/**
+ * Utility functions for processing Gmail message payloads and MIME parts.
+ * Handles base64url decoding and text extraction from complex MIME structures.
+ */
 import { convert } from "html-to-text";
components/gmail/actions/find-email/find-email.mjs (1)

65-65: Consider initializing newPayload conditionally.

Minor optimization: only initialize newPayload when withTextPayload is true to make the intent clearer.

 for await (const message of messagesToEmit) {
-  let newPayload = "";
+  let newPayload = this.withTextPayload ? "" : undefined;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56a1a2e and 388bd1d.

📒 Files selected for processing (2)
  • components/gmail/actions/find-email/find-email.mjs (2 hunks)
  • components/gmail/actions/find-email/utils.mjs (1 hunks)
🔇 Additional comments (4)
components/gmail/actions/find-email/find-email.mjs (4)

3-7: LGTM! Clean import of utility functions.

The import structure is well-organized and follows ES6 module conventions properly.


13-13: LGTM! Appropriate version bump for bug fix.

Version bump to 0.1.1 is appropriate for addressing the empty payload issue mentioned in the PR objectives.


67-72: LGTM! Correct message-id header extraction.

The header extraction logic properly handles case-insensitive lookup and safely assigns the value. This addresses one of the requirements mentioned in the PR objectives.


83-89: LGTM! Proper handling of multipart messages.

The conditional logic correctly uses the appropriate utility functions based on the withTextPayload flag, which should resolve the empty payload issue mentioned in the PR objectives.

lcaresia
lcaresia previously approved these changes Jun 4, 2025
@dannyroosevelt dannyroosevelt moved this from Ready for PR Review to Ready for QA in Component (Source and Action) Backlog Jun 4, 2025
@michelle0927 michelle0927 moved this from Ready for QA to In Review in Component (Source and Action) Backlog Jun 4, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 388bd1d and 2a66677.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • components/gmail/actions/find-email/find-email.mjs (2 hunks)
  • components/gmail/common/utils.mjs (2 hunks)
  • components/gmail/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/gmail/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/gmail/actions/find-email/find-email.mjs
🔇 Additional comments (2)
components/gmail/common/utils.mjs (2)

1-1: LGTM: Import statement is appropriate.

The html-to-text import is correctly used for converting HTML content to plain text in the utility functions.


49-54: LGTM: Export structure is clean.

The export object properly exposes all utility functions including the existing parseArray function.

Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for QA!

@dannyroosevelt dannyroosevelt merged commit 4632fa3 into PipedreamHQ:master Jun 5, 2025
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

User submitted Submitted by a user

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ACTION] make sure messageId is returned in the plain text payload for Gmail Search Email action

6 participants