mail_mcp 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mail_mcp/app.rb +8 -4
- data/lib/mail_mcp/imap_client.rb +5 -2
- data/lib/mail_mcp/tools/update_mail_message_flags_tool.rb +34 -3
- data/lib/mail_mcp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: caf27cd17b2adac73fae31883b7f0ae1e20b7c2be61e583180d9fe7d230e3c23
|
|
4
|
+
data.tar.gz: bab6dfc1f67f681fd30689a4c38eb4ab4cac6ec0abe485755e74f25333e1c761
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bad25881c7462f141971105d5455b9cec71af498aa3dadc7617caea6ba2aa5802cfa91b4f899ef637bafcbf8d23c7d902a8f3af3c942b9e83c1f26e324433fc1
|
|
7
|
+
data.tar.gz: 438d165458bf0b62c1a66d45ad65766f99c9517e5d0d986b1be4e370968a53e0d81254a83a17152eecdc7117f19cdca473df4d8bfffffa365c0398ff4548f62e
|
data/lib/mail_mcp/app.rb
CHANGED
|
@@ -144,7 +144,7 @@ module MailMCP
|
|
|
144
144
|
|
|
145
145
|
def resolve_mcp_context
|
|
146
146
|
auth = request.env["HTTP_AUTHORIZATION"]
|
|
147
|
-
return [nil,
|
|
147
|
+
return [nil, unauthorized_response("missing bearer token")] unless auth&.start_with?("Bearer ")
|
|
148
148
|
|
|
149
149
|
creds = JwtService.verify(auth[7..])
|
|
150
150
|
context = CredentialContext.new(
|
|
@@ -161,12 +161,16 @@ module MailMCP
|
|
|
161
161
|
)
|
|
162
162
|
[context, nil]
|
|
163
163
|
rescue JwtService::Error => e
|
|
164
|
-
|
|
164
|
+
[nil, unauthorized_response(e.message)]
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# 401 challenge that tells an MCP client where to run the OAuth flow.
|
|
168
|
+
def unauthorized_response(description)
|
|
169
|
+
[
|
|
165
170
|
401,
|
|
166
171
|
{ "Content-Type" => "application/json", "WWW-Authenticate" => mcp_www_authenticate },
|
|
167
|
-
[JSON.generate({ error: "invalid_token", error_description:
|
|
172
|
+
[JSON.generate({ error: "invalid_token", error_description: description })]
|
|
168
173
|
]
|
|
169
|
-
[nil, error]
|
|
170
174
|
end
|
|
171
175
|
|
|
172
176
|
def exchange_code(params, client_id)
|
data/lib/mail_mcp/imap_client.rb
CHANGED
|
@@ -190,12 +190,15 @@ module MailMCP
|
|
|
190
190
|
|
|
191
191
|
def extract_attachments(mail)
|
|
192
192
|
mail.attachments.map do |att|
|
|
193
|
+
# Mail#decoded does not memoize — it base64-decodes into a new String on
|
|
194
|
+
# every call, so decode once and reuse for both the upload and the size.
|
|
195
|
+
content = att.decoded
|
|
193
196
|
url = AttachmentStore.upload(
|
|
194
|
-
content:
|
|
197
|
+
content: content,
|
|
195
198
|
filename: att.filename || "attachment",
|
|
196
199
|
content_type: att.content_type
|
|
197
200
|
)
|
|
198
|
-
{ filename: att.filename, content_type: att.content_type, size:
|
|
201
|
+
{ filename: att.filename, content_type: att.content_type, size: content.bytesize, url: url }
|
|
199
202
|
end
|
|
200
203
|
end
|
|
201
204
|
end
|
|
@@ -10,25 +10,56 @@ module MailMCP
|
|
|
10
10
|
open_world_hint: true
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
+
# IMAP allows only these six backslash-prefixed system flags; anything else
|
|
14
|
+
# must be sent as a keyword (a bare atom with no leading backslash).
|
|
15
|
+
SYSTEM_FLAGS = %w[Seen Answered Flagged Deleted Draft Recent].freeze
|
|
16
|
+
|
|
17
|
+
# Friendly color names map to Mozilla/Thunderbird $labelN keywords, the
|
|
18
|
+
# de-facto cross-client convention for colored flags.
|
|
19
|
+
COLOR_KEYWORDS = {
|
|
20
|
+
"red" => "$label1",
|
|
21
|
+
"orange" => "$label2",
|
|
22
|
+
"green" => "$label3",
|
|
23
|
+
"blue" => "$label4",
|
|
24
|
+
"purple" => "$label5"
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
13
27
|
input_schema(
|
|
14
28
|
type: "object",
|
|
15
29
|
properties: {
|
|
16
30
|
folder: { type: "string" },
|
|
17
31
|
uid: { type: "integer" },
|
|
18
32
|
add: { type: "array", items: { type: "string" },
|
|
19
|
-
description: "Flags to add
|
|
33
|
+
description: "Flags to add. Settable system flags: '\\\\Seen', '\\\\Answered', " \
|
|
34
|
+
"'\\\\Flagged', '\\\\Deleted', '\\\\Draft' (\\\\Recent is recognized " \
|
|
35
|
+
"but cannot be set by clients). Color names " \
|
|
36
|
+
"('red', 'orange', 'green', 'blue', 'purple') map to " \
|
|
37
|
+
"$labelN keywords. Any other value is sent as a custom keyword." },
|
|
20
38
|
remove: { type: "array", items: { type: "string" }, description: "Flags to remove" }
|
|
21
39
|
},
|
|
22
40
|
required: %w[folder uid]
|
|
23
41
|
)
|
|
24
42
|
|
|
25
43
|
def self.call(folder:, uid:, server_context:, add: [], remove: [])
|
|
26
|
-
add_flags = add.map(
|
|
27
|
-
remove_flags = remove.map(
|
|
44
|
+
add_flags = add.map { |f| normalize_flag(f) }
|
|
45
|
+
remove_flags = remove.map { |f| normalize_flag(f) }
|
|
28
46
|
ImapClient.connect(server_context.imap_config) do |c|
|
|
29
47
|
c.update_flags(folder: folder, uid: uid, add: add_flags, remove: remove_flags)
|
|
30
48
|
end
|
|
31
49
|
MCP::Tool::Response.new([{ type: "text", text: "Flags updated for message #{uid}" }])
|
|
32
50
|
end
|
|
51
|
+
|
|
52
|
+
# System flags become Symbols (net/imap renders them with a leading
|
|
53
|
+
# backslash). Custom keywords stay Strings (rendered as bare atoms).
|
|
54
|
+
# Friendly color names are translated to their $labelN keyword first.
|
|
55
|
+
def self.normalize_flag(flag)
|
|
56
|
+
name = flag.to_s.delete_prefix("\\")
|
|
57
|
+
return COLOR_KEYWORDS.fetch(name.downcase) if COLOR_KEYWORDS.key?(name.downcase)
|
|
58
|
+
|
|
59
|
+
# System flags are case-insensitive per RFC 3501; normalize to the
|
|
60
|
+
# canonical capitalization so e.g. "seen" / "\\SEEN" still set :Seen.
|
|
61
|
+
system_flag = SYSTEM_FLAGS.find { |f| f.casecmp?(name) }
|
|
62
|
+
system_flag ? system_flag.to_sym : name
|
|
63
|
+
end
|
|
33
64
|
end
|
|
34
65
|
end
|
data/lib/mail_mcp/version.rb
CHANGED