protected static MapiMessage GetDeliveryReceipt(MapiFolder folder, string subject, bool dsnOnly) { string value = DsnHumanReadableWriter.GetLocalizedSubjectPrefix(DsnFlags.Relay).ToString(); MapiTable contentsTable; MapiTable mapiTable = contentsTable = folder.GetContentsTable(); try { mapiTable.SetColumns(new PropTag[] { PropTag.EntryId, PropTag.Subject, PropTag.MessageClass }); PropValue[][] array = mapiTable.QueryRows(1000, QueryRowsFlags.None); for (int i = 0; i <= array.GetUpperBound(0); i++) { if (!dsnOnly || ObjectClass.IsDsnPositive(array[i][2].Value.ToString())) { string text = array[i][1].Value.ToString(); if ((!text.StartsWith(value, StringComparison.OrdinalIgnoreCase) || subject.StartsWith(value, StringComparison.OrdinalIgnoreCase)) && text.EndsWith(subject, StringComparison.OrdinalIgnoreCase)) { byte[] bytes = array[i][0].GetBytes(); return((MapiMessage)folder.OpenEntry(bytes)); } } } } finally { if (contentsTable != null) { ((IDisposable)contentsTable).Dispose(); } } return(null); }