Exemplo n.º 1
0
        private static MapiStream OpenAndLockStream(MapiFolder oofHistoryFolder, byte[] initialBytes, long hashCode, out bool isNew)
        {
            MapiStream mapiStream = null;

            isNew = false;
            OpenPropertyFlags openPropertyFlags = OpenPropertyFlags.Modify | OpenPropertyFlags.DeferredErrors;

            try
            {
                mapiStream = oofHistoryFolder.OpenStream(PropTag.OofHistory, openPropertyFlags);
                OofHistory.LockStreamWithRetry(mapiStream, hashCode);
            }
            catch (MapiExceptionNotFound)
            {
                if (mapiStream != null)
                {
                    mapiStream.Dispose();
                    mapiStream = null;
                }
                OofHistory.Tracer.TraceDebug(hashCode, "OOF history property does not exist, trying to open with create flag.");
                openPropertyFlags |= OpenPropertyFlags.Create;
                mapiStream         = oofHistoryFolder.OpenStream(PropTag.OofHistory, openPropertyFlags);
                OofHistory.LockStreamWithRetry(mapiStream, hashCode);
                OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, hashCode);
                isNew = true;
            }
            return(mapiStream);
        }
Exemplo n.º 2
0
        private static int RemoveEntriesWithProperty(int historyLength, byte[] buffer, OofHistory.PropId propId, byte[] propValue, long hashCode)
        {
            int  num = 6;
            int  currentEntryStart = 6;
            int  result            = 6;
            uint num2 = BitConverter.ToUInt32(buffer, 2);

            if (10000U < num2)
            {
                num2 = 10000U;
            }
            uint num3 = num2;

            for (uint num4 = 0U; num4 < num2; num4 += 1U)
            {
                if (num >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, "Unable to get property count of entry " + num4);
                    return(result);
                }
                byte propertyCount = buffer[num++];
                bool flag;
                if (OofHistory.MatchAnyPropertiesInEntry(buffer, propId, propValue, propertyCount, historyLength, num4, hashCode, ref num, out flag))
                {
                    num3 -= 1U;
                }
                else
                {
                    if (flag)
                    {
                        return(result);
                    }
                    OofHistory.HandleNonMatchingProperty(buffer, num, currentEntryStart, ref result);
                }
                currentEntryStart = num;
            }
            if (num3 < num2)
            {
                ExBitConverter.Write(num3, buffer, 2);
            }
            return(result);
        }
Exemplo n.º 3
0
        internal static void RemoveOofHistoryEntriesWithProperty(MailboxSession itemStore, bool oofEnabled, OofHistory.PropId propId, byte[] propValue)
        {
            MapiFolder mapiFolder  = null;
            MapiFolder mapiFolder2 = null;
            MapiStream mapiStream  = null;
            bool       flag        = false;

            byte[] initialBytes = oofEnabled ? OofHistory.InitialBytesOofStateOn : OofHistory.InitialBytesOofStateOff;
            try
            {
                if (OofHistory.TryOpenFolder(itemStore, out mapiFolder, out mapiFolder2))
                {
                    long hashCode = (long)itemStore.GetHashCode();
                    bool flag2;
                    mapiStream = OofHistory.OpenAndLockStream(mapiFolder2, initialBytes, hashCode, out flag2);
                    flag       = true;
                    if (!flag2)
                    {
                        int num;
                        if (OofHistory.TryGetStreamLengthForEntryRemoval(hashCode, mapiStream, out num))
                        {
                            byte[] buffer;
                            if (OofHistory.TryReadAllFromStream(hashCode, mapiStream, num, out buffer))
                            {
                                int num2 = OofHistory.RemoveEntriesWithProperty(num, buffer, propId, propValue, hashCode);
                                if (num2 < num)
                                {
                                    mapiStream.Seek(0L, SeekOrigin.Begin);
                                    mapiStream.Write(buffer, 0, num2);
                                    mapiStream.SetLength((long)num2);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mapiStream != null)
                {
                    try
                    {
                        if (flag)
                        {
                            mapiStream.UnlockRegion(0L, 1L, 1);
                        }
                    }
                    finally
                    {
                        mapiStream.Dispose();
                    }
                }
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                    mapiFolder = null;
                }
                if (mapiFolder2 != null)
                {
                    mapiFolder2.Dispose();
                    mapiFolder2 = null;
                }
            }
        }
Exemplo n.º 4
0
        private static bool MatchAnyPropertiesInEntry(byte[] buffer, OofHistory.PropId propId, byte[] propValue, byte propertyCount, int historyLength, uint currentEntry, long hashCode, ref int index, out bool isCorrupt)
        {
            isCorrupt = false;
            bool flag = false;

            for (byte b = 0; b < propertyCount; b += 1)
            {
                if (index >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property id of property ",
                        b,
                        " entry ",
                        currentEntry
                    }));
                    isCorrupt = true;
                    return(false);
                }
                byte b2 = buffer[index++];
                if (index + 2 >= historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property size of property ",
                        b,
                        " entry ",
                        currentEntry,
                        " property id ",
                        b2,
                        " index ",
                        index
                    }));
                    isCorrupt = true;
                    return(false);
                }
                ushort num = BitConverter.ToUInt16(buffer, index);
                index += 2;
                if (index + (int)num > historyLength)
                {
                    OofHistory.HandleInsufficientDataCorruption(hashCode, string.Concat(new object[]
                    {
                        "Unable to get property content of property ",
                        b,
                        " entry ",
                        currentEntry,
                        " property id ",
                        b2,
                        " property size ",
                        num,
                        " index ",
                        index
                    }));
                    isCorrupt = true;
                    return(false);
                }
                if (flag)
                {
                    index += (int)num;
                }
                else if (OofHistory.MatchProperty(buffer, b2, propId, num, propValue, ref index))
                {
                    flag = true;
                }
            }
            return(flag);
        }
Exemplo n.º 5
0
        internal static void ClearOofHistory(MailboxSession itemStore, bool oofEnabled)
        {
            MapiFolder mapiFolder  = null;
            MapiFolder mapiFolder2 = null;
            MapiStream mapiStream  = null;
            bool       flag        = false;

            byte[] initialBytes = oofEnabled ? OofHistory.InitialBytesOofStateOn : OofHistory.InitialBytesOofStateOff;
            try
            {
                if (OofHistory.TryOpenFolder(itemStore, out mapiFolder, out mapiFolder2))
                {
                    long num = (long)itemStore.GetHashCode();
                    bool flag2;
                    mapiStream = OofHistory.OpenAndLockStream(mapiFolder2, initialBytes, num, out flag2);
                    flag       = true;
                    if (!flag2)
                    {
                        byte[] array = new byte[2];
                        if (2 != mapiStream.Read(array, 0, 2))
                        {
                            OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, num);
                        }
                        else
                        {
                            bool flag3 = 0 != array[1];
                            if (flag3 == oofEnabled)
                            {
                                OofHistory.Tracer.TraceDebug <bool>(num, "Current OOF state {0} matches in OOF history and mailbox properties, clear is not executed.", oofEnabled);
                            }
                            else
                            {
                                OofHistory.ResetOofHistoryProperty(mapiStream, initialBytes, num);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mapiStream != null)
                {
                    try
                    {
                        if (flag)
                        {
                            mapiStream.UnlockRegion(0L, 1L, 1);
                        }
                    }
                    finally
                    {
                        mapiStream.Dispose();
                    }
                }
                if (mapiFolder != null)
                {
                    mapiFolder.Dispose();
                    mapiFolder = null;
                }
                if (mapiFolder2 != null)
                {
                    mapiFolder2.Dispose();
                    mapiFolder2 = null;
                }
            }
        }
Exemplo n.º 6
0
        private void UpdateOofRule(Rule rule, ReplyBody reply, string ruleName, string messageClass, OofReplyType oofReplyType, RuleGenerator.ConditionType conditionType, int sequenceNumber, OofState mailboxOofState)
        {
            bool        flag        = false;
            bool        flag2       = false;
            Restriction restriction = this.GetRestriction(conditionType);

            RuleAction.OOFReply ruleAction    = (RuleAction.OOFReply)rule.Actions[0];
            ReplyTemplate       replyTemplate = null;

            try
            {
                replyTemplate = ReplyTemplate.Find(this.itemStore, ruleAction);
                if (replyTemplate != null)
                {
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updating ReplyTemplate to Body: '{1}'", this.itemStore.MailboxOwner, reply.RawMessage);
                    if (this.userOofSettings.SetByLegacyClient)
                    {
                        flag2 = !replyTemplate.PlainTextBody.Equals(reply.RawMessage, StringComparison.Ordinal);
                        replyTemplate.PlainTextBody = reply.RawMessage;
                    }
                    else
                    {
                        string value = TextUtil.ConvertHtmlToPlainText(reply.RawMessage);
                        flag2 = !replyTemplate.PlainTextBody.Equals(value, StringComparison.Ordinal);
                        replyTemplate.CharSet  = this.GetDefaultCharsetForCountryCode(reply.LanguageTag);
                        replyTemplate.HtmlBody = reply.RawMessage;
                    }
                    replyTemplate.OofReplyType = oofReplyType;
                    replyTemplate.ClassName    = messageClass;
                    replyTemplate.SaveChanges();
                    if (flag2)
                    {
                        rule.StateFlags |= RuleStateFlags.ClearOOFHistory;
                        byte[] propValue = this.itemStore.__ContainedMapiStore.GlobalIdFromId(rule.ID);
                        OofHistory.RemoveOofHistoryEntriesWithProperty(this.itemStore, mailboxOofState != OofState.Disabled, OofHistory.PropId.GlobalRuleId, propValue);
                        RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated reply template for global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                    }
                }
                else
                {
                    Guid   guid = Guid.NewGuid();
                    byte[] replyTemplateMessageEntryID = this.CreateOofReplyTemplate(this.itemStore, guid, reply, messageClass, oofReplyType);
                    rule.Actions = new RuleAction[]
                    {
                        new RuleAction.OOFReply(replyTemplateMessageEntryID, guid)
                    };
                    flag = true;
                    RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Created new reply template and updated global rule '{1}'", this.itemStore.MailboxOwner, ruleName);
                }
                RuleGenerator.TracerPfd.TracePfd <int, string, IExchangePrincipal>((long)this.GetHashCode(), "PFD IWO {0} Updated OOF Rule '{1}' for Mailbox:{2}", 25495, ruleName, this.itemStore.MailboxOwner);
            }
            finally
            {
                if (replyTemplate != null)
                {
                    replyTemplate.Dispose();
                }
            }
            if (!ConditionComparer.Equals(rule.Condition, restriction))
            {
                rule.Condition = restriction;
                flag           = true;
                RuleGenerator.Tracer.TraceDebug <IExchangePrincipal, string>((long)this.GetHashCode(), "Mailbox:{0}: Updated rule '{1}' with new condition", this.itemStore.MailboxOwner, ruleName);
            }
            if (flag || flag2)
            {
                this.ruleManager.Update(rule);
            }
        }