Add Mail tools to move, flag and tag messages - #61
Open
oleksandr-nc wants to merge 2 commits into
Open
oleksandr-nc wants to merge 2 commits into
oleksandr-nc wants to merge 2 commits into
Conversation
Five write tools call the Mail app's JSON routes through a new app_request_json client helper, and list/get output now includes tags. The Mail integration tests read from Dovecot instead of smtp4dev, whose IMAP server has no MOVE, folders or keywords. Closes #59. Signed-off-by: Oleksandr Piskun <oleksandr2088@icloud.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 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. Comment |
test_server.py pins the registered tool names and count, so the five new Mail tools failed it with 161 == 156. Signed-off-by: Oleksandr Piskun <oleksandr2088@icloud.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 96.22% 96.43% +0.21%
==========================================
Files 31 31
Lines 3363 3478 +115
==========================================
+ Hits 3236 3354 +118
+ Misses 127 124 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #59.
Adds five Mail tools so an inbox can be triaged through the MCP server, and adds tags to the message output.
Tools
/index.php/apps/mail)move_mail_message(message_id, destination_mailbox_id)ADDITIVEPOST /api/messages/{id}/moveset_mail_message_flags(message_id, seen, flagged, answered)ADDITIVE_IDEMPOTENTPUT /api/messages/{id}/flagscreate_mail_tag(display_name, color)ADDITIVE_IDEMPOTENTPOST /api/tagsadd_mail_message_tag(message_id, imap_label)ADDITIVE_IDEMPOTENTPUT /api/messages/{id}/tags/{imapLabel}remove_mail_message_tag(message_id, imap_label)ADDITIVE_IDEMPOTENTDELETE /api/messages/{id}/tags/{imapLabel}list_mail_messagesandget_mail_messagereturntags(display name and IMAP label). The OCS message endpoint has no tags, soget_mail_messagereads them fromGET /api/messages/{id}.set_mail_message_flagssends only the flags that were passed and rejects a call with none.create_mail_tagchecks the name (at most 128 characters) and requires a hex color, because Mail stores any string as a color (it accepted"red"). Creating an existing tag returns it unchanged, color included.move_mail_messagesays the old ID is no longer valid. The new ID only exists once Nextcloud syncs the destination mailbox, which happens automatically for the inbox and background-synced folders and otherwise when the folder is opened in Mail, so the tool doesn't return it.Client
NextcloudClient.app_request_json()calls/index.php/apps/{path}through_do_requestwithOCS-APIRequest: true, which is what lets these CSRF-protected routes accept Basic auth with an app password (200 with the header, 412 without). It returns the plain JSON body, orNonewhen the body is empty, and_raise_for_app_statussurfaces Mail'sdata.messageandmessageerrors.Mail integration tests read from Dovecot
smtp4dev's IMAP server can't back these tools: it advertises no MOVE, refuses to create folders, and doesn't keep
\Flaggedor keywords. GreenMail was tried next, but 2.0.1, 2.1.8 and 2.1.13 all failFETCH BODY[1.MIME]on single-part messages with aClassCastException, which makes Mail's message view return "Could not connect to IMAP server".The integration job now runs
dovecot/dovecot:2.4.5for IMAP and keeps smtp4dev for SMTP, so thesend_maildelivery checks are unchanged. Dovecot refuses plaintext logins, so the account uses STARTTLS with the image's self-signed certificate andapp.mail.verify-tls-peer=false. Test messages are put into the INBOX with IMAP APPEND instead of being sent over SMTP.Docs
The README Mail tables list the new tools, the Mail row says OCS + REST, and the tool count is corrected to 161 (162 with
NEXTCLOUD_MCP_UPLOAD_ROOT); the heading said 140.Verification
ruff check,ruff format --check,isortandpyrightare clean; unit tests: 142 passed, 38 of them new (16 for the client helper, 22 for the tools).tests/integration/test_mail.py: 48 passed against a local Nextcloud 36 dev instance with Mail 5.12.0-rc.1, Dovecot 2.4.5 and smtp4dev. The routes used are the same in Mail 5.11.5, which CI installs on Nextcloud 34.