Exemplo n.º 1
0
        public void TestCleanPdfExcludeAttachments()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "Comments_Bookmarks_Attachments_Markups.pdf");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "Comments_Bookmarks_Attachments_Markups"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Attachments).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Properties).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Bookmarks).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Markups).Count > 0);

            var task = new TaskCleanPdf(attachment, new TaskCleanOptions() { ExcludedMetadataTypes = new List<MetadataType>() { MetadataType.Attachments}});
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Attachments).Count > 0);
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.High.ContainsKey(MetadataType.Markups));

            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.Medium.ContainsKey(MetadataType.Markups));

            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Properties));
            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Bookmarks));
            Assert.IsFalse(attachment.RiskAnalysis.Low.ContainsKey(MetadataType.Markups));
        }
Exemplo n.º 2
0
        public bool OpenActualDocumentFromPlaceHolder(Attachment attachment)
        {
            try
            {
                if (attachment.Size > (1024*5))
                {
                    Logger.LogTrace("Returning without doing anything as the file size is > 5k");
                    return false;
                }

                using (var lcfm = new LocalCopyOfFileManager())
                {
                    string filename = lcfm.GetLocalCopyOfFileTarget(attachment.FileName);
                    attachment.SaveAsFile(filename);

                    Logger.LogTrace("Saving placeholder file to " + filename);
                    var lah = new LargeAttachmentHelper(filename);
                    if (lah.IsLargeAttachment)
                    {
                        Logger.LogTrace("Opening actual file from" + lah.ActualPath);
                        var startInfo = new ProcessStartInfo();
                        startInfo.FileName = lah.ActualPath;
                        Process.Start(startInfo);
                        return true;
                    }
                }
                return false;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                throw;
            }
        }
Exemplo n.º 3
0
        public static bool HasLargeAttachments(MailItem mailItem)
        {
            using (var lcfm = new LocalCopyOfFileManager())
            {
                var tempfile = lcfm.GetLocalCopyOfFileTarget(Guid.NewGuid().ToString());
                mailItem.SaveAs(tempfile);

                foreach (Attachment attachment in mailItem.Attachments)
                {
                    try
                    {
                        var file = lcfm.GetLocalCopyOfFileTarget(attachment.FileName);
                        attachment.SaveAsFile(file);
                        var lah = new LargeAttachmentHelper(file);
                        if (lah.IsLargeAttachment)
                        {
                            return true;
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.LogError(e);
                    }
                }
                return false;
            }
        }
Exemplo n.º 4
0
        public PlatformSaveOnline()
        {
            //WPF Support
            if (System.Windows.Application.Current == null)
                new System.Windows.Application { ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown };

            localCopyOfFileManager = new LocalCopyOfFileManager();
        }
        public void TestConstruction()
        {
			using (LocalCopyOfFileManager fileManager = new LocalCopyOfFileManager())
			{
				Assert.AreNotEqual("", fileManager.ManagedFolder.ToString(), "Expected file manager to have a temporay directory");
				Assert.AreEqual(true, System.IO.Directory.Exists(fileManager.ManagedFolder.ToString()),
				                "Expected the managed directory to exist");
			}
        }
Exemplo n.º 6
0
        public static List<string> Expand(IProtectAttachment attachment, string password, CancellationToken token, LocalCopyOfFileManager lcfm)
        {
            var files = new List<string>();
            string destination = lcfm.ManagedFolder;
            using (var fs = File.OpenRead(attachment.FileName))
            {
                var zf = new ZipFile(fs);
                if (!string.IsNullOrEmpty(password))
                {
                    zf.Password = password; // AES encrypted entries are handled automatically
                }

                int i = 0;
                foreach (ZipEntry zipEntry in zf)
                {
                    i += 1;

                    if (token.IsCancellationRequested)
                        break;

                    if (!zipEntry.IsFile)
                    {
                        continue; // Ignore directories
                    }

                    // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
                    var entryFileName = zipEntry.Name;
                    // Optionally match entrynames against a selection list here to skip as desired.
                    // The unpacked length is available in the zipEntry.Size property.

                    var fullPath = Path.Combine(Path.Combine(destination, i.ToString()) , entryFileName);
                    var directory = Path.GetDirectoryName(fullPath);
                    if (!string.IsNullOrEmpty(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    var buffer = new byte[4096]; // 4K is optimum
                    using (var zipStream = zf.GetInputStream(zipEntry))
                    {
                        // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size
                        // of the file, but does not waste memory.
                        // The "using" will close the stream even if an exception occurs.
                        using (FileStream streamWriter = File.Create(fullPath))
                        {
                            StreamUtils.Copy(zipStream, streamWriter, buffer);
                        }
                    }

                    files.Add(fullPath);
                }

                zf.IsStreamOwner = true; // Makes close also shut the underlying stream
                zf.Close(); // Ensure we release resources
            }
            return files;
        }
Exemplo n.º 7
0
        public ProtectAttachment(IFile file, LocalCopyOfFileManager lcofm = null)
            : this()
        {

            FileName = file.FileName;
            Name = file.DisplayName;
            
            File = file;
            Id = Guid.NewGuid().ToString();

            _lcofm = lcofm ?? new LocalCopyOfFileManager(true, Path.GetDirectoryName(file.FileName));
        }
        public void TestGetTempFileNameWithPath()
        {
			using (LocalCopyOfFileManager fileManager = new LocalCopyOfFileManager())
			{
				string tesfile = fileManager.GetLocalCopyOfFileTarget(m_testFilePathName);
				Assert.AreNotEqual("", fileManager.ManagedFolder.ToString(), "Expected file manager to have a temporay directory");
				Assert.AreEqual(true, System.IO.Directory.Exists(fileManager.ManagedFolder.ToString()),
				                "Expected the managed directory to exist");
				string testFilePath = string.Format(@"{0}\1\{1}", fileManager.ManagedFolder, m_testFile);

				Assert.AreEqual(testFilePath, tesfile,
				                "Expected the temporay file name to match the managed folder & the test file name");
			}
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     try
     {
         if (_lcfm != null)
         {
             _lcfm.Dispose();
             _lcfm = null;
         }
     }
     catch (Exception)
     {
         
         throw;
     }
 }
Exemplo n.º 10
0
        public void TestDocumentTracking()
        {
            var filenames = new List<string>()
                { 
                    "SupportsCleaning.doc",
                    "5DocStats2BuiltInProps.docx",
                    "హాయ్ .docx",
                    "SmallTextComplexDocument.doc",
                    "small.doc",
                    "final.docx",
                    "15Footnotes1Field5DocStats2BuiltInProps.docx"
                };

            filenames.ForEach(delegate(string x)
                {
                    var id = String.Empty;
                    try
                    {
                        var lcfm = new LocalCopyOfFileManager();
                        var sourceFile = Path.Combine(TestRoot, x);
                        Assert.IsTrue(File.Exists(sourceFile), String.Format("File does not exist [{0}]", sourceFile));

                        var testFile = lcfm.GetLocalCopyOfFileTarget(x);
                        File.Copy(sourceFile, testFile, true);
                        Assert.IsTrue(File.Exists(testFile), String.Format("File does not exist [{0}]", testFile));

                        var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, x));

                        var readyRedlineTask = new TaskReadyRedline(attachment);
                        readyRedlineTask.Execute(new CancellationToken());

                        var intelligentDocument = new IntelligentDocument();
                        intelligentDocument.SetFileName(attachment.FileName);
                        Assert.IsTrue(intelligentDocument.IsDocumentBeingTracked(), String.Format("Failed to add tracking id to test file [{0}]", x));
                        
                        id = intelligentDocument.GetDocumentTrackingId();
                        Assert.IsFalse(String.IsNullOrEmpty(id), String.Format("Failed to get tracking id for test file [{0}]", x));
                        Assert.IsFalse(String.IsNullOrEmpty(GetDocumentChecksum(id)), String.Format("Failed to get checksum for test file [{0}]", x));
                    }
                    finally
                    {
                        DeleteEntry(id);
                    }
                });
        }
Exemplo n.º 11
0
        public void AddAttachment(WsMailItem mailItem, string sourceFile)
        {
            using (var lcfm = new LocalCopyOfFileManager())
            {
                string displayName = Path.GetFileName(sourceFile) + LargeAttachmentHelper.FileExtension;
                string destinationfile = lcfm.GetLocalCopyOfFileTarget(Path.GetFileName(sourceFile)) +
                                         LargeAttachmentHelper.FileExtension;

                Logger.LogInfo(
                    string.Format(
                        "Add Large Attachment. Source File = {0}, Target DisplayName = {1}, Target File = {2}",
                        sourceFile, displayName, destinationfile));

                var attachmentManager = new BigAttachmentsManager();
                attachmentManager.AddAttachmentPlaceHolder(sourceFile, destinationfile);
                attachmentManager.AddAttachmentToMessage(mailItem, displayName, destinationfile);
            }
        }
        public void TestGetTempFileRepeated()
        {
			using (LocalCopyOfFileManager fileManager = new LocalCopyOfFileManager())
			{
				string tesfile = fileManager.GetLocalCopyOfFileTarget(m_testFile);
				string testFilePath = string.Format(@"{0}\1\{1}", fileManager.ManagedFolder, m_testFile);
				Assert.AreEqual(testFilePath, tesfile,
				                "Expected the temporay file name to match the managed folder & the test file name");

				System.IO.File.Copy(m_testFilePathName, tesfile, true);
				Assert.AreEqual(true, System.IO.File.Exists(tesfile));

				string updateTestfile = fileManager.GetLocalCopyOfFileTarget(m_testFile);
				Assert.AreNotEqual(tesfile, updateTestfile,
				                   "Expected the file to return a new sub directory path for a file that may exist already in the temp folder");
				Assert.AreEqual(true, updateTestfile.Contains("\\2\\"));
			}
        }
Exemplo n.º 13
0
		private List<SendLinkInfo> GetFilesToUpload(IEnumerable<Attachment> processedAttachments, string id)
		{
			List<SendLinkInfo> files = new List<SendLinkInfo>();

			LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager(false, GetWorkingDirectory(id));
			foreach (Attachment serviceAttachment in processedAttachments)
			{
				string displayName = serviceAttachment.Name;
				FileInfo tempFile = new FileInfo(lcofm.GetLocalCopyOfFileTarget(displayName));
				using (FileStream fs = new FileStream(tempFile.FullName, FileMode.Create))
				{
					fs.Write(serviceAttachment.Content, 0, serviceAttachment.Content.Length);
					fs.Close();
				}
				SendLinkInfo sendLinkInfo = new SendLinkInfo { ContentId = serviceAttachment.Id, DisplayName = displayName, FilePath = tempFile.FullName };
				files.Add(sendLinkInfo);
			}
			return files;
		}
Exemplo n.º 14
0
        private void UnPackZipFile(IProtectAttachment protectAttachment, CancellationToken token, string password)
        {
            if (protectAttachment.FileType != FileType.ZIP) 
                return;

            var lcfm = new LocalCopyOfFileManager();
            var files = ZipFilePackager.Expand(protectAttachment, password, token, lcfm);
            foreach (var file in files)
            {
                if (token.IsCancellationRequested)
                    return;

                ProtectAttachment attachment;
                var fileType = FileTypeBridge.GetSupportedFileType(file);
                switch (fileType)
                {
                    case FileType.Unknown:
                        {
                            attachment = new ProtectAttachment(new SimpleFile(file, Path.GetFileName(file)), lcfm);
                            break;
                        }
                    case FileType.Email:
                    case FileType.ZIP:
                    case FileType.OutlookMessageFile:
                        {
                            attachment = new ProtectAttachment(FcsFileFactory.Create(file, Path.GetFileName(file)), lcfm);
                            UnPack(attachment, token);
                            break;
                        }
                    default:
                        {
                            attachment = new ProtectAttachment(FcsFileFactory.Create(file, Path.GetFileName(file)), lcfm);
                            break;
                        }
                }

                attachment.Directory = GetDirectory(attachment.FileName, lcfm);

                protectAttachment.Children.Add(attachment);
            }
        }
Exemplo n.º 15
0
        public ProtectAttachment(Microsoft.Office.Interop.Outlook.Attachment attachment)
            : this()
        {
            // 17470 [WS 8.0] Protect files is not enabled when .msg with no subject is attached through Right click->send To->Mail Recipient.ZenQ
            Name = attachment.DisplayName ?? "";

            var filename = string.Empty;
            filename = attachment.FileName.ToLower() == ".msg"
                           ? Guid.NewGuid().ToString() + ".msg"
                           : attachment.FileName;
            // --

            Index = attachment.Index.ToString(CultureInfo.InvariantCulture);
            var wsAttachment = attachment as WsAttachment;
            if (wsAttachment != null)
            {
                Id = wsAttachment.Id.ToString();
                RecordKey = wsAttachment.RecordKey;
            }
            _lcofm = new LocalCopyOfFileManager();
            filename = _lcofm.GetLocalCopyOfFileTarget(filename);
            attachment.SaveAsFile(filename);

            var lah = new LargeAttachmentHelper(filename);
            if (lah.IsLargeAttachment)
            {
                LargeAttachmentFileName = filename;
                var tempfile = _lcofm.GetLocalCopyOfFileTarget(Path.GetFileName(lah.ActualPath));
                System.IO.File.Copy(lah.ActualPath, tempfile, true);
                filename = tempfile;
                Name = Path.GetFileName(filename);
            }

            File = FcsFileFactory.Create(filename, Name);
            Position = attachment.Position;
            FileName = filename;
        }
Exemplo n.º 16
0
        public void TestCleanTrackChanges()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "SmallTextComplexDocument.doc");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "SmallTextComplexDocument"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.TrackedChange).Count > 0);

            var task = new TaskClean(attachment, new TaskCleanOptions());
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsNull(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.TrackedChange));
            Assert.IsNull(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.Comment));

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();
        }
Exemplo n.º 17
0
        public void TestCleanStripsBinaryData()
        {
            var lcfm = new LocalCopyOfFileManager();
            var sourceFile = Path.Combine(TestRoot, "Small.doc");
            var testFile = lcfm.GetLocalCopyOfFileTarget(sourceFile);

            File.Copy(sourceFile, testFile, true);

            var attachment = new ProtectAttachment(FcsFileFactory.Create(testFile, "Small"));

            var discoveryTask = new TaskDiscovery(attachment);
            discoveryTask.Execute(new CancellationToken());

            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.DocumentStatistic).Count > 0);
            Assert.IsTrue(attachment.RiskAnalysis.DiscoveryResult.GetItemsForType(MetadataType.AttachedTemplate).Count > 0);

            var task = new TaskClean(attachment, new TaskCleanOptions());
            task.Execute(new CancellationToken());

            discoveryTask.Execute(new CancellationToken());
            Assert.IsFalse(attachment.RiskAnalysis.HasMetaData);

            new Workshare.API.Cleaning.OfficeApplicationCacheControl().ReleaseOfficeApplications();
        }
Exemplo n.º 18
0
		public void Test_05_ExecuteAction_SMTP_ZipPolicy()
		{
			IPolicyCache policyCache = TestHelpers.CreatePolicyCache(
				new string[] { Path.Combine(POLICY_FOLDER, "TestActionProcessor - Zip Policy Set.policy") });

			Assert.IsNotNull(policyCache);
			Assert.AreEqual(1, policyCache.PolicySets.Count);

			PolicyEngineCache policyEngineCache = new PolicyEngineCache(policyCache, null);
			ConditionProcessor conditionProcessor = new ConditionProcessor(policyEngineCache, null);

			List<string> attachments = new List<string>();
			using (LocalCopyOfFileManager lcfm = new LocalCopyOfFileManager())
			{
				string folderName = lcfm.ManagedFolder;

				string fileName = Path.Combine(folderName, "TestProfanity.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestProfanity.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "Dirty.doc");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "Dirty.doc"), fileName);
				attachments.Add(fileName);
				fileName = Path.Combine(folderName, "TestDoc.ppt");
				System.IO.File.Copy(Path.Combine(TEST_FOLDER, "TestDoc.ppt"), fileName);
				attachments.Add(fileName);

				IUniversalRequestObject uro = TestHelpers.CreateSmtpUro(attachments);

				// PROCESS CONDITIONS
				IContainer container;
				PolicyResponseObject pro = conditionProcessor.Process(RunAt.Client, uro, out container);
				Assert.IsNotNull(pro);

				// PROCESS ROUTING
				RoutingProcessor routingProcessor = new RoutingProcessor(policyEngineCache);
				Assert.IsNotNull(routingProcessor.Process(pro));

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));

				// PROCESS ACTIONS
				ActionProcessor actionProcessor = new ActionProcessor(policyCache, policyEngineCache);
				actionProcessor.ProcessActions(pro);

				ActionUtils.PopulateResolvedActionCollection(pro);

				// EXECUTE ACTIONS
				ActionExecuter executer = new ActionExecuter(null);
				executer.ExecuteActions(pro, ref container);

				Assert.AreEqual(4, pro.ContentCollection.Count);
				Assert.AreEqual(FileType.Email.ToString(), pro.ContentCollection[0].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[1].Type);
				Assert.AreEqual(FileType.WordDocument.ToString(), pro.ContentCollection[2].Type);
				Assert.AreEqual(FileType.PowerPoint.ToString(), pro.ContentCollection[3].Type);

				Assert.AreEqual(3, pro.UniversalRequestObject.Attachments.Count);
				Assert.AreEqual("TestProfanity.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[0].Name));
				Assert.AreEqual("Dirty.doc", Path.GetFileName(pro.UniversalRequestObject.Attachments[1].Name));
				Assert.AreEqual("TestDoc.ppt", Path.GetFileName(pro.UniversalRequestObject.Attachments[2].Name));
			}
		}
Exemplo n.º 19
0
		public void ScanAttachment_FilePathOnly_MaintainDisplayNameInAttachments()
		{
			IContentScanner scannerService = GetContentScanner();
			IContentEnforcer enforceService = GetContentEnforcer(null);

			using (LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager())
			{
				Request request =
					CreateRequest_Email("", "some message body", "<html><body>some message body</body></html>",
										"Outlook", "*****@*****.**");

				List<CustomProperty> props = new List<CustomProperty>(request.Properties);
				props.Add(new CustomProperty(RequestAdaptor.PassContentAsFileProperty, string.Empty));

				request.Properties = props.ToArray();

				AddEmailRecipient(request, "*****@*****.**", true);

				string filepath = lcofm.GetLocalCopyOfFileTarget("TriggerPolicy3.doc");
				File.Copy(Path.Combine(TESTPATH, "TriggerPolicy3.doc"), filepath);
				AddAttachment(request, filepath, true, "application/msword");

				string filepath2 = lcofm.GetLocalCopyOfFileTarget("doc13.doc");
				File.Copy(Path.Combine(TESTPATH, "doc13.doc"), filepath2);
				AddAttachment(request, filepath2, true, "application/msword");

				Response response =
					scannerService.Scan(request, null, ProcessLevel.Actions, RunAt.Client);

				Assert.AreEqual("TriggerPolicy3.doc", response.Contents[1].DisplayName,
								"Should be the friendly name only.  Not the full path");
				Assert.IsNull(response.Contents[1].Content, "Content should be empty as its passed by file");
			}
		}
Exemplo n.º 20
0
		public void ScanAttachment_IgnoreExpressionDetails()
		{
			IContentScanner scannerService = GetContentScanner();
			IContentEnforcer enforceService = GetContentEnforcer(null);

			using (LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager())
			{
				Request request =
					CreateRequest_Email("", "some message body", "<html><body>some message body</body></html>",
										"Outlook", "*****@*****.**");

				List<CustomProperty> props = new List<CustomProperty>(request.Properties);
				props.Add(new CustomProperty(RequestAdaptor.PassContentAsFileProperty, string.Empty));
				props.Add(new CustomProperty(RemovableDeviceRequestPropertyKeys.IgnoreExpressionDetail,
												true.ToString()));
				request.Properties = props.ToArray();

				AddEmailRecipient(request, "*****@*****.**", true);

				string filepath = lcofm.GetLocalCopyOfFileTarget("TriggerPolicy3.doc");
				File.Copy(Path.Combine(TESTPATH, "TriggerPolicy3.doc"), filepath);
				AddAttachment(request, filepath, true, "application/msword");

				string filepath2 = lcofm.GetLocalCopyOfFileTarget("doc13.doc");
				File.Copy(Path.Combine(TESTPATH, "doc13.doc"), filepath2);
				AddAttachment(request, filepath2, true, "application/msword");


				Response response =
					scannerService.Scan(request, null, ProcessLevel.Actions, RunAt.Client);

				Assert.AreEqual("TriggerPolicy3.doc", response.Contents[1].DisplayName,
								"Should be the friendly name only.  Not the full path");
				Assert.IsNull(response.Contents[1].Content, "Content should be empty as its passed by file");


				//Expecting to see zero item arrays where the expressiondetails would normally live.
				Assert.IsTrue(ExpressionDetailIsEmpty(response.Contents));

				if (response.ResolvedActions != null)
				{
					foreach (ResolvedAction ra in response.ResolvedActions)
					{
						Assert.IsTrue(ExpressionDetailIsEmpty(ra.Contents));
					}
				}

				//When said property is missing, expect usual behavior; nonempty expression detail collections.
				props.RemoveAll(delegate(CustomProperty cp)
									{
										return cp.Name == RemovableDeviceRequestPropertyKeys.IgnoreExpressionDetail;
									});
				request.Properties = props.ToArray();

				response = scannerService.Scan(request, null, ProcessLevel.Actions, RunAt.Client);

				//Expecting to see NON-zero item arrays where the expressiondetails would normally live.
				Assert.IsFalse(ExpressionDetailIsEmpty(response.Contents));

				if (response.ResolvedActions != null)
				{
					foreach (ResolvedAction ra in response.ResolvedActions)
					{
						Assert.IsFalse(ExpressionDetailIsEmpty(ra.Contents));
					}
				}
			}
		}
Exemplo n.º 21
0
		private bool ProcessMailSynchronously(bool bSendAndProtect, Microsoft.Office.Interop.Outlook.MailItem mailItem)
		{
            if (_lcfm == null)
                _lcfm = new LocalCopyOfFileManager(true);
            mailItem.SaveAs(_lcfm.GetLocalCopyOfFileTarget(Guid.NewGuid().ToString()));

			Logger.LogInfo("[WORKSHARE PROTECT ASYNCH-MODE] - Processing mail synchronously.");
			OutlookHookWorker outlookHookWorker = new OutlookHookWorker();
			outlookHookWorker.SendAndProtect = bSendAndProtect;
			outlookHookWorker.ProtectSimple = this.UsingProtectSimple;
            outlookHookWorker.IsDeterministicSendEnabled = IsDeterministicSendEnabled();

            outlookHookWorker.IsOutlookSecurityDisabled = DisableOutlookSecurity();

            bool result = outlookHookWorker.NotifyOfItemSend(mailItem);
			m_bIsProtectDisabledForCurrentRouting = outlookHookWorker.IsProtectDisabledForCurrentRouting;
			m_bIsSendLink = outlookHookWorker.IsSendLink;
			m_bFormattedMsgText = outlookHookWorker.FormattedMsgText;
            CleanUpForInterwovenEMM();
			if (outlookHookWorker.IsOutlookSecurityDisabled)
			{
				EnableOutlookSecurity();
			}

            return result;
		}
Exemplo n.º 22
0
        public static bool IsLargeAttachmentFile(Attachment attachment)
        {
            if (Path.HasExtension(attachment.FileName) && Path.GetExtension(attachment.FileName).ToLower() == ".wsl")
            {
                using (var lcfm = new LocalCopyOfFileManager())
                {
                    var tempFile = lcfm.GetLocalCopyOfFileTarget(attachment.FileName);
                    attachment.SaveAsFile(tempFile);

                    var lah = new LargeAttachmentHelper(tempFile);
                    return lah.IsLargeAttachment;
                }
            }
            return false;
        }
Exemplo n.º 23
0
        private string GetProposedFileName(string filename, string newExtension, bool delete = false)
        {
            var lcofm = new LocalCopyOfFileManager(delete);
            string proposedFilename = lcofm.GetLocalCopyOfFileTarget(filename ?? string.Empty);

            if (!string.IsNullOrEmpty(newExtension))
            {
                proposedFilename = Path.ChangeExtension(proposedFilename, newExtension);
            }

            return proposedFilename;
        }
	    private void Dispose(bool disposing)
	    {
	        // For embedded messages there may be circumstances where the msg file is
	        // still being accessed/deleted in other code so use try/catch to ensure
	        // that we don't fail the whole send process.
	        try
	        {
	            foreach (string s in _msgFileBackingCopies)
	            {
	                DeleteFile(s);
	            }
	            _msgFileBackingCopies.Clear();
	        }
    	    catch (Exception ex)
	        {
    	        Interop.Logging.Logger.LogError(ex);
	        }

	        try
	        {
	            foreach (string sFolder in _msgFileCreatedFolders)
	            {
	                Directory.Delete(sFolder);
	            }
	            _msgFileCreatedFolders.Clear();
	        }
	        catch (Exception ex)
	        {
	            Interop.Logging.Logger.LogError(ex);
	        }

	        CleanupTempCopies();

			_localFileManager = null;
			
			if (_mapIutils != null)
			{
				_mapIutils.Cleanup();
				
                if (Marshal.IsComObject(_mapIutils))
                {
                    Marshal.ReleaseComObject(_mapIutils);
                }
				_mapIutils = null;
			}

			if (_outlookApp != null)
			{
                if (Marshal.IsComObject(_outlookApp))
                {
				    Marshal.ReleaseComObject(_outlookApp);
                }
				_outlookApp = null;
			}
		}
Exemplo n.º 25
0
	    public void Dispose()
	    {
	        if (m_lcofm != null)
	        {
	            m_lcofm.Dispose();
	            m_lcofm = null;
	        }
	    }
Exemplo n.º 26
0
	    public BackgroundProcessor()
	    {
            _lcfm = new LocalCopyOfFileManager(true);
	    }
Exemplo n.º 27
0
		protected string GetProposedFileName(string filename, string newExtension, string id, bool delete = false)
		{
			LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager(delete, GetWorkingDirectory(id));
            string proposedFilename = lcofm.GetLocalCopyOfFileTarget(filename ?? string.Empty);   //.GetValidFileName(filename ?? string.Empty, false);

            if (!string.IsNullOrEmpty(newExtension))
            {
                proposedFilename = Path.ChangeExtension(proposedFilename, newExtension);
            }

            return proposedFilename;
		}
Exemplo n.º 28
0
        protected override void Dispose(bool disposing)
        {
            if (m_disposed)
                return;

            Utils.SafeDelete(FileName);
            if (Children != null)
            {
                foreach (var child in Children)
                {
                    child.Dispose();
                }
                Children.Clear();
            }

            if (_lcofm != null)
            {
                _lcofm.Dispose();
                _lcofm = null;
            }
            
            base.Dispose(disposing);
            m_disposed = true;
        }
Exemplo n.º 29
0
		private void OnApplicationQuit()
		{
			m_applicationEvents.MAPILogonComplete -= OnMapiLogonComplete;
			m_applicationEvents.Quit -= OnApplicationQuit;

		    if (m_distributionListCacher != null)
			{
				if (!m_distributionListCacher.HasExited)
				{
					m_distributionListCacher.Kill();
				}
			}

            if (m_outboxMonitor != null)
            {
                m_outboxMonitor.Dispose();
            }

		    if (_lcfm != null)
		    {
		        _lcfm.Dispose();
		        _lcfm = null;
		    }

		    ((IDisposable)m_application).Dispose();
		    m_application = null;
			GarbageCollect();
		}
Exemplo n.º 30
0
        internal void UpdateProxyAttachments(IProxy mailItem, Workshare.PolicyContent.Attachment[] processedAttachments)
		{
			using (LocalCopyOfFileManager lcofm = new LocalCopyOfFileManager())
			{
				for (int i = 0; i < processedAttachments.Length; ++i)
				{
					//Write processed file to disk
					Workshare.PolicyContent.Attachment serviceAttachment = processedAttachments[i];
				    string tempFileName = lcofm.GetLocalCopyOfFileTarget(serviceAttachment.Name);
                    File.Copy(serviceAttachment.FileName, tempFileName);

					//Find the matching proxy attachment
					if (0 != mailItem.ContainsAttachment(serviceAttachment.Id))
					{
						//Update existing attachment
						NotesProxy.Attachment proxyAttachment = mailItem.GetAttachmentById(serviceAttachment.Id) as NotesProxy.Attachment;
						FileInfo oldFile = new FileInfo(proxyAttachment.GetFileName());
						File.Delete(oldFile.FullName);

						//Copy processed file to original location
						string oldPath = oldFile.DirectoryName;
                        string newFile = Path.Combine(oldFile.DirectoryName, Path.GetFileName(tempFileName));
						File.Copy(tempFileName, newFile, true);

						//Update proxy attachment info
						proxyAttachment.SetFileName(newFile);
						proxyAttachment.SetDisplayName(serviceAttachment.Name);
						proxyAttachment.SetProcessStatus(AttachmentProcessStatus.ProcessStatus_Update);

                        File.Delete(tempFileName);
					}
					else
					{
						//Create a new copy before LCFM deletes the file
						string newFile = Path.Combine(GetWorkshareWorkingDirectory(), serviceAttachment.Name);
                        File.Copy(tempFileName, newFile, true);

						//Add attachment to proxy
						NotesProxy.Attachment proxyAttachment = new NotesProxy.Attachment();
						proxyAttachment.SetFileName(newFile);
						proxyAttachment.SetDisplayName(serviceAttachment.Name);
						proxyAttachment.SetProcessStatus(AttachmentProcessStatus.ProcessStatus_New);
						proxyAttachment.SetContentId(serviceAttachment.Id);
						proxyAttachment.SetContentItemIndex(-1);
						mailItem.AddAttachment(proxyAttachment);

                        File.Delete(tempFileName);
					}
				}
			}
		}