Skip to content

Commit

Permalink
Merge branch 'feature/183' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-brooke committed Jun 21, 2017
2 parents 0c64d42 + 55958cd commit 3e29c41
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
12 changes: 2 additions & 10 deletions SuiteCRMAddIn/BusinessLogic/EmailArchiving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,16 @@ namespace SuiteCRMAddIn.BusinessLogic
/// </remarks>
public class EmailArchiving : RepeatingProcess
{
private UserSession SuiteCRMUserSession => Globals.ThisAddIn.SuiteCRMUserSession;

/// <summary>
/// Magic property tag to get the email address from an Outlook Recipient object.
/// Convenience property to get a handle on the global user session.
/// </summary>
const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
private UserSession SuiteCRMUserSession => Globals.ThisAddIn.SuiteCRMUserSession;

/// <summary>
/// Canonical format to use when saving date/times to CRM; essentially, ISO8601 without the 'T'.
/// </summary>
public const string EmailDateFormat = "yyyy-MM-dd HH:mm:ss";

/// <summary>
/// The name of the Outlook user property on which we will store the CRM Category associated
/// with an email, of any.
/// </summary>
public const string CRMCategoryPropertyName = "SuiteCRMCategory";

public EmailArchiving(string name, ILogger log) : base(name, log)
{
}
Expand Down
7 changes: 4 additions & 3 deletions SuiteCRMAddIn/Dialogs/ArchiveDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace SuiteCRMAddIn.Dialogs
{
using BusinessLogic;
using Exceptions;
using Extensions;
using Microsoft.Office.Interop.Outlook;
using SuiteCRMClient;
using SuiteCRMClient.Email;
Expand Down Expand Up @@ -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();
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions SuiteCRMAddIn/Extensions/MailItemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public static class MailItemExtensions
/// <see cref="SuiteCRMAddIn.BusinessLogic.Synchroniser{OutlookItemType}.CrmIdPropertyName"/>
public const string CrmIdPropertyName = "SEntryID";

/// <summary>
/// The name of the Outlook user property on which we will store the CRM Category associated
/// with an email, of any.
/// </summary>
public const string CRMCategoryPropertyName = "SuiteCRMCategory";

/// <summary>
/// Shorthand to refer to the global user session.
/// </summary>
Expand Down Expand Up @@ -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)
{
Expand Down
14 changes: 9 additions & 5 deletions SuiteCRMClient/Email/ArchiveableEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class ArchiveableEmail
public string HTMLBody { get; set; }
public string CC { get; set; }

public string Category { get; set; }

/// <summary>
/// Date/Time sent, if known, else now.
/// </summary>
Expand Down Expand Up @@ -281,14 +283,16 @@ private void SaveContacts(List<string> crmContactIds, RESTObjects.eNewSetEntryRe
private object ConstructPacket(string htmlBody)
{
List<RESTObjects.eNameValue> emailData = new List<RESTObjects.eNameValue>();
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,
Expand Down

0 comments on commit 3e29c41

Please sign in to comment.