internal static Workshare.PolicyContent.ContentItem GetContentItem(IContentItem contentIn, bool keepContentBytes) { bool useFileInstead = false; if (null == contentIn) throw new ArgumentNullException("contentIn"); useFileInstead = contentIn.Properties.ContainsKey(ContentDataSourceKey); Workshare.PolicyContent.ContentItem contentOut = new Workshare.PolicyContent.ContentItem(); contentOut.ContentType = contentIn.Type; contentOut.Encrypted = contentIn.Encrypted; contentOut.Name = contentIn.Name; contentOut.DisplayName = contentIn.DisplayName; contentOut.Size = contentIn.Size; List<CustomProperty> properties = new List<CustomProperty>(); if (keepContentBytes && !useFileInstead) contentOut.Content = GetContentBytes(contentIn); if (useFileInstead) { string filename = contentIn.Properties[ContentDataSourceKey]; if (string.IsNullOrEmpty(filename)) // need to create new file then { filename = Path.GetTempFileName(); contentIn.Properties[ContentDataSourceKey] = filename; GetContentToFile(contentIn, filename); } } int index = 0; if (contentIn.Properties != null && contentIn.Properties.Count > 0) { HandleContentIds(contentIn, contentOut); foreach (KeyValuePair<string, string> kvp in contentIn.Properties) { CustomProperty cp = new CustomProperty(kvp.Key, kvp.Value); properties.Add(cp); } } contentOut.Properties = properties.ToArray(); contentOut.PolicySets = new PolicySet[contentIn.PolicySetCollection.Count]; index = 0; foreach (IPolicySetResponse response in contentIn.PolicySetCollection) { contentOut.PolicySets[index++] = PolicySetAdaptor.GetPolicySet(response); } return contentOut; }
protected static void SetPropertyValue(CustomProperty[] properties, string propertyName, string newValue) { if ((null == properties) || string.IsNullOrEmpty(propertyName)) return; foreach (CustomProperty property in properties) { if (propertyName == property.Name) property.Value = newValue; } }
protected static string GetPropertyValue(CustomProperty[] properties, string propertyName) { if ((null == properties) || string.IsNullOrEmpty(propertyName)) return string.Empty; foreach (CustomProperty property in properties) { if (propertyName == property.Name) return property.Value; } return string.Empty; }
public void TestSkipVerified_GetPolicyResponse() { Workshare.PolicyContent.Policy @in = new Workshare.PolicyContent.Policy(); IPolicyResponse @out = PolicyAdaptor.GetIPolicyResponse(@in); Assert.IsFalse(@out.SkipVerifiedMessages, "By default assume that skipverified is false."); CustomProperty skipVerified = new CustomProperty(PolicyConstants.SkipVerifiedMessages, bool.TrueString); @in.Properties = new CustomProperty[] { skipVerified }; @out = PolicyAdaptor.GetIPolicyResponse(@in); Assert.IsTrue(@out.SkipVerifiedMessages, "The value should correspond to the custom property."); @in.Properties[0].Value = bool.FalseString; @out = PolicyAdaptor.GetIPolicyResponse(@in); Assert.IsFalse(@out.SkipVerifiedMessages, "The value should correspond to the custom property."); }
/// <summary> /// Create a basic ClientMail request. /// </summary> /// <remarks> /// Sets up the destination and source routing etc /// </remarks> /// <returns></returns> public static Request CreateRequest(CustomProperty[] properties) { Request request = new Request(); request.PolicyType = PolicyType.ClientEmail.ToString(); request.DateTime = DateTime.Now; request.Properties = properties; RoutingEntity source = new RoutingEntity(); request.Source = source; source.PolicyType = request.PolicyType; source.RoutingType = Workshare.PolicyContent.RoutingTypes.Source; source.Properties = new CustomProperty[] { new CustomProperty(SMTPPropertyKeys.RequestChannel, RequestChannel.Outlook) }; PolicyContent.RoutingItem item = new PolicyContent.RoutingItem(); item.Content = "*****@*****.**"; item.Properties = new CustomProperty[] { new CustomProperty(SMTPItemPropertyKeys.DisplayName, "lnpair"), new CustomProperty(SMTPItemPropertyKeys.AddressType, AddressType.From) }; source.Items = new PolicyContent.RoutingItem[] { item }; // Populate the destination routing entity RoutingEntity dest = new RoutingEntity(); request.Destination = source; dest.PolicyType = request.PolicyType; dest.RoutingType = Workshare.PolicyContent.RoutingTypes.Destination; dest.Properties = new CustomProperty[] { new CustomProperty(SMTPPropertyKeys.RequestChannel, RequestChannel.Outlook) }; item = new PolicyContent.RoutingItem(); item.Content = "*****@*****.**"; item.Properties = new CustomProperty[] { new CustomProperty(SMTPItemPropertyKeys.DisplayName, "lnpair"), new CustomProperty(SMTPItemPropertyKeys.AddressType, AddressType.From) , new CustomProperty(SMTPItemPropertyKeys.Internal, bool.FalseString)}; dest.Items = new PolicyContent.RoutingItem[] { item }; return request; }
public void TestClientVerified_GetPro() { Response response = new Response(); response.Contents = new Workshare.PolicyContent.ContentItem[0]; Request request = new Request(); request.PolicyType = PolicyType.Mta.ToString(); Workshare.Policy.IContainer container; IPolicyResponseObject pro = ResponseAdaptor.GetPRO(response, request, out container); Assert.IsFalse(pro.VerifiedOnClient, "Expect this to be false - the input reponse did not have the CustomProperty that governs this flag."); CustomProperty verifiedOnClient = new CustomProperty(PolicyConstants.ClientVerified, bool.FalseString); response.Properties = new CustomProperty[] { verifiedOnClient }; pro = ResponseAdaptor.GetPRO(response, request, out container); Assert.IsFalse(pro.VerifiedOnClient, "Expect this to be false - the input response CustomProperty has a value of false."); response.Properties[0].Value = bool.TrueString; pro = ResponseAdaptor.GetPRO(response, request, out container); Assert.IsTrue(pro.VerifiedOnClient, "Expect this to be true - the input response CustomProperty has a value of true."); }
private string GetPropertyValue(string propertyName, CustomProperty[] properties) { foreach (CustomProperty prop in properties) { if (0 == string.Compare(propertyName, prop.Name, StringComparison.InvariantCultureIgnoreCase)) return prop.Value; } throw new ArgumentException("propertyName "); }
private void ProcessMimeContentProperty(Request request) { CustomProperty mimeProperty = new CustomProperty(MailMessagePropertyKeys.MimeContent, m_emailProxy.MimeContent); List<CustomProperty> props = new List<CustomProperty>(request.Properties); props.Add(mimeProperty); request.Properties = props.ToArray(); }
private void ProcessHeaders(Request request) { CustomProperty priority = new CustomProperty(MailMessagePropertyKeys.xPriority, string.Empty); switch (m_emailProxy.Priority) { case Priority.High: priority.Value = "1"; break; case Priority.Normal: priority.Value = "3"; break; case Priority.Low: priority.Value = "5"; break; default: break; } List<CustomProperty> props = new List<CustomProperty>(request.Properties); props.Add(priority); request.Properties = props.ToArray(); }
private string GetPropertyValue(string propName, CustomProperty[] customProperties) { foreach (CustomProperty prop in customProperties) { if (0 == string.Compare(prop.Name, propName, StringComparison.InvariantCultureIgnoreCase)) return prop.Value; } return null; }
private void ProcessRecipient(Request request, IEmailRecipient recipient, string addressType) { Workshare.PolicyContent.RoutingItem routingItem = new Workshare.PolicyContent.RoutingItem(); routingItem.Content = recipient.EmailAddress; CustomProperty displayName = new CustomProperty(SMTPItemPropertyKeys.DisplayName, recipient.Name.Trim()); CustomProperty addressTypeProp = new CustomProperty(SMTPItemPropertyKeys.AddressType, addressType); CustomProperty internalFlag = new CustomProperty(SMTPItemPropertyKeys.Internal, recipient.Internal.ToString()); CustomProperty modified = new CustomProperty(EmailProperties.ModifiedKey, bool.FalseString); routingItem.Properties = new CustomProperty[] { displayName, addressTypeProp, internalFlag, modified }; AddReadOnlyAttribute(routingItem); AddOrReplaceDestinationRoutingItem(request, routingItem); }
private void ProcessSender(Request request) { string senderAddress = m_emailProxy.Sender.EmailAddress; string senderName = m_emailProxy.Sender.Name; Workshare.PolicyContent.RoutingItem routingItem = new Workshare.PolicyContent.RoutingItem(); routingItem.Content = senderAddress; CustomProperty displayName = new CustomProperty(SMTPItemPropertyKeys.DisplayName, senderName); CustomProperty addressType = new CustomProperty(SMTPItemPropertyKeys.AddressType, AddressType.From); CustomProperty internalFlag = new CustomProperty(SMTPItemPropertyKeys.Internal, m_emailProxy.Sender.Internal.ToString()); routingItem.Properties = new CustomProperty[] { displayName, addressType, internalFlag }; request.Source.Items = new Workshare.PolicyContent.RoutingItem[] { routingItem }; }
private string AddAttachment(Request request, IEmailAttachment attachment) { string contentType = MimeAttachmentsProxy.GetContentType(attachment); string attachmentName = attachment.DisplayName; // 14781 - CR: 00180301 Professional 7.00 FP3 - Rodyk - Illegal Characters in Path error sending MSG attachments var invalidFileNameCharacters = Path.GetInvalidFileNameChars(); if (attachmentName.IndexOfAny(invalidFileNameCharacters) == -1) { // Hack alert. TFS6626 - customer with 'Lawsoft' which creates dodgy .msg files that have the DisplayName field of the attachment set wrongly // the DisplayName is missing the '.' separating the name and the extension. We work around this for now if (string.IsNullOrEmpty(Path.GetExtension(attachmentName)) && !string.IsNullOrEmpty(Path.GetExtension(attachment.FileName))) { // do we have a display name with no extension and a file name with an extension // there must be a '.' in the filename, since it has an extension. // now test to see if we remove the '.' separating the extension, does the filename end with the attachment name if (attachment.FileName.Remove(attachment.FileName.LastIndexOf('.'), 1).EndsWith(attachmentName)) { // yep, so we have FileName = 'c:\blah\blah\test.docx' and display name = 'testdocx' // which isn't good - as we check for profiles to display based on the extension (which would be blank) // and we re-instate only the displayname of the attachment, not the file name // so we will get the corrected display name from the filename attachmentName = Path.GetFileName(attachment.FileName); } } } string contentId = attachment.ContentId; string index = attachment.ContentItemIndex.ToString(CultureInfo.InvariantCulture); if (string.IsNullOrEmpty(contentId)) contentId = Guid.NewGuid().ToString(); IFile file = new File(attachment.FileName, attachmentName); Attachment requestAttachment = new Attachment(file, contentType, contentId, index, false); requestAttachment.IsSignature = attachment.IsSignature; if (attachment.IsSignature) { requestAttachment.IgnoreForWorkshareActions = true; } CustomProperty prop = new CustomProperty(PropertyNames.LocalFileName, attachment.FileName); if (attachment.RecordKey != null) { string recordkey = attachment.RecordKey; CustomProperty prop2 = new CustomProperty(PropertyNames.RecordKey, recordkey); requestAttachment.Properties = new CustomProperty[] { prop, prop2 }; } else { requestAttachment.Properties = new CustomProperty[] { prop }; } List<Attachment> attachments = new List<Attachment>(request.Attachments); attachments.Add(requestAttachment); request.Attachments = attachments.ToArray(); return attachmentName; }
private static Request GetRequest(string file) { Request request = new Request(); request.PolicyType = PolicyType.ActiveContent.ToString(); request.DateTime = System.DateTime.Now; List<CustomProperty> props = new List<CustomProperty>(); props.Add(new CustomProperty(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.UserName, System.Environment.UserName)); props.Add(new CustomProperty(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.Application, "Professional.Policy.Inspector")); props.Add(new CustomProperty(Workshare.Policy.Interfaces.ActiveContentPropertyKeys.MachineName, System.Environment.MachineName)); request.Properties = props.ToArray(); Attachment attachment = new Attachment(System.IO.Path.GetFileName(file), "", null, "0", false); attachment.Content = System.IO.File.ReadAllBytes(file); request.Attachments = new Attachment[] { attachment }; request.Source = new RoutingEntity(); request.Source.RoutingType = "Source"; request.Source.PolicyType = request.PolicyType; request.Source.Items = new RoutingItem[1]; request.Source.Items[0] = new RoutingItem(); request.Source.Items[0].Content = System.Environment.UserName; request.Source.Items[0].Properties = new CustomProperty[2]; CustomProperty addressType = new CustomProperty(); addressType.Name = Workshare.Policy.Routing.SMTPItemPropertyKeys.AddressType; addressType.Value = Workshare.Policy.Routing.AddressType.CurrentUser; request.Source.Items[0].Properties[0] = addressType; CustomProperty displayName = new CustomProperty(); displayName.Name = Workshare.Policy.Routing.SMTPItemPropertyKeys.DisplayName; displayName.Value = System.Environment.UserName; request.Source.Items[0].Properties[1] = displayName; return request; }
// Migrate content properties from the document to the zip. (This is a helper method for the Zip Action processing.) private static void MigrateContentPropertiesFromDocumentToZip(ContentItem documentContentItem, string zipFilePath, out CustomProperty[] zipProperties) { var docProps = new List<CustomProperty>(); // Precreate the local file name property in the zip's list. var zipProps = new List<CustomProperty> { new CustomProperty("LocalFileName", zipFilePath) }; // Iterate all properties and decide where to put them. foreach (CustomProperty property in documentContentItem.Properties) { switch (property.Name) { case "LocalFileName": // Only add the local file name to the doc's list. docProps.Add(property); break; case "RecordKey": // The record key is now only for the zip. zipProps.Add(property); break; default: // Add unknown properties to both property lists. docProps.Add(property); // Make a copy for the zip's list. zipProps.Add(new CustomProperty(property.Name, property.Value)); break; } } // Convert the lists into arrays which are returned. documentContentItem.Properties = docProps.ToArray(); zipProperties = zipProps.ToArray(); }
private bool PropertyIsTrue(CustomProperty[] properties, string propertyName) { string value = PolicyManagerUtils.GetPropertyValue(properties, propertyName); return (!string.IsNullOrEmpty(value) && Convert.ToBoolean(value, CultureInfo.InvariantCulture)); }
public static Request GetRequest(IUniversalRequestObject uroIn) { if (null == uroIn) throw new ArgumentNullException("uroIn"); Request requestOut = new Request(); requestOut.DateTime = uroIn.DataTimeStamp; requestOut.Source = RoutingEntityAdaptor.GetRoutingEntity(uroIn.Source); requestOut.Destination = RoutingEntityAdaptor.GetRoutingEntity(uroIn.Destination); requestOut.PolicyType = uroIn.PolicyType.ToString(); requestOut.Properties = new CustomProperty[0]; if ( uroIn.Properties != null && uroIn.Properties.Count > 0) { List<CustomProperty> props = new List<CustomProperty>(); foreach (KeyValuePair<string, string> pair in uroIn.Properties) { props.Add(new CustomProperty(pair.Key, pair.Value)); } requestOut.Properties = props.ToArray(); } requestOut.Attachments = new Attachment[0]; if ( uroIn.Attachments != null && uroIn.Attachments.Count > 0) { bool returnFile = uroIn.Properties.ContainsKey(RequestAdaptor.PassContentAsFileProperty); List<Attachment> attachments = new List<Attachment>(); foreach (RequestAttachment attachment in uroIn.Attachments) { attachments.Add( returnFile ? AttachmentAdaptor.GetAttachmentAsFile(attachment) : AttachmentAdaptor.GetAttachment(attachment)); } requestOut.Attachments = attachments.ToArray(); } RequestAttachment mimeAttachment = uroIn.OriginalContentBytes; if ( mimeAttachment != null) { CustomProperty mimeProperty = new CustomProperty(SMTPPropertyTags.OriginalMimeContent, mimeAttachment.Data.AsString(mimeAttachment.Data.Length, Encoding.Unicode)); CustomProperty[] oldProps = requestOut.Properties; List<CustomProperty> newProps = new List<CustomProperty>(oldProps); newProps.Add(mimeProperty); requestOut.Properties = newProps.ToArray(); } return requestOut; }