private void NewWorkItem(IIncomingEmailMessage message) { var workItemUpdates = new Dictionary <string, string>(); InitWorkItemFields(message, workItemUpdates); var workItemId = _workItemManager.CreateWorkItem(workItemUpdates); Logger.InfoFormat("Added new work item {0} for message with subject: {1} (conversation index:{2})", workItemId, message.Subject, message.ConversationId); try { // Since the work item *has* been created, failures in this stage are not treated as critical var overrides = new OverridesExtractor(_config).GetOverrides(message); TryApplyFieldOverrides(overrides, workItemId); ProcessAttachments(message, workItemId); if (_config.WorkItemSettings.AttachOriginalMessage) { AttachMessageToWorkItem(message, workItemId, "OriginalMessage"); } } catch (Exception ex) { Logger.ErrorFormat("Exception caught while applying settings to work item {0}\n{1}", workItemId, ex); } var workItem = _workItemManager.GetWorkItemFields(workItemId); _ackEmailHandler.SendAckEmail(message, workItem); }
private void NewWorkItem(IIncomingEmailMessage message) { var workItemUpdates = new Dictionary<string, string>(); InitWorkItemFields(message, workItemUpdates); var workItemId = _workItemManager.CreateWorkItem(workItemUpdates); Logger.InfoFormat("Added new work item {0} for message with subject: {1} (conversation index:{2})", workItemId, message.Subject, message.ConversationIndex); try { // Since the work item *has* been created, failures in this stage are not treated as critical var overrides = new OverridesExtractor(_config).GetOverrides(message); TryApplyFieldOverrides(overrides, workItemId); ProcessAttachments(message, workItemId); if (_config.WorkItemSettings.AttachOriginalMessage) { AttachMessageToWorkItem(message, workItemId, "OriginalMessage"); } } catch (Exception ex) { Logger.ErrorFormat("Exception caught while applying settings to work item {0}\n{1}", workItemId, ex); } _ackEmailHandler.SendAckEmail(message, workItemId.ToString(CultureInfo.InvariantCulture)); }
private void UpdateWorkItem(IIncomingEmailMessage message, int workItemId) { Logger.InfoFormat("Modifying work item {0} subject: {1}", workItemId, message.Subject); var resolver = new SpecialValueResolver(message, _workItemManager.GetNameResolver()); var workItemUpdates = new Dictionary <string, string>(); if (_config.WorkItemSettings.OverrideChangedBy) { workItemUpdates["Changed By"] = resolver.Sender; } if (_config.WorkItemSettings.ApplyOverridesDuringUpdate) { var extractor = new OverridesExtractor(_config); var overrides = extractor.GetOverrides(message.GetLastMessageText()); Logger.DebugFormat("Found {0} overrides for update message", overrides.Count); overrides.ToList().ForEach(x => workItemUpdates[x.Key] = x.Value); } // Construct the text to be appended _workItemManager.ModifyWorkItem(workItemId, message.GetLastMessageText(), workItemUpdates); ProcessAttachments(message, workItemId); if (_config.WorkItemSettings.AttachUpdateMessages) { AttachMessageToWorkItem(message, workItemId, "ReplyMessage"); } }
private void NewWorkItem(IIncomingEmailMessage message) { var workItemUpdates = new Dictionary <string, string>(); InitWorkItemFields(message, workItemUpdates); var overrides = new OverridesExtractor(_config).GetOverrides(message); var workItemId = _workItemManager.CreateWorkItem(workItemUpdates, overrides); Logger.InfoFormat("Added new work item {0} for message with subject: {1} (conversation index:{2})", workItemId, message.Subject, message.ConversationIndex); if (_config.WorkItemSettings.AttachOriginalMessage) { try { ProcessAttachments(message, workItemId); string originalMessageFile = message.SaveToFile(); _workItemManager.AttachFiles(workItemId, new List <string> { originalMessageFile }); } catch (Exception ex) { Logger.ErrorFormat("Exception caught while applying settings to work item {0}\n{1}", workItemId, ex); } } _ackEmailHandler.SendAckEmail(message, workItemId.ToString(CultureInfo.InvariantCulture)); }
public void TestDefaultDateBasedOverride() { var config = GetConfig(); config.WorkItemSettings.DateBasedOverrides.Add(new Config.DateBasedFieldOverrides()); config.WorkItemSettings.DateBasedOverrides[0].FieldName = BasicField; config.WorkItemSettings.DateBasedOverrides[0].DefaultValue = BasicValue; config.WorkItemSettings.DateBasedOverrides[0].Entries = new List<Config.DateBasedOverrideEntry> { new Config.DateBasedOverrideEntry { StartDate = DateTime.Now + TimeSpan.FromDays(10), Value = BasicValue2 } }; var mailManager = new MailManagerMock(); var message = mailManager.AddMessage(false); var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField)); Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of mnemonic resolution"); }
public void TestSimpleMnemonicOverride() { var config = GetConfig(); config.WorkItemSettings.Mnemonics.Add( new Config.MnemonicDefinition { Mnemonic = BasicMnemonic.ToUpper(), Field = BasicField, Value = BasicValue }); var mailManager = new MailManagerMock(); var message = mailManager.AddMessage(false); message.PlainTextBody += string.Format("@@@{0}", BasicMnemonic.ToLower()); var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField)); Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of mnemonic resolution"); }
private void UpdateWorkItem(IIncomingEmailMessage message, int workItemId) { Logger.InfoFormat("Modifying work item {0} subject: {1}", workItemId, message.Subject); var resolver = new SpecialValueResolver(message, _workItemManager.GetNameResolver()); var workItemUpdates = new Dictionary <string, string>(); if (_config.WorkItemSettings.OverrideChangedBy) { workItemUpdates["Changed By"] = resolver.Sender; } bool isHtmlEnabled = _config.WorkItemSettings.EnableExperimentalHtmlFeatures; bool commentIsHtml = message.IsHtmlBody && isHtmlEnabled; string lastMessageText = message.GetLastMessageText(isHtmlEnabled); if (_config.WorkItemSettings.ApplyOverridesDuringUpdate) { // OverrideExtractor can't currently handle HTML input, so we need to make sure we pass it the plain text version string lastMessagePlainText = commentIsHtml ? message.GetLastMessageText(enableExperimentalHtmlFeatures: false) : lastMessageText; var extractor = new OverridesExtractor(_config); var overrides = extractor.GetOverrides(lastMessagePlainText); Logger.DebugFormat("Found {0} overrides for update message", overrides.Count); overrides.ToList().ForEach(x => workItemUpdates[x.Key] = x.Value); } using (var attachments = SaveAttachments(message)) { _workItemManager.ModifyWorkItem(workItemId, lastMessageText, commentIsHtml, workItemUpdates, attachments); } if (_config.WorkItemSettings.AttachUpdateMessages) { AttachMessageToWorkItem(message, workItemId, "ReplyMessage"); } }
private void TryApplyFieldOverrides(IIncomingEmailMessage message, int workItemId) { var overrides = new OverridesExtractor(message, _config).GetOverrides(); if (overrides.Count == 0) { Logger.DebugFormat("No overrides found. Skipping applying overrides."); return; } try { Logger.DebugFormat("Overrides found. Calling 'ModifyWorkItem'"); _workItemManager.ModifyWorkItem(workItemId, "", overrides); } catch (Exception ex) { Logger.ErrorFormat("Exception caught while trying to apply overrides to work item {0}. Overrides: {1}\n{2}", workItemId, overrides, ex); } }
private void UpdateWorkItem(IIncomingEmailMessage message, int workItemId) { Logger.InfoFormat("Modifying work item {0} subject: {1}", workItemId, message.Subject); var resolver = new SpecialValueResolver(message, _workItemManager.GetNameResolver()); var workItemUpdates = new Dictionary<string, string>(); if (_config.WorkItemSettings.OverrideChangedBy) { workItemUpdates["Changed By"] = resolver.Sender; } if (_config.WorkItemSettings.ApplyOverridesDuringUpdate) { var extractor = new OverridesExtractor(_config); var overrides = extractor.GetOverrides(message.GetLastMessageText()); Logger.DebugFormat("Found {0} overrides for update message", overrides.Count); overrides.ToList().ForEach(x => workItemUpdates[x.Key] = x.Value); } // Construct the text to be appended _workItemManager.ModifyWorkItem(workItemId, message.GetLastMessageText(), workItemUpdates); ProcessAttachments(message, workItemId); if (_config.WorkItemSettings.AttachUpdateMessages) { AttachMessageToWorkItem(message, workItemId, "ReplyMessage"); } }
private void NewWorkItem(IIncomingEmailMessage message) { var workItemUpdates = new Dictionary<string, string>(); InitWorkItemFields(message, workItemUpdates); var overrides = new OverridesExtractor(_config).GetOverrides(message); var workItemId = _workItemManager.CreateWorkItem(workItemUpdates, overrides); Logger.InfoFormat("Added new work item {0} for message with subject: {1} (conversation index:{2})", workItemId, message.Subject, message.ConversationIndex); if (_config.WorkItemSettings.AttachOriginalMessage) { try { ProcessAttachments(message, workItemId); string originalMessageFile = message.SaveToFile(); _workItemManager.AttachFiles(workItemId, new List<string> { originalMessageFile }); } catch (Exception ex) { Logger.ErrorFormat("Exception caught while applying settings to work item {0}\n{1}", workItemId, ex); } } _ackEmailHandler.SendAckEmail(message, workItemId.ToString(CultureInfo.InvariantCulture)); }
public void TestOverridesPrecedenceMnemonicTrumps() { const string aliasValue = "AliasValue"; const string mnemonicValue = "MnemonicValue"; var config = GetConfigWithAllOverrides( BasicAlias, BasicField, aliasValue, BasicMnemonic, BasicField, mnemonicValue); var message = GetMessageWithOverrides(BasicAlias, BasicMnemonic, null, null); var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists (mnemonic)", BasicField)); Assert.AreEqual(mnemonicValue, dictionary[BasicField], "Validate the right value was assigned as part of explicit overrides resolution"); }
public void TestCombinedOverrides() { const string aliasField = "AliasField"; const string mnemonicField = "MnemonicField"; const string explicitField = "ExplicitField"; const string aliasValue = "AliasValue"; const string mnemonicValue = "MnemonicValue"; const string explicitValue = "ExplicitValue"; var config = GetConfigWithAllOverrides( BasicAlias, aliasField, aliasValue,BasicMnemonic, mnemonicField, mnemonicValue); var message = GetMessageWithOverrides(BasicAlias, BasicMnemonic, explicitField, explicitValue); var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(mnemonicField), string.Format("Validate override for field {0} exists (mnemonic)", BasicField)); Assert.IsTrue(dictionary.ContainsKey(explicitField), string.Format("Validate override for field {0} exists (explicit)", BasicField)); Assert.IsTrue(dictionary.ContainsKey(aliasField), string.Format("Validate override for field {0} exists (recipient)", BasicField)); Assert.AreEqual(mnemonicValue, dictionary[mnemonicField], "Validate the right value was assigned as part of mnemonic overrides resolution"); Assert.AreEqual(explicitValue, dictionary[explicitField], "Validate the right value was assigned as part of explicit overrides resolution"); Assert.AreEqual(aliasValue, dictionary[aliasField], "Validate the right value was assigned as part of recipient overrides resolution"); }
public void TestSimpleRecipientOverride() { var config = GetConfig(); config.WorkItemSettings.RecipientOverrides.Add( new Config.RecipientOverrideDefinition {Alias = BasicAlias.ToUpper(), Field = BasicField,Value = BasicValue}); var mailManager = new MailManagerMock(); var message = mailManager.AddMessage(false); // Add the alias that will be resolved var newTo = message.ToAddresses.ToList(); newTo.Add(BasicAlias.ToLower()); message.ToAddresses = newTo; var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField)); Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of recipient overrides resolution"); }
public void TestSimpleExplicitOverride() { var config = GetConfig(); var mailManager = new MailManagerMock(); var message = mailManager.AddMessage(false); message.PlainTextBody += string.Format("###{0}:{1}", BasicField, BasicValue); var extractor = new OverridesExtractor(config); var dictionary = extractor.GetOverrides(message); Assert.IsTrue(dictionary.ContainsKey(BasicField), string.Format("Validate override for field {0} exists", BasicField)); Assert.AreEqual(BasicValue, dictionary[BasicField], "Validate the right value was assigned as part of explicit overrides resolution"); }