internal MailCache GetCache(ILabelSource labelsource) { if (labelsource == null) { return(mGlobalCache); } MailCache ret; if (!mLabelCache.TryGetValue(labelsource.Id, out ret)) { ret = new MailCache(); mLabelCache.Add(labelsource.Id, ret); } return(ret); }
internal void UpdateAccountCounts(ViewMailItem item) { int[,] statetable = new int[, ] { //Label Added|Label Removed|No Change(True)|No Change(False) { 0, -1, -1, 0 }, /*Read Set*/ { 1, 0, 1, 0 }, /*Read Unset*/ { 1, -1, 0, 0 }, /*No Change(Unread)*/ { 0, 0, 0, 0 } /*No Change(Read)*/ }; int readstate = -1; if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagSet)) { readstate = 0; UnreadCount--; } else if (item.MetaState.HasFlag(ViewMailMetaState.ReadFlagUnset)) { readstate = 1; UnreadCount++; } else if (item.IsItemUnread) { readstate = 2; } else { readstate = 3; } if (UnreadCount < 0) { UnreadCount = 0; } for (int i = 0; i < item.Labels.Count; i++) { var vlabel = item.Labels[i]; Label label = ((ISourceInfo)vlabel.Label).LabelSource as Label; int labelstate = -1; if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelAdded)) { labelstate = 0; } else if (vlabel.MetaState.HasFlag(ViewMailMetaState.LabelRemoved)) { labelstate = 1; } else if (vlabel.Subscribed) { labelstate = 2; } else { labelstate = 3; } label.UnreadCount += statetable[readstate, labelstate]; MailCache cache = GetCache(label); if (cache != null && cache.IsValid) { cache.MailItems.Remove(item); if (vlabel.Subscribed) { cache.MailItems.Add(item); } } } ViewAccount.Sync(this); }