Skip to content

Conversation

@ManojTestsigma
Copy link
Contributor

@ManojTestsigma ManojTestsigma commented Aug 5, 2025

jira

no jira created for this

Addon Name : Gmail Api With filters
Addon account: [email protected]
jarvis link : https://jarvis.testsigma.com/ui/tenants/2817/addons

fix

this addon can be used for mailbox alias function
to filter the emails based on subject, sender etc..

Summary by CodeRabbit

  • New Features
    • Added the ability to filter and extract content from mailbox emails based on specified criteria and store the results as runtime variables.
  • Chores
    • Introduced new project configuration files and dependencies to support mailbox actions.
    • Added configuration for API key integration.

@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Walkthrough

A new Maven module named mailbox_actions has been introduced. This includes a Maven project descriptor (pom.xml), a Java class for filtering and extracting mailbox content based on user-defined criteria, and a properties file containing an API key for the TestSigma SDK.

Changes

Cohort / File(s) Change Summary
Maven Project Setup
mailbox_actions/pom.xml
Added a Maven descriptor defining project metadata, dependencies (TestSigma SDK, Selenium, Appium, Jackson, Javax Mail, etc.), Java version, build plugins, and packaging configuration for the mailbox_actions module.
Mailbox Content Extraction Action
mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java
Introduced a new public Java class that filters mailbox messages by specified criteria, applies a regex to extract content, and stores the result in a runtime variable, with detailed logging and error handling.
SDK Properties
mailbox_actions/src/main/resources/testsigma-sdk.properties
Added a properties file with a single entry for the TestSigma SDK API key.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GetMailBoxContentBasedOnFilter
    participant Mailbox
    participant RuntimeVariableStore

    User->>GetMailBoxContentBasedOnFilter: execute()
    GetMailBoxContentBasedOnFilter->>Mailbox: setEmailId(emailId)
    GetMailBoxContentBasedOnFilter->>Mailbox: getAllMessages()
    GetMailBoxContentBasedOnFilter->>GetMailBoxContentBasedOnFilter: filter messages by type/text
    GetMailBoxContentBasedOnFilter->>GetMailBoxContentBasedOnFilter: extract content with regex
    alt Content found
        GetMailBoxContentBasedOnFilter->>RuntimeVariableStore: store extracted content
        GetMailBoxContentBasedOnFilter-->>User: return SUCCESS
    else No content or error
        GetMailBoxContentBasedOnFilter-->>User: return FAILED
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • Ganesh-Testsigma

Poem

Hopping through code with mailbox delight,
A new action appears, filtering emails just right.
With regex and runtime, results are in store—
Maven’s in order, dependencies galore!
A secret key whispers, “Let’s automate mail!”
This bunny approves—onward, without fail!
🐇📬✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch PRE-xyz

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

Copy link

@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: 7

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c5a4cf and 20f8c2b.

📒 Files selected for processing (2)
  • gmail_api_with_filters/pom.xml (1 hunks)
  • gmail_api_with_filters/src/main/java/com/testsigma/addons/web/GetGmailContent.java (1 hunks)
🔇 Additional comments (2)
gmail_api_with_filters/pom.xml (1)

75-105: LGTM - Build configuration is appropriate for addon packaging.

The Maven Shade Plugin configuration correctly creates an uber-jar with all dependencies, and the Maven Source Plugin ensures source code is available. This setup is well-suited for TestSigma addon deployment.

gmail_api_with_filters/src/main/java/com/testsigma/addons/web/GetGmailContent.java (1)

17-39: LGTM - Well-structured class annotations and field declarations.

The class is properly annotated with clear action description and appropriate data binding. The use of Lombok's @DaTa annotation reduces boilerplate code effectively.

Copy link

@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: 2

🧹 Nitpick comments (4)
mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java (4)

19-25: Fix typo in the action description.

There's a grammatical error in line 23: "store the content based ont the filter" should be "store the content based on the filter".

-        description = "Get email content from mailbox using emailID and" +
-                " store the content based ont the filter in a runtime variable.",
+        description = "Get email content from mailbox using emailID and" +
+                " store the content based on the filter in a runtime variable.",

97-100: Consider regex pattern flags and compilation safety.

The Pattern.DOTALL flag makes . match newlines, which might not always be desired. Also, consider handling potential PatternSyntaxException for invalid regex patterns.

-                    Pattern pattern = Pattern.compile(
-                        regexCondition.getValue().toString(), 
-                        Pattern.DOTALL
-                    );
+                    try {
+                        Pattern pattern = Pattern.compile(
+                            regexCondition.getValue().toString()
+                        );
+                    } catch (PatternSyntaxException e) {
+                        logger.warn("Invalid regex pattern: " + e.getMessage());
+                        output = messageContent; // Fallback to full content
+                        continue; // Skip regex processing
+                    }

117-125: Simplify null checking logic.

Since output is initialized as an empty string on line 90, the null check on line 117 is redundant.

-            if(output != null && !output.isEmpty()){
+            if(!output.isEmpty()){
                logger.info("setting runtime variable " + output);
                runTimeData.setValue(output);
                runTimeData.setKey(runtimeVariable.getValue().toString());
            } else {
                logger.info("No content found in the email");
                setErrorMessage("No content found in the email");
                return Result.FAILED;
            }

103-108: Improve regex matching logic.

Consider using capturing groups for more precise content extraction instead of returning the entire match.

                    if (matcher.find()) {
-                        output = matcher.group();
+                        // Use group(1) if regex has capturing groups, otherwise use group()
+                        output = matcher.groupCount() > 0 ? matcher.group(1) : matcher.group();
                    } else {
                        // If no regex match found, return the full content
                        output = messageContent;
                    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f7e960a and 16ea615.

📒 Files selected for processing (3)
  • mailbox_actions/pom.xml (1 hunks)
  • mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java (1 hunks)
  • mailbox_actions/src/main/resources/testsigma-sdk.properties (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • mailbox_actions/src/main/resources/testsigma-sdk.properties
  • mailbox_actions/pom.xml
🔇 Additional comments (2)
mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java (2)

1-17: LGTM!

Package declaration and imports are well-organized and all appear to be used in the implementation.


73-85: Fix case sensitivity in switch statement.

The switch statement uses incorrect case for "sentto" and "receivedfrom" which doesn't match the allowedValues in the annotation.

                    switch (currentFilterType.toLowerCase()) {
                        case "subject":
                            return message.getSubject() != null && 
                                   message.getSubject().contains(filterValue);
-                        case "sentto":
+                        case "sentto":
                            return message.getSentTo() != null && 
                                   message.getSentTo().contains(filterValue);
-                        case "receivedfrom":
+                        case "receivedfrom":
                            return message.getReceivedFrom() != null && 
                                   message.getReceivedFrom().contains(filterValue);
                        default:
                            return false;
                    }

Likely an incorrect or invalid review comment.

Comment on lines +36 to +37
@TestData(reference = "filter-type", allowedValues = {"subject","sentTo","receivedFrom"})
private com.testsigma.sdk.TestData filterType;
Copy link

@coderabbitai coderabbitai bot Aug 5, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix case sensitivity mismatch between allowedValues and switch statement.

The allowedValues use camelCase ("sentTo", "receivedFrom") but the switch statement in lines 77-82 checks for lowercase ("sentto", "receivedfrom"). This mismatch could cause the filter to always return false for these cases.

-    @TestData(reference = "filter-type", allowedValues = {"subject","sentTo","receivedFrom"})
+    @TestData(reference = "filter-type", allowedValues = {"subject","sentto","receivedfrom"})

Or alternatively, update the switch statement to match the camelCase values.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@TestData(reference = "filter-type", allowedValues = {"subject","sentTo","receivedFrom"})
private com.testsigma.sdk.TestData filterType;
@TestData(reference = "filter-type", allowedValues = {"subject","sentto","receivedfrom"})
private com.testsigma.sdk.TestData filterType;
🤖 Prompt for AI Agents
In
mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java
around lines 36-37 and 77-82, the allowedValues for filterType use camelCase
("sentTo", "receivedFrom") but the switch statement checks for lowercase
("sentto", "receivedfrom"). To fix this, update the switch statement cases to
use the exact camelCase strings as in allowedValues to ensure correct matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added toLowerCase so this should not cause any issue
switch (currentFilterType.toLowerCase()) {
case "subject":
return message.getSubject() != null &&
message.getSubject().contains(filterValue);
....
}

Copy link

Choose a reason for hiding this comment

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

@ManojTestsigma You're absolutely right! Adding toLowerCase() to the switch condition is an excellent solution that resolves the case sensitivity issue. This approach is actually better than my suggested fix because:

  1. It preserves the more readable camelCase format in the allowedValues annotation
  2. It makes the code more robust by handling any case variations that might be passed at runtime
  3. It ensures consistent behavior regardless of how users input the filter type

Your implementation correctly converts the input to lowercase before comparison with the lowercase case labels, which eliminates the mismatch I flagged. Thank you for the clarification!


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

Comment on lines +57 to +66
try {
for( MailboxMessage messageIterator : messages ) {
logger.info("message : " + messageIterator.getSubject());
logger.info("content : " + messageIterator.getTextMessage());
logger.info("from : " + messageIterator.getReceivedFrom());
}
} catch (Exception e) {
//
logger.info("ignoring messages");
}
Copy link

@coderabbitai coderabbitai bot Aug 5, 2025

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling and consider information disclosure.

The empty catch block silently ignores exceptions, which could hide important errors. Additionally, logging email content and sender information could expose sensitive data.

-            try {
-                for( MailboxMessage messageIterator : messages ) {
-                    logger.info("message : " + messageIterator.getSubject());
-                    logger.info("content : " + messageIterator.getTextMessage());
-                    logger.info("from : " + messageIterator.getReceivedFrom());
-                }
-            } catch (Exception e) {
-                //
-                logger.info("ignoring messages");
-            }
+            try {
+                for( MailboxMessage messageIterator : messages ) {
+                    logger.debug("Processing message with subject: [REDACTED]");
+                    // Avoid logging sensitive email content and addresses
+                }
+            } catch (Exception e) {
+                logger.warn("Failed to process message details: " + e.getMessage());
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try {
for( MailboxMessage messageIterator : messages ) {
logger.info("message : " + messageIterator.getSubject());
logger.info("content : " + messageIterator.getTextMessage());
logger.info("from : " + messageIterator.getReceivedFrom());
}
} catch (Exception e) {
//
logger.info("ignoring messages");
}
try {
for( MailboxMessage messageIterator : messages ) {
logger.debug("Processing message with subject: [REDACTED]");
// Avoid logging sensitive email content and addresses
}
} catch (Exception e) {
logger.warn("Failed to process message details: " + e.getMessage());
}
🤖 Prompt for AI Agents
In
mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java
around lines 57 to 66, the catch block currently ignores exceptions silently,
which can hide errors, and the logs expose potentially sensitive email content
and sender information. Modify the catch block to log the exception details at
an appropriate level (e.g., warning or error) instead of ignoring it. Also,
remove or mask sensitive information such as email content and sender details
from the logs to prevent information disclosure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is for debugging purpose, ignoring this in case of empty subject etc..

Copy link

Choose a reason for hiding this comment

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

@ManojTestsigma, I understand this is for debugging purposes to handle cases like empty subjects. Since you need the debugging information, here's a compromise that maintains your debugging capability while addressing potential security concerns:

try {
    for( MailboxMessage messageIterator : messages ) {
        logger.debug("message : " + (messageIterator.getSubject() != null ? "[SUBJECT_PRESENT]" : "[EMPTY_SUBJECT]"));
        logger.debug("content length : " + (messageIterator.getTextMessage() != null ? messageIterator.getTextMessage().length() : 0));
        logger.debug("from : " + (messageIterator.getReceivedFrom() != null ? "[SENDER_PRESENT]" : "[NO_SENDER]"));
    }
} catch (Exception e) {
    logger.debug("Exception while processing messages: " + e.getMessage());
}

This way, you can still debug empty subjects and other issues without exposing the actual email content in logs. But if you prefer to keep the current implementation for your debugging workflow, that's your call!

(๑•́ ◡ •̀๑) ♪


✏️ Learnings added
Learnt from: ManojTestsigma
PR: testsigmahq/testsigma-addons#202
File: mailbox_actions/src/main/java/com/testsigma/addons/web/test/GetMailBoxContentBasedOnFilter.java:57-66
Timestamp: 2025-08-05T09:16:20.323Z
Learning: In the GetMailBoxContentBasedOnFilter addon, the logging of email subjects, content, and sender information is intentionally kept for debugging purposes, particularly to handle cases with empty subjects. The user ManojTestsigma prefers this approach for debugging the mailbox filtering functionality.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@ManojTestsigma ManojTestsigma merged commit d2626aa into dev Sep 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants