public void TestIsMatchBlackberry() { IRouter mtaRouter = new Workshare.Policy.Routing.MtaRouter.MtaRouter(); PolicyType policyType = PolicyType.Mta; IUniversalRoutingEntity sourceEntity = new UniversalRoutingEntity(); sourceEntity.PolicyType = policyType; sourceEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Blackberry); IRoutingItem routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); sourceEntity.Items.Add(routingItem); IUniversalRoutingEntity targetEntity = new UniversalRoutingEntity(); targetEntity.PolicyType = policyType; targetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); targetEntity.Items.Add(routingItem); //invalid data Assert.IsFalse(mtaRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(null, targetEntity), "Expected null data to return false"); Assert.IsTrue(mtaRouter.IsMatch(sourceEntity, targetEntity), "Expected nominal case to return true"); }
private static void PopulateDestinationFromMailMessage(UniversalRequestObject uro, System.Net.Mail.MailMessage mailMessage) { uro.Destination.PolicyType = uro.PolicyType; uro.Destination.Properties = new Dictionary<string, string>(); uro.Destination.Items = new Collection<IRoutingItem>(); foreach (MailAddress mailAddress in mailMessage.To) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.CC) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.Bcc) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.BCC); uro.Destination.Items.Add(routingItem); } }
private void IsMatchMailServer(string requestChannel) { IRouter mtaRouter = new Workshare.Policy.Routing.MtaRouter.MtaRouter(); PolicyType policyType = PolicyType.Mta; IUniversalRoutingEntity sourceEntity = new UniversalRoutingEntity(); sourceEntity.PolicyType = policyType; sourceEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; if (!string.IsNullOrEmpty(requestChannel)) sourceEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, requestChannel); IRoutingItem routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); sourceEntity.Items.Add(routingItem); IUniversalRoutingEntity targetEntity = new UniversalRoutingEntity(); targetEntity.PolicyType = policyType; targetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); targetEntity.Items.Add(routingItem); //invalid data Assert.IsFalse(mtaRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(null, targetEntity), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, targetEntity), "Expected nominal case to return false"); }
public void Test01_TestInternalRecipients() { PolicyResponseObject pro1 = GetPRO(); IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.From; pro1.UniversalRequestObject.Source.Items.Add(sourceRoutingItem); IRoutingItem toRoutingItem = new RoutingItem("*****@*****.**"); toRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.To; pro1.UniversalRequestObject.Destination.Items.Add(toRoutingItem); IRoutingItem bccRoutingItem = new RoutingItem("*****@*****.**"); bccRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.BCC; pro1.UniversalRequestObject.Destination.Items.Add(bccRoutingItem); IRoutingItem ccRoutingItem1 = new RoutingItem("*****@*****.**"); ccRoutingItem1.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.CC; pro1.UniversalRequestObject.Destination.Items.Add(ccRoutingItem1); IRoutingItem ccRoutingItem2 = new RoutingItem("/O=WSDEV/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=LNPAIR"); ccRoutingItem2.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.CC; pro1.UniversalRequestObject.Destination.Items.Add(ccRoutingItem2); IPolicyResponseObject iPro = pro1 as IPolicyResponseObject; InternalExternalHelper.SetMessageRouting(iPro); Assert.AreEqual(bool.TrueString, pro1.UniversalRequestObject.Destination.Items[0].Properties[SMTPItemPropertyKeys.Internal], "'Internal Contact' property was incorrect."); Assert.AreEqual(bool.FalseString, pro1.UniversalRequestObject.Destination.Items[1].Properties[SMTPItemPropertyKeys.Internal], "'Internal Contact' property was incorrect."); Assert.AreEqual(bool.FalseString, pro1.UniversalRequestObject.Destination.Items[2].Properties[SMTPItemPropertyKeys.Internal], "'Internal Contact' property was incorrect."); Assert.AreEqual(bool.TrueString, pro1.UniversalRequestObject.Destination.Items[3].Properties[SMTPItemPropertyKeys.Internal], "'Internal Contact' property was incorrect."); }
public void AddTargetEmailAddress(string address, string recipientField,bool isInternal) { IRoutingItem toRoutingItem = new RoutingItem(address); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, recipientField); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, address); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.Internal, isInternal.ToString()); m_uro.Destination.Items.Add(toRoutingItem); }
public void AddSourceEmailAddress(string address) { IRoutingItem sourceRoutingItem = new RoutingItem(address); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, address); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.Internal, bool.FalseString); m_uro.Source.Items.Add(sourceRoutingItem); }
private static void PopulateSourceFromMailMessage(UniversalRequestObject uro, System.Net.Mail.MailMessage mailMessage) { uro.Source.PolicyType = uro.PolicyType; uro.Source.Properties = new Dictionary<string, string>(); uro.Source.Items = new Collection<IRoutingItem>(); RoutingItem routingItem = new RoutingItem(mailMessage.From.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailMessage.From.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(routingItem); }
public void Test03_TestInternalRecipients_InvalidArgs() { PolicyResponseObject pro1 = GetPRO(); IRoutingItem sourceRoutingItem = new RoutingItem(""); sourceRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.From; pro1.UniversalRequestObject.Source.Items.Add(sourceRoutingItem); IRoutingItem toRoutingItem = new RoutingItem(null); toRoutingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.To; pro1.UniversalRequestObject.Destination.Items.Add(toRoutingItem); IPolicyResponseObject iPro = pro1 as IPolicyResponseObject; InternalExternalHelper.SetMessageRouting(iPro); }
static private void ClearDuplicateAddresses(Collection<IRoutingItem> addresses) { char[] splitParams = { ',' }; if (addresses != null) { for (int i = 0; i < addresses.Count; i++) { if ((!string.IsNullOrEmpty(addresses[i].Content) && (addresses[i].Content.IndexOf(',') >= 0))) { string[] splitAddresses = addresses[i].Content.Split(splitParams); string splitAddress = splitAddresses[0]; IRoutingItem newRoutingItem = new RoutingItem(splitAddress); foreach (KeyValuePair<string, string> kvp in addresses[i].Properties) { newRoutingItem.Properties.Add(kvp.Key, kvp.Value); } addresses[i] = newRoutingItem; } } } }
internal static IUniversalRoutingEntity GetUniversalRoutingEntity(RoutingEntity routingEntity) { if (null == routingEntity) return null; UniversalRoutingEntity routing = new UniversalRoutingEntity(); routing.PolicyType = (PolicyType)Enum.Parse(typeof(PolicyType), routingEntity.PolicyType); routing.RoutingType = routingEntity.RoutingType; routing.Items = new Collection<IRoutingItem>(); if (routingEntity.Items != null) { foreach (Workshare.PolicyContent.RoutingItem routingItem in routingEntity.Items) { Workshare.Policy.Routing.RoutingItem item = new Workshare.Policy.Routing.RoutingItem(routingItem.Content); item.Properties = new Dictionary<string, string>(); if (routingItem.Properties != null) { foreach (CustomProperty custProp in routingItem.Properties) { item.Properties[custProp.Name] = custProp.Value; } } routing.Items.Add(item); } } routing.Properties = new Dictionary<string, string>(); if (routingEntity.Properties != null) { foreach (CustomProperty property in routingEntity.Properties) { routing.Properties[property.Name] = property.Value; } } return routing; }
public UniversalRoutingEntity(UniversalRoutingEntity source) { m_policyType = source.PolicyType; m_routingType = source.RoutingType; m_properties = new Dictionary<string,string>(); foreach (KeyValuePair<string,string> property in source.Properties) { m_properties.Add(property.Key, property.Value); } m_items = new Collection<IRoutingItem>(); foreach (IRoutingItem sourceRoutingItem in source.Items) { RoutingItem routingItem = new RoutingItem(sourceRoutingItem.Content); foreach (KeyValuePair<string, string> property in sourceRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_items.Add(routingItem); } }
private void ProcessSMTPRouting() { m_sourceEntity.PolicyType = m_uro.PolicyType; m_sourceEntity.Properties = new Dictionary<string, string>(); m_sourceEntity.Items = new Collection<IRoutingItem>(); if (m_uro.Source != null) { foreach (IRoutingItem sourceRoutingItem in m_uro.Source.Items) { RoutingItem routingItem = new RoutingItem(sourceRoutingItem.Content); foreach (KeyValuePair<string, string> property in sourceRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_sourceEntity.Items.Add(routingItem); } } m_destinationEntity.PolicyType = m_uro.PolicyType; m_destinationEntity.Properties = new Dictionary<string, string>(); m_destinationEntity.Items = new Collection<IRoutingItem>(); if (m_uro.Destination != null) { foreach (IRoutingItem destinationRoutingItem in m_uro.Destination.Items) { RoutingItem routingItem = new RoutingItem(destinationRoutingItem.Content); foreach (KeyValuePair<string, string> property in destinationRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_destinationEntity.Items.Add(routingItem); } } }
public static UniversalRequestObject GetUro(bool bAddAttachments) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem); IRoutingItem ccRoutingItem1 = new RoutingItem("*****@*****.**"); ccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem1); IRoutingItem ccRoutingItem2 = new RoutingItem("*****@*****.**"); ccRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem2); IRoutingItem bccRoutingItem = new RoutingItem("*****@*****.**"); bccRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.BCC); uro.Destination.Items.Add(bccRoutingItem); if (bAddAttachments) { string attachment1 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment1.txt"); string attachment2 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment2.txt"); string attachment3 = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestURO_Attachments\attachment3.txt"); RequestAttachment ra = new RequestAttachment(); ra.FileName = attachment1; ra.Name = Path.GetFileName(attachment1); ra.File = new Workshare.FCS.Lite.Interface.File(attachment1, Path.GetFileNameWithoutExtension(attachment1)); ra.ContentType = "text"; uro.Attachments.Add(ra); RequestAttachment ra2 = new RequestAttachment(); ra2.FileName = attachment2; ra2.Name = Path.GetFileName(attachment2); ra2.File = new Workshare.FCS.Lite.Interface.File(attachment2, Path.GetFileNameWithoutExtension(attachment2)); ra2.ContentType = "fish"; uro.Attachments.Add(ra2); RequestAttachment ra3 = new RequestAttachment(); ra3.FileName = attachment3; ra3.Name = Path.GetFileName(attachment3); ra3.File = new Workshare.FCS.Lite.Interface.File(attachment3, Path.GetFileNameWithoutExtension(attachment3)); ra3.ContentType = "TEXT"; uro.Attachments.Add(ra3); } return uro; }
public void TestIsMatch() { //set up activation context here so that the real code doesn't try to read the manifest from the nunit shadow cache using (WsActivationContext wsac = new WsActivationContext()) { //test setup Workshare.Policy.Routing.InternalExternalRouter router = new Workshare.Policy.Routing.InternalExternalRouter(); UniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientEmail; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity1.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem1 = new RoutingItem("*****@*****.**"); smtpRoutingItem1.Properties[SMTPItemPropertyKeys.Internal] = true.ToString(); sourceEntity1.Items.Add(smtpRoutingItem1); UniversalRoutingEntity smtpTargetEntity = new UniversalRoutingEntity(); smtpTargetEntity.PolicyType = PolicyType.ClientEmail; smtpTargetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; smtpTargetEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpTargetRoutingItem = new RoutingItem("Recipients:Internal"); smtpTargetEntity.Items.Add(smtpTargetRoutingItem); //test null data Assert.IsFalse(router.IsMatch(sourceEntity1, null), "Expected null data to return false"); Assert.IsFalse(router.IsMatch(null, smtpTargetEntity), "Expected null data to return false"); Assert.IsFalse(router.IsMatch(null, null), "Expected null data to return false"); //nominal case - includes internal only Assert.IsTrue(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected nominal internal address to return true"); // mixture of internal and external UniversalRoutingEntity sourceEntity2 = new UniversalRoutingEntity(); sourceEntity2.PolicyType = PolicyType.ClientEmail; sourceEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity2.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem2 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem2); RoutingItem smtpRoutingItem3 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem3); Assert.IsFalse(router.IsMatch(sourceEntity2, smtpTargetEntity), "Expected mixture of internal and external address to return false"); //external only UniversalRoutingEntity sourceEntity3 = new UniversalRoutingEntity(); sourceEntity3.PolicyType = PolicyType.ClientEmail; sourceEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity3.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem4 = new RoutingItem("*****@*****.**"); sourceEntity3.Items.Add(smtpRoutingItem4); Assert.IsFalse(router.IsMatch(sourceEntity3, smtpTargetEntity), "Expected external address to return false"); //mismatching request type sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected mismatching request type to return false"); sourceEntity1.PolicyType = PolicyType.ClientEmail; //mismatching routing type sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected mismatching routing type to return false"); sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //no routing items in source sourceEntity2.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity2, smtpTargetEntity), "Expected no routing items in source to return false"); //no routing items in target smtpTargetEntity.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected no routing items in destination to return false"); //no request channel property sourceEntity1.Properties.Remove(SMTPPropertyKeys.RequestChannel); Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected missing requestchannel property to return false"); } }
RoutingItem GetRoutingItem(string content, string displayname, string addresstype) { RoutingItem retVal = new RoutingItem(content); retVal.Properties["DisplayName"] = displayname; retVal.Properties["AddressType"] = addresstype; return retVal; }
public void TestIsMatch() { //setup Workshare.Policy.Routing.LDAPRouter router = new Workshare.Policy.Routing.LDAPRouter(); UniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientEmail; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem1 = new RoutingItem("[email protected]"); sourceEntity1.Items.Add(smtpRoutingItem1); UniversalRoutingEntity sourceEntity2 = new UniversalRoutingEntity(); sourceEntity2.PolicyType = PolicyType.ClientEmail; sourceEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem2 = new RoutingItem("[email protected]"); sourceEntity2.Items.Add(smtpRoutingItem2); RoutingItem smtpRoutingItem3 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem3); UniversalRoutingEntity sourceEntity3 = new UniversalRoutingEntity(); sourceEntity3.PolicyType = PolicyType.ClientEmail; sourceEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem4 = new RoutingItem("*****@*****.**"); sourceEntity3.Items.Add(smtpRoutingItem4); UniversalRoutingEntity targetEntity1 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientEmail; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpTargetRoutingItem1 = new RoutingItem("[email protected]"); targetEntity1.Items.Add(smtpTargetRoutingItem1); RoutingItem smtpTargetRoutingItem2 = new RoutingItem("c=US;a= ;p=WSDEV;o=Exchange;s=Pair;g=SF"); targetEntity1.Items.Add(smtpTargetRoutingItem2); UniversalRoutingEntity targetEntity2 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientEmail; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //test invalid inputs Assert.IsFalse(router.IsMatch(sourceEntity1, null)); Assert.IsFalse(router.IsMatch(null, targetEntity1)); Assert.IsFalse(router.IsMatch(null, null)); //nominal - all addresses are in target Assert.IsTrue(router.IsMatch(sourceEntity1, targetEntity1), "Expected all addresses in target to return true"); //some, but not all, addresses are in target Assert.IsFalse(router.IsMatch(sourceEntity2, targetEntity1), "Expected some addresses in target to return false"); //no addresses are in target Assert.IsFalse(router.IsMatch(sourceEntity3, targetEntity1), "Expected no addresses in target to return false"); //test mismatching request type sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching request types to return false"); sourceEntity1.PolicyType = PolicyType.ClientEmail; //test mismatching routing type sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching routing types to return false"); sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //no target routing items Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity2), "Expected no target routing items to return false"); //no source routing items sourceEntity1.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected no source routing items to return false"); }
public void TestIsMatch() { IRouter deviceRouter = new Workshare.Policy.Routing.DeviceRouter.DeviceRouter(); IUniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; IRoutingItem routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); sourceEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); sourceEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); sourceEntity1.Items.Add(routingItem); IUniversalRoutingEntity targetEntity1 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientRemovableMedia; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType0"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity1.Items.Add(routingItem); IUniversalRoutingEntity targetEntity2 = new UniversalRoutingEntity(); targetEntity2.PolicyType = PolicyType.ClientRemovableMedia; targetEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity2.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity2.Items.Add(routingItem); IUniversalRoutingEntity targetEntity3 = new UniversalRoutingEntity(); targetEntity3.PolicyType = PolicyType.ClientRemovableMedia; targetEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity3.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity3.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity3.Items.Add(routingItem); IUniversalRoutingEntity targetEntity4 = new UniversalRoutingEntity(); targetEntity4.PolicyType = PolicyType.ClientRemovableMedia; targetEntity4.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity4.Items.Add(routingItem); IUniversalRoutingEntity targetEntity5 = new UniversalRoutingEntity(); targetEntity5.PolicyType = PolicyType.ClientRemovableMedia; targetEntity5.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity5.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity5.Items.Add(routingItem); IUniversalRoutingEntity targetEntity6 = new UniversalRoutingEntity(); targetEntity6.PolicyType = PolicyType.ClientRemovableMedia; targetEntity6.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity6.Items.Add(routingItem); //invalid data Assert.IsFalse(deviceRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, null), "Expected null data to return false"); Assert.IsFalse(deviceRouter.IsMatch(null, targetEntity1), "Expected null data to return false"); //nominal case. Matching Type, Id and Name are explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected nominal case to return true"); //Matching, but no volume names explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity2), "Expected unstated volume name to return true"); //Not matching, as volume name is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity3), "Expected incorrect volume name to return false"); //Matching, but no volume name or id explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity4), "Expected unstated volume id or name to return true"); //Not matching, as volume id is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity5), "Expected incorrect volume id to return false"); //Not matching, as device type is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity6), "Expected incorrect device type to return false"); //different routing types on entities sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching routing types on entities to return false"); //different request types on entities sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity1.PolicyType = PolicyType.ActiveContent; Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching request types on entities to return false"); }
private void ProcessSender(IUniversalRequestObject uro) { string senderAddress = m_emailProxy.Sender.EmailAddress; string senderName = m_emailProxy.Sender.Name; IRoutingItem routingItem = new RoutingItem(senderAddress); routingItem.Properties[SMTPItemPropertyKeys.DisplayName] = senderName; routingItem.Properties[SMTPItemPropertyKeys.AddressType] = AddressType.From; routingItem.Properties[SMTPItemPropertyKeys.Internal] = m_emailProxy.Sender.Internal.ToString(); uro.Source.Items.Add(routingItem); }
private void ProcessRecipient(IUniversalRequestObject uro, IEmailRecipient recipient, string addressType) { IRoutingItem routingItem = new RoutingItem(recipient.EmailAddress); routingItem.Properties[SMTPItemPropertyKeys.DisplayName] = recipient.Name.Trim(); routingItem.Properties[SMTPItemPropertyKeys.AddressType] = addressType; routingItem.Properties[SMTPItemPropertyKeys.Internal] = recipient.Internal.ToString(); routingItem.Properties[EmailProperties.ModifiedKey] = bool.FalseString; AddReadOnlyAttribute(routingItem); AddOrReplaceDestinationRoutingItem(uro, routingItem); }
private void ProcessRemovableDeviceRouting() { // This is the same as SMTP. Should all be the same once this has all been sorted out. m_sourceEntity.PolicyType = m_uro.PolicyType; m_sourceEntity.Properties = new Dictionary<string, string>(); m_sourceEntity.Items = new Collection<IRoutingItem>(); foreach (IRoutingItem sourceRoutingItem in m_uro.Source.Items) { RoutingItem routingItem = new RoutingItem(sourceRoutingItem.Content); foreach (KeyValuePair<string, string> property in sourceRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_sourceEntity.Items.Add(routingItem); } m_destinationEntity.PolicyType = m_uro.PolicyType; m_destinationEntity.Properties = new Dictionary<string, string>(); m_destinationEntity.Items = new Collection<IRoutingItem>(); foreach (IRoutingItem destinationRoutingItem in m_uro.Destination.Items) { RoutingItem routingItem = new RoutingItem(destinationRoutingItem.Content); foreach (KeyValuePair<string, string> property in destinationRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_destinationEntity.Items.Add(routingItem); } }
/// <summary> /// Build a routing item from the colon delimited string input. /// /// The first item in the string contains the content, with the remaining /// containing key-value pairs that define the item's properties. /// </summary> /// <param name="input"></param> /// <returns></returns> private IRoutingItem BuildRoutingItemFromString(string input) { // Strip off the content string content = String.Empty; int contentEnd = input.IndexOf('?'); if (contentEnd != -1) { content = input.Substring(0, contentEnd).Trim(); } IRoutingItem routingItem = new RoutingItem(content); string inputProperties = input.Substring(contentEnd + 1); Dictionary<string, string> properties = BuildPropertyDictionaryFromString(inputProperties); routingItem.Properties = properties; return routingItem; }
private void ProcessHTTPRouting() { m_sourceEntity.PolicyType = m_uro.PolicyType; m_sourceEntity.Properties = new Dictionary<string, string>(); m_sourceEntity.Items = new Collection<IRoutingItem>(); RoutingItem routingItem = new RoutingItem("source"); if (m_uro.Properties != null && m_uro.Properties.ContainsKey(IPPropertyKeys.OriginIP)) routingItem.Properties.Add(HTTPItemPropertyKeys.IPAddress, m_uro.Properties[IPPropertyKeys.OriginIP]); if (m_uro.Properties != null && m_uro.Properties.ContainsKey(IPPropertyKeys.OriginPort)) routingItem.Properties.Add(HTTPItemPropertyKeys.IPPort, m_uro.Properties[IPPropertyKeys.OriginPort]); m_sourceEntity.Items.Add(routingItem); m_destinationEntity.PolicyType = m_uro.PolicyType; m_destinationEntity.Properties = new Dictionary<string, string>(); m_destinationEntity.Items = new Collection<IRoutingItem>(); routingItem = new RoutingItem("destination"); if (m_uro.Properties != null && m_uro.Properties.ContainsKey(IPPropertyKeys.DestinationIP)) routingItem.Properties.Add(HTTPItemPropertyKeys.IPAddress, m_uro.Properties[IPPropertyKeys.DestinationIP]); if (m_uro.Properties != null && m_uro.Properties.ContainsKey(IPPropertyKeys.DestinationPort)) routingItem.Properties.Add(HTTPItemPropertyKeys.IPPort, m_uro.Properties[IPPropertyKeys.DestinationPort]); m_destinationEntity.Items.Add(routingItem); }
private UniversalRequestObject GetUro2() { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem1 = new RoutingItem("*****@*****.**"); toRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem1); IRoutingItem toRoutingItem2 = new RoutingItem("*****@*****.**"); toRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem2); IRoutingItem toRoutingItem3 = new RoutingItem("*****@*****.**"); toRoutingItem3.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem3); TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestPrivacy.doc"), "TestPrivacy.doc"); TestHelpers.AddAttachment(uro, "Doc", Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\TestProfanity.doc"), "TestProfanity.doc"); return uro; }
public void TestProcessPolicyWhenChangesMadeToPolicySetAfterPolicyEngineLoaded() { string testPath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\"); string rulesxml = System.IO.File.ReadAllText(testPath + "EnforceRulesU.xml"); string objectsxml = System.IO.File.ReadAllText(testPath + "EnforceObjectsU.xml"); Workshare.Policy.Engine.UroPolicyEngine engine = new Workshare.Policy.Engine.UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(-1); Assert.AreEqual(0, cache.PolicySets.Count, "Expected not policy sets to exist"); IPolicySetCache policySetCache = cache.NewPolicySet("Test"); Assert.AreEqual(1, cache.PolicySets.Count, "Expected one policy sets to exist"); policySetCache.LatestVersion.Content = System.IO.File.ReadAllText(testPath + "TestPolicyEngine.xml"); engine.PolicyCache = cache; UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "f**k"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Subject line"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.Source.PolicyType = uro.PolicyType; uro.Source.RoutingType = RoutingTypes.Source; IRoutingItem fromRoutingItem = new RoutingItem("*****@*****.**"); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(fromRoutingItem); uro.Destination.PolicyType = uro.PolicyType; uro.Destination.RoutingType = RoutingTypes.Destination; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; PolicyResponseObject conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; PolicyResponseObject rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; PolicyResponseObject actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; ContentItem content = actionPolicyInfo.ContentCollection[0] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(1, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); IPolicySetVersionCache latestVersion = cache.PolicySets[0].LatestVersion; cache.PolicySets[0].NewVersion(cache.PolicySets[0].LatestVersion.Content.Replace("(?i:f**k)", "(?i:jou ma se)")); conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[0] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(0, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); uro.Properties[MailMessagePropertyKeys.Body] = "jou ma se"; conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[0] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; Assert.AreEqual(1, policySet.PolicyReportCollection[2].ExpressionCollection[0].ExpressionDetailCollection.Count); }
public static IUniversalRequestObject CreateRemovableDeviceUro(List<string> attachments, string destinationFolder) { UniversalRequestObject uro = new UniversalRequestObject(); uro.PolicyType = PolicyType.ClientRemovableMedia; uro.Properties.Add("Subject", "profanity f**k violation"); IUniversalRoutingEntity source = uro.Source; source.PolicyType = uro.PolicyType; source.RoutingType = RoutingTypes.Source; IRoutingItem routingItem = new RoutingItem(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments")); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, "SMTP"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "pair"); source.Items.Add(routingItem); IUniversalRoutingEntity destination = uro.Destination; destination.PolicyType = uro.PolicyType; destination.RoutingType = RoutingTypes.Destination; IRoutingItem deviceIdRoutingItem = new RoutingItem("UNDEFINED"); deviceIdRoutingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); destination.Items.Add(deviceIdRoutingItem); IRoutingItem deviceNameRoutingItem = new RoutingItem("UNDEFINED"); deviceNameRoutingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); destination.Items.Add(deviceNameRoutingItem); IRoutingItem deviceTypeRoutingItem = new RoutingItem(destinationFolder); deviceTypeRoutingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); destination.Items.Add(deviceTypeRoutingItem); uro.DataTimeStamp = System.DateTime.Now; if(null == attachments) return uro; foreach(string filename in attachments) { TestHelpers.AddAttachment(uro, "Doc", filename, System.IO.Path.GetFileName(filename)); } return uro; }
public static IUniversalRequestObject CreateUro(IRequestAttachmentProvider attachmentProvider) { IUniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Harmless"); uro.Properties.Add(MailMessagePropertyKeys.Body, "Mostly harmless"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "EAT test subject"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.Properties.Add("RequestChannel", RequestChannel.Outlook.ToString()); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.PolicyType = uro.PolicyType; uro.Source.RoutingType = RoutingTypes.Source; IRoutingItem fromRoutingItem = new RoutingItem("*****@*****.**"); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "pair"); uro.Source.Items.Add(fromRoutingItem); uro.Destination.PolicyType = uro.PolicyType; uro.Destination.RoutingType = RoutingTypes.Destination; IRoutingItem toRoutingItem = new RoutingItem("*****@*****.**"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "Henry.McAlpine"); uro.Destination.Items.Add(toRoutingItem); foreach (RequestAttachment attachment in attachmentProvider.RequestAttachments) { uro.Attachments.Add(attachment); } return uro; }
public void TestProcessZipPolicy() { string testPath = Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\projects\Hygiene\src\TestDocuments\"); UroPolicyEngine engine = new UroPolicyEngine(); IPolicyCache cache = new MockPolicyCache(-1); Assert.AreEqual(0, cache.PolicySets.Count, "Expected not policy sets to exist"); IPolicySetCache policySetCache = cache.NewPolicySet("Test"); Assert.AreEqual(1, cache.PolicySets.Count, "Expected one policy sets to exist"); policySetCache.LatestVersion.Content = System.IO.File.ReadAllText(testPath + "BlockZipFilesAndZipWordFilesPolicy.xml"); engine.PolicyCache = cache; UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "You breaka my policy, I breaka you're middle toe"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Zip my attachment if they are word doc and block zip attachments"); uro.Properties.Add(MailMessagePropertyKeys.Attachments, "I am a dirty zip.zip; Dirty.doc"); // Add a zip attachment RequestAttachment zipAttachment = TestHelpers.AddAttachment(uro, RequestObjectContentType.ZIP, testPath + "I am a dirty zip.zip", "I am a dirty zip.zip"); // Add a word doc RequestAttachment wordAttachment = TestHelpers.AddAttachment(uro, RequestObjectContentType.DOC, testPath + "Dirty.doc", "Dirty.doc"); uro.Source.PolicyType = uro.PolicyType; uro.Source.RoutingType = RoutingTypes.Source; IRoutingItem fromRoutingItem = new RoutingItem("*****@*****.**"); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); fromRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "pair"); uro.Source.Items.Add(fromRoutingItem); uro.Destination.PolicyType = uro.PolicyType; uro.Destination.RoutingType = RoutingTypes.Destination; IRoutingItem toRoutingItem = new RoutingItem("sam test"); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); toRoutingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "sam test"); uro.Destination.Items.Add(toRoutingItem); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = DateTime.Now; PolicyResponseObject conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; PolicyResponseObject rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; PolicyResponseObject actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; Assert.AreEqual(4, actionPolicyInfo.ContentCollection.Count); ContentItem content = actionPolicyInfo.ContentCollection[1] as ContentItem; PolicySetResponse policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse zipPolicyInfo = policySet.PolicyReportCollection[1]; Assert.IsTrue(zipPolicyInfo.Triggered); content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; IPolicyResponse wordPolicyInfo = policySet.PolicyReportCollection[0]; Assert.IsFalse(wordPolicyInfo.Triggered); // Remove the zip attachment. uro.Attachments.Remove(zipAttachment); conditionPolicyInfo = engine.ProcessConditions(RunAt.Client, uro) as PolicyResponseObject; rountingPolicyInfo = engine.ProcessRoutings(conditionPolicyInfo) as PolicyResponseObject; actionPolicyInfo = engine.ProcessActions(rountingPolicyInfo) as PolicyResponseObject; content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; zipPolicyInfo = policySet.PolicyReportCollection[1]; Assert.IsFalse(zipPolicyInfo.Triggered); content = actionPolicyInfo.ContentCollection[1] as ContentItem; policySet = content.PolicySetCollection[0] as PolicySetResponse; wordPolicyInfo = policySet.PolicyReportCollection[0]; Assert.IsTrue(wordPolicyInfo.Triggered); Assert.AreEqual(1, actionPolicyInfo.UniversalRequestObject.Attachments.Count); Assert.AreEqual(RequestObjectContentType.DOC, actionPolicyInfo.UniversalRequestObject.Attachments[0].ContentType); Assert.AreEqual("Dirty.doc", Path.GetFileName(actionPolicyInfo.UniversalRequestObject.Attachments[0].Name)); IUniversalRequestObject outputUro = engine.ExecuteActions(actionPolicyInfo); Assert.AreEqual(1, outputUro.Attachments.Count, "Expected a zip attachment to be created"); IRequestAttachment outputAttachment = outputUro.Attachments[0]; Assert.AreEqual("Dirty.zip", Path.GetFileName(outputUro.Attachments[0].Name), "Is LDAP configured correctly?"); CheckZipFile(outputUro.Attachments[0].Data.AsStream(), new string[] { "Dirty.doc" }, true, "", false); }
private void PopulateSourceFromMailMessage(MailMessage mailMessage) { m_source.Properties = new Dictionary<string, string>(); m_source.Items = new Collection<IRoutingItem>(); RoutingItem routingItem = new RoutingItem(mailMessage.From.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailMessage.From.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); m_source.Items.Add(routingItem); }
private UniversalRequestObject GetUro3(bool bAddAttachments) { UniversalRequestObject uro = new UniversalRequestObject(); uro.Properties.Add(MailMessagePropertyKeys.FileHeader, "Stuff"); uro.Properties.Add(MailMessagePropertyKeys.Body, "4408 0412 3456 7890 piss"); uro.Properties.Add(MailMessagePropertyKeys.Subject, "Random Subject line"); if (bAddAttachments) uro.Properties.Add(MailMessagePropertyKeys.Attachments, "attachment1.txt; f**k.txt; c**t.txt"); else uro.Properties.Add(MailMessagePropertyKeys.Attachments, ""); uro.PolicyType = PolicyType.ClientEmail; uro.DataTimeStamp = System.DateTime.Now; uro.Source.RoutingType = RoutingTypes.Source; uro.Source.PolicyType = uro.PolicyType; IRoutingItem sourceRoutingItem = new RoutingItem("*****@*****.**"); sourceRoutingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.From); uro.Source.Items.Add(sourceRoutingItem); uro.Destination.RoutingType = RoutingTypes.Destination; uro.Destination.PolicyType = uro.PolicyType; IRoutingItem toRoutingItem1 = new RoutingItem("*****@*****.**"); toRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem1); IRoutingItem toRoutingItem2 = new RoutingItem("*****@*****.**"); toRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); uro.Destination.Items.Add(toRoutingItem2); IRoutingItem ccRoutingItem1 = new RoutingItem("*****@*****.**"); ccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem1); IRoutingItem ccRoutingItem2 = new RoutingItem("*****@*****.**"); ccRoutingItem2.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(ccRoutingItem2); IRoutingItem bccRoutingItem1 = new RoutingItem("*****@*****.**"); bccRoutingItem1.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); uro.Destination.Items.Add(bccRoutingItem1); if (bAddAttachments) { RequestAttachment ra = new RequestAttachment((new ASCIIEncoding()).GetBytes("tuff")); ra.Name = "attachment1.txt"; ra.ContentType = "text"; uro.Attachments.Add(ra); RequestAttachment ra2 = new RequestAttachment((new ASCIIEncoding()).GetBytes("is a big fishy, yes?")); ra2.Name = "f**k.txt"; ra2.ContentType = "fish"; uro.Attachments.Add(ra2); RequestAttachment ra3 = new RequestAttachment((new ASCIIEncoding()).GetBytes("tuff")); ra3.Name = "c**t.txt"; ra3.ContentType = "TEXT"; uro.Attachments.Add(ra3); } return uro; }
private void PopulateDestinationFromMailMessage(MailMessage mailMessage) { m_destination.Properties = new Dictionary<string, string>(); m_destination.Items = new Collection<IRoutingItem>(); foreach (MailAddress mailAddress in mailMessage.To) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.To); m_destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.CC) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.CC); m_destination.Items.Add(routingItem); } foreach (MailAddress mailAddress in mailMessage.Bcc) { RoutingItem routingItem = new RoutingItem(mailAddress.Address); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, mailAddress.User); routingItem.Properties.Add(SMTPItemPropertyKeys.AddressType, AddressType.BCC); m_destination.Items.Add(routingItem); } }