1package tui
2
3import (
4 "fmt"
5 "io"
6 "strings"
7 "time"
8
9 "charm.land/bubbles/v2/key"
10 "charm.land/bubbles/v2/list"
11 tea "charm.land/bubbletea/v2"
12 "charm.land/lipgloss/v2"
13 "github.com/floatpane/matcha/config"
14 "github.com/floatpane/matcha/fetcher"
15)
16
17var (
18 // In bubbles v2, list.DefaultStyles() takes a boolean for hasDarkBackground
19 paginationStyle = list.DefaultStyles(true).PaginationStyle.PaddingLeft(4)
20 inboxHelpStyle = list.DefaultStyles(true).HelpStyle.PaddingLeft(4).PaddingBottom(1)
21 tabStyle = lipgloss.NewStyle().Padding(0, 2)
22 activeTabStyle = lipgloss.NewStyle().Padding(0, 2).Foreground(lipgloss.Color("42")).Bold(true).Underline(true)
23 tabBarStyle = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).PaddingBottom(1).MarginBottom(1)
24)
25
26var dateStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("243"))
27var senderStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("250")).Bold(true)
28
29type item struct {
30 title, desc string
31 originalIndex int
32 uid uint32
33 accountID string
34 accountEmail string
35 date time.Time
36}
37
38func (i item) Title() string { return i.title }
39func (i item) Description() string { return i.desc }
40func (i item) FilterValue() string { return i.title + " " + i.desc }
41
42type itemDelegate struct{}
43
44func (d itemDelegate) Height() int { return 1 }
45func (d itemDelegate) Spacing() int { return 0 }
46func (d itemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil }
47func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) {
48 i, ok := listItem.(item)
49 if !ok {
50 return
51 }
52
53 prefix := fmt.Sprintf("%d. ", index+1)
54 sender := parseSenderName(i.desc)
55 styledSender := senderStyle.Render(sender)
56 separator := " · "
57
58 // For "ALL" view, show account indicator instead of number
59 if i.accountEmail != "" {
60 prefix = fmt.Sprintf("%d. [%s] ", index+1, truncateEmail(i.accountEmail))
61 }
62
63 // Format and right-align date
64 dateStr := formatRelativeDate(i.date)
65 styledDate := dateStyle.Render(dateStr)
66 dateWidth := lipgloss.Width(styledDate)
67
68 listWidth := m.Width()
69 isSelected := index == m.Index()
70 cursorWidth := 0
71 if isSelected {
72 cursorWidth = 2 // "> " prefix
73 }
74
75 // Available width for the whole left side (prefix + sender + separator + subject)
76 maxLeft := listWidth - dateWidth - 2 - cursorWidth // 2 for spacing
77 if maxLeft < 10 {
78 maxLeft = 10
79 }
80
81 prefixWidth := lipgloss.Width(prefix)
82 senderWidth := lipgloss.Width(styledSender)
83 sepWidth := len(separator)
84 subjectBudget := maxLeft - prefixWidth - senderWidth - sepWidth
85
86 subject := i.title
87 if subjectBudget < 4 {
88 subjectBudget = 4
89 }
90 if lipgloss.Width(subject) > subjectBudget {
91 for lipgloss.Width(subject) > subjectBudget-1 && len(subject) > 0 {
92 subject = subject[:len(subject)-1]
93 }
94 subject += "…"
95 }
96
97 str := prefix + styledSender + separator + subject
98
99 // Pad to push date to the right
100 padding := listWidth - lipgloss.Width(str) - dateWidth - cursorWidth
101 if padding < 1 {
102 padding = 1
103 }
104
105 fn := itemStyle.Render
106 if index == m.Index() {
107 fn = func(s ...string) string {
108 return selectedItemStyle.Render("> " + s[0])
109 }
110 }
111
112 fmt.Fprint(w, fn(str+strings.Repeat(" ", padding)+styledDate))
113}
114
115// formatRelativeDate formats a time as relative if within the last week,
116// otherwise as an absolute date.
117func formatRelativeDate(t time.Time) string {
118 if t.IsZero() {
119 return ""
120 }
121 now := time.Now()
122 d := now.Sub(t)
123
124 switch {
125 case d < time.Minute:
126 return "just now"
127 case d < time.Hour:
128 mins := int(d.Minutes())
129 if mins == 1 {
130 return "1 min ago"
131 }
132 return fmt.Sprintf("%d min ago", mins)
133 case d < 24*time.Hour:
134 hours := int(d.Hours())
135 if hours == 1 {
136 return "1 hour ago"
137 }
138 return fmt.Sprintf("%d hours ago", hours)
139 case d < 7*24*time.Hour:
140 days := int(d.Hours() / 24)
141 if days == 1 {
142 return "1 day ago"
143 }
144 return fmt.Sprintf("%d days ago", days)
145 default:
146 if t.Year() == now.Year() {
147 return t.Format("Jan 02")
148 }
149 return t.Format("Jan 02, 2006")
150 }
151}
152
153// parseSenderName extracts the display name from a "Name <email>" string,
154// falling back to the local part of the email address.
155func parseSenderName(from string) string {
156 if idx := strings.Index(from, " <"); idx > 0 {
157 return strings.TrimSpace(from[:idx])
158 }
159 // No display name — use local part of email
160 if idx := strings.Index(from, "@"); idx > 0 {
161 return from[:idx]
162 }
163 return from
164}
165
166// truncateEmail shortens an email for display
167func truncateEmail(email string) string {
168 parts := strings.Split(email, "@")
169 if len(parts) >= 1 && len(parts[0]) > 8 {
170 return parts[0][:8] + "..."
171 }
172 if len(parts) >= 1 {
173 return parts[0]
174 }
175 return email
176}
177
178// AccountTab represents a tab for an account
179type AccountTab struct {
180 ID string
181 Label string
182 Email string
183}
184
185type Inbox struct {
186 list list.Model
187 isFetching bool
188 isRefreshing bool
189 emailsCount int
190 accounts []config.Account
191 emailsByAccount map[string][]fetcher.Email
192 allEmails []fetcher.Email
193 tabs []AccountTab
194 activeTabIndex int
195 width int
196 height int
197 currentAccountID string // Empty means "ALL"
198 emailCountByAcct map[string]int
199 mailbox MailboxKind
200 folderName string // Custom folder name override for title
201 noMoreByAccount map[string]bool // Per-account: true when pagination returns 0 results
202 extraShortHelpKeys []key.Binding
203}
204
205func NewInbox(emails []fetcher.Email, accounts []config.Account) *Inbox {
206 return NewInboxWithMailbox(emails, accounts, MailboxInbox)
207}
208
209func NewSentInbox(emails []fetcher.Email, accounts []config.Account) *Inbox {
210 return NewInboxWithMailbox(emails, accounts, MailboxSent)
211}
212
213func NewTrashInbox(emails []fetcher.Email, accounts []config.Account) *Inbox {
214 return NewInboxWithMailbox(emails, accounts, MailboxTrash)
215}
216
217func NewArchiveInbox(emails []fetcher.Email, accounts []config.Account) *Inbox {
218 return NewInboxWithMailbox(emails, accounts, MailboxArchive)
219}
220
221func NewInboxWithMailbox(emails []fetcher.Email, accounts []config.Account, mailbox MailboxKind) *Inbox {
222 // Build tabs: empty for single account, "ALL" + accounts for multiple
223 var tabs []AccountTab
224 if len(accounts) <= 1 {
225 tabs = []AccountTab{{ID: "", Label: "", Email: ""}}
226 } else {
227 tabs = []AccountTab{{ID: "", Label: "ALL", Email: ""}}
228 for _, acc := range accounts {
229 // Use FetchEmail for display, fall back to Email if not set
230 displayEmail := acc.FetchEmail
231 if displayEmail == "" {
232 displayEmail = acc.Email
233 }
234 tabs = append(tabs, AccountTab{ID: acc.ID, Label: displayEmail, Email: displayEmail})
235 }
236 }
237
238 // Group emails by account
239 emailsByAccount := make(map[string][]fetcher.Email)
240 for _, email := range emails {
241 emailsByAccount[email.AccountID] = append(emailsByAccount[email.AccountID], email)
242 }
243
244 // Track email counts per account
245 emailCountByAcct := make(map[string]int)
246 for accID, accEmails := range emailsByAccount {
247 emailCountByAcct[accID] = len(accEmails)
248 }
249
250 inbox := &Inbox{
251 accounts: accounts,
252 emailsByAccount: emailsByAccount,
253 allEmails: emails,
254 tabs: tabs,
255 activeTabIndex: 0,
256 currentAccountID: "",
257 emailCountByAcct: emailCountByAcct,
258 mailbox: mailbox,
259 }
260
261 inbox.updateList()
262 return inbox
263}
264
265// NewInboxSingleAccount creates an inbox for a single account (legacy support)
266func NewInboxSingleAccount(emails []fetcher.Email) *Inbox {
267 return NewInbox(emails, nil)
268}
269
270func (m *Inbox) updateList() {
271 // Capture current index to restore later
272 currentIndex := m.list.Index()
273
274 var displayEmails []fetcher.Email
275 var showAccountLabel bool
276
277 if m.currentAccountID == "" {
278 // "ALL" view - show all emails sorted by date
279 displayEmails = m.allEmails
280 showAccountLabel = !(len(m.accounts) <= 1)
281 } else {
282 // Specific account view
283 displayEmails = m.emailsByAccount[m.currentAccountID]
284 showAccountLabel = false
285 }
286
287 m.emailsCount = len(displayEmails)
288
289 items := make([]list.Item, len(displayEmails))
290 for i, email := range displayEmails {
291 accountEmail := ""
292 if showAccountLabel {
293 // Find the account email for display
294 for _, acc := range m.accounts {
295 if acc.ID == email.AccountID {
296 accountEmail = acc.FetchEmail
297 break
298 }
299 }
300 }
301
302 items[i] = item{
303 title: email.Subject,
304 desc: email.From,
305 originalIndex: i,
306 uid: email.UID,
307 accountID: email.AccountID,
308 accountEmail: accountEmail,
309 date: email.Date,
310 }
311 }
312
313 l := list.New(items, itemDelegate{}, 20, 14)
314 l.Title = m.getTitle()
315 l.SetShowStatusBar(true)
316 l.SetFilteringEnabled(true)
317 l.Styles.Title = lipgloss.NewStyle().Foreground(lipgloss.Color("42")).Bold(true)
318 l.Styles.PaginationStyle = paginationStyle
319 l.Styles.HelpStyle = inboxHelpStyle
320 l.SetStatusBarItemName("email", "emails")
321 l.AdditionalShortHelpKeys = func() []key.Binding {
322 bindings := []key.Binding{
323 key.NewBinding(key.WithKeys("d"), key.WithHelp("\uf014 d", "delete")),
324 key.NewBinding(key.WithKeys("a"), key.WithHelp("\uea98 a", "archive")),
325 key.NewBinding(key.WithKeys("r"), key.WithHelp("\ue348 r", "refresh")),
326 }
327 if len(m.tabs) > 1 {
328 bindings = append(bindings,
329 key.NewBinding(key.WithKeys("left", "h"), key.WithHelp("←/h", "prev tab")),
330 key.NewBinding(key.WithKeys("right", "l"), key.WithHelp("→/l", "next tab")),
331 )
332 }
333 bindings = append(bindings, m.extraShortHelpKeys...)
334 return bindings
335 }
336
337 l.KeyMap.Quit.SetEnabled(false)
338
339 // Disable default help to render it manually at the bottom
340 l.SetShowHelp(false)
341
342 if m.width > 0 {
343 l.SetWidth(m.width)
344 }
345 if m.height > 0 {
346 l.SetHeight(m.height / 2)
347 }
348
349 // Restore index
350 // If index is out of bounds (e.g. list shrank), clamp it.
351 if currentIndex >= len(items) {
352 currentIndex = len(items) - 1
353 }
354 if currentIndex < 0 {
355 currentIndex = 0
356 }
357 l.Select(currentIndex)
358
359 m.list = l
360}
361
362func (m *Inbox) getTitle() string {
363 var title string
364 if m.currentAccountID == "" {
365 title = m.getBaseTitle() + " - All Accounts"
366 } else {
367 title = m.getBaseTitle()
368 for _, acc := range m.accounts {
369 if acc.ID == m.currentAccountID {
370 if acc.Name != "" {
371 title = fmt.Sprintf("%s - %s", m.getBaseTitle(), acc.Name)
372 } else {
373 title = fmt.Sprintf("%s - %s", m.getBaseTitle(), acc.FetchEmail)
374 }
375 break
376 }
377 }
378 }
379 if m.isRefreshing {
380 title += " (refreshing...)"
381 }
382 if m.isFetching {
383 title += " (loading more...)"
384 }
385 return title
386}
387
388func (m *Inbox) getBaseTitle() string {
389 if m.folderName != "" {
390 return m.folderName
391 }
392 switch m.mailbox {
393 case MailboxSent:
394 return "Sent"
395 case MailboxTrash:
396 return "Trash"
397 case MailboxArchive:
398 return "Archive"
399 default:
400 return "Inbox"
401 }
402}
403
404func (m *Inbox) Init() tea.Cmd {
405 return nil
406}
407
408func (m *Inbox) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
409 var cmds []tea.Cmd
410
411 switch msg := msg.(type) {
412 case tea.KeyPressMsg:
413 if m.list.FilterState() == list.Filtering {
414 break
415 }
416 switch keypress := msg.String(); keypress {
417 case "left", "h":
418 if len(m.tabs) > 1 {
419 m.activeTabIndex--
420 if m.activeTabIndex < 0 {
421 m.activeTabIndex = len(m.tabs) - 1
422 }
423 m.currentAccountID = m.tabs[m.activeTabIndex].ID
424 m.updateList()
425 return m, nil
426 }
427 case "right", "l":
428 if len(m.tabs) > 1 {
429 m.activeTabIndex++
430 if m.activeTabIndex >= len(m.tabs) {
431 m.activeTabIndex = 0
432 }
433 m.currentAccountID = m.tabs[m.activeTabIndex].ID
434 m.updateList()
435 return m, nil
436 }
437 case "d":
438 selectedItem, ok := m.list.SelectedItem().(item)
439 if ok {
440 return m, func() tea.Msg {
441 return DeleteEmailMsg{UID: selectedItem.uid, AccountID: selectedItem.accountID, Mailbox: m.mailbox}
442 }
443 }
444 case "a":
445 selectedItem, ok := m.list.SelectedItem().(item)
446 if ok {
447 return m, func() tea.Msg {
448 return ArchiveEmailMsg{UID: selectedItem.uid, AccountID: selectedItem.accountID, Mailbox: m.mailbox}
449 }
450 }
451 case "r":
452 // Copy counts to avoid race conditions if used elsewhere (though here it's just passing data)
453 counts := make(map[string]int)
454 for k, v := range m.emailCountByAcct {
455 counts[k] = v
456 }
457 return m, func() tea.Msg {
458 return RequestRefreshMsg{Mailbox: m.mailbox, Counts: counts}
459 }
460 case "enter":
461 selectedItem, ok := m.list.SelectedItem().(item)
462 if ok {
463 idx := selectedItem.originalIndex
464 uid := selectedItem.uid
465 accountID := selectedItem.accountID
466 return m, func() tea.Msg {
467 return ViewEmailMsg{Index: idx, UID: uid, AccountID: accountID, Mailbox: m.mailbox}
468 }
469 }
470 }
471 case tea.WindowSizeMsg:
472 m.width = msg.Width
473 m.height = msg.Height
474 m.list.SetWidth(msg.Width)
475 m.list.SetHeight(msg.Height / 2)
476 if m.shouldFetchMore() {
477 return m, tea.Batch(m.fetchMoreCmds()...)
478 }
479 return m, nil
480
481 case FetchingMoreEmailsMsg:
482 m.isFetching = true
483 m.list.Title = m.getTitle()
484 return m, nil
485
486 case EmailsAppendedMsg:
487 if msg.Mailbox != m.mailbox {
488 return m, nil
489 }
490 m.isFetching = false
491 m.list.Title = m.getTitle()
492
493 if len(msg.Emails) == 0 {
494 if m.noMoreByAccount == nil {
495 m.noMoreByAccount = make(map[string]bool)
496 }
497 m.noMoreByAccount[msg.AccountID] = true
498 return m, nil
499 }
500
501 // Add emails to the appropriate account
502 for _, email := range msg.Emails {
503 m.emailsByAccount[email.AccountID] = append(m.emailsByAccount[email.AccountID], email)
504 m.allEmails = append(m.allEmails, email)
505 }
506 m.emailCountByAcct[msg.AccountID] = len(m.emailsByAccount[msg.AccountID])
507
508 m.updateList()
509 return m, nil
510
511 case RefreshingEmailsMsg:
512 if msg.Mailbox != m.mailbox {
513 return m, nil
514 }
515 m.isRefreshing = true
516 m.list.Title = m.getTitle()
517 return m, nil
518
519 case EmailsRefreshedMsg:
520 if msg.Mailbox != m.mailbox {
521 return m, nil
522 }
523 // Only clear the refreshing indicator. The actual email data is
524 // merged by the main model (preserving paginated emails) and
525 // pushed to us via SetEmails, so we must not overwrite it here.
526 m.isRefreshing = false
527 m.list.Title = m.getTitle()
528 return m, nil
529 }
530
531 var cmd tea.Cmd
532 m.list, cmd = m.list.Update(msg)
533 cmds = append(cmds, cmd)
534
535 if m.shouldFetchMore() {
536 cmds = append(cmds, m.fetchMoreCmds()...)
537 }
538 return m, tea.Batch(cmds...)
539}
540
541func (m *Inbox) shouldFetchMore() bool {
542 if m.isFetching {
543 return false
544 }
545 if m.allAccountsExhausted() {
546 return false
547 }
548 if len(m.list.Items()) == 0 {
549 return false
550 }
551 if m.list.FilterState() == list.Filtering {
552 return false
553 }
554 // Fetch if we've reached the bottom OR if we don't have enough items to fill the view
555 return m.list.Index() >= len(m.list.Items())-1 || len(m.list.Items()) < m.list.Height()
556}
557
558// allAccountsExhausted returns true if all relevant accounts have no more emails to fetch.
559func (m *Inbox) allAccountsExhausted() bool {
560 if len(m.noMoreByAccount) == 0 {
561 return false
562 }
563 if m.currentAccountID != "" {
564 return m.noMoreByAccount[m.currentAccountID]
565 }
566 // "ALL" view: all accounts must be exhausted
567 for _, acc := range m.accounts {
568 if !m.noMoreByAccount[acc.ID] {
569 return false
570 }
571 }
572 return len(m.accounts) > 0
573}
574
575func (m *Inbox) fetchMoreCmds() []tea.Cmd {
576 var cmds []tea.Cmd
577 limit := uint32(m.list.Height())
578 if limit < 20 {
579 limit = 20
580 }
581
582 if m.currentAccountID == "" {
583 if len(m.accounts) == 0 {
584 return nil
585 }
586 for _, acc := range m.accounts {
587 accountID := acc.ID
588 if m.noMoreByAccount[accountID] {
589 continue
590 }
591 offset := uint32(len(m.emailsByAccount[accountID]))
592 cmds = append(cmds, func(id string, off uint32) tea.Cmd {
593 return func() tea.Msg {
594 return FetchMoreEmailsMsg{Offset: off, AccountID: id, Mailbox: m.mailbox, Limit: limit}
595 }
596 }(accountID, offset))
597 }
598 return cmds
599 }
600
601 if m.noMoreByAccount[m.currentAccountID] {
602 return nil
603 }
604 offset := uint32(len(m.emailsByAccount[m.currentAccountID]))
605 cmds = append(cmds, func(id string, off uint32) tea.Cmd {
606 return func() tea.Msg {
607 return FetchMoreEmailsMsg{Offset: off, AccountID: id, Mailbox: m.mailbox, Limit: limit}
608 }
609 }(m.currentAccountID, offset))
610 return cmds
611}
612
613func (m *Inbox) View() tea.View {
614 var b strings.Builder
615
616 // Render tabs if there are multiple accounts
617 if len(m.tabs) > 1 {
618 var tabViews []string
619 for i, tab := range m.tabs {
620 label := tab.Label
621 if tab.ID == "" {
622 label = "ALL"
623 }
624
625 if i == m.activeTabIndex {
626 tabViews = append(tabViews, activeTabStyle.Render(label))
627 } else {
628 tabViews = append(tabViews, tabStyle.Render(label))
629 }
630 }
631 tabBar := tabBarStyle.Render(lipgloss.JoinHorizontal(lipgloss.Top, tabViews...))
632 b.WriteString(tabBar)
633 b.WriteString("\n")
634 }
635
636 b.WriteString(m.list.View())
637
638 // Ensure we don't start gap calculation on the same line as the list
639 if !strings.HasSuffix(b.String(), "\n") {
640 b.WriteString("\n")
641 }
642
643 helpView := inboxHelpStyle.Render(m.list.Help.View(m.list))
644
645 if m.height > 0 {
646 usedHeight := lipgloss.Height(b.String())
647 helpHeight := lipgloss.Height(helpView)
648
649 gap := m.height - usedHeight - helpHeight
650 if gap > 0 {
651 b.WriteString(strings.Repeat("\n", gap))
652 }
653 } else {
654 b.WriteString("\n")
655 }
656
657 b.WriteString(helpView)
658
659 return tea.NewView(b.String())
660}
661
662// GetCurrentAccountID returns the currently selected account ID
663func (m *Inbox) GetCurrentAccountID() string {
664 return m.currentAccountID
665}
666
667// GetEmailAtIndex returns the email at the given index for the current view
668func (m *Inbox) GetEmailAtIndex(index int) *fetcher.Email {
669 var displayEmails []fetcher.Email
670 if m.currentAccountID == "" {
671 displayEmails = m.allEmails
672 } else {
673 displayEmails = m.emailsByAccount[m.currentAccountID]
674 }
675
676 if index >= 0 && index < len(displayEmails) {
677 return &displayEmails[index]
678 }
679 return nil
680}
681
682func (m *Inbox) GetMailbox() MailboxKind {
683 return m.mailbox
684}
685
686// RemoveEmail removes an email by UID and account ID
687func (m *Inbox) RemoveEmail(uid uint32, accountID string) {
688 // Remove from account-specific list
689 if emails, ok := m.emailsByAccount[accountID]; ok {
690 var filtered []fetcher.Email
691 for _, e := range emails {
692 if e.UID != uid {
693 filtered = append(filtered, e)
694 }
695 }
696 m.emailsByAccount[accountID] = filtered
697 }
698
699 // Remove from all emails list
700 var filteredAll []fetcher.Email
701 for _, e := range m.allEmails {
702 if !(e.UID == uid && e.AccountID == accountID) {
703 filteredAll = append(filteredAll, e)
704 }
705 }
706 m.allEmails = filteredAll
707
708 m.updateList()
709}
710
711// SetSize sets the width and height of the inbox, then updates the list.
712func (m *Inbox) SetSize(width, height int) {
713 m.width = width
714 m.height = height
715 m.list.SetWidth(width)
716 m.list.SetHeight(height / 2)
717}
718
719// SetFolderName sets a custom folder name for the inbox title.
720func (m *Inbox) SetFolderName(name string) {
721 m.folderName = name
722 m.list.Title = m.getTitle()
723}
724
725// SetEmails updates all emails (used after fetch)
726func (m *Inbox) SetEmails(emails []fetcher.Email, accounts []config.Account) {
727 m.accounts = accounts
728 m.allEmails = emails
729 m.noMoreByAccount = make(map[string]bool)
730
731 // Rebuild tabs: empty for single account, "ALL" + accounts for multiple
732 var tabs []AccountTab
733 if len(accounts) <= 1 {
734 tabs = []AccountTab{{ID: "", Label: "", Email: ""}}
735 } else {
736 tabs = []AccountTab{{ID: "", Label: "ALL", Email: ""}}
737 for _, acc := range accounts {
738 tabs = append(tabs, AccountTab{ID: acc.ID, Label: acc.FetchEmail, Email: acc.Email})
739 }
740 }
741 m.tabs = tabs
742
743 // Re-group emails by account
744 m.emailsByAccount = make(map[string][]fetcher.Email)
745 for _, email := range emails {
746 m.emailsByAccount[email.AccountID] = append(m.emailsByAccount[email.AccountID], email)
747 }
748
749 // Update email counts
750 m.emailCountByAcct = make(map[string]int)
751 for accID, accEmails := range m.emailsByAccount {
752 m.emailCountByAcct[accID] = len(accEmails)
753 }
754
755 m.updateList()
756}