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 err := store.Init(ctxbg)
33 tcheck(t, err, "store init")
36 tcheck(t, err, "store close")
38 defer store.Switchboard()()
40 log := mlog.New("webmail", nil)
41 acc, err := store.OpenAccount(log, "mjl", false)
42 tcheck(t, err, "open account")
43 err = acc.SetPassword(log, "test1234")
44 tcheck(t, err, "set password")
47 pkglog.Check(err, "closing account")
51 api := Webmail{maxMessageSize: 1024 * 1024, cookiePath: "/"}
53 respRec := httptest.NewRecorder()
54 reqInfo := requestInfo{log, "mjl@mox.example", acc, "", respRec, &http.Request{RemoteAddr: "127.0.0.1:1234"}}
55 ctx := context.WithValue(ctxbg, requestInfoCtxKey, reqInfo)
57 // Prepare loginToken.
58 loginCookie := &http.Cookie{Name: "webmaillogin"}
59 loginCookie.Value = api.LoginPrep(ctx)
60 reqInfo.Request.Header = http.Header{"Cookie": []string{loginCookie.String()}}
62 api.Login(ctx, loginCookie.Value, "mjl@mox.example", "test1234")
63 var sessionCookie *http.Cookie
64 for _, c := range respRec.Result().Cookies() {
65 if c.Name == "webmailsession" {
70 if sessionCookie == nil {
71 t.Fatalf("missing session cookie")
73 sct := strings.SplitN(sessionCookie.Value, " ", 2)
74 if len(sct) != 2 || sct[1] != "mjl" {
75 t.Fatalf("unexpected accountname %q in session cookie", sct[1])
77 sessionToken := store.SessionToken(sct[0])
79 reqInfo = requestInfo{log, "mjl@mox.example", acc, sessionToken, respRec, &http.Request{}}
80 ctx = context.WithValue(ctxbg, requestInfoCtxKey, reqInfo)
82 api.MailboxCreate(ctx, "Lists/Go/Nuts")
84 var zerom store.Message
86 inboxMinimal = &testmsg{"Inbox", store.Flags{}, nil, msgMinimal, zerom, 0}
87 inboxFlags = &testmsg{"Inbox", store.Flags{Seen: true}, []string{"testlabel"}, msgAltRel, zerom, 0} // With flags, and larger.
88 listsMinimal = &testmsg{"Lists", store.Flags{}, nil, msgMinimal, zerom, 0}
89 listsGoNutsMinimal = &testmsg{"Lists/Go/Nuts", store.Flags{}, nil, msgMinimal, zerom, 0}
90 trashMinimal = &testmsg{"Trash", store.Flags{}, nil, msgMinimal, zerom, 0}
91 junkMinimal = &testmsg{"Trash", store.Flags{}, nil, msgMinimal, zerom, 0}
92 trashAlt = &testmsg{"Trash", store.Flags{}, nil, msgAlt, zerom, 0}
93 inboxAltReply = &testmsg{"Inbox", store.Flags{}, nil, msgAltReply, zerom, 0}
95 var testmsgs = []*testmsg{inboxMinimal, inboxFlags, listsMinimal, listsGoNutsMinimal, trashMinimal, junkMinimal, trashAlt, inboxAltReply}
96 for _, tm := range testmsgs {
103 tokens = append(tokens, api.Token(ctx))
105 // Only last 10 tokens are still valid and around, checked below.
108 tneedError(t, func() { api.Request(ctx, Request{ID: 1, Cancel: true}) }) // Zero/invalid SSEID.
110 // We start an actual HTTP server to easily get a body we can do blocking reads on.
111 // With a httptest.ResponseRecorder, it's a bit more work to parse SSE events as
113 server := httptest.NewServer(http.HandlerFunc(Handler(1024*1024, "/webmail/", false, "")))
116 serverURL, err := url.Parse(server.URL)
117 tcheck(t, err, "parsing server url")
118 _, port, err := net.SplitHostPort(serverURL.Host)
119 tcheck(t, err, "parsing host port in server url")
120 eventsURL := fmt.Sprintf("http://%s/events", net.JoinHostPort("localhost", port))
123 Page: Page{Count: 10},
125 requestJSON, err := json.Marshal(request)
126 tcheck(t, err, "marshal request as json")
128 testFail := func(method, path string, expStatusCode int) {
130 req, err := http.NewRequest(method, path, nil)
131 tcheck(t, err, "making request")
132 resp, err := http.DefaultClient.Do(req)
133 tcheck(t, err, "http transaction")
135 if resp.StatusCode != expStatusCode {
136 t.Fatalf("got statuscode %d, expected %d", resp.StatusCode, expStatusCode)
140 testFail("POST", eventsURL+"?singleUseToken="+tokens[0]+"&request="+string(requestJSON), http.StatusMethodNotAllowed) // Must be GET.
141 testFail("GET", eventsURL, http.StatusBadRequest) // Missing token.
142 testFail("GET", eventsURL+"?singleUseToken="+tokens[0]+"&request="+string(requestJSON), http.StatusBadRequest) // Bad (old) token.
143 testFail("GET", eventsURL+"?singleUseToken="+tokens[len(tokens)-5]+"&request=bad", http.StatusBadRequest) // Bad request.
145 // Start connection for testing and filters below.
146 req, err := http.NewRequest("GET", eventsURL+"?singleUseToken="+tokens[len(tokens)-1]+"&request="+string(requestJSON), nil)
147 tcheck(t, err, "making request")
148 resp, err := http.DefaultClient.Do(req)
149 tcheck(t, err, "http transaction")
150 defer resp.Body.Close()
151 if resp.StatusCode != http.StatusOK {
152 t.Fatalf("got statuscode %d, expected %d (%s)", resp.StatusCode, http.StatusOK, readBody(resp.Body))
155 evr := eventReader{t, bufio.NewReader(resp.Body), resp.Body}
157 evr.Get("start", &start)
158 tcompare(t, start.Introbox, "Introbox")
159 var viewMsgs EventViewMsgs
160 evr.Get("viewMsgs", &viewMsgs)
161 tcompare(t, len(viewMsgs.MessageItems), 3)
162 tcompare(t, viewMsgs.ViewEnd, true)
164 var inbox, archive, lists, trash store.Mailbox
165 for _, mb := range start.Mailboxes {
168 } else if mb.Name == start.MailboxName {
170 } else if mb.Name == "Lists" {
172 } else if mb.Name == "Trash" {
177 // Can only use a token once.
178 testFail("GET", eventsURL+"?singleUseToken="+tokens[len(tokens)-1]+"&request=bad", http.StatusBadRequest)
180 // Check a few initial query/page combinations.
181 testConn := func(token, more string, request Request, check func(EventStart, eventReader)) {
184 reqJSON, err := json.Marshal(request)
185 tcheck(t, err, "marshal request json")
186 req, err := http.NewRequest("GET", eventsURL+"?singleUseToken="+token+more+"&request="+string(reqJSON), nil)
187 tcheck(t, err, "making request")
188 resp, err := http.DefaultClient.Do(req)
189 tcheck(t, err, "http transaction")
190 defer resp.Body.Close()
191 if resp.StatusCode != http.StatusOK {
192 t.Fatalf("got statuscode %d, expected %d", resp.StatusCode, http.StatusOK)
195 xevr := eventReader{t, bufio.NewReader(resp.Body), resp.Body}
196 var xstart EventStart
197 xevr.Get("start", &xstart)
201 // Connection with waitMinMsec/waitMaxMsec, just exercising code path.
203 Page: Page{Count: 10},
205 testConn(api.Token(ctx), "&waitMinMsec=1&waitMaxMsec=2", waitReq, func(start EventStart, evr eventReader) {
207 evr.Get("viewMsgs", &vm)
208 tcompare(t, len(vm.MessageItems), 3)
211 // Connection with DestMessageID.
212 destMsgReq := Request{
214 Filter: Filter{MailboxID: inbox.ID},
216 Page: Page{DestMessageID: inboxFlags.ID, Count: 10},
218 testConn(tokens[len(tokens)-3], "", destMsgReq, func(start EventStart, evr eventReader) {
220 evr.Get("viewMsgs", &vm)
221 tcompare(t, len(vm.MessageItems), 3)
222 tcompare(t, vm.ParsedMessage.ID, destMsgReq.Page.DestMessageID)
224 // todo: destmessageid past count, needs large mailbox
226 // Connection with missing DestMessageID, still fine.
227 badDestMsgReq := Request{
229 Filter: Filter{MailboxID: inbox.ID},
231 Page: Page{DestMessageID: inboxFlags.ID + 999, Count: 10},
233 testConn(api.Token(ctx), "", badDestMsgReq, func(start EventStart, evr eventReader) {
235 evr.Get("viewMsgs", &vm)
236 tcompare(t, len(vm.MessageItems), 3)
239 // Connection with missing unknown AnchorMessageID, resets view.
240 badAnchorMsgReq := Request{
242 Filter: Filter{MailboxID: inbox.ID},
244 Page: Page{AnchorMessageID: inboxFlags.ID + 999, Count: 10},
246 testConn(api.Token(ctx), "", badAnchorMsgReq, func(start EventStart, evr eventReader) {
247 var viewReset EventViewReset
248 evr.Get("viewReset", &viewReset)
251 evr.Get("viewMsgs", &vm)
252 tcompare(t, len(vm.MessageItems), 3)
255 // Connection that starts with a filter, without mailbox.
256 searchReq := Request{
258 Filter: Filter{Labels: []string{`\seen`}},
260 Page: Page{Count: 10},
262 testConn(api.Token(ctx), "", searchReq, func(start EventStart, evr eventReader) {
264 evr.Get("viewMsgs", &vm)
265 tcompare(t, len(vm.MessageItems), 1)
266 tcompare(t, vm.MessageItems[0][0].Message.ID, inboxFlags.ID)
269 // Paginate from previous last element. There is nothing new.
271 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}})
272 evr.Get("viewMsgs", &viewMsgs)
273 tcompare(t, len(viewMsgs.MessageItems), 0)
275 // Request archive mailbox, empty.
277 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: archive.ID}}, Page: Page{Count: 10}})
278 evr.Get("viewMsgs", &viewMsgs)
279 tcompare(t, len(viewMsgs.MessageItems), 0)
280 tcompare(t, viewMsgs.ViewEnd, true)
282 threadlen := func(mil [][]MessageItem) int {
284 for _, l := range mil {
290 // Request with threading, should also include parent message from Trash mailbox (trashAlt).
292 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: inbox.ID}, Threading: "unread"}, Page: Page{Count: 10}})
293 evr.Get("viewMsgs", &viewMsgs)
294 tcompare(t, len(viewMsgs.MessageItems), 3)
295 tcompare(t, threadlen(viewMsgs.MessageItems), 3+1)
296 tcompare(t, viewMsgs.ViewEnd, true)
297 // And likewise when querying Trash, should also include child message in Inbox (inboxAltReply).
299 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: trash.ID}, Threading: "on"}, Page: Page{Count: 10}})
300 evr.Get("viewMsgs", &viewMsgs)
301 tcompare(t, len(viewMsgs.MessageItems), 3)
302 tcompare(t, threadlen(viewMsgs.MessageItems), 3+1)
303 tcompare(t, viewMsgs.ViewEnd, true)
304 // Without threading, the inbox has just 3 messages.
306 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{Filter: Filter{MailboxID: inbox.ID}, Threading: "off"}, Page: Page{Count: 10}})
307 evr.Get("viewMsgs", &viewMsgs)
308 tcompare(t, len(viewMsgs.MessageItems), 3)
309 tcompare(t, threadlen(viewMsgs.MessageItems), 3)
310 tcompare(t, viewMsgs.ViewEnd, true)
312 testFilter := func(orderAsc bool, f Filter, nf NotFilter, expIDs []int64) {
315 api.Request(ctx, Request{ID: 1, SSEID: start.SSEID, ViewID: viewID, Query: Query{OrderAsc: orderAsc, Filter: f, NotFilter: nf}, Page: Page{Count: 10}})
316 evr.Get("viewMsgs", &viewMsgs)
317 ids := make([]int64, len(viewMsgs.MessageItems))
318 for i, mi := range viewMsgs.MessageItems {
319 ids[i] = mi[0].Message.ID
321 tcompare(t, ids, expIDs)
322 tcompare(t, viewMsgs.ViewEnd, true)
327 testFilter(false, Filter{MailboxID: lists.ID, MailboxChildrenIncluded: true}, znf, []int64{listsGoNutsMinimal.ID, listsMinimal.ID}) // Mailbox and sub mailbox.
328 testFilter(true, Filter{MailboxID: lists.ID, MailboxChildrenIncluded: true}, znf, []int64{listsMinimal.ID, listsGoNutsMinimal.ID}) // Oldest first first.
329 testFilter(false, Filter{MailboxID: -1}, znf, []int64{inboxAltReply.ID, listsGoNutsMinimal.ID, listsMinimal.ID, inboxFlags.ID, inboxMinimal.ID}) // All except trash/junk/rejects.
330 testFilter(false, Filter{Labels: []string{`\seen`}}, znf, []int64{inboxFlags.ID})
331 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Labels: []string{`\seen`}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
332 testFilter(false, Filter{Labels: []string{`testlabel`}}, znf, []int64{inboxFlags.ID})
333 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Labels: []string{`testlabel`}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
334 testFilter(false, Filter{MailboxID: inbox.ID, Oldest: &inboxFlags.m.Received}, znf, []int64{inboxAltReply.ID, inboxFlags.ID})
335 testFilter(false, Filter{MailboxID: inbox.ID, Newest: &inboxMinimal.m.Received}, znf, []int64{inboxMinimal.ID})
336 testFilter(false, Filter{MailboxID: inbox.ID, SizeMin: inboxFlags.m.Size}, znf, []int64{inboxFlags.ID})
337 testFilter(false, Filter{MailboxID: inbox.ID, SizeMax: inboxMinimal.m.Size}, znf, []int64{inboxMinimal.ID})
338 testFilter(false, Filter{From: []string{"mjl+altrel@mox.example"}}, znf, []int64{inboxFlags.ID})
339 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{From: []string{"mjl+altrel@mox.example"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
340 testFilter(false, Filter{To: []string{"mox+altrel@other.example"}}, znf, []int64{inboxFlags.ID})
341 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{To: []string{"mox+altrel@other.example"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
342 testFilter(false, Filter{From: []string{"mjl+altrel@mox.example", "bogus"}}, znf, []int64{})
343 testFilter(false, Filter{To: []string{"mox+altrel@other.example", "bogus"}}, znf, []int64{})
344 testFilter(false, Filter{Subject: []string{"test", "alt", "rel"}}, znf, []int64{inboxFlags.ID})
345 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Subject: []string{"alt"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
346 testFilter(false, Filter{MailboxID: inbox.ID, Words: []string{"the text body", "body", "the "}}, znf, []int64{inboxFlags.ID})
347 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Words: []string{"the text body"}}, []int64{inboxAltReply.ID, inboxMinimal.ID})
348 testFilter(false, Filter{Headers: [][2]string{{"X-Special", ""}}}, znf, []int64{inboxFlags.ID})
349 testFilter(false, Filter{Headers: [][2]string{{"X-Special", "testing"}}}, znf, []int64{inboxFlags.ID})
350 testFilter(false, Filter{Headers: [][2]string{{"X-Special", "other"}}}, znf, []int64{})
351 testFilter(false, Filter{Attachments: AttachmentImage}, znf, []int64{inboxFlags.ID})
352 testFilter(false, Filter{MailboxID: inbox.ID}, NotFilter{Attachments: AttachmentImage}, []int64{inboxAltReply.ID, inboxMinimal.ID})
355 getChanges := func(changes ...any) {
357 var viewChanges EventViewChanges
358 evr.Get("viewChanges", &viewChanges)
359 if len(viewChanges.Changes) != len(changes) {
360 t.Fatalf("got %d changes, expected %d", len(viewChanges.Changes), len(changes))
362 for i, dst := range changes {
363 src := viewChanges.Changes[i]
364 dstType := reflect.TypeOf(dst).Elem().Name()
365 if src[0] != dstType {
366 t.Fatalf("change %d is of type %s, expected %s", i, src[0], dstType)
368 // Marshal and unmarshal is easiest...
369 buf, err := json.Marshal(src[1])
370 tcheck(t, err, "marshal change")
371 dec := json.NewDecoder(bytes.NewReader(buf))
372 dec.DisallowUnknownFields()
373 err = dec.Decode(dst)
374 tcheck(t, err, "parsing change")
379 api.MailboxCreate(ctx, "Newbox")
380 var chmbadd ChangeMailboxAdd
382 tcompare(t, chmbadd.Mailbox.Name, "Newbox")
384 // ChangeMailboxRename
385 api.MailboxRename(ctx, chmbadd.Mailbox.ID, "Newbox2")
386 var chmbrename ChangeMailboxRename
387 getChanges(&chmbrename)
388 tcompare(t, chmbrename, ChangeMailboxRename{
389 ChangeRenameMailbox: store.ChangeRenameMailbox{MailboxID: chmbadd.Mailbox.ID, OldName: "Newbox", NewName: "Newbox2", Flags: nil, ModSeq: 13},
392 // ChangeMailboxSpecialUse
393 api.MailboxSetSpecialUse(ctx, store.Mailbox{ID: chmbadd.Mailbox.ID, SpecialUse: store.SpecialUse{Archive: true}})
394 var chmbspecialuseOld, chmbspecialuseNew ChangeMailboxSpecialUse
395 getChanges(&chmbspecialuseOld, &chmbspecialuseNew)
396 tcompare(t, chmbspecialuseOld, ChangeMailboxSpecialUse{
397 ChangeMailboxSpecialUse: store.ChangeMailboxSpecialUse{MailboxID: archive.ID, MailboxName: "Archive", SpecialUse: store.SpecialUse{}, ModSeq: 14},
399 tcompare(t, chmbspecialuseNew, ChangeMailboxSpecialUse{
400 ChangeMailboxSpecialUse: store.ChangeMailboxSpecialUse{MailboxID: chmbadd.Mailbox.ID, MailboxName: "Newbox2", SpecialUse: store.SpecialUse{Archive: true}, ModSeq: 14},
403 // ChangeMailboxRemove
404 api.MailboxDelete(ctx, chmbadd.Mailbox.ID)
405 var chmbremove ChangeMailboxRemove
406 getChanges(&chmbremove)
407 tcompare(t, chmbremove, ChangeMailboxRemove{
408 ChangeRemoveMailbox: store.ChangeRemoveMailbox{MailboxID: chmbadd.Mailbox.ID, Name: "Newbox2", ModSeq: 15},
412 inboxNew := &testmsg{"Inbox", store.Flags{}, nil, msgMinimal, zerom, 0}
413 tdeliver(t, acc, inboxNew)
414 var chmsgadd ChangeMsgAdd
415 var chmbcounts ChangeMailboxCounts
416 getChanges(&chmsgadd, &chmbcounts)
417 tcompare(t, chmsgadd.ChangeAddUID.MailboxID, inbox.ID)
418 tcompare(t, chmsgadd.MessageItems[0].Message.ID, inboxNew.ID)
420 tcompare(t, chmbcounts, ChangeMailboxCounts{
421 ChangeMailboxCounts: store.ChangeMailboxCounts{
423 MailboxName: inbox.Name,
424 MailboxCounts: store.MailboxCounts{Total: 4, Unread: 3, Unseen: 3},
429 api.FlagsAdd(ctx, []int64{inboxNew.ID}, []string{`\seen`, `changelabel`, `aaa`})
430 var chmsgflags ChangeMsgFlags
431 var chmbkeywords ChangeMailboxKeywords
432 getChanges(&chmsgflags, &chmbcounts, &chmbkeywords)
433 tcompare(t, chmsgadd.ChangeAddUID.MailboxID, inbox.ID)
434 tcompare(t, chmbkeywords, ChangeMailboxKeywords{
435 ChangeMailboxKeywords: store.ChangeMailboxKeywords{
437 MailboxName: inbox.Name,
438 Keywords: []string{`aaa`, `changelabel`, `testlabel`},
442 tcompare(t, chmbcounts, ChangeMailboxCounts{
443 ChangeMailboxCounts: store.ChangeMailboxCounts{
445 MailboxName: inbox.Name,
446 MailboxCounts: store.MailboxCounts{Total: 4, Unread: 2, Unseen: 2},
451 api.MessageDelete(ctx, []int64{inboxNew.ID, inboxMinimal.ID})
452 var chmsgremove ChangeMsgRemove
453 getChanges(&chmbcounts, &chmsgremove)
454 tcompare(t, chmsgremove.ChangeRemoveUIDs.MailboxID, inbox.ID)
455 tcompare(t, chmsgremove.ChangeRemoveUIDs.UIDs, []store.UID{inboxMinimal.m.UID, inboxNew.m.UID})
457 tcompare(t, chmbcounts, ChangeMailboxCounts{
458 ChangeMailboxCounts: store.ChangeMailboxCounts{
460 MailboxName: inbox.Name,
461 MailboxCounts: store.MailboxCounts{Total: 2, Unread: 1, Unseen: 1},
466 api.ThreadCollapse(ctx, []int64{inboxAltReply.ID}, true)
467 var chmsgthread ChangeMsgThread
468 getChanges(&chmsgthread)
469 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: true})
471 // Now collapsing the thread root, the child is already collapsed so no change.
472 api.ThreadCollapse(ctx, []int64{trashAlt.ID}, true)
473 getChanges(&chmsgthread)
474 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: true})
476 // Expand thread root, including change for child.
477 api.ThreadCollapse(ctx, []int64{trashAlt.ID}, false)
478 var chmsgthread2 ChangeMsgThread
479 getChanges(&chmsgthread, &chmsgthread2)
480 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: false})
481 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: false})
483 // Mute thread, including child, also collapses.
484 api.ThreadMute(ctx, []int64{trashAlt.ID}, true)
485 getChanges(&chmsgthread, &chmsgthread2)
486 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: true, Collapsed: true})
487 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: true, Collapsed: true})
489 // And unmute Mute thread, including child. Messages are not expanded.
490 api.ThreadMute(ctx, []int64{trashAlt.ID}, false)
491 getChanges(&chmsgthread, &chmsgthread2)
492 tcompare(t, chmsgthread.ChangeThread, store.ChangeThread{MessageIDs: []int64{trashAlt.ID}, Muted: false, Collapsed: true})
493 tcompare(t, chmsgthread2.ChangeThread, store.ChangeThread{MessageIDs: []int64{inboxAltReply.ID}, Muted: false, Collapsed: true})
495 // todo: check move operations and their changes, e.g. MailboxDelete, MailboxEmpty, MessageRemove.
498type eventReader struct {
504func (r eventReader) Get(name string, event any) {
505 timer := time.AfterFunc(2*time.Second, func() {
507 pkglog.Print("event timeout")
517 line, err := r.br.ReadBytes(byte('\n'))
518 tcheck(t, err, "read line")
519 line = bytes.TrimRight(line, "\n")
520 // fmt.Printf("have line %s\n", line)
522 if bytes.HasPrefix(line, []byte("event: ")) {
523 ev = string(line[len("event: "):])
524 } else if bytes.HasPrefix(line, []byte("data: ")) {
525 data = line[len("data: "):]
526 } else if bytes.HasPrefix(line, []byte(":")) {
528 } else if len(line) == 0 {
534 t.Fatalf("got event %q (%s), expected %q", ev, data, name)
536 dec := json.NewDecoder(bytes.NewReader(data))
537 dec.DisallowUnknownFields()
538 err := dec.Decode(event)
539 tcheck(t, err, "unmarshal json")