Skip to content

feat(Email Trigger (IMAP) Node): IMAP trigger node returns message UIDs #13152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025

Conversation

umanamente
Copy link
Contributor

@umanamente umanamente commented Feb 9, 2025

Summary

This PR adds returning the UID for each email message in the IMAP Trigger node. This allows subsequent nodes to use the UID for email manipulation. For example, the community IMAP node n8n-nodes-imap supports moving and copying emails between mailboxes, which requires the UID. Previously, this information was missing in the IMAP Trigger node output.

Steps to test:

  1. Configure the IMAP Trigger node.
  2. Wait for it to return a new email message.
  3. Check the output data — the attributes field should contain the UID field.

2025-02-09 12_49_53

Related Linear tickets, Github issues, and Community forum posts

Review / Merge checklist

  • PR title and summary are descriptive.
  • Docs updated or follow-up ticket created. NO DOCS AVAILABLE IN BASELINE
  • Tests included. - NO TESTS AVAILABLE IN BASELINE
  • PR labeled with release/backport (if necessary). - NO NEED

@n8n-assistant n8n-assistant bot added community Authored by a community member node/improvement New feature or request in linear Issue or PR has been created in Linear for internal review labels Feb 9, 2025
@Joffcom
Copy link
Member

Joffcom commented Feb 9, 2025

Hey @umanamente,

Thanks for the PR, We have created "GHC-783" as the internal reference to get this reviewed.

One of us will be in touch if there are any changes needed, in most cases this is normally within a couple of weeks but it depends on the current workload of the team.

dana-gill
dana-gill previously approved these changes Feb 13, 2025
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@umanamente umanamente changed the title feat(IMAP trigger): IMAP trigger node returns message UIDs feat(IMAP trigger Node): IMAP trigger node returns message UIDs Feb 13, 2025
@umanamente umanamente requested a review from dana-gill February 21, 2025 10:22
@umanamente umanamente changed the title feat(IMAP trigger Node): IMAP trigger node returns message UIDs feat(Email Trigger (IMAP) Node): IMAP trigger node returns message UIDs Feb 22, 2025
@dana-gill
Copy link
Contributor

@umanamente hi, could you please fix the tests 🙏 thank you!

