From 82cc68090b708b58be0e4339bd28ee9895926087 Mon Sep 17 00:00:00 2001 From: James John McGuire Date: Wed, 2 Oct 2024 13:04:22 +0900 Subject: [PATCH 1/2] Initial Functionality for Item Details --- ToolKit.Application/Program.cs | 23 ++ ToolKit.Library/OutlookAppointment.cs | 128 +++++++- ToolKit.Library/OutlookItem.cs | 443 +++++++++++++++++++------- ToolKit.Library/OutlookMail.cs | 240 +++++++++++--- ToolKit.Library/OutlookStore.cs | 55 +++- 5 files changed, 726 insertions(+), 163 deletions(-) diff --git a/ToolKit.Application/Program.cs b/ToolKit.Application/Program.cs index 1f213bf..7fb463c 100644 --- a/ToolKit.Application/Program.cs +++ b/ToolKit.Application/Program.cs @@ -104,6 +104,9 @@ public static async Task Main(string[] arguments) switch (command.Name) { + case "details": + result = Details(command); + break; case "dbx-to-pst": result = DbxToPst(command); break; @@ -157,6 +160,22 @@ public static async Task Main(string[] arguments) return result; } + private static int Details(Command command) + { + OutlookAccount outlookAccount = OutlookAccount.Instance; + OutlookStore outlookStore = new (outlookAccount); + + string pstFilePath = command.Parameters[0]; + string entryId = command.Parameters[1]; + + outlookStore.Details(pstFilePath, entryId); + + string message = "Details saved in file: " + entryId + ".txt"; + Console.WriteLine(message); + + return 0; + } + private static void DisplayParameters( Command command, string[] arguments) { @@ -315,6 +334,10 @@ private static List GetCommands() "remove-empty-folders", null, 1, "Prune empty folders"); commands.Add(removeEmptyFolders); + Command details = new ( + "details", null, 2, "Show details of given item"); + commands.Add(details); + return commands; } diff --git a/ToolKit.Library/OutlookAppointment.cs b/ToolKit.Library/OutlookAppointment.cs index f846fc4..ff54903 100644 --- a/ToolKit.Library/OutlookAppointment.cs +++ b/ToolKit.Library/OutlookAppointment.cs @@ -108,6 +108,47 @@ public IList GetProperties(bool strict = false) return buffers; } + /// + /// Get the text of all relevant properties. + /// + /// Indicates whether the check should be strict + /// or not. + /// The text of all relevant properties. + public string GetPropertiesText(bool strict = false) + { + string propertiesText = string.Empty; + + propertiesText += GetBooleansText(); + propertiesText += Environment.NewLine; + + propertiesText += + OutlookItem.GetActionsText(appointmentItem.Actions); + propertiesText += Environment.NewLine; + + propertiesText += + OutlookItem.GetAttachmentsText(appointmentItem.Attachments); + propertiesText += Environment.NewLine; + + propertiesText += GetDateTimesText(); + propertiesText += Environment.NewLine; + + propertiesText += GetEnumsText(); + propertiesText += Environment.NewLine; + + propertiesText += + OutlookItem.GetRecipientsText(appointmentItem.Recipients); + propertiesText += Environment.NewLine; + + propertiesText += GetStringPropertiesText(strict); + propertiesText += Environment.NewLine; + + propertiesText += OutlookItem.GetUserPropertiesText( + appointmentItem.UserProperties); + propertiesText += Environment.NewLine; + + return propertiesText; + } + /// /// Get the item's synopses. /// @@ -162,6 +203,38 @@ private ushort GetBooleans() return boolHolder; } + private string GetBooleansText() + { + string booleansText = string.Empty; + + booleansText += OutlookItem.GetBooleanText( + appointmentItem.AllDayEvent); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.AutoResolvedWinner); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.ForceUpdateToAllAttendees); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.IsConflict); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.IsRecurring); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.NoAging); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.ReminderOverrideDefault); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.ReminderPlaySound); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.ReminderSet); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.ResponseRequested); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.Saved); + booleansText += OutlookItem.GetBooleanText( + appointmentItem.UnRead); + + return booleansText; + } + private byte[] GetDateTimes() { List times = []; @@ -180,6 +253,24 @@ private byte[] GetDateTimes() return data; } + private string GetDateTimesText() + { + List times = []; + + DateTime endUTC = appointmentItem.EndUTC; + times.Add(endUTC); + + DateTime replyTime = appointmentItem.ReplyTime; + times.Add(replyTime); + + DateTime startUTC = appointmentItem.StartUTC; + times.Add(startUTC); + + string dateTimesText = OutlookItem.GetDateTimesText(times); + + return dateTimesText; + } + private byte[] GetEnums() { List ints = []; @@ -213,9 +304,38 @@ private byte[] GetEnums() return buffer; } + private string GetEnumsText() + { + string enumsText = string.Empty; + + enumsText += nameof(appointmentItem.BusyStatus); + enumsText += nameof(appointmentItem.Class); + enumsText += nameof(appointmentItem.Importance); + enumsText += nameof(appointmentItem.MarkForDownload); + enumsText += nameof(appointmentItem.MeetingStatus); + enumsText += nameof(appointmentItem.RecurrenceState); + enumsText += nameof(appointmentItem.ResponseStatus); + enumsText += nameof(appointmentItem.Sensitivity); + + return enumsText; + } + private byte[] GetStringProperties( bool strict = false, bool ignoreConversation = true) + { + string buffer = + GetStringPropertiesText(strict, ignoreConversation); + + Encoding encoding = Encoding.UTF8; + byte[] data = encoding.GetBytes(buffer); + + return data; + } + + private string GetStringPropertiesText( + bool strict = false, + bool ignoreConversation = true) { string billingInformation = null; @@ -278,13 +398,9 @@ private byte[] GetStringProperties( builder.Append(resources); builder.Append(subject); - string buffer = builder.ToString(); - - Encoding encoding = Encoding.UTF8; - - byte[] data = encoding.GetBytes(buffer); + string stringProperties = builder.ToString(); - return data; + return stringProperties; } } } diff --git a/ToolKit.Library/OutlookItem.cs b/ToolKit.Library/OutlookItem.cs index 1525138..94ae541 100644 --- a/ToolKit.Library/OutlookItem.cs +++ b/ToolKit.Library/OutlookItem.cs @@ -7,6 +7,7 @@ using Common.Logging; using DigitalZenWorks.Common.Utilities; using Microsoft.Office.Interop.Outlook; +using Org.BouncyCastle.Asn1.Cms; using System; using System.Collections.Generic; using System.Globalization; @@ -17,6 +18,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using static System.Runtime.InteropServices.JavaScript.JSType; namespace DigitalZenWorks.Email.ToolKit { @@ -212,6 +214,26 @@ public static byte[] GetActions(Actions actions) { byte[] actionsData = null; + if (actions != null) + { + string actionsText = GetActionsText(actions); + + Encoding encoding = Encoding.UTF8; + actionsData = encoding.GetBytes(actionsText); + } + + return actionsData; + } + + /// + /// Get Actions Data. + /// + /// The item actions. + /// The item actions data as text. + public static string GetActionsText(Actions actions) + { + string actionsText = null; + if (actions != null) { int total = actions.Count; @@ -221,23 +243,22 @@ public static byte[] GetActions(Actions actions) Microsoft.Office.Interop.Outlook.Action action = actions[index]; - byte[] metaDataBytes = GetActionData(action); + string actionText = GetActionText(action); - if (actionsData == null) + if (actionText == null) { - actionsData = metaDataBytes; + actionsText = actionText; } else { - actionsData = - BitBytes.MergeByteArrays(actionsData, metaDataBytes); + actionsText += actionText; } Marshal.ReleaseComObject(action); } } - return actionsData; + return actionsText; } /// @@ -249,6 +270,29 @@ public static byte[] GetAttachments(Attachments attachments) { byte[] attachmentsData = null; + if (attachments != null) + { + string attachmentsText = GetAttachmentsText(attachments); + + if (attachmentsText != null) + { + Encoding encoding = Encoding.UTF8; + attachmentsData = encoding.GetBytes(attachmentsText); + } + } + + return attachmentsData; + } + + /// + /// Get Attachments Data. + /// + /// The item attachments. + /// The item attachments data as text. + public static string GetAttachmentsText(Attachments attachments) + { + string attachmentsText = null; + if (attachments != null) { int total = attachments.Count; @@ -257,23 +301,42 @@ public static byte[] GetAttachments(Attachments attachments) { Attachment attachment = attachments[index]; - byte[] attachementData = GetAttachmentData(attachment); + string attachmentText = GetAttachmentText(attachment); - if (attachmentsData == null) + if (attachmentsText == null) { - attachmentsData = attachementData; + attachmentsText = attachmentText; } else { - attachmentsData = BitBytes.MergeByteArrays( - attachmentsData, attachementData); + attachmentsText += attachmentText; } Marshal.ReleaseComObject(attachment); } } - return attachmentsData; + return attachmentsText; + } + + /// + /// Get boolean text. + /// + /// The item to check. + /// The formatted text value. + public static string GetBooleanText(bool item) + { + string booleanText = string.Empty; + + string name = nameof(item); + + booleanText = string.Format( + CultureInfo.InvariantCulture, + "{0}: {1}", + name, + item.ToString()); + + return booleanText; } /// @@ -285,6 +348,26 @@ public static byte[] GetDateTimesBytes(IList times) { byte[] data = null; + if (times != null) + { + string buffer = GetDateTimesText(times); + + Encoding encoding = Encoding.UTF8; + data = encoding.GetBytes(buffer); + } + + return data; + } + + /// + /// Get DateTime Properites Data. + /// + /// The DataTime properties data. + /// The DataTime properties data as text. + public static string GetDateTimesText(IList times) + { + string dateTimesText = null; + if (times != null) { List timesStrings = []; @@ -302,13 +385,58 @@ public static byte[] GetDateTimesBytes(IList times) builder.Append(timeString); } - string buffer = builder.ToString(); + dateTimesText = builder.ToString(); + } - Encoding encoding = Encoding.UTF8; - data = encoding.GetBytes(buffer); + return dateTimesText; + } + + public static string GetDetails( + object mapiItem, bool strict = false) + { + string details = null; + + if (mapiItem != null) + { + try + { + IList buffers = []; + + switch (mapiItem) + { + case AppointmentItem appointmentItem: + OutlookAppointment appointment = new (mapiItem); + details = appointment.GetPropertiesText(strict); + break; + //case ContactItem contact: + // OutlookContact outlookContact = new(mapiItem); + // buffers = outlookContact.GetProperties(strict); + // break; + case MailItem mailItem: + OutlookMail mail = new (mapiItem); + details = mail.GetPropertiesText(strict); + break; + default: + string message = "Item is of unsupported type: " + + mapiItem.ToString(); + Log.Warn(message); + break; + } + } + catch (System.Exception exception) when + (exception is ArgumentException || + exception is ArgumentNullException || + exception is ArgumentOutOfRangeException || + exception is ArrayTypeMismatchException || + exception is COMException || + exception is InvalidCastException || + exception is RankException) + { + Log.Error(exception.ToString()); + } } - return data; + return details; } /// @@ -426,17 +554,36 @@ exception is InvalidCastException || /// /// The enums recipients data. /// The recipients properties data in bytes. + public static byte[] GetRecipients(Recipients recipients) + { + byte[] data = null; + + if (recipients != null) + { + string recipientsData = GetRecipientsText(recipients); + + Encoding encoding = Encoding.UTF8; + data = encoding.GetBytes(recipientsData); + } + + return data; + } + + /// + /// Get recipients properites data. + /// + /// The enums recipients data. + /// The recipients properties data as text. [System.Diagnostics.CodeAnalysis.SuppressMessage( "StyleCop.CSharp.NamingRules", "SA1305:Field names should not use Hungarian notation", Justification = "It isn't hungarian notation.")] - public static byte[] GetRecipients(Recipients recipients) + public static string GetRecipientsText(Recipients recipients) { - byte[] data = null; + string recipientsData = null; if (recipients != null) { - string recipientsData; List toList = []; List ccList = []; List bccList = []; @@ -502,12 +649,9 @@ public static byte[] GetRecipients(Recipients recipients) } recipientsData = builder.ToString(); - - Encoding encoding = Encoding.UTF8; - data = encoding.GetBytes(recipientsData); } - return data; + return recipientsData; } /// @@ -521,12 +665,35 @@ public static byte[] GetUserProperties(UserProperties userProperties) if (userProperties != null) { + Encoding encoding = Encoding.UTF8; + + string propertiesText = GetUserPropertiesText(userProperties); + + properties = encoding.GetBytes(propertiesText); + } + + return properties; + } + + /// + /// Get user properites data. + /// + /// The user properties data. + /// The user properties data as text. + public static string GetUserPropertiesText( + UserProperties userProperties) + { + string properties = null; + + if (userProperties != null) + { + properties = string.Empty; int total = userProperties.Count; for (int index = 1; index <= total; index++) { UserProperty property = userProperties[index]; - properties = GetUserProperty(properties, property); + properties += GetUserPropertyText(property); } } @@ -831,93 +998,127 @@ private static bool DoubleCheckDuplicate( private static byte[] GetActionData( Microsoft.Office.Interop.Outlook.Action action) { - Encoding encoding = Encoding.UTF8; - - int copyLikeEnum = (int)action.CopyLike; - bool enabledBool = action.Enabled; - int enabledInt = Convert.ToInt32(enabledBool); - int replyStyleEnum = (int)action.ReplyStyle; - int responseStyleEnum = (int)action.ResponseStyle; - int showOnEnum = (int)action.ShowOn; - - string copyLike = - copyLikeEnum.ToString(CultureInfo.InvariantCulture); - string enabled = - enabledInt.ToString(CultureInfo.InvariantCulture); - string replyStyle = - replyStyleEnum.ToString(CultureInfo.InvariantCulture); - string responseStyle = responseStyleEnum.ToString( - CultureInfo.InvariantCulture); - string showOn = - showOnEnum.ToString(CultureInfo.InvariantCulture); - - string metaData = string.Format( - CultureInfo.InvariantCulture, - "{0}{1}{2}{3}{4}{5}{6}", - copyLike, - enabled, - action.Name, - action.Prefix, - replyStyle, - responseStyle, - showOn); - - byte[] metaDataBytes = encoding.GetBytes(metaData); - - return metaDataBytes; - } - - private static byte[] GetAttachmentData(Attachment attachment) - { - string basePath = Path.GetTempPath(); + byte[] actionData = null; - Encoding encoding = Encoding.UTF8; + if (action != null) + { + Encoding encoding = Encoding.UTF8; - int attachmentIndex = attachment.Index; - string indexValue = attachmentIndex.ToString( - CultureInfo.InvariantCulture); + string metaData = GetActionText(action); - int positionValue = attachment.Position; - string position = positionValue.ToString( - CultureInfo.InvariantCulture); + actionData = encoding.GetBytes(metaData); + } - int intType = (int)attachment.Type; - string attachmentType = - intType.ToString(CultureInfo.InvariantCulture); + return actionData; + } - string metaData = string.Format( - CultureInfo.InvariantCulture, - "{0}{1}{2}{3}", - attachment.DisplayName, - indexValue, - position, - attachmentType); + private static string GetActionText( + Microsoft.Office.Interop.Outlook.Action action) + { + string actionText = null; - try - { - metaData += attachment.FileName; - } - catch (COMException) + if (action != null) { + int copyLikeEnum = (int)action.CopyLike; + bool enabledBool = action.Enabled; + int enabledInt = Convert.ToInt32(enabledBool); + int replyStyleEnum = (int)action.ReplyStyle; + int responseStyleEnum = (int)action.ResponseStyle; + int showOnEnum = (int)action.ShowOn; + + string copyLike = + copyLikeEnum.ToString(CultureInfo.InvariantCulture); + string enabled = + enabledInt.ToString(CultureInfo.InvariantCulture); + string replyStyle = + replyStyleEnum.ToString(CultureInfo.InvariantCulture); + string responseStyle = responseStyleEnum.ToString( + CultureInfo.InvariantCulture); + string showOn = + showOnEnum.ToString(CultureInfo.InvariantCulture); + + actionText = string.Format( + CultureInfo.InvariantCulture, + "{0}{1}{2}{3}{4}{5}{6}", + copyLike, + enabled, + action.Name, + action.Prefix, + replyStyle, + responseStyle, + showOn); } - try + return actionText; + } + + private static byte[] GetAttachmentData(Attachment attachment) + { + byte[] attachmentData = null; + + if (attachment != null) { - metaData += attachment.PathName; + string attachmentText = GetAttachmentText(attachment); + + Encoding encoding = Encoding.UTF8; + attachmentData = encoding.GetBytes(attachmentText); } - catch (COMException) + + return attachmentData; + } + + private static string GetAttachmentText(Attachment attachment) + { + string attachmentData = null; + + if (attachment != null) { - } + string basePath = Path.GetTempPath(); + + int attachmentIndex = attachment.Index; + string indexValue = attachmentIndex.ToString( + CultureInfo.InvariantCulture); - byte[] metaDataBytes = encoding.GetBytes(metaData); + int positionValue = attachment.Position; + string position = positionValue.ToString( + CultureInfo.InvariantCulture); - string filePath = basePath + attachment.FileName; - attachment.SaveAsFile(filePath); + int intType = (int)attachment.Type; + string attachmentType = + intType.ToString(CultureInfo.InvariantCulture); - byte[] fileBytes = File.ReadAllBytes(filePath); + string metaData = string.Format( + CultureInfo.InvariantCulture, + "{0}{1}{2}{3}", + attachment.DisplayName, + indexValue, + position, + attachmentType); - byte[] attachmentData = - BitBytes.MergeByteArrays(metaDataBytes, fileBytes); + try + { + metaData += attachment.FileName; + } + catch (COMException) + { + } + + try + { + metaData += attachment.PathName; + } + catch (COMException) + { + } + + string filePath = basePath + attachment.FileName; + attachment.SaveAsFile(filePath); + + byte[] fileBytes = File.ReadAllBytes(filePath); + string hashBase64 = Convert.ToBase64String(fileBytes); + + attachmentData = metaData + hashBase64; + } return attachmentData; } @@ -1034,29 +1235,45 @@ private static byte[] GetUserProperty( private static byte[] GetUserPropertyData(UserProperty property) { - Encoding encoding = Encoding.UTF8; + byte[] propertyData = null; - int typeEnum = (int)property.Type; - var propertyValue = property.Value; + if (property != null) + { + string metaData = GetUserPropertyText(property); + + Encoding encoding = Encoding.UTF8; + propertyData = encoding.GetBytes(metaData); + } - string typeValue = - typeEnum.ToString(CultureInfo.InvariantCulture); - string value = - propertyValue.ToString(CultureInfo.InvariantCulture); + return propertyData; + } - string metaData = string.Format( - CultureInfo.InvariantCulture, - "{0}{1}{2}{3}{4}{5}", - property.Formula, - property.Name, - typeValue, - property.ValidationFormula, - property.ValidationText, - value); + private static string GetUserPropertyText(UserProperty property) + { + string propertyText = null; - byte[] metaDataBytes = encoding.GetBytes(metaData); + if (property != null) + { + int typeEnum = (int)property.Type; + var propertyValue = property.Value; + + string typeValue = + typeEnum.ToString(CultureInfo.InvariantCulture); + string value = + propertyValue.ToString(CultureInfo.InvariantCulture); + + propertyText = string.Format( + CultureInfo.InvariantCulture, + "{0}{1}{2}{3}{4}{5}", + property.Formula, + property.Name, + typeValue, + property.ValidationFormula, + property.ValidationText, + value); + } - return metaDataBytes; + return propertyText; } private static string GetSynopses(object mapiItem) diff --git a/ToolKit.Library/OutlookMail.cs b/ToolKit.Library/OutlookMail.cs index 83b4fa1..3b2185c 100644 --- a/ToolKit.Library/OutlookMail.cs +++ b/ToolKit.Library/OutlookMail.cs @@ -84,14 +84,15 @@ public IList GetProperties(bool strict = false) buffer = OutlookItem.GetAttachments(mailItem.Attachments); buffers.Add(buffer); - buffer = GetDateTimes(); + buffer = GetDateTimesBytes(); buffers.Add(buffer); buffer = GetEnums(); buffers.Add(buffer); - buffer = OutlookItem.GetRecipients(mailItem.Recipients); - buffers.Add(buffer); + // Recipients is included with string properties. + //buffer = OutlookItem.GetRecipients(mailItem.Recipients); + //buffers.Add(buffer); buffer = GetStringProperties(strict); buffers.Add(buffer); @@ -108,6 +109,43 @@ public IList GetProperties(bool strict = false) return buffers; } + /// + /// Get the text of all relevant properties. + /// + /// Indicates whether the check should be strict + /// or not. + /// The text of all relevant properties. + public string GetPropertiesText(bool strict = false) + { + string propertiesText = string.Empty; + + propertiesText += GetBooleansText(); + propertiesText += Environment.NewLine; + + propertiesText += + OutlookItem.GetActionsText(mailItem.Actions); + propertiesText += Environment.NewLine; + + propertiesText += + OutlookItem.GetAttachmentsText(mailItem.Attachments); + propertiesText += Environment.NewLine; + + propertiesText += GetDateTimesText(); + propertiesText += Environment.NewLine; + + propertiesText += GetEnumsText(); + propertiesText += Environment.NewLine; + + propertiesText += GetStringPropertiesText(strict); + propertiesText += Environment.NewLine; + + propertiesText += OutlookItem.GetUserPropertiesText( + mailItem.UserProperties); + propertiesText += Environment.NewLine; + + return propertiesText; + } + /// /// Get the item's synopses. /// @@ -165,6 +203,7 @@ private ushort GetBooleans() rawValue = mailItem.DeleteAfterSubmit; boolHolder = BitBytes.SetBit(boolHolder, 3, rawValue); + // IsConflict ? rawValue = mailItem.IsMarkedAsTask; boolHolder = BitBytes.SetBit(boolHolder, 4, rawValue); @@ -204,7 +243,45 @@ private ushort GetBooleans() return boolHolder; } - private byte[] GetDateTimes() + private string GetBooleansText() + { + string booleansText = string.Empty; + + booleansText += OutlookItem.GetBooleanText( + mailItem.AutoForwarded); + booleansText += OutlookItem.GetBooleanText( + mailItem.AutoResolvedWinner); + booleansText += OutlookItem.GetBooleanText( + mailItem.DeleteAfterSubmit); + //booleansText += OutlookItem.GetBooleanText( + // mailItem.IsConflict); + booleansText += OutlookItem.GetBooleanText( + mailItem.IsMarkedAsTask); + booleansText += OutlookItem.GetBooleanText( + mailItem.NoAging); + booleansText += OutlookItem.GetBooleanText( + mailItem.OriginatorDeliveryReportRequested); + booleansText += OutlookItem.GetBooleanText( + mailItem.ReadReceiptRequested); + booleansText += OutlookItem.GetBooleanText( + mailItem.RecipientReassignmentProhibited); + booleansText += OutlookItem.GetBooleanText( + mailItem.ReminderOverrideDefault); + booleansText += OutlookItem.GetBooleanText( + mailItem.ReminderPlaySound); + booleansText += OutlookItem.GetBooleanText( + mailItem.ReminderSet); + booleansText += OutlookItem.GetBooleanText( + mailItem.Saved); + booleansText += OutlookItem.GetBooleanText( + mailItem.Submitted); + booleansText += OutlookItem.GetBooleanText( + mailItem.UnRead); + + return booleansText; + } + + private List GetDateTimes() { List times = []; @@ -247,11 +324,27 @@ private byte[] GetDateTimes() DateTime taskStartDateDateTime = mailItem.TaskStartDate; times.Add(taskStartDateDateTime); + return times; + } + + private byte[] GetDateTimesBytes() + { + List times = GetDateTimes(); + byte[] data = OutlookItem.GetDateTimesBytes(times); return data; } + private string GetDateTimesText() + { + List times = GetDateTimes(); + + string dateTimesText = OutlookItem.GetDateTimesText(times); + + return dateTimesText; + } + private byte[] GetEnums() { List ints = []; @@ -300,13 +393,44 @@ private byte[] GetEnums() return buffer; } + private string GetEnumsText() + { + string enumsText = string.Empty; + + enumsText += nameof(mailItem.BodyFormat); + enumsText += nameof(mailItem.Class); + enumsText += nameof(mailItem.Importance); + enumsText += nameof(mailItem.MarkForDownload); + enumsText += nameof(mailItem.Permission); + enumsText += nameof(mailItem.PermissionService); + enumsText += nameof(mailItem.Sensitivity); + + return enumsText; + } + private byte[] GetStringProperties( bool strict = false, bool ignoreConversation = true) { - byte[] data = null; + string propertiesText = + GetStringPropertiesText(false, true, false); + + Encoding encoding = Encoding.UTF8; + byte[] data = encoding.GetBytes(propertiesText); + + return data; + } + + private string GetStringPropertiesText( + bool strict = false, + bool ignoreConversation = true, + bool addNewLine = false) + { + List properties = []; string bcc = mailItem.BCC; + properties.Add(bcc); + string billingInformation = null; try @@ -317,6 +441,8 @@ private byte[] GetStringProperties( { } + properties.Add(billingInformation); + string body = mailItem.Body; if (body != null && strict == false) @@ -324,18 +450,31 @@ private byte[] GetStringProperties( body = body.TrimEnd(); } + properties.Add(billingInformation); + string categories = mailItem.Categories; + properties.Add(billingInformation); + string cc = mailItem.CC; + properties.Add(billingInformation); + string companies = mailItem.Companies; + properties.Add(billingInformation); + string conversationID = null; if (ignoreConversation == false) { conversationID = mailItem.ConversationID; + properties.Add(billingInformation); } string conversationTopic = mailItem.ConversationTopic; + properties.Add(billingInformation); + string flagRequest = mailItem.FlagRequest; + properties.Add(billingInformation); + string header = mailItem.PropertyAccessor.GetProperty( "http://schemas.microsoft.com/mapi/proptag/0x007D001F"); @@ -357,6 +496,8 @@ private byte[] GetStringProperties( header = NormalizeHeaders(header); } + properties.Add(billingInformation); + string htmlBody = mailItem.HTMLBody; if (htmlBody != null && strict == false) @@ -364,72 +505,93 @@ private byte[] GetStringProperties( htmlBody = HtmlEmail.Trim(htmlBody); } + properties.Add(billingInformation); + string messageClass = mailItem.MessageClass; + properties.Add(billingInformation); + string mileage = mailItem.Mileage; + properties.Add(billingInformation); + string receivedByEntryID = null; + properties.Add(billingInformation); + string receivedByName = mailItem.ReceivedByName; + properties.Add(billingInformation); + string receivedOnBehalfOfEntryID = null; + properties.Add(billingInformation); string receivedOnBehalfOfName = null; + properties.Add(billingInformation); + string reminderSoundFile = mailItem.ReminderSoundFile; + properties.Add(billingInformation); + string replyRecipientNames = mailItem.ReplyRecipientNames; + properties.Add(billingInformation); + string retentionPolicyName = mailItem.RetentionPolicyName; + properties.Add(billingInformation); + string senderEmailAddress = mailItem.SenderEmailAddress; + properties.Add(billingInformation); + string senderEmailType = mailItem.SenderEmailType; + properties.Add(billingInformation); + string senderName = mailItem.SenderName; + properties.Add(billingInformation); + string sentOnBehalfOfName = mailItem.SentOnBehalfOfName; + properties.Add(billingInformation); + string subject = mailItem.Subject; + properties.Add(billingInformation); + string taskSubject = mailItem.TaskSubject; + properties.Add(billingInformation); + string to = mailItem.To; + properties.Add(billingInformation); + string votingOptions = mailItem.VotingOptions; + properties.Add(billingInformation); + string votingResponse = mailItem.VotingResponse; + properties.Add(billingInformation); if (strict == true) { // Might need to investigate further. receivedByEntryID = mailItem.ReceivedByEntryID; + properties.Add(billingInformation); + receivedOnBehalfOfEntryID = mailItem.ReceivedOnBehalfOfEntryID; + properties.Add(billingInformation); + receivedOnBehalfOfName = mailItem.ReceivedOnBehalfOfName; + properties.Add(billingInformation); } StringBuilder builder = new (); - builder.Append(bcc); - builder.Append(billingInformation); - builder.Append(body); - builder.Append(categories); - builder.Append(cc); - builder.Append(companies); - builder.Append(conversationID); - builder.Append(conversationTopic); - builder.Append(flagRequest); - builder.Append(header); - builder.Append(htmlBody); - builder.Append(messageClass); - builder.Append(mileage); - builder.Append(receivedByEntryID); - builder.Append(receivedByName); - builder.Append(receivedOnBehalfOfEntryID); - builder.Append(receivedOnBehalfOfName); - builder.Append(reminderSoundFile); - builder.Append(replyRecipientNames); - builder.Append(retentionPolicyName); - builder.Append(senderEmailAddress); - builder.Append(senderEmailAddress); - builder.Append(senderName); - builder.Append(sentOnBehalfOfName); - builder.Append(subject); - builder.Append(taskSubject); - builder.Append(to); - builder.Append(votingOptions); - builder.Append(votingResponse); - - string buffer = builder.ToString(); - Encoding encoding = Encoding.UTF8; - data = encoding.GetBytes(buffer); + foreach (string item in properties) + { + if (addNewLine == true) + { + builder.AppendLine(item); + } + else + { + builder.Append(item); + } + } - return data; + string stringProperties = builder.ToString(); + + return stringProperties; } } } diff --git a/ToolKit.Library/OutlookStore.cs b/ToolKit.Library/OutlookStore.cs index ae0bc73..6a4e194 100644 --- a/ToolKit.Library/OutlookStore.cs +++ b/ToolKit.Library/OutlookStore.cs @@ -222,6 +222,39 @@ public static void RemoveFolder( } } + /// + /// List the folders. + /// + /// The PST file to check. + /// The entry id of the item to check. + public void Details(string pstFilePath, string entryId) + { + Store store = outlookAccount.GetStore(pstFilePath); + + if (store != null) + { + object mapiItem = GetItemFromEntryId(entryId); + + OutlookItem outlookItem = new (mapiItem); + + string details = OutlookItem.GetDetails(mapiItem); + + if (details != null) + { + string fileName = entryId + ".txt"; + + File.WriteAllText(fileName, details); + Log.Info("Item Details Saved in " + fileName); + } + else + { + Log.Warn("Item Details is NULL!"); + } + + Marshal.ReleaseComObject(mapiItem); + } + } + /// /// Gets folder from entry id. /// @@ -241,6 +274,19 @@ public MAPIFolder GetFolderFromID(string entryId, Store store) return folder; } + /// + /// Get the item by its entry id. + /// + /// The entryId of the item. + /// The item object. + public object GetItemFromEntryId(string entryId) + { + NameSpace session = outlookAccount.Session; + object item = session.GetItemFromID(entryId); + + return item; + } + /// /// Get the item's synopses. /// @@ -260,14 +306,13 @@ public string GetItemSynopses(string entryId) } /// - /// Get the item's synopses. + /// Get the item by its entry id. /// - /// The entryId of the MailItem to check. - /// The synoses of the item. + /// The entryId of the item. + /// The MailItem object. public MailItem GetMailItemFromEntryId(string entryId) { - NameSpace session = outlookAccount.Session; - MailItem mailItem = session.GetItemFromID(entryId); + MailItem mailItem = GetItemFromEntryId(entryId) as MailItem; return mailItem; } From 37d51cf9cab231c54a3876b7bd5b6246e62cd482 Mon Sep 17 00:00:00 2001 From: James John McGuire Date: Tue, 15 Oct 2024 21:18:03 +0900 Subject: [PATCH 2/2] Improve Formatting of Output Text --- ToolKit.Application/Program.cs | 3 - ToolKit.Library/OutlookItem.cs | 94 +++++++++-- ToolKit.Library/OutlookMail.cs | 290 ++++++++++++++++++++++----------- 3 files changed, 278 insertions(+), 109 deletions(-) diff --git a/ToolKit.Application/Program.cs b/ToolKit.Application/Program.cs index 7fb463c..1ec8d63 100644 --- a/ToolKit.Application/Program.cs +++ b/ToolKit.Application/Program.cs @@ -170,9 +170,6 @@ private static int Details(Command command) outlookStore.Details(pstFilePath, entryId); - string message = "Details saved in file: " + entryId + ".txt"; - Console.WriteLine(message); - return 0; } diff --git a/ToolKit.Library/OutlookItem.cs b/ToolKit.Library/OutlookItem.cs index 94ae541..c209c3a 100644 --- a/ToolKit.Library/OutlookItem.cs +++ b/ToolKit.Library/OutlookItem.cs @@ -230,7 +230,8 @@ public static byte[] GetActions(Actions actions) /// /// The item actions. /// The item actions data as text. - public static string GetActionsText(Actions actions) + public static string GetActionsText( + Actions actions, bool addNewLine = false) { string actionsText = null; @@ -243,7 +244,7 @@ public static string GetActionsText(Actions actions) Microsoft.Office.Interop.Outlook.Action action = actions[index]; - string actionText = GetActionText(action); + string actionText = GetActionText(action, addNewLine); if (actionText == null) { @@ -254,6 +255,11 @@ public static string GetActionsText(Actions actions) actionsText += actionText; } + if (addNewLine == true) + { + actionsText += Environment.NewLine; + } + Marshal.ReleaseComObject(action); } } @@ -364,24 +370,27 @@ public static byte[] GetDateTimesBytes(IList times) /// /// The DataTime properties data. /// The DataTime properties data as text. - public static string GetDateTimesText(IList times) + public static string GetDateTimesText( + IList times, List labels = null) { string dateTimesText = null; if (times != null) { - List timesStrings = []; + StringBuilder builder = new (); - foreach (DateTime time in times) + for (int index = 0; index < times.Count; index++) { + DateTime time = times[index]; + string timeString = time.ToString("O"); - timesStrings.Add(timeString); - } - StringBuilder builder = new (); + if (labels != null) + { + string label = labels[index]; + timeString = FormatValue(label, timeString); + } - foreach (string timeString in timesStrings) - { builder.Append(timeString); } @@ -414,7 +423,7 @@ public static string GetDetails( // break; case MailItem mailItem: OutlookMail mail = new (mapiItem); - details = mail.GetPropertiesText(strict); + details = mail.GetPropertiesText(strict, true); break; default: string message = "Item is of unsupported type: " + @@ -977,6 +986,57 @@ public async Task MoveAsync(MAPIFolder destination) await MoveAsync(mapiItem, destination).ConfigureAwait(false); } + public static string FormatEnumValue( + string propertyName, + object propertyValue) + { + int enumValue = (int)propertyValue; + string textValue = enumValue.ToString(); + + string result = string.Format( + CultureInfo.InvariantCulture, + "{0}: {1}", + propertyName, + textValue); + + result += Environment.NewLine; + + return result; + } + + public static string FormatValue( + string propertyName, + string propertyValue) + { + string formattedText = null; + + if (propertyValue != null) + { + formattedText = string.Format( + CultureInfo.InvariantCulture, + "{0}: {1}", + propertyName, + propertyValue); + + formattedText += Environment.NewLine; + } + + return formattedText; + } + + public static string FormatValueConditional( + string propertyName, + string propertyValue, + bool formatValue = false) + { + if (formatValue == true) + { + propertyValue = FormatValue(propertyName, propertyValue); + } + + return propertyValue; + } + private static bool DoubleCheckDuplicate( string baseSynopses, object mapiItem) { @@ -1013,7 +1073,8 @@ private static byte[] GetActionData( } private static string GetActionText( - Microsoft.Office.Interop.Outlook.Action action) + Microsoft.Office.Interop.Outlook.Action action, + bool addNewLine = false) { string actionText = null; @@ -1037,9 +1098,16 @@ private static string GetActionText( string showOn = showOnEnum.ToString(CultureInfo.InvariantCulture); + string format = "{0}{1}{2}{3}{4}{5}{6}"; + + if (addNewLine == true) + { + format = "{0} {1} {2} {3} {4} {5} {6}"; + } + actionText = string.Format( CultureInfo.InvariantCulture, - "{0}{1}{2}{3}{4}{5}{6}", + format, copyLike, enabled, action.Name, diff --git a/ToolKit.Library/OutlookMail.cs b/ToolKit.Library/OutlookMail.cs index 3b2185c..a8afb92 100644 --- a/ToolKit.Library/OutlookMail.cs +++ b/ToolKit.Library/OutlookMail.cs @@ -115,7 +115,8 @@ public IList GetProperties(bool strict = false) /// Indicates whether the check should be strict /// or not. /// The text of all relevant properties. - public string GetPropertiesText(bool strict = false) + public string GetPropertiesText( + bool strict = false, bool addNewLine = false) { string propertiesText = string.Empty; @@ -123,20 +124,21 @@ public string GetPropertiesText(bool strict = false) propertiesText += Environment.NewLine; propertiesText += - OutlookItem.GetActionsText(mailItem.Actions); + OutlookItem.GetActionsText(mailItem.Actions, addNewLine); propertiesText += Environment.NewLine; propertiesText += OutlookItem.GetAttachmentsText(mailItem.Attachments); propertiesText += Environment.NewLine; - propertiesText += GetDateTimesText(); + propertiesText += GetDateTimesText(addNewLine); propertiesText += Environment.NewLine; propertiesText += GetEnumsText(); propertiesText += Environment.NewLine; - propertiesText += GetStringPropertiesText(strict); + propertiesText += + GetStringPropertiesText(strict, true, addNewLine); propertiesText += Environment.NewLine; propertiesText += OutlookItem.GetUserPropertiesText( @@ -247,41 +249,67 @@ private string GetBooleansText() { string booleansText = string.Empty; - booleansText += OutlookItem.GetBooleanText( - mailItem.AutoForwarded); - booleansText += OutlookItem.GetBooleanText( - mailItem.AutoResolvedWinner); - booleansText += OutlookItem.GetBooleanText( - mailItem.DeleteAfterSubmit); - //booleansText += OutlookItem.GetBooleanText( - // mailItem.IsConflict); - booleansText += OutlookItem.GetBooleanText( - mailItem.IsMarkedAsTask); - booleansText += OutlookItem.GetBooleanText( - mailItem.NoAging); - booleansText += OutlookItem.GetBooleanText( - mailItem.OriginatorDeliveryReportRequested); - booleansText += OutlookItem.GetBooleanText( - mailItem.ReadReceiptRequested); - booleansText += OutlookItem.GetBooleanText( - mailItem.RecipientReassignmentProhibited); - booleansText += OutlookItem.GetBooleanText( - mailItem.ReminderOverrideDefault); - booleansText += OutlookItem.GetBooleanText( - mailItem.ReminderPlaySound); - booleansText += OutlookItem.GetBooleanText( - mailItem.ReminderSet); - booleansText += OutlookItem.GetBooleanText( - mailItem.Saved); - booleansText += OutlookItem.GetBooleanText( - mailItem.Submitted); - booleansText += OutlookItem.GetBooleanText( - mailItem.UnRead); + string boolValue = mailItem.AutoForwarded.ToString(); + booleansText += + OutlookItem.FormatValue("AutoForwarded", boolValue); + + boolValue = mailItem.AutoResolvedWinner.ToString(); + booleansText += + OutlookItem.FormatValue("AutoResolvedWinner", boolValue); + + boolValue = mailItem.DeleteAfterSubmit.ToString(); + booleansText += + OutlookItem.FormatValue("DeleteAfterSubmit", boolValue); + + // mailItem.IsConflict + boolValue = mailItem.IsMarkedAsTask.ToString(); + booleansText += + OutlookItem.FormatValue("IsMarkedAsTask", boolValue); + + boolValue = mailItem.NoAging.ToString(); + booleansText += + OutlookItem.FormatValue("NoAging", boolValue); + + boolValue = mailItem.OriginatorDeliveryReportRequested.ToString(); + booleansText += OutlookItem.FormatValue( + "OriginatorDeliveryReportRequested", boolValue); + + boolValue = mailItem.ReadReceiptRequested.ToString(); + booleansText += + OutlookItem.FormatValue("ReadReceiptRequested", boolValue); + + boolValue = mailItem.RecipientReassignmentProhibited.ToString(); + booleansText += OutlookItem.FormatValue( + "RecipientReassignmentProhibited", boolValue); + + boolValue = mailItem.ReminderOverrideDefault.ToString(); + booleansText += + OutlookItem.FormatValue("ReminderOverrideDefault", boolValue); + + boolValue = mailItem.ReminderPlaySound.ToString(); + booleansText += + OutlookItem.FormatValue("ReminderPlaySound", boolValue); + + boolValue = mailItem.ReminderSet.ToString(); + booleansText += + OutlookItem.FormatValue("ReminderSet", boolValue); + + boolValue = mailItem.Saved.ToString(); + booleansText += + OutlookItem.FormatValue("Saved", boolValue); + + boolValue = mailItem.Submitted.ToString(); + booleansText += + OutlookItem.FormatValue("Submitted", boolValue); + + boolValue = mailItem.UnRead.ToString(); + booleansText += + OutlookItem.FormatValue("UnRead", boolValue); return booleansText; } - private List GetDateTimes() + private List GetDateTimes(bool format = false) { List times = []; @@ -336,11 +364,25 @@ private byte[] GetDateTimesBytes() return data; } - private string GetDateTimesText() + private string GetDateTimesText(bool addNewLine = false) { List times = GetDateTimes(); - string dateTimesText = OutlookItem.GetDateTimesText(times); + List labels = + [ + "DeferredDeliveryTimeDateTime", + "ExpiryTime", + "ReceivedTime", + "ReminderTime", + "RetentionExpirationDate", + "SentOn", + "TaskCompletedDate", + "TaskDueDate", + "mailItem.TaskStartDate" + ]; + + string dateTimesText = + OutlookItem.GetDateTimesText(times, labels); return dateTimesText; } @@ -397,13 +439,26 @@ private string GetEnumsText() { string enumsText = string.Empty; - enumsText += nameof(mailItem.BodyFormat); - enumsText += nameof(mailItem.Class); - enumsText += nameof(mailItem.Importance); - enumsText += nameof(mailItem.MarkForDownload); - enumsText += nameof(mailItem.Permission); - enumsText += nameof(mailItem.PermissionService); - enumsText += nameof(mailItem.Sensitivity); + enumsText += + OutlookItem.FormatEnumValue("BodyFormat", mailItem.BodyFormat); + + enumsText += + OutlookItem.FormatEnumValue("Class", mailItem.Class); + + enumsText += + OutlookItem.FormatEnumValue("Importance", mailItem.Importance); + + enumsText += OutlookItem.FormatEnumValue( + "MarkForDownload", mailItem.MarkForDownload); + + enumsText += + OutlookItem.FormatEnumValue("Permission", mailItem.Permission); + + enumsText += OutlookItem.FormatEnumValue( + "PermissionService", mailItem.PermissionService); + + enumsText += OutlookItem.FormatEnumValue( + "Sensitivity", mailItem.Sensitivity); return enumsText; } @@ -424,11 +479,14 @@ private byte[] GetStringProperties( private string GetStringPropertiesText( bool strict = false, bool ignoreConversation = true, - bool addNewLine = false) + bool formatText = false) { List properties = []; + string formattedText = string.Empty; string bcc = mailItem.BCC; + + bcc = OutlookItem.FormatValueConditional("BCC", bcc, formatText); properties.Add(bcc); string billingInformation = null; @@ -441,6 +499,8 @@ private string GetStringPropertiesText( { } + billingInformation = OutlookItem.FormatValueConditional( + "BillingInformation", billingInformation, formatText); properties.Add(billingInformation); string body = mailItem.Body; @@ -450,30 +510,44 @@ private string GetStringPropertiesText( body = body.TrimEnd(); } - properties.Add(billingInformation); + body = OutlookItem.FormatValueConditional( + "Body", body, formatText); + properties.Add(body); string categories = mailItem.Categories; - properties.Add(billingInformation); + categories = OutlookItem.FormatValueConditional( + "Categories", categories, formatText); + properties.Add(categories); string cc = mailItem.CC; - properties.Add(billingInformation); + cc = OutlookItem.FormatValueConditional( + "CC", cc, formatText); + properties.Add(cc); string companies = mailItem.Companies; - properties.Add(billingInformation); + companies = OutlookItem.FormatValueConditional( + "Companies", companies, formatText); + properties.Add(companies); string conversationID = null; if (ignoreConversation == false) { conversationID = mailItem.ConversationID; - properties.Add(billingInformation); + conversationID = OutlookItem.FormatValueConditional( + "ConversationID", conversationID, formatText); + properties.Add(conversationID); } string conversationTopic = mailItem.ConversationTopic; - properties.Add(billingInformation); + conversationTopic = OutlookItem.FormatValueConditional( + "ConversationTopic", conversationTopic, formatText); + properties.Add(conversationTopic); string flagRequest = mailItem.FlagRequest; - properties.Add(billingInformation); + flagRequest = OutlookItem.FormatValueConditional( + "FlagRequest", flagRequest, formatText); + properties.Add(flagRequest); string header = mailItem.PropertyAccessor.GetProperty( "http://schemas.microsoft.com/mapi/proptag/0x007D001F"); @@ -496,7 +570,9 @@ private string GetStringPropertiesText( header = NormalizeHeaders(header); } - properties.Add(billingInformation); + header = OutlookItem.FormatValueConditional( + "Header (0x007D001F)", header, formatText); + properties.Add(header); string htmlBody = mailItem.HTMLBody; @@ -505,88 +581,116 @@ private string GetStringPropertiesText( htmlBody = HtmlEmail.Trim(htmlBody); } - properties.Add(billingInformation); + htmlBody = OutlookItem.FormatValueConditional( + "HTMLBody", htmlBody, formatText); + properties.Add(htmlBody); string messageClass = mailItem.MessageClass; - properties.Add(billingInformation); + messageClass = OutlookItem.FormatValueConditional( + "MessageClass", messageClass, formatText); + properties.Add(messageClass); string mileage = mailItem.Mileage; - properties.Add(billingInformation); - - string receivedByEntryID = null; - properties.Add(billingInformation); + mileage = OutlookItem.FormatValueConditional( + "Mileage", mileage, formatText); + properties.Add(mileage); string receivedByName = mailItem.ReceivedByName; - properties.Add(billingInformation); - - string receivedOnBehalfOfEntryID = null; - properties.Add(billingInformation); - - string receivedOnBehalfOfName = null; - properties.Add(billingInformation); + receivedByName = OutlookItem.FormatValueConditional( + "ReceivedByName", receivedByName, formatText); + properties.Add(receivedByName); string reminderSoundFile = mailItem.ReminderSoundFile; - properties.Add(billingInformation); + reminderSoundFile = OutlookItem.FormatValueConditional( + "ReminderSoundFile", reminderSoundFile, formatText); + properties.Add(reminderSoundFile); string replyRecipientNames = mailItem.ReplyRecipientNames; - properties.Add(billingInformation); + replyRecipientNames = OutlookItem.FormatValueConditional( + "ReplyRecipientNames", replyRecipientNames, formatText); + properties.Add(replyRecipientNames); string retentionPolicyName = mailItem.RetentionPolicyName; - properties.Add(billingInformation); + retentionPolicyName = OutlookItem.FormatValueConditional( + "RetentionPolicyName", retentionPolicyName, formatText); + properties.Add(retentionPolicyName); string senderEmailAddress = mailItem.SenderEmailAddress; - properties.Add(billingInformation); + senderEmailAddress = OutlookItem.FormatValueConditional( + "SenderEmailAddress", senderEmailAddress, formatText); + properties.Add(senderEmailAddress); string senderEmailType = mailItem.SenderEmailType; - properties.Add(billingInformation); + senderEmailType = OutlookItem.FormatValueConditional( + "SenderEmailType", senderEmailType, formatText); + properties.Add(senderEmailType); string senderName = mailItem.SenderName; - properties.Add(billingInformation); + senderName = OutlookItem.FormatValueConditional( + "SenderName", senderName, formatText); + properties.Add(senderName); string sentOnBehalfOfName = mailItem.SentOnBehalfOfName; - properties.Add(billingInformation); + sentOnBehalfOfName = OutlookItem.FormatValueConditional( + "SentOnBehalfOfName", sentOnBehalfOfName, formatText); + properties.Add(sentOnBehalfOfName); string subject = mailItem.Subject; - properties.Add(billingInformation); + subject = OutlookItem.FormatValueConditional( + "Subject", subject, formatText); + properties.Add(subject); string taskSubject = mailItem.TaskSubject; - properties.Add(billingInformation); + taskSubject = OutlookItem.FormatValueConditional( + "TaskSubject", taskSubject, formatText); + properties.Add(taskSubject); string to = mailItem.To; - properties.Add(billingInformation); + to = OutlookItem.FormatValueConditional( + "To", to, formatText); + properties.Add(to); string votingOptions = mailItem.VotingOptions; - properties.Add(billingInformation); + votingOptions = OutlookItem.FormatValueConditional( + "VotingOptions", votingOptions, formatText); + properties.Add(votingOptions); string votingResponse = mailItem.VotingResponse; - properties.Add(billingInformation); + votingResponse = OutlookItem.FormatValueConditional( + "VotingResponse", votingResponse, formatText); + properties.Add(votingResponse); if (strict == true) { // Might need to investigate further. - receivedByEntryID = mailItem.ReceivedByEntryID; - properties.Add(billingInformation); + string receivedByEntryID = mailItem.ReceivedByEntryID; + receivedByEntryID = OutlookItem.FormatValueConditional( + "ReceivedByEntryID", receivedByEntryID, formatText); + properties.Add(receivedByEntryID); - receivedOnBehalfOfEntryID = + string receivedOnBehalfOfEntryID = mailItem.ReceivedOnBehalfOfEntryID; - properties.Add(billingInformation); - - receivedOnBehalfOfName = mailItem.ReceivedOnBehalfOfName; - properties.Add(billingInformation); + receivedOnBehalfOfEntryID = + OutlookItem.FormatValueConditional( + "ReceivedOnBehalfOfEntryID", + receivedOnBehalfOfEntryID, + formatText); + properties.Add(receivedOnBehalfOfEntryID); + + string receivedOnBehalfOfName = + mailItem.ReceivedOnBehalfOfName; + receivedOnBehalfOfName = OutlookItem.FormatValueConditional( + "ReceivedOnBehalfOfName", + receivedOnBehalfOfName, + formatText); + properties.Add(receivedOnBehalfOfName); } StringBuilder builder = new (); foreach (string item in properties) { - if (addNewLine == true) - { - builder.AppendLine(item); - } - else - { - builder.Append(item); - } + builder.Append(item); } string stringProperties = builder.ToString();