@@ -18,6 +18,15 @@ const companyMailbox = "ned@devantler.tech"
1818
1919var mailboxIDPattern = regexp .MustCompile (`^[A-Za-z0-9_-]{1,512}$` )
2020
21+ var (
22+ errMailboxTransport = errors .New ("mailbox-transport" )
23+ errMailboxResponse = errors .New ("mailbox-response" )
24+ )
25+
26+ type mailboxHTTPStatus int
27+
28+ func (mailboxHTTPStatus ) Error () string { return "mailbox-http" }
29+
2130type mailboxClient struct {
2231 account , endpoint , password string
2332 http * http.Client
@@ -47,23 +56,23 @@ func (c *mailboxClient) request(ctx context.Context, method, path, contentType s
4756 }
4857 response , err := c .http .Do (req )
4958 if err != nil {
50- return nil , errors . New ( "mailbox-transport" )
59+ return nil , errMailboxTransport
5160 }
5261 defer func () { _ = response .Body .Close () }()
5362 if response .StatusCode != http .StatusOK && response .StatusCode != http .StatusCreated {
54- return nil , errors . New ( "mailbox-http" )
63+ return nil , mailboxHTTPStatus ( response . StatusCode )
5564 }
5665 data , err := io .ReadAll (io .LimitReader (response .Body , (4 << 20 )+ 1 ))
5766 if err != nil || len (data ) > 4 << 20 {
58- return nil , errors . New ( "mailbox-response" )
67+ return nil , errMailboxResponse
5968 }
6069 return data , nil
6170}
6271
6372// mailboxMethods names the JMAP capability of each permitted method. Census
6473// reads that can initialize defaults require an unchanged collection state.
6574var mailboxMethods = map [string ]string {
66- "Email/get" : jmapMail , "Email/query" : jmapMail , "Email/import" : jmapMail , "Email/ set" : jmapMail ,
75+ "Email/get" : jmapMail , "Email/query" : jmapMail , "Email/set" : jmapMail ,
6776 "Mailbox/get" : jmapMail , "Mailbox/set" : jmapMail , "Mailbox/query" : jmapMail ,
6877 "Calendar/get" : "urn:ietf:params:jmap:calendars" , "CalendarEvent/query" : "urn:ietf:params:jmap:calendars" , "CalendarEvent/get" : "urn:ietf:params:jmap:calendars" ,
6978 "Calendar/changes" : "urn:ietf:params:jmap:calendars" ,
@@ -141,29 +150,26 @@ func (c *mailboxClient) createMarker(ctx context.Context, nonce string) (*mailbo
141150 marker .uncertain = true
142151 return marker , errors .New ("marker-mailbox" )
143152 }
144- message := "From: Email recovery diagnostic <email-recovery@example.invalid>\r \n To: email-recovery@example.invalid\r \n Subject: Email recovery verification\r \n Message-ID: <" + marker .identity .messageID + ">\r \n MIME-Version: 1.0\r \n Content-Type: text/plain; charset=utf-8\r \n \r \n " + marker .identity .body + "\r \n "
145- data , err := c .request (ctx , http .MethodPost , "/jmap/upload/" + c .account + "/" , "message/rfc822" , []byte (message ))
146- if err != nil {
147- return marker , err
148- }
149- var upload object
150- if json .Unmarshal (data , & upload ) != nil || text (upload , "accountId" ) != c .account || ! mailboxIDPattern .MatchString (text (upload , "blobId" )) {
151- return marker , errors .New ("marker-upload" )
152- }
153- marker .identity .blob = text (upload , "blobId" )
154- imported , err := c .call (ctx , "Email/import" , object {"emails" : object {"proof" : object {"blobId" : marker .identity .blob , "mailboxIds" : object {marker .identity .mailbox : true }, "keywords" : object {"$seen" : true }}}})
153+ // The production listener refuses blob uploads. A text-only draft stays
154+ // inside the diagnostic mailbox and does not need upload or submission.
155+ const partID = "verification"
156+ created , err = c .call (ctx , "Email/set" , object {"create" : object {"proof" : object {
157+ "mailboxIds" : object {marker .identity .mailbox : true }, "keywords" : object {"$draft" : true , "$seen" : true },
158+ "from" : []any {object {"email" : companyMailbox }}, "subject" : "Email recovery verification" ,
159+ "header:Message-ID:asMessageIds" : []any {marker .identity .messageID },
160+ "textBody" : []any {object {"partId" : partID , "type" : "text/plain" }},
161+ "bodyValues" : object {partID : object {"value" : marker .identity .body }},
162+ }}})
155163 if err != nil {
156164 marker .uncertain = true
157165 return marker , err
158166 }
159- createdEmail := child (child (imported , "created" ), "proof" )
167+ createdEmail := child (child (created , "created" ), "proof" )
160168 marker .identity .email = text (createdEmail , "id" )
161- // Import may normalize or relink an uploaded blob. Its returned Email
162- // identity, rather than the temporary upload identity, binds later reads.
163169 marker .identity .blob = text (createdEmail , "blobId" )
164170 if ! mailboxIDPattern .MatchString (marker .identity .email ) || ! mailboxIDPattern .MatchString (marker .identity .blob ) {
165171 marker .uncertain = true
166- return marker , errors .New ("marker-import " )
172+ return marker , errors .New ("marker-create " )
167173 }
168174 if _ , err = c .verifyMessage (ctx , marker .identity ); err != nil {
169175 return marker , err
0 commit comments