21 "github.com/mjl-/mox/mlog"
22 "github.com/mjl-/mox/mox-"
23 "github.com/mjl-/mox/store"
26func TestView(t *testing.T) {
28 os.RemoveAll("../testdata/webmail/data")
30 mox.ConfigStaticPath = filepath.FromSlash("../testdata/webmail/mox.conf")
31 mox.MustLoadConfig(true, false)
32 defer store.Switchboard()()
34 log := mlog.New("webmail", nil)
35 acc, err := store.OpenAccount(log, "mjl")
36 tcheck(t, err, "open account")
37 err = acc.SetPassword(log, "test1234")
38 tcheck(t, err, "set password")
41 pkglog.Check(err, "closing account")
44 api := Webmail{maxMessageSize: 1024 * 1024, cookiePath: "/"}
46 respRec := httptest.NewRecorder()
47 reqInfo := requestInfo{"mjl@mox.example", "mjl", "", respRec, &http.Request{RemoteAddr: "127.0.0.1:1234"}}
48 ctx := context.WithValue(ctxbg, requestInfoCtxKey, reqInfo)
50 // Prepare loginToken.
51 loginCookie := &http.Cookie{Name: "webmaillogin"}
52 loginCookie.Value = api.LoginPrep(ctx)
53 reqInfo.Request.Header = http.Header{"Cookie": []string{loginCookie.String()}}
55 api.Login(ctx, loginCookie.Value, "mjl@mox.example", "test1234")
56 var sessionCookie *http.Cookie
57 for _, c := range respRec.Result().Cookies() {
58 if c.Name == "webmailsession" {
63 if sessionCookie == nil {
64 t.Fatalf("missing session cookie")
66 sct := strings.SplitN(sessionCookie.Value, " ", 2)
67 if len(sct) != 2 || sct[1] != "mjl" {
68 t.Fatalf("unexpected accountname %q in session cookie", sct[1])
70 sessionToken := store.SessionToken(sct[0])
72 reqInfo = requestInfo{"mjl@mox.example", "mjl", sessionToken, respRec, &http.Request{}}
73 ctx = context.WithValue(ctxbg, requestInfoCtxKey, reqInfo)
75 api.MailboxCreate(ctx, "Lists/Go/Nuts")
77 var zerom store.Message
79 inboxMinimal = &testmsg{"Inbox", store.Flags{}, nil, msgMinimal, zerom, 0}
80 inboxFlags = &testmsg{"Inbox", store.Flags{Seen: true}, []string{"testlabel"}, msgAltRel, zerom, 0} // With flags, and larger.
81 listsMinimal = &testmsg{"Lists", store.Flags{}, nil, msgMinimal, zerom, 0}
82 listsGoNutsMinimal = &testmsg{"Lists/Go/Nuts", store.Flags{}, nil, msgMinimal, zerom, 0}
83 trashMinimal = &testmsg{"Trash", store.Flags{}, nil, msgMinimal, zerom, 0}
84 junkMinimal = &testmsg{"Trash", store.Flags{}, nil, msgMinimal, zerom, 0}
85 trashAlt = &testmsg{"Trash", store.Flags{}, nil, msgAlt, zerom, 0}
86 inboxAltReply = &testmsg{"Inbox", store.Flags{}, nil, msgAltReply, zerom, 0}
88 var testmsgs = []*testmsg{inboxMinimal, inboxFlags, listsMinimal, listsGoNutsMinimal, trashMinimal, junkMinimal, trashAlt, inboxAltReply}
89 for _, tm := range testmsgs {
95 for i := 0; i < 20; i++ {
96 tokens = append(tokens, api.Token(ctx))
98 // Only last 10 tokens are still valid and around, checked below.
101 tneedError(t, func() { api.Request(ctx, Request{ID: 1, Cancel: true}) }) // Zero/invalid SSEID.
103 // We start an actual HTTP server to easily get a body we can do blocking reads on.
104 // With a httptest.ResponseRecorder, it's a bit more work to parse SSE events as
106 server := httptest.NewServer(http.HandlerFunc(Handler(1024*1024, "/webmail/", false)))
109 serverURL, err := url.Parse(server.URL)
110 tcheck(t, err, "parsing server url")
111 _, port, err := net.SplitHostPort(serverURL.Host)
112 tcheck(t, err, "parsing host port in server url")
113 eventsURL := fmt.Sprintf("http://%s/events", net.JoinHostPort("localhost", port))
116 Page: Page{Count: 10},
118 requestJSON, err := json.Marshal(request)
119 tcheck(t, err, "marshal request as json")
121 testFail := func(method, path string, expStatusCode int) {
123 req, err := http.NewRequest(method, path, nil)
124 tcheck(t, err, "making request")
125 resp, err := http.DefaultClient.Do(req)
126 tcheck(t, err, "http transaction")
128 if resp.StatusCode != expStatusCode {
129 t.Fatalf("got statuscode %d, expected %d", resp.StatusCode, expStatusCode)
133 testFail("POST", eventsURL+"?token="+tokens[0]+"&request="+string(requestJSON), http.StatusMethodNotAllowed) // Must be GET.
134 testFail("GET", eventsURL, http.StatusBadRequest) // Missing token.
135 testFail("GET", eventsURL+"?token="+tokens[0]+"&request="+string(requestJSON), http.StatusBadRequest) // Bad (old) token.
136 testFail("GET", eventsURL+"?token="+tokens[len(tokens)-5]+"&request=bad", http.StatusBadRequest) // Bad request.
138 // Start connection for testing and filters below.
139 req, err := http.NewRequest("GET", eventsURL+"?token="+tokens[len(tokens)-1]+"&request="+string(requestJSON), nil)
140 tcheck(t, err, "making request")
141 resp, err := http.DefaultClient.Do(req)
142 tcheck(t, err, "http transaction")
143 defer resp.Body.Close()
144 if resp.StatusCode != http.StatusOK {
145 t.Fatalf("got statuscode %d, expected %d (%s)", resp.StatusCode, http.StatusOK, readBody(resp.Body))
148 evr := eventReader{t, bufio.NewReader(resp.Body), resp.Body}
150 evr.Get("start", &start)
151 var viewMsgs EventViewMsgs
152 evr.Get("viewMsgs", &viewMsgs)
153 tcompare(t, len(viewMsgs.MessageItems), 3)
154 tcompare(t, viewMsgs.ViewEnd, true)
156 var inbox, archive, lists, trash store.Mailbox
157 for _, mb := range start.Mailboxes {
160 } else if mb.Name == start.MailboxName {
162 } else if mb.Name == "Lists" {
164 } else if mb.Name == "Trash" {
169 // Can only use a token once.
170 testFail("GET", eventsURL+"?token="+tokens[len(tokens)-1]+"&request=bad", http.StatusBadRequest)
172 // Check a few initial query/page combinations.
173 testConn := func(token, more string, request Request, check func(EventStart, eventReader)) {
176 reqJSON, err := json.Marshal(request)
177 tcheck(t, err, "marshal request json")
178 req, err := http.NewRequest("GET", eventsURL+"?token="+token+more+"&request="+string(reqJSON), nil)
179 tcheck(t, err, "making request")
180 resp, err := http.DefaultClient.Do(req)
181 tcheck(t, err, "http transaction")
182 defer resp.Body.Close()
183 if resp.StatusCode != http.StatusOK {
184 t.Fatalf("got statuscode %d, expected %d", resp.StatusCode, http.StatusOK)
187 xevr := eventReader{t, bufio.NewReader(resp.Body), resp.Body}
188 var xstart EventStart
189 xevr.Get("start", &xstart)
193 // Connection with waitMinMsec/waitMaxMsec, just exercising code path.
195 Page: Page{Count: 10},
197 testConn(api.Token(ctx), "&waitMinMsec=1&waitMaxMsec=2", waitReq, func(start EventStart, evr eventReader) {
199 evr.Get("viewMsgs", &vm)
200 tcompare(t, len(vm.MessageItems), 3)
203 // Connection with DestMessageID.
204 destMsgReq := Request{
206 Filter: Filter{MailboxID: inbox.ID},
208 Page: Page{DestMessageID: inboxFlags.ID, Count: 10},
210 testConn(tokens[len(tokens)-3], "", destMsgReq, func(start EventStart, evr eventReader) {
212 evr.Get("viewMsgs", &vm)
213 tcompare(t, len(vm.MessageItems), 3)
214 tcompare(t, vm.ParsedMessage.ID, destMsgReq.Page.DestMessageID)
216 // todo: destmessageid past count, needs large mailbox
218 // Connection with missing DestMessageID, still fine.
219 badDestMsgReq := Request{
221 Filter: Filter{MailboxID: inbox.ID},
223 Page: Page{DestMessageID: inboxFlags.ID + 999, Count: 10},
225 testConn(api.Token(ctx), "", badDestMsgReq, func(start EventStart, evr eventReader) {
227 evr.Get("viewMsgs", &vm)
228 tcompare(t, len(vm.MessageItems), 3)
231 // Connection with missing unknown AnchorMessageID, resets view.
232 badAnchorMsgReq := Request{
234 Filter: Filter{MailboxID: inbox.ID},
236 Page: Page{AnchorMessageID: inboxFlags.ID + 999, Count: 10},
238 testConn(api.Token(ctx), "", badAnchorMsgReq, func(start EventStart, evr eventReader) {
239 var viewReset EventViewReset
240 evr.Get("viewReset", &viewReset)
243 evr.Get("viewMsgs", &vm)
244 tcompare(t, len(vm.MessageItems), 3)
247 // Connection that starts with a filter, without mailbox.
248 searchReq := Request{
250 Filter: Filter{Labels: []string{`\seen`}},
252 Page: Page{Count: 10},
254 testConn(api.Token(ctx), "", searchReq, func(start EventStart, evr eventReader) {
256 evr.Get("viewMsgs", &vm)
257 tcompare(t, len(vm.MessageItems), 1)
258 tcompare(t, vm.MessageItems[0][0].Message.ID, inboxFlags.ID)
261 // Paginate from previous last element. There is nothing new.
263 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: inbox.ID}}, Page: Page{Count: 10, AnchorMessageID: viewMsgs.MessageItems[len(viewMsgs.MessageItems)-1][0].Message.ID}})
264 evr.Get("viewMsgs", &viewMsgs)
265 tcompare(t, len(viewMsgs.MessageItems), 0)
267 // Request archive mailbox, empty.
269 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: archive.ID}}, Page: Page{Count: 10}})
270 evr.Get("viewMsgs", &viewMsgs)
271 tcompare(t, len(viewMsgs.MessageItems), 0)
272 tcompare(t, viewMsgs.ViewEnd, true)
274 threadlen := func(mil [][]MessageItem) int {
276 for _, l := range mil {
282 // Request with threading, should also include parent message from Trash mailbox (trashAlt).
284 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: inbox.ID}, Threading: "unread"}, Page: Page{Count: 10}})
285 evr.Get("viewMsgs", &viewMsgs)
286 tcompare(t, len(viewMsgs.MessageItems), 3)
287 tcompare(t, threadlen(viewMsgs.MessageItems), 3+1)
288 tcompare(t, viewMsgs.ViewEnd, true)
289 // And likewise when querying Trash, should also include child message in Inbox (inboxAltReply).
291 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: trash.ID}, Threading: "on"}, Page: Page{Count: 10}})
292 evr.Get("viewMsgs", &viewMsgs)
293 tcompare(t, len(viewMsgs.MessageItems), 3)
294 tcompare(t, threadlen(viewMsgs.MessageItems), 3+1)
295 tcompare(t, viewMsgs.ViewEnd, true)
296 // Without threading, the inbox has just 3 messages.
298 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: inbox.ID}, Threading: "off"}, Page: Page{Count: 10}})
299 evr.Get("viewMsgs", &viewMsgs)
300 tcompare(t, len(viewMsgs.MessageItems), 3)
301 tcompare(t, threadlen(viewMsgs.MessageItems), 3)
302 tcompare(t, viewMsgs.ViewEnd, true)
304 testFilter := func(orderAsc bool, f Filter, nf NotFilter, expIDs []int64) {
307 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{OrderAsc: orderAsc, Filter: f, NotFilter: nf}, Page: Page{Count: 10}})
308 evr.Get("viewMsgs", &viewMsgs)
309 ids := make([]int64, len(viewMsgs.MessageItems))
310 for i, mi := range viewMsgs.MessageItems {
311 ids[i] = mi[0].Message.ID
313 tcompare(t, ids, expIDs)
314 tcompare(t, viewMsgs.ViewEnd, true)
319 testFilter(false, Filter{MailboxID: lists.ID, MailboxChildrenIncluded: true}, znf, []int64{listsGoNutsMinimal.ID, listsMinimal.ID}) // Mailbox and sub mailbox.
320 testFilter(true, Filter{MailboxID: lists.ID, MailboxChildrenIncluded: true}, znf, []int64{listsMinimal.ID, listsGoNutsMinimal.ID}) // Oldest first first.
321 testFilter(false, Filter{MailboxID: -1}, znf, []int64{inboxAltReply.ID, listsGoNutsMinimal.ID, listsMinimal.ID, inboxFlags.ID, inboxMinimal.ID}) // All except trash/junk/rejects.
322 testFilter(false, Filter{Labels: []string{`\seen`}}, znf, []int64{inboxFlags.ID})
323 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Labels: []string{`\seen`}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
324 testFilter(false, Filter{Labels: []string{`testlabel`}}, znf, []int64{inboxFlags.ID})
325 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Labels: []string{`testlabel`}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
326 testFilter(false, Filter{MailboxID: inbox.ID, Oldest: &inboxFlags.m.Received}, znf, []int64{inboxAltReply.ID, inboxFlags.ID})
327 testFilter(false, Filter{MailboxID: inbox.ID, Newest: &inboxMinimal.m.Received}, znf, []int64{inboxMinimal.ID})
328 testFilter(false, Filter{MailboxID: inbox.ID, SizeMin: inboxFlags.m.Size}, znf, []int64{inboxFlags.ID})
329 testFilter(false, Filter{MailboxID: inbox.ID, SizeMax: inboxMinimal.m.Size}, znf, []int64{inboxMinimal.ID})
330 testFilter(false, Filter{From: []string{"mjl+altrel@mox.example"}}, znf, []int64{inboxFlags.ID})
331 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{From: []string{"mjl+altrel@mox.example"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
332 testFilter(false, Filter{To: []string{"mox+altrel@other.example"}}, znf, []int64{inboxFlags.ID})
333 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{To: []string{"mox+altrel@other.example"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
334 testFilter(false, Filter{From: []string{"mjl+altrel@mox.example", "bogus"}}, znf, []int64{})
335 testFilter(false, Filter{To: []string{"mox+altrel@other.example", "bogus"}}, znf, []int64{})
336 testFilter(false, Filter{Subject: []string{"test", "alt", "rel"}}, znf, []int64{inboxFlags.ID})
337 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Subject: []string{"alt"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
338 testFilter(false, Filter{MailboxID: inbox.ID, Words: []string{"the text body", "body", "the "}}, znf, []int64{inboxFlags.ID})
339 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Words: []string{"the text body"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
340 testFilter(false, Filter{Headers: [][2]string{{"X-Special", ""}}}, znf, []int64{inboxFlags.ID})
341 testFilter(false, Filter{Headers: [][2]string{{"X-Special", "testing"}}}, znf, []int64{inboxFlags.ID})
342 testFilter(false, Filter{Headers: [][2]string{{"X-Special", "other"}}}, znf, []int64{})
343 testFilter(false, Filter{Attachments: AttachmentImage}, znf, []int64{inboxFlags.ID})
344 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Attachments: AttachmentImage}, []int64{inboxAltReply.ID, inboxMinimal.ID})
347 getChanges := func(changes ...any) {
349 var viewChanges EventViewChanges
350 evr.Get("viewChanges", &viewChanges)
351 if len(viewChanges.Changes) != len(changes) {
352 t.Fatalf("got %d changes, expected %d", len(viewChanges.Changes), len(changes))
354 for i, dst := range changes {
355 src := viewChanges.Changes[i]
356 dstType := reflect.TypeOf(dst).Elem().Name()
357 if src[0] != dstType {
358 t.Fatalf("change %d is of type %s, expected %s", i, src[0], dstType)
360 // Marshal and unmarshal is easiest...
361 buf, err := json.Marshal(src[1])
362 tcheck(t, err, "marshal change")
363 dec := json.NewDecoder(bytes.NewReader(buf))
364 dec.DisallowUnknownFields()
365 err = dec.Decode(dst)
366 tcheck(t, err, "parsing change")
371 api.MailboxCreate(ctx, "Newbox")
372 var chmbadd ChangeMailboxAdd
374 tcompare(t, chmbadd.Mailbox.Name, "Newbox")
376 // ChangeMailboxRename
377 api.MailboxRename(ctx, chmbadd.Mailbox.ID, "Newbox2")
378 var chmbrename ChangeMailboxRename
379 getChanges(&chmbrename)
380 tcompare(t, chmbrename, ChangeMailboxRename{
381 ChangeRenameMailbox: store.ChangeRenameMailbox{MailboxID: chmbadd.Mailbox.ID, OldName: "Newbox", NewName: "Newbox2", Flags: nil},
384 // ChangeMailboxSpecialUse
385 api.MailboxSetSpecialUse(ctx, store.Mailbox{ID: chmbadd.Mailbox.ID, SpecialUse: store.SpecialUse{Archive: true}})
386 var chmbspecialuseOld, chmbspecialuseNew ChangeMailboxSpecialUse
387 getChanges(&chmbspecialuseOld, &chmbspecialuseNew)
388 tcompare(t, chmbspecialuseOld, ChangeMailboxSpecialUse{
389 ChangeMailboxSpecialUse: store.ChangeMailboxSpecialUse{MailboxID: archive.ID, MailboxName: "Archive", SpecialUse: store.SpecialUse{}},
391 tcompare(t, chmbspecialuseNew, ChangeMailboxSpecialUse{
392 ChangeMailboxSpecialUse: store.ChangeMailboxSpecialUse{MailboxID: chmbadd.Mailbox.ID, MailboxName: "Newbox2", SpecialUse: store.SpecialUse{Archive: true}},
395 // ChangeMailboxRemove
396 api.MailboxDelete(ctx, chmbadd.Mailbox.ID)
397 var chmbremove ChangeMailboxRemove
398 getChanges(&chmbremove)
399 tcompare(t, chmbremove, ChangeMailboxRemove{
400 ChangeRemoveMailbox: store.ChangeRemoveMailbox{MailboxID: chmbadd.Mailbox.ID, Name: "Newbox2"},
404 inboxNew := &testmsg{"Inbox", store.Flags{}, nil, msgMinimal, zerom, 0}
405 tdeliver(t, acc, inboxNew)
406 var chmsgadd ChangeMsgAdd
407 var chmbcounts ChangeMailboxCounts
408 getChanges(&chmsgadd, &chmbcounts)
409 tcompare(t, chmsgadd.ChangeAddUID.MailboxID, inbox.ID)
410 tcompare(t, chmsgadd.MessageItems[0].Message.ID, inboxNew.ID)
412 tcompare(t, chmbcounts, ChangeMailboxCounts{
413 ChangeMailboxCounts: store.ChangeMailboxCounts{
415 MailboxName: inbox.Name,
416 MailboxCounts: store.MailboxCounts{Total: 4, Unread: 3, Unseen: 3},
421 api.FlagsAdd(ctx, []int64{inboxNew.ID}, []string{`\seen`, `changelabel`, `aaa`})
422 var chmsgflags ChangeMsgFlags
423 var chmbkeywords ChangeMailboxKeywords
424 getChanges(&chmsgflags, &chmbcounts, &chmbkeywords)
425 tcompare(t, chmsgadd.ChangeAddUID.MailboxID, inbox.ID)
426 tcompare(t, chmbkeywords, ChangeMailboxKeywords{
427 ChangeMailboxKeywords: store.ChangeMailboxKeywords{
429 MailboxName: inbox.Name,
430 Keywords: []string{`aaa`, `changelabel`},
434 tcompare(t, chmbcounts, ChangeMailboxCounts{
435 ChangeMailboxCounts: store.ChangeMailboxCounts{
437 MailboxName: inbox.Name,
438 MailboxCounts: store.MailboxCounts{Total: 4, Unread: 2, Unseen: 2},
443 api.MessageDelete(ctx, []int64{inboxNew.ID, inboxMinimal.ID})
444 var chmsgremove ChangeMsgRemove
445 getChanges(&chmbcounts, &chmsgremove)
446 tcompare(t, chmsgremove.ChangeRemoveUIDs.MailboxID, inbox.ID)
447 tcompare(t, chmsgremove.ChangeRemoveUIDs.UIDs, []store.UID{inboxMinimal.m.UID, inboxNew.m.UID})
449 tcompare(t, chmbcounts, ChangeMailboxCounts{
450 ChangeMailboxCounts: store.ChangeMailboxCounts{
452 MailboxName: inbox.Name,
453 MailboxCounts: store.MailboxCounts{Total: 2, Unread: 1, Unseen: 1},
458 api.ThreadCollapse(ctx, []int64{inboxAltReply.ID}, true)
459 var chmsgthread ChangeMsgThread
460 getChanges(&chmsgthread)
461 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: true})
463 // Now collapsing the thread root, the child is already collapsed so no change.
464 api.ThreadCollapse(ctx, []int64{trashAlt.ID}, true)
465 getChanges(&chmsgthread)
466 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: true})
468 // Expand thread root, including change for child.
469 api.ThreadCollapse(ctx, []int64{trashAlt.ID}, false)
470 var chmsgthread2 ChangeMsgThread
471 getChanges(&chmsgthread, &chmsgthread2)
472 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: false})
473 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: false})
475 // Mute thread, including child, also collapses.
476 api.ThreadMute(ctx, []int64{trashAlt.ID}, true)
477 getChanges(&chmsgthread, &chmsgthread2)
478 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: true, Collapsed: true})
479 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: true, Collapsed: true})
481 // And unmute Mute thread, including child. Messages are not expanded.
482 api.ThreadMute(ctx, []int64{trashAlt.ID}, false)
483 getChanges(&chmsgthread, &chmsgthread2)
484 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: true})
485 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: true})
487 // todo: check move operations and their changes, e.g. MailboxDelete, MailboxEmpty, MessageRemove.
490type eventReader struct {
496func (r eventReader) Get(name string, event any) {
497 timer := time.AfterFunc(2*time.Second, func() {
499 pkglog.Print("event timeout")
509 line, err := r.br.ReadBytes(byte('\n'))
510 tcheck(t, err, "read line")
511 line = bytes.TrimRight(line, "\n")
512 // fmt.Printf("have line %s\n", line)
514 if bytes.HasPrefix(line, []byte("event: ")) {
515 ev = string(line[len("event: "):])
516 } else if bytes.HasPrefix(line, []byte("data: ")) {
517 data = line[len("data: "):]
518 } else if bytes.HasPrefix(line, []byte(":")) {
520 } else if len(line) == 0 {
526 t.Fatalf("got event %q (%s), expected %q", ev, data, name)
528 dec := json.NewDecoder(bytes.NewReader(data))
529 dec.DisallowUnknownFields()
530 err := dec.Decode(event)
531 tcheck(t, err, "unmarshal json")