private void Parse(byte[] buffer) { if (buffer.Length < 22) { return; } short frequencyValue = BitConverter.ToInt16(buffer, 4); this.frequency = EnumUtil.ParseRecurrencePatternFrequency(frequencyValue); short typeValue = BitConverter.ToInt16(buffer, 6); this.type = EnumUtil.ParseRecurrencePatternType(typeValue); short calendarTypeValue = BitConverter.ToInt16(buffer, 8); this.calendarType = EnumUtil.ParseCalendarType(calendarTypeValue); short firstDateTimeValue = BitConverter.ToInt16(buffer, 10); period = BitConverter.ToInt16(buffer, 14); int nextPosition = 22; if (this.type == RecurrencePatternType.Day) { //skip } else if (this.type == RecurrencePatternType.Week) { int dayOfWeekValue = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; IList <Independentsoft.Msg.DayOfWeek> list = new List <Independentsoft.Msg.DayOfWeek>(); if ((dayOfWeekValue & 0x00000001) == 0x00000001) { list.Add(Independentsoft.Msg.DayOfWeek.Sunday); } if ((dayOfWeekValue & 0x00000002) == 0x00000002) { list.Add(Independentsoft.Msg.DayOfWeek.Monday); } if ((dayOfWeekValue & 0x00000004) == 0x00000004) { list.Add(Independentsoft.Msg.DayOfWeek.Tuesday); } if ((dayOfWeekValue & 0x00000008) == 0x00000008) { list.Add(Independentsoft.Msg.DayOfWeek.Wednesday); } if ((dayOfWeekValue & 0x00000010) == 0x00000010) { list.Add(Independentsoft.Msg.DayOfWeek.Thursday); } if ((dayOfWeekValue & 0x00000020) == 0x00000020) { list.Add(Independentsoft.Msg.DayOfWeek.Friday); } if ((dayOfWeekValue & 0x00000040) == 0x00000040) { list.Add(Independentsoft.Msg.DayOfWeek.Saturday); } dayOfWeek = new DayOfWeek[list.Count]; for (int i = 0; i < list.Count; i++) { dayOfWeek[i] = (Independentsoft.Msg.DayOfWeek)list[i]; } } else if (this.type == RecurrencePatternType.Month || this.type == RecurrencePatternType.HijriMonth) { dayOfMonth = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; } else if (this.type == RecurrencePatternType.MonthEnd || this.type == RecurrencePatternType.HijriMonthEnd || this.type == RecurrencePatternType.MonthNth || this.type == RecurrencePatternType.HijriMonthNth) { if (buffer.Length < 50) { return; } int dayOfWeekValue = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; int dayOfWeekIndexValue = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; IList <Independentsoft.Msg.DayOfWeek> list = new List <Independentsoft.Msg.DayOfWeek>(); if ((dayOfWeekValue & 0x00000001) == 0x00000001) { list.Add(Independentsoft.Msg.DayOfWeek.Sunday); } if ((dayOfWeekValue & 0x00000002) == 0x00000002) { list.Add(Independentsoft.Msg.DayOfWeek.Monday); } if ((dayOfWeekValue & 0x00000004) == 0x00000004) { list.Add(Independentsoft.Msg.DayOfWeek.Tuesday); } if ((dayOfWeekValue & 0x00000008) == 0x00000008) { list.Add(Independentsoft.Msg.DayOfWeek.Wednesday); } if ((dayOfWeekValue & 0x00000010) == 0x00000010) { list.Add(Independentsoft.Msg.DayOfWeek.Thursday); } if ((dayOfWeekValue & 0x00000020) == 0x00000020) { list.Add(Independentsoft.Msg.DayOfWeek.Friday); } if ((dayOfWeekValue & 0x00000040) == 0x00000040) { list.Add(Independentsoft.Msg.DayOfWeek.Saturday); } dayOfWeek = new DayOfWeek[list.Count]; for (int i = 0; i < list.Count; i++) { dayOfWeek[i] = (Independentsoft.Msg.DayOfWeek)list[i]; } if (dayOfWeekIndexValue == 0x00000001) { dayOfWeekIndex = DayOfWeekIndex.First; } else if (dayOfWeekIndexValue == 0x00000002) { dayOfWeekIndex = DayOfWeekIndex.Second; } else if (dayOfWeekIndexValue == 0x00000003) { dayOfWeekIndex = DayOfWeekIndex.Third; } else if (dayOfWeekIndexValue == 0x00000004) { dayOfWeekIndex = DayOfWeekIndex.Fourth; } else if (dayOfWeekIndexValue == 0x00000005) { dayOfWeekIndex = DayOfWeekIndex.Last; } } int endTypeValue = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; this.endType = EnumUtil.ParseRecurrenceEndType(endTypeValue); occurenceCount = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; int firstDayOfWeekValue = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; this.firstDayOfWeek = EnumUtil.ParseDayOfWeek(firstDayOfWeekValue); deletedInstanceCount = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; if (deletedInstanceCount > 0) { deletedInstanceDates = new DateTime[deletedInstanceCount]; for (int i = 0; i < deletedInstanceCount; i++) { if (buffer.Length < nextPosition + 4) { return; } int minutes = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; deletedInstanceDates[i] = Util.GetDateTime(minutes); } } modifiedInstanceCount = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; if (modifiedInstanceCount > 0) { modifiedInstanceDates = new DateTime[modifiedInstanceCount]; for (int i = 0; i < modifiedInstanceCount; i++) { if (buffer.Length < nextPosition + 4) { return; } int minutes = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; modifiedInstanceDates[i] = Util.GetDateTime(minutes); } } if (buffer.Length < nextPosition + 4) { return; } int startDateMinutes = BitConverter.ToInt32(buffer, nextPosition); nextPosition += 4; this.startDate = Util.GetDateTime(startDateMinutes); int endDateMinutes = BitConverter.ToInt32(buffer, nextPosition); this.endDate = Util.GetDateTime(endDateMinutes); }
public AppointmentRecurrencePatternStructure(byte[] buffer) { int position = 0; ReaderVersion = LittleEndianReader.ReadUInt16(buffer, ref position); WriterVersion = LittleEndianReader.ReadUInt16(buffer, ref position); RecurFrequency = (RecurrenceFrequency)LittleEndianReader.ReadUInt16(buffer, ref position); PatternType = (PatternType)LittleEndianReader.ReadUInt16(buffer, ref position); CalendarType = LittleEndianReader.ReadUInt16(buffer, ref position); FirstDateTime = LittleEndianReader.ReadUInt32(buffer, ref position); Period = LittleEndianReader.ReadUInt32(buffer, ref position); SlidingFlag = LittleEndianReader.ReadUInt32(buffer, ref position); ReadPatternTypeSpecific(buffer, ref position); EndType = (RecurrenceEndType)LittleEndianReader.ReadUInt32(buffer, ref position); if ((uint)EndType == 0xFFFFFFFF) // SHOULD be 0x00002023 but can be 0xFFFFFFFF { EndType = RecurrenceEndType.NeverEnd; } OccurrenceCount = LittleEndianReader.ReadUInt32(buffer, ref position); FirstDOW = LittleEndianReader.ReadUInt32(buffer, ref position); uint DeletedInstanceCount = LittleEndianReader.ReadUInt32(buffer, ref position); for (int index = 0; index < DeletedInstanceCount; index++) { DateTime date = DateTimeHelper.ReadDateTimeFromMinutes(buffer, ref position); DeletedInstanceDates.Add(date); } uint ModifiedInstanceCount = LittleEndianReader.ReadUInt32(buffer, ref position); if (ModifiedInstanceCount > DeletedInstanceCount) { throw new InvalidRecurrencePatternException("Invalid structure format"); } for (int index = 0; index < ModifiedInstanceCount; index++) { DateTime date = DateTimeHelper.ReadDateTimeFromMinutes(buffer, ref position); ModifiedInstanceDates.Add(date); } StartDate = DateTimeHelper.ReadDateTimeFromMinutes(buffer, ref position); // end date will be in 31/12/4500 23:59:00 if there is no end date EndDate = DateTimeHelper.ReadDateTimeFromMinutes(buffer, ref position); ReaderVersion2 = LittleEndianReader.ReadUInt32(buffer, ref position); WriterVersion2 = LittleEndianReader.ReadUInt32(buffer, ref position); StartTimeOffset = LittleEndianReader.ReadUInt32(buffer, ref position); EndTimeOffset = LittleEndianReader.ReadUInt32(buffer, ref position); ushort exceptionCount = LittleEndianReader.ReadUInt16(buffer, ref position); if (exceptionCount != ModifiedInstanceCount) { // This MUST be the same value as the value of the ModifiedInstanceCount in the associated ReccurencePattern structure throw new InvalidRecurrencePatternException("Invalid structure format"); } for (int index = 0; index < exceptionCount; index++) { ExceptionInfoStructure exception = new ExceptionInfoStructure(buffer, position); ExceptionList.Add(exception); position += exception.RecordLength; } // Outlook 2003 SP3 was observed using a signature of older version (0x3006) when there was no need for extended exception if (WriterVersion2 >= Outlook2003VersionSignature) { uint reservedBlock1Size = LittleEndianReader.ReadUInt32(buffer, ref position); position += (int)reservedBlock1Size; foreach (ExceptionInfoStructure exception in ExceptionList) { exception.ReadExtendedException(buffer, ref position, WriterVersion2); } uint reservedBlock2Size = LittleEndianReader.ReadUInt32(buffer, ref position); position += (int)reservedBlock2Size; } }