My agentic slop goes here. Not intended for anyone else!
1# Query 5: Draft Emails Needing Attention
2
3## Use Case Description
4Find 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.
5
6## Key JMAP Concepts Used
7- **Mailbox role filtering**: Finding drafts mailbox by role
8- **Keyword filtering**: Using `$draft` keyword to identify draft emails
9- **Age-based sorting**: Finding oldest drafts first for prioritization
10- **Mailbox/query**: Locating system mailboxes by role
11- **Multi-step queries**: Mailbox discovery followed by email filtering
12
13## JMAP Request
14
15```json
16{
17 "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
18 "methodCalls": [
19 [
20 "Mailbox/query",
21 {
22 "accountId": "u12345678",
23 "filter": {
24 "role": "drafts"
25 }
26 },
27 "mb0"
28 ],
29 [
30 "Email/query",
31 {
32 "accountId": "u12345678",
33 "filter": {
34 "operator": "AND",
35 "conditions": [
36 {
37 "hasKeyword": "$draft"
38 },
39 {
40 "#inMailbox": {
41 "resultOf": "mb0",
42 "name": "Mailbox/query",
43 "path": "/ids/0"
44 }
45 },
46 {
47 "before": "2024-08-20T00:00:00Z"
48 }
49 ]
50 },
51 "sort": [
52 {
53 "property": "receivedAt",
54 "isAscending": true
55 }
56 ],
57 "limit": 10
58 },
59 "q0"
60 ],
61 [
62 "Email/get",
63 {
64 "accountId": "u12345678",
65 "#ids": {
66 "resultOf": "q0",
67 "name": "Email/query",
68 "path": "/ids"
69 },
70 "properties": [
71 "id", "threadId", "keywords", "from", "to", "cc", "bcc", "subject",
72 "receivedAt", "sentAt", "preview", "textBody", "htmlBody", "attachments",
73 "bodyValues"
74 ],
75 "bodyProperties": ["value", "isEncodingProblem", "isTruncated"]
76 },
77 "g0"
78 ]
79 ]
80}
81```
82
83## Expected Response Structure
84
85```json
86{
87 "methodResponses": [
88 [
89 "Mailbox/query",
90 {
91 "accountId": "u12345678",
92 "queryState": "mq1234567893",
93 "canCalculateChanges": true,
94 "position": 0,
95 "ids": ["Mdrafts"],
96 "total": 1,
97 "limit": null
98 },
99 "mb0"
100 ],
101 [
102 "Email/query",
103 {
104 "accountId": "u12345678",
105 "queryState": "q1234567893",
106 "canCalculateChanges": true,
107 "position": 0,
108 "ids": ["Memail201", "Memail202", "Memail203"],
109 "total": 7,
110 "limit": 10
111 },
112 "q0"
113 ],
114 [
115 "Email/get",
116 {
117 "accountId": "u12345678",
118 "state": "s9876543214",
119 "list": [
120 {
121 "id": "Memail201",
122 "threadId": "Tthread301",
123 "keywords": {"$draft": true},
124 "from": [{"email": "me@example.com", "name": "John Doe"}],
125 "to": [{"email": "client@company.com", "name": "Important Client"}],
126 "cc": [],
127 "bcc": [],
128 "subject": "Proposal Follow-up - ",
129 "receivedAt": "2024-08-10T15:30:00Z",
130 "sentAt": null,
131 "preview": "Hi [Client Name], Thank you for taking the time to review our proposal...",
132 "textBody": [{"id": "draft1", "mimeType": "text/plain"}],
133 "htmlBody": null,
134 "bodyValues": {
135 "draft1": {
136 "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",
137 "isEncodingProblem": false,
138 "isTruncated": false
139 }
140 },
141 "attachments": []
142 },
143 {
144 "id": "Memail202",
145 "threadId": "Tthread302",
146 "keywords": {"$draft": true, "$flagged": true},
147 "from": [{"email": "me@example.com", "name": "John Doe"}],
148 "to": [{"email": "hr@company.com", "name": "HR Department"}],
149 "cc": [],
150 "bcc": [],
151 "subject": "Time off request - urgent",
152 "receivedAt": "2024-08-15T11:45:00Z",
153 "sentAt": null,
154 "preview": "Dear HR Team, I would like to request time off for the following dates...",
155 "textBody": [{"id": "draft2", "mimeType": "text/plain"}],
156 "htmlBody": null,
157 "bodyValues": {
158 "draft2": {
159 "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",
160 "isEncodingProblem": false,
161 "isTruncated": false
162 }
163 },
164 "attachments": []
165 }
166 ],
167 "notFound": []
168 },
169 "g0"
170 ]
171 ]
172}
173```
174
175## Explanation of Key Features
176
177### Mailbox Role Discovery
178- **Mailbox/query** with `role: "drafts"` locates the system drafts folder
179- Role-based lookup works across different email providers and configurations
180- Handles cases where drafts folder has custom names or locations
181
182### Result Reference Chaining
183- `#inMailbox` with `resultOf` uses the drafts mailbox ID from step 1
184- `path: "/ids/0"` extracts the first (and typically only) drafts mailbox ID
185- Eliminates hardcoded mailbox IDs and adapts to server configurations
186
187### Draft-Specific Filtering
188- `hasKeyword: "$draft"` ensures emails are actually drafts
189- `before` filter finds older drafts that may need attention
190- Double verification (mailbox + keyword) handles edge cases
191
192### Draft Content Analysis
193The response reveals common draft patterns:
194- **Incomplete subjects**: "Proposal Follow-up - " (trailing dash/space)
195- **Placeholder text**: "[Client Name]", "[NEED TO ADD DETAILS]"
196- **Template content**: Standardized openings with missing specifics
197- **Flagged drafts**: Important drafts marked with `$flagged` keyword
198
199### Draft Management Workflow
200
201**Identification Criteria:**
2021. Age-based priority (older drafts first)
2032. Content completeness analysis
2043. Recipient validation
2054. Subject line completion
206
207**Action Items Discovery:**
208- Search for placeholder patterns: `[...]`, `TODO`, `FIXME`
209- Identify incomplete subjects (trailing punctuation)
210- Check for missing recipients or CCs
211- Validate attachment references in text
212
213**Completion Workflow:**
2141. Load draft for editing
2152. Fill in placeholder content
2163. Complete recipient lists
2174. Finalize subject line
2185. Review and send or save
219
220### Advanced Draft Queries
221
222**High Priority Drafts:**
223```json
224{
225 "operator": "AND",
226 "conditions": [
227 {"hasKeyword": "$draft"},
228 {"hasKeyword": "$flagged"},
229 {"before": "2024-08-18T00:00:00Z"}
230 ]
231}
232```
233
234**Template Drafts:**
235```json
236{
237 "operator": "AND",
238 "conditions": [
239 {"hasKeyword": "$draft"},
240 {"text": "["}
241 ]
242}
243```
244
245**Drafts with Attachments:**
246```json
247{
248 "operator": "AND",
249 "conditions": [
250 {"hasKeyword": "$draft"},
251 {"hasAttachment": true}
252 ]
253}
254```