@@ -42,6 +42,9 @@ describe('Test IMap V2 utils', () => {
headers: { '': 'Body content' },
headerLines: undefined,
html: false,
attributes: {
uid: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add the following test cases:

  1. Expect the uid to be defined
  2. uid is in the wrong format -- Probably requires some try/catch in getEmails of v2.

🙏

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 added the first test: 'Expect the uid to be defined.'
I think the second test is unnecessary since the uid is already used in the code. Let me know your thoughts.

@dana-gill
Copy link
Contributor

Hey @umanamente thanks for adding the test case for uid to be defined 😄 I think there was a bit of miscommunication on my end for what I would expect to see for test cases. Here are the test cases I would expect to see for this PR:

  1. uid is not defined
  2. uid is defined

So you would have the following tests cases:

it('should return new emails' => ... )
// keep as is

it('should return new emails with uid if uid is present' => ... )
// this should be the same 'should return new emails' except you add uid to message and expect uid

Let me know if this makes sense

@umanamente
Copy link
Contributor Author

If uid is not present, the node itself will break, since uid is used in the code before returning

@koordinator7
Copy link

\ @umanamente

Good day. Please tell me how I can get UID in the IMAP node? If it's not too much trouble, in more detail, where and what code should I write?

@umanamente umanamente requested a review from dana-gill March 14, 2025 02:29
@umanamente
Copy link
Contributor Author

@dana-gill
I don't think adding a test to validate the UID makes sense because if the UID is not valid, the existing node functionality will break. If this test is necessary, it should be added by the developers maintaining this node, as it affects the node's functionality itself rather than the changes introduced in this pull request.

Please let me know your thoughts and if any further changes are needed before it can be merged.

@koordinator7
Copy link

@umanamente
Good day. Please tell me how I can get UID in the IMAP node? If it's not too much trouble, in more detail, where and what code should I write?

@umanamente
Copy link
Contributor Author

@umanamente
Good day. Please tell me how I can get UID in the IMAP node? If it's not too much trouble, in more detail, where and what code should I write?

This function is not available in the node yet. This pull request adds it, but it needs to be merged first.

@koordinator7
Copy link

@umanamente

This function is not available in the node yet. This pull request adds it, but it needs to be merged first.
Thank you. I understand that the standard IMAP node does not yet contain UID. But you somehow get UID in the IMAP node. Please tell me what I need to do to get UID too. If it is not difficult, please provide more details.

dana-gill
dana-gill previously approved these changes Mar 18, 2025
@dana-gill
Copy link
Contributor

Hey @umanamente could you rebase off of master and then ping me and you've done that? Thanks

@umanamente
Copy link
Contributor Author

Hey @umanamente could you rebase off of master and then ping me and you've done that? Thanks

@dana-gill , sure, done

@dana-gill
Copy link
Contributor

@umanamente it looks like the unit tests are failing. could you please patch them up and then ping me again when the pr is ready? thanks!

@koordinator7
Copy link

Hey @umanamente
Help!!! "This function is not available in the node yet". This pull request adds it, but it needs to be merged first.
Thank you. I understand that the standard IMAP node does not yet contain UID. But you somehow get UID in the IMAP node. Please tell me what I need to do to get UID too. If it is not difficult, please provide more details.

@umanamente
Copy link
Contributor Author

@dana-gill ,
I’ve fixed the unit tests. The issue was that the same staticData object was being reused across different runs. During the first run, the function added the last email's ID to staticData, and since that ID persisted between runs, the email was getting filtered out, resulting in an empty array. I’ve updated it so that a fresh staticData object is created before each run.

Could you please run the tests again?

@umanamente umanamente requested a review from dana-gill April 3, 2025 04:08
@umanamente umanamente requested a review from dana-gill April 3, 2025 23:48
@umanamente
Copy link
Contributor Author

@dana-gill
Could you please let me know what the next steps are and if anything is needed from my side for this Pull Request to be merged?

@dana-gill dana-gill merged commit 4578709 into n8n-io:master Apr 8, 2025
18 checks passed
@dana-gill
Copy link
Contributor

@dana-gill Could you please let me know what the next steps are and if anything is needed from my side for this Pull Request to be merged?

merged ;)

Copy link

cypress bot commented Apr 8, 2025

n8n    Run #10142

Run Properties:  status check passed Passed #10142  •  git commit eee38f5bf4: 🌳 fix/pay-insights-service-tests 🖥️ browsers:node18.12.0-chrome107 🤖 schedule...
Project n8n
Branch Review fix/pay-insights-service-tests
Run status status check passed Passed #10142
Run duration 03m 43s
Commit git commit eee38f5bf4: 🌳 fix/pay-insights-service-tests 🖥️ browsers:node18.12.0-chrome107 🤖 schedule...
Committer Guillaume Jacquart
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 7
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 474
View all changes introduced in this branch ↗︎

@github-actions github-actions bot mentioned this pull request Apr 10, 2025
@janober
Copy link
Member

janober commented Apr 10, 2025

Got released with [email protected]

xbinaryx pushed a commit to xbinaryx/n8n that referenced this pull request Apr 18, 2025
@Alexandero89
Copy link
Contributor

@umanamente thanks for your PR and the time you invested.

i just noticed that the UID is only available when i choose the format of the mails to be "Simple".
When i choose the format "Resolved" there is not attributes and no uid.
Was this planned and is this maybe a technical restriction or would it maybe be possible to extend it to the resolved format.

Thanks in advance

@Alexandero89
Copy link
Contributor

Ok, i created a PR with this feature: #15539

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Authored by a community member in linear Issue or PR has been created in Linear for internal review node/improvement New feature or request Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants