private uint CreateMsgWithAttachement(out byte[] entryId) { ASCIIEncoding asciiencoding = new ASCIIEncoding(); uint @int; using (MapiMessage mapiMessage = this.testFolder.CreateMessage()) { PropValue[] props = new PropValue[] { new PropValue(PropTag.Subject, string.Format("CITestSearch: {0}.", this.searchString)), new PropValue(PropTag.Body, string.Format("The unique search string in the body is: {0}.", this.searchString)), new PropValue(PropTag.MessageDeliveryTime, (DateTime)ExDateTime.Now) }; this.threadExit.CheckStop(); mapiMessage.SetProps(props); int num; using (MapiAttach mapiAttach = mapiMessage.CreateAttach(out num)) { string s = string.Format("This is a test msg created by test-search task (MSExchangeSearch {0}).It will be deleted soon...", this.searchString); byte[] bytes = asciiencoding.GetBytes(s); using (MapiStream mapiStream = mapiAttach.OpenStream(PropTag.AttachDataBin, OpenPropertyFlags.Create)) { mapiStream.Write(bytes, 0, bytes.Length); mapiStream.Flush(); this.threadExit.CheckStop(); } props = new PropValue[] { new PropValue(PropTag.AttachFileName, "CITestSearch.txt"), new PropValue(PropTag.AttachMethod, AttachMethods.ByValue) }; mapiAttach.SetProps(props); mapiAttach.SaveChanges(); } this.threadExit.CheckStop(); mapiMessage.SaveChanges(); entryId = mapiMessage.GetProp(PropTag.EntryId).GetBytes(); @int = (uint)mapiMessage.GetProp(PropTag.DocumentId).GetInt(); } return(@int); }
private static void ResetOofHistoryProperty(MapiStream oofHistoryStream, byte[] initialBytes, long hashCode) { OofHistory.Tracer.TraceDebug(hashCode, "Resetting OOF history to initial values."); if (!oofHistoryStream.CanWrite) { throw new InvalidOperationException("OOF history property stream is not writable."); } if (!oofHistoryStream.CanSeek) { throw new InvalidOperationException("OOF history property stream is not seekable."); } if (0L != oofHistoryStream.Position) { oofHistoryStream.Seek(0L, SeekOrigin.Begin); } oofHistoryStream.Write(initialBytes, 0, 6); if (oofHistoryStream.Length > 6L) { oofHistoryStream.SetLength(6L); } }
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; } } }