My agentic slop goes here. Not intended for anyone else!
Query 5: Draft Emails Needing Attention#
Use Case Description#
Find draft emails that need attention, focusing on older drafts that may have been forgotten. This helps users manage their composition workflow and complete pending communications.
Key JMAP Concepts Used#
- Mailbox role filtering: Finding drafts mailbox by role
- Keyword filtering: Using
$draftkeyword to identify draft emails - Age-based sorting: Finding oldest drafts first for prioritization
- Mailbox/query: Locating system mailboxes by role
- Multi-step queries: Mailbox discovery followed by email filtering
JMAP Request#
{
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
"methodCalls": [
[
"Mailbox/query",
{
"accountId": "u12345678",
"filter": {
"role": "drafts"
}
},
"mb0"
],
[
"Email/query",
{
"accountId": "u12345678",
"filter": {
"operator": "AND",
"conditions": [
{
"hasKeyword": "$draft"
},
{
"#inMailbox": {
"resultOf": "mb0",
"name": "Mailbox/query",
"path": "/ids/0"
}
},
{
"before": "2024-08-20T00:00:00Z"
}
]
},
"sort": [
{
"property": "receivedAt",
"isAscending": true
}
],
"limit": 10
},
"q0"
],
[
"Email/get",
{
"accountId": "u12345678",
"#ids": {
"resultOf": "q0",
"name": "Email/query",
"path": "/ids"
},
"properties": [
"id", "threadId", "keywords", "from", "to", "cc", "bcc", "subject",
"receivedAt", "sentAt", "preview", "textBody", "htmlBody", "attachments",
"bodyValues"
],
"bodyProperties": ["value", "isEncodingProblem", "isTruncated"]
},
"g0"
]
]
}
Expected Response Structure#
{
"methodResponses": [
[
"Mailbox/query",
{
"accountId": "u12345678",
"queryState": "mq1234567893",
"canCalculateChanges": true,
"position": 0,
"ids": ["Mdrafts"],
"total": 1,
"limit": null
},
"mb0"
],
[
"Email/query",
{
"accountId": "u12345678",
"queryState": "q1234567893",
"canCalculateChanges": true,
"position": 0,
"ids": ["Memail201", "Memail202", "Memail203"],
"total": 7,
"limit": 10
},
"q0"
],
[
"Email/get",
{
"accountId": "u12345678",
"state": "s9876543214",
"list": [
{
"id": "Memail201",
"threadId": "Tthread301",
"keywords": {"$draft": true},
"from": [{"email": "me@example.com", "name": "John Doe"}],
"to": [{"email": "client@company.com", "name": "Important Client"}],
"cc": [],
"bcc": [],
"subject": "Proposal Follow-up - ",
"receivedAt": "2024-08-10T15:30:00Z",
"sentAt": null,
"preview": "Hi [Client Name], Thank you for taking the time to review our proposal...",
"textBody": [{"id": "draft1", "mimeType": "text/plain"}],
"htmlBody": null,
"bodyValues": {
"draft1": {
"value": "Hi [Client Name],\n\nThank you for taking the time to review our proposal. I wanted to follow up on a few key points:\n\n- Timeline considerations\n- Budget adjustments\n- [NEED TO ADD SPECIFIC DETAILS]\n\nPlease let me know your thoughts.\n\nBest regards,\nJohn",
"isEncodingProblem": false,
"isTruncated": false
}
},
"attachments": []
},
{
"id": "Memail202",
"threadId": "Tthread302",
"keywords": {"$draft": true, "$flagged": true},
"from": [{"email": "me@example.com", "name": "John Doe"}],
"to": [{"email": "hr@company.com", "name": "HR Department"}],
"cc": [],
"bcc": [],
"subject": "Time off request - urgent",
"receivedAt": "2024-08-15T11:45:00Z",
"sentAt": null,
"preview": "Dear HR Team, I would like to request time off for the following dates...",
"textBody": [{"id": "draft2", "mimeType": "text/plain"}],
"htmlBody": null,
"bodyValues": {
"draft2": {
"value": "Dear HR Team,\n\nI would like to request time off for the following dates:\n\n[DATES TO BE FILLED IN]\n\nReason: [NEED TO SPECIFY]\n\nI will ensure all my current projects are completed or properly handed off before my departure.\n\nThank you for your consideration.\n\nBest regards,\nJohn",
"isEncodingProblem": false,
"isTruncated": false
}
},
"attachments": []
}
],
"notFound": []
},
"g0"
]
]
}
Explanation of Key Features#
Mailbox Role Discovery#
- Mailbox/query with
role: "drafts"locates the system drafts folder - Role-based lookup works across different email providers and configurations
- Handles cases where drafts folder has custom names or locations
Result Reference Chaining#
#inMailboxwithresultOfuses the drafts mailbox ID from step 1path: "/ids/0"extracts the first (and typically only) drafts mailbox ID- Eliminates hardcoded mailbox IDs and adapts to server configurations
Draft-Specific Filtering#
hasKeyword: "$draft"ensures emails are actually draftsbeforefilter finds older drafts that may need attention- Double verification (mailbox + keyword) handles edge cases
Draft Content Analysis#
The response reveals common draft patterns:
- Incomplete subjects: "Proposal Follow-up - " (trailing dash/space)
- Placeholder text: "[Client Name]", "[NEED TO ADD DETAILS]"
- Template content: Standardized openings with missing specifics
- Flagged drafts: Important drafts marked with
$flaggedkeyword
Draft Management Workflow#
Identification Criteria:
- Age-based priority (older drafts first)
- Content completeness analysis
- Recipient validation
- Subject line completion
Action Items Discovery:
- Search for placeholder patterns:
[...],TODO,FIXME - Identify incomplete subjects (trailing punctuation)
- Check for missing recipients or CCs
- Validate attachment references in text
Completion Workflow:
- Load draft for editing
- Fill in placeholder content
- Complete recipient lists
- Finalize subject line
- Review and send or save
Advanced Draft Queries#
High Priority Drafts:
{
"operator": "AND",
"conditions": [
{"hasKeyword": "$draft"},
{"hasKeyword": "$flagged"},
{"before": "2024-08-18T00:00:00Z"}
]
}
Template Drafts:
{
"operator": "AND",
"conditions": [
{"hasKeyword": "$draft"},
{"text": "["}
]
}
Drafts with Attachments:
{
"operator": "AND",
"conditions": [
{"hasKeyword": "$draft"},
{"hasAttachment": true}
]
}