@lengelhard/imap-email-mcp 1.2.0 → 1.2.1
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.
- package/index.js +61 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -853,15 +853,75 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
853
853
|
bcc: args.bcc
|
|
854
854
|
};
|
|
855
855
|
|
|
856
|
+
// Send via SMTP and capture the raw RFC 5322 message
|
|
856
857
|
const info = await transporter.sendMail(mailOptions);
|
|
857
858
|
|
|
859
|
+
// Build RFC 5322 message string to APPEND to Sent folder via IMAP
|
|
860
|
+
// Use the same content that was sent so the Sent copy is identical
|
|
861
|
+
const sentDate = new Date();
|
|
862
|
+
const boundary = `----=_Part_${Date.now()}`;
|
|
863
|
+
let rawMessage = '';
|
|
864
|
+
rawMessage += `From: ${SMTP_CONFIG.auth.user}\r\n`;
|
|
865
|
+
rawMessage += `To: ${args.to}\r\n`;
|
|
866
|
+
if (args.cc) rawMessage += `Cc: ${args.cc}\r\n`;
|
|
867
|
+
if (args.bcc) rawMessage += `Bcc: ${args.bcc}\r\n`;
|
|
868
|
+
rawMessage += `Subject: ${args.subject}\r\n`;
|
|
869
|
+
rawMessage += `Date: ${sentDate.toUTCString()}\r\n`;
|
|
870
|
+
rawMessage += `Message-ID: ${info.messageId}\r\n`;
|
|
871
|
+
rawMessage += `MIME-Version: 1.0\r\n`;
|
|
872
|
+
|
|
873
|
+
if (args.html) {
|
|
874
|
+
rawMessage += `Content-Type: multipart/alternative; boundary="${boundary}"\r\n\r\n`;
|
|
875
|
+
rawMessage += `--${boundary}\r\n`;
|
|
876
|
+
rawMessage += `Content-Type: text/plain; charset=utf-8\r\n\r\n`;
|
|
877
|
+
rawMessage += `${args.body || ''}\r\n`;
|
|
878
|
+
rawMessage += `--${boundary}\r\n`;
|
|
879
|
+
rawMessage += `Content-Type: text/html; charset=utf-8\r\n\r\n`;
|
|
880
|
+
rawMessage += `${args.html}\r\n`;
|
|
881
|
+
rawMessage += `--${boundary}--\r\n`;
|
|
882
|
+
} else {
|
|
883
|
+
rawMessage += `Content-Type: text/plain; charset=utf-8\r\n\r\n`;
|
|
884
|
+
rawMessage += `${args.body || ''}\r\n`;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// APPEND to Sent folder via IMAP
|
|
888
|
+
let sentFolderResult = 'skipped';
|
|
889
|
+
try {
|
|
890
|
+
const connection = await connectIMAP();
|
|
891
|
+
try {
|
|
892
|
+
// Try common Sent folder names in order
|
|
893
|
+
const sentFolderCandidates = ['Sent', 'INBOX.Sent', 'Sent Items', 'Sent Mail', '[Gmail]/Sent Mail'];
|
|
894
|
+
let sentFolder = 'Sent'; // default fallback
|
|
895
|
+
|
|
896
|
+
const folders = await connection.getBoxes();
|
|
897
|
+
const flatFolders = Object.keys(folders);
|
|
898
|
+
for (const candidate of sentFolderCandidates) {
|
|
899
|
+
if (flatFolders.some(f => f.toLowerCase() === candidate.toLowerCase())) {
|
|
900
|
+
sentFolder = candidate;
|
|
901
|
+
break;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
await connection.append(rawMessage, {
|
|
906
|
+
mailbox: sentFolder,
|
|
907
|
+
flags: ['\\Seen']
|
|
908
|
+
});
|
|
909
|
+
sentFolderResult = `saved to ${sentFolder}`;
|
|
910
|
+
} finally {
|
|
911
|
+
connection.end();
|
|
912
|
+
}
|
|
913
|
+
} catch (appendErr) {
|
|
914
|
+
sentFolderResult = `failed: ${appendErr.message}`;
|
|
915
|
+
}
|
|
916
|
+
|
|
858
917
|
return {
|
|
859
918
|
content: [{
|
|
860
919
|
type: 'text',
|
|
861
920
|
text: JSON.stringify({
|
|
862
921
|
success: true,
|
|
863
922
|
messageId: info.messageId,
|
|
864
|
-
response: info.response
|
|
923
|
+
response: info.response,
|
|
924
|
+
sentFolder: sentFolderResult
|
|
865
925
|
}, null, 2)
|
|
866
926
|
}]
|
|
867
927
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lengelhard/imap-email-mcp",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "MCP server for Claude Code that provides email capabilities through IMAP/SMTP. Read, search, compose, and manage emails from any IMAP provider.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|