From 55958cd0af5ac3b5b080ff7cfb0720c14a6aae1e Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Wed, 21 Jun 2017 09:40:12 +0100 Subject: [PATCH] #183: fix. --- SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs | 12 ++---------- SuiteCRMAddIn/Dialogs/ArchiveDialog.cs | 7 ++++--- SuiteCRMAddIn/Extensions/MailItemExtensions.cs | 9 +++++++++ SuiteCRMClient/Email/ArchiveableEmail.cs | 14 +++++++++----- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs b/SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs index 77e4c313..7d58ad37 100644 --- a/SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs +++ b/SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs @@ -45,24 +45,16 @@ namespace SuiteCRMAddIn.BusinessLogic /// public class EmailArchiving : RepeatingProcess { - private UserSession SuiteCRMUserSession => Globals.ThisAddIn.SuiteCRMUserSession; - /// - /// Magic property tag to get the email address from an Outlook Recipient object. + /// Convenience property to get a handle on the global user session. /// - const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; + private UserSession SuiteCRMUserSession => Globals.ThisAddIn.SuiteCRMUserSession; /// /// Canonical format to use when saving date/times to CRM; essentially, ISO8601 without the 'T'. /// public const string EmailDateFormat = "yyyy-MM-dd HH:mm:ss"; - /// - /// The name of the Outlook user property on which we will store the CRM Category associated - /// with an email, of any. - /// - public const string CRMCategoryPropertyName = "SuiteCRMCategory"; - public EmailArchiving(string name, ILogger log) : base(name, log) { } diff --git a/SuiteCRMAddIn/Dialogs/ArchiveDialog.cs b/SuiteCRMAddIn/Dialogs/ArchiveDialog.cs index 9bd6fe63..5ba9c298 100644 --- a/SuiteCRMAddIn/Dialogs/ArchiveDialog.cs +++ b/SuiteCRMAddIn/Dialogs/ArchiveDialog.cs @@ -24,6 +24,7 @@ namespace SuiteCRMAddIn.Dialogs { using BusinessLogic; using Exceptions; + using Extensions; using Microsoft.Office.Interop.Outlook; using SuiteCRMClient; using SuiteCRMClient.Email; @@ -838,11 +839,11 @@ private void categoryInput_SelectedIndexChanged(object sender, EventArgs e) { foreach (MailItem mail in Globals.ThisAddIn.SelectedEmails) { - if (mail.UserProperties[EmailArchiving.CRMCategoryPropertyName] == null) + if (mail.UserProperties[MailItemExtensions.CRMCategoryPropertyName] == null) { - mail.UserProperties.Add(EmailArchiving.CRMCategoryPropertyName, OlUserPropertyType.olText); + mail.UserProperties.Add(MailItemExtensions.CRMCategoryPropertyName, OlUserPropertyType.olText); } - mail.UserProperties[EmailArchiving.CRMCategoryPropertyName].Value = categoryInput.SelectedItem.ToString(); + mail.UserProperties[MailItemExtensions.CRMCategoryPropertyName].Value = categoryInput.SelectedItem.ToString(); } } } diff --git a/SuiteCRMAddIn/Extensions/MailItemExtensions.cs b/SuiteCRMAddIn/Extensions/MailItemExtensions.cs index 15813665..d2582b78 100644 --- a/SuiteCRMAddIn/Extensions/MailItemExtensions.cs +++ b/SuiteCRMAddIn/Extensions/MailItemExtensions.cs @@ -51,6 +51,12 @@ public static class MailItemExtensions /// public const string CrmIdPropertyName = "SEntryID"; + /// + /// The name of the Outlook user property on which we will store the CRM Category associated + /// with an email, of any. + /// + public const string CRMCategoryPropertyName = "SuiteCRMCategory"; + /// /// Shorthand to refer to the global user session. /// @@ -182,6 +188,9 @@ public static ArchiveableEmail AsArchiveable(this Outlook.MailItem olItem, Email mailArchive.Body = olItem.Body; mailArchive.HTMLBody = olItem.HTMLBody; mailArchive.Reason = reason; + mailArchive.Category = olItem.UserProperties[CRMCategoryPropertyName] != null ? + olItem.UserProperties[CRMCategoryPropertyName].Value : + string.Empty; if (Properties.Settings.Default.ArchiveAttachments) { diff --git a/SuiteCRMClient/Email/ArchiveableEmail.cs b/SuiteCRMClient/Email/ArchiveableEmail.cs index 1b408f2c..9bd9c522 100644 --- a/SuiteCRMClient/Email/ArchiveableEmail.cs +++ b/SuiteCRMClient/Email/ArchiveableEmail.cs @@ -46,6 +46,8 @@ public class ArchiveableEmail public string HTMLBody { get; set; } public string CC { get; set; } + public string Category { get; set; } + /// /// Date/Time sent, if known, else now. /// @@ -281,14 +283,16 @@ private void SaveContacts(List crmContactIds, RESTObjects.eNewSetEntryRe private object ConstructPacket(string htmlBody) { List emailData = new List(); - emailData.Add(new RESTObjects.eNameValue() { name = "from_addr", value = From }); - emailData.Add(new RESTObjects.eNameValue() { name = "to_addrs", value = To.Replace("\n", "") }); - emailData.Add(new RESTObjects.eNameValue() { name = "name", value = Subject }); - emailData.Add(new RESTObjects.eNameValue() { name = "date_sent", value = Sent.ToString(EmailDateFormat) }); - emailData.Add(new RESTObjects.eNameValue() { name = "description", value = Body }); + emailData.Add(new RESTObjects.eNameValue() { name = "from_addr", value = this.From }); + emailData.Add(new RESTObjects.eNameValue() { name = "to_addrs", value = this.To.Replace("\n", "") }); + emailData.Add(new RESTObjects.eNameValue() { name = "name", value = this.Subject }); + emailData.Add(new RESTObjects.eNameValue() { name = "date_sent", value = this.Sent.ToString(EmailDateFormat) }); + emailData.Add(new RESTObjects.eNameValue() { name = "description", value = this.Body }); emailData.Add(new RESTObjects.eNameValue() { name = "description_html", value = htmlBody }); emailData.Add(new RESTObjects.eNameValue() { name = "assigned_user_id", value = clsSuiteCRMHelper.GetUserId() }); emailData.Add(new RESTObjects.eNameValue() { name = "status", value = "archived" }); + emailData.Add(new RESTObjects.eNameValue() { name = "category_id", value = this.Category }); + object contactData = new { @session = SuiteCRMUserSession.id,