/// <summary>
		/// Re-apply password to zip contents(recursively)
		/// Remove temp files generated by original zip unpacking (and used by action processing)
		/// Note: We do NOT re-apply the zip files password here, ReEncryptAttachment() does it at higher level
		/// </summary>
		/// <param name="zipContainerAttachment"></param>
		/// <param name="ui"></param>
		/// <param name="cancelSend"></param>
		/// <returns></returns>
		private bool EncryptZipContents(Attachment zipContainerAttachment, IContentEncryptionUi ui, out bool cancelSend)
		{
			Logger.LogInfo("EncryptZipContents called for:" + zipContainerAttachment.FileName);

			cancelSend = false;

			using (var tempFileController = new TempFileController()) // Remember the temp files we generated.
			{
				for (int i = 0; i < zipContainerAttachment.File.Files.Count; i++) // So we can recreate FCS files on fly
				{
					IFile file = (IFile) zipContainerAttachment.File.Files[i];
					Attachment tmpAttachment = new Attachment(file, "contenttype", file.ContentId, null, false);

					// This attachment may be itself a zip; so before we re-encrypt it, we need to re-encrypt its contents.
					if (!ProcessContainerContents(tmpAttachment, ui, false, out cancelSend))
					{
						return false;
					}

					// Ignore the return value, this will fail if the attachment was not encrypted originally.
					ReEncryptAttachment(tmpAttachment);

					// Ensure the changes get copied back
					zipContainerAttachment.File.Files[i] = tmpAttachment.File;
					tempFileController.Add(file.FileName);
				}

				// Re-create the actual zip file with the now processed files
				if (!zipContainerAttachment.File.PackContainer(string.Empty))
				// Don't specify a password at this point, allow ReEncryptAttachment()
				{
					LastErrorText = string.Format("Unable to repack [{0}]", zipContainerAttachment.File.FileName);
					Logger.LogError(LastErrorText);
					return false;
				}
			}

			return true;
		}
Пример #2
0
        protected string GetExtensionForMasqueradingAttachment(OutlookAttachment attachment)
        {
            if (attachment.FileName.Contains('~')) // only interested in 8.3 formated file names.
            {
                var extension = Path.GetExtension(attachment.FileName);

                if (!string.IsNullOrEmpty(extension))
                {
                    using (var tfc = new TempFileController())
                    {
                        var tempfile = tfc.GetTempFilename(extension.TrimStart('.'), true);
                        attachment.SaveAsFile(tempfile);

                        using (IFile file = new Workshare.FCS.Lite.Interface.File(tempfile, attachment.DisplayName))
                        {
                            switch (file.FileType)
                            {
                                case FileType.WordDocumentX:
                                    return "docx";
                                case FileType.ExcelSheetX:
                                    return "xlsx";
                                case FileType.PowerPointX:
                                    return "pptx";
                            }
                        }
                    }
                }
            }
            return string.Empty;
        }