예제 #1
0
 public PowerPointEncryption(Attachment attachment, FCS.Lite.Interface.File file) :
     base(attachment, file)
 {
     switch (file.FileType)
     {
         case FileType.PowerPointX:
             m_ppFileTypeExtension = ".pptx";
             break;
         case FileType.PowerPointMacroX:
             m_ppFileTypeExtension = ".pptm";
             break;
         case FileType.PowerPointTemplateX:
             m_ppFileTypeExtension = ".potx";
             break;
         case FileType.PowerPointMacroTemplateX:
             m_ppFileTypeExtension = ".potm";
             break;
         case FileType.PowerPoint:
             m_ppFileTypeExtension = ".ppt";
             break;
         case FileType.PowerPointShowX:
             m_ppFileTypeExtension = ".ppsx";
             break;
         case FileType.PowerPointMacroShowX:
             m_ppFileTypeExtension = ".ppsm";
             break;
     }
 }
예제 #2
0
		/// <summary>
		/// Re-encrypts an attachment that was built from a decrypted attachment (changes content bytes in-place)
		/// </summary>
		public override void ReEncryptInternal(Attachment attachment)
		{
			string extension = Extension;
			string originalPath = attachment.FileName;// Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);

			ReEncrypt(originalPath);
		}
        public void DataSourceNotSpecified()
        {
            Attachment attachment = new Attachment("Hello", "txt", "xxx", "1", false); //setup
            attachment.Content = null; // set to null explicitly as this is what this test is about

            RequestAttachment reqAttach = AttachmentAdaptor.GetRequestAttachment(attachment); //execute and verify
        }
예제 #4
0
		static Attachment CreateBaseAttachment(RequestAttachment attachmentIn, string filename)
		{
			if (null == attachmentIn)
				throw new ArgumentNullException("attachmentIn");

			Attachment attachmentOut = new Attachment(new FCS.Lite.Interface.File(attachmentIn.FileName, attachmentIn.Name),
													  attachmentIn.ContentType,
													  attachmentIn.ContentId,
													  attachmentIn.ContentItemIndex.ToString(CultureInfo.InvariantCulture),
													  false);

			// We need to add all its child attachments as well (it could be a zip, or a zip in a zip in a etc)
			foreach (var file in attachmentIn.File.Files)
			{
				PopulateChildFiles(attachmentOut.File, file);
			}

			List<CustomProperty> props = new List<CustomProperty>();
			if (!string.IsNullOrEmpty(filename))
			{
				props.Add(new CustomProperty(ContentItemAdaptor.ContentDataSourceKey, filename));
			}

			foreach (string key in attachmentIn.Properties.Keys)
			{
				props.Add(new CustomProperty(key, attachmentIn.Properties[key]));
			}
			attachmentOut.Properties = props.ToArray();

			attachmentOut.IsSignature = attachmentIn.IsSignature;

			return attachmentOut;
		}
예제 #5
0
		public void VerifyAttachmentAreReadFromDisk()
		{
			//setup
			string someRandomFile = Path.GetTempFileName();
			try {

				File.WriteAllText(someRandomFile, "Hello world to you too");
			Request request = new Request();

			request.PolicyType = PolicyType.ClientEmail.ToString();
			request.Destination = new RoutingEntity();
			request.Source = new RoutingEntity();

			request.Source.Properties = new CustomProperty[] { new CustomProperty(SMTPRoutingPropertyTags.RequestChannel, "Outlook"), };
			request.Source.RoutingType = Workshare.PolicyContent.RoutingTypes.Source;

			request.Destination.Properties = new CustomProperty[] { new CustomProperty(SMTPRoutingPropertyTags.RequestChannel, "Outlook"), };
			request.Destination.RoutingType = Workshare.PolicyContent.RoutingTypes.Destination;

			request.Destination.Items = new Workshare.PolicyContent.RoutingItem[0];

			request.Source.PolicyType = request.Destination.PolicyType = request.PolicyType;

			request.DateTime = DateTime.Now;

			request.Properties = new CustomProperty[] { new CustomProperty(RequestAdaptor.PassContentAsFileProperty, string.Empty) };

			
		 
			string contentype = "text/plain";
			string id = Guid.NewGuid().ToString();
			string index = "1";


			Attachment attachment = new Attachment(someRandomFile, contentype, id, index, false);
			attachment.Content = null;

			attachment.Properties = new CustomProperty[] { new CustomProperty(ContentItemAdaptor.ContentDataSourceKey, someRandomFile) };

			request.Attachments = new Attachment[] { attachment };

			//execute
			IUniversalRequestObject uro = RequestAdaptor.GetURO(request);

			Assert.AreEqual(1, uro.Attachments.Count, "Incorrect number of attachments");
			foreach (RequestAttachment attach in uro.Attachments)
			{
				Assert.IsTrue(attach.Data == null, "Expected null data. Use file instead.");
				Assert.IsTrue(File.Exists(attach.FileName), "Should reference a valid file");
			}

			Assert.IsTrue(uro.Properties.ContainsKey(RequestAdaptor.PassContentAsFileProperty), "ContentAsFiles key missing");

			} finally{
				File.Delete(someRandomFile);
			}
		}
        public void DataSourceMustBeValidFileOnDisk()
        {
            //setup
            string nonExistent = Path.GetRandomFileName();
			Attachment attachment = new Attachment("Hello", "txt", "xxx", "1", false); 
            attachment.Content = null; 
            attachment.Properties = new CustomProperty[] { new CustomProperty(ContentItemAdaptor.ContentDataSourceKey, nonExistent) };

            //execute & verify
            RequestAttachment reqAttach = AttachmentAdaptor.GetRequestAttachment(attachment);
        }
        public void ContentAsFileSetsProperty()
        {
            string someRandomFile = Path.GetTempFileName();

            try {

				Attachment attachment = new Attachment(someRandomFile, "txt", "xxx", "1", false); //setup
                attachment.Properties = new CustomProperty[] { new CustomProperty(ContentItemAdaptor.ContentDataSourceKey, someRandomFile) };
                
                RequestAttachment reqAttach = AttachmentAdaptor.GetRequestAttachment(attachment); //execute


                //verify
                Assert.IsTrue(reqAttach.Properties.ContainsKey(ContentItemAdaptor.ContentDataSourceKey), "Request Attachment doesnt contain file data source key");
                Assert.AreEqual(someRandomFile, reqAttach.Properties[ContentItemAdaptor.ContentDataSourceKey], "Incorrect file data source");

            } finally{
                File.Delete(someRandomFile);
            }

        }
예제 #8
0
		internal static RequestAttachment GetRequestAttachment(Attachment attachment)
		{
			if (null == attachment)
				throw new ArgumentNullException("attachment");

			RequestAttachment ra = new RequestAttachment
									   {
										   ContentId = attachment.Id,
										   ContentItemIndex = Int32.Parse(attachment.Index, CultureInfo.InvariantCulture),
										   ContentType = attachment.ContentType,
										   File = attachment.File is Engine.File ? attachment.File : new Engine.File(attachment.File),
										   FileName = attachment.FileName,
										   Name = attachment.Name,
										   IsSignature = attachment.IsSignature
									   };

			if (null != attachment.Properties)
			{
				foreach (CustomProperty prop in attachment.Properties)
				{
					ra.Properties[prop.Name] = prop.Value;
				}
			}

			//When a null content byte array is passed, go to disk.
			if (ra.Properties.ContainsKey(ContentItemAdaptor.ContentDataSourceKey))
			{
				if (!File.Exists(ra.Properties[ContentItemAdaptor.ContentDataSourceKey]))
				{
					throw new ArgumentException(
						@"When passing an attachment with null 
					content you must pass the 'ContentDataSource'
					property of the attachment, which should point to a valid file on disk.");
				}

				ra.FileName = ra.Properties[ContentItemAdaptor.ContentDataSourceKey];
			}

			return ra;
		}
예제 #9
0
		private void AddRecordKeyToAttachmentProperties(Attachment attach, ContentItem ci)
		{
			List<CustomProperty> lcpAttach = new List<CustomProperty>(attach.Properties);
			if (lcpAttach.Exists(
				delegate(CustomProperty cp)
				{
					return (cp.Name == "RecordKey");
				}))
			{
				return;
			}

			List<CustomProperty> lcpCI = new List<CustomProperty>(ci.Properties);
			lcpAttach.Add(lcpCI.Find(
				delegate(CustomProperty cp)
				{
					return (cp.Name == "RecordKey");
				}));
			attach.Properties = lcpAttach.ToArray();
		}
예제 #10
0
		protected virtual void ViewDoc(Attachment attachment)
		{
			try
			{
				string filename = attachment.FileName;

				FileType type = attachment.File.FileType;
				switch (type)
				{
				case FileType.WordDocument:
				case FileType.WordDocumentX:
				case FileType.WordDocumentMacroX:
				case FileType.WordDocumentTemplateX:
				case FileType.WordDocumentMacroTemplateX:
				case FileType.RTFDocument:
					DoOpenWordDocument(type, filename, true);
					break;

				case FileType.ExcelSheet:
				case FileType.ExcelSheetX:
				case FileType.ExcelSheetMacroX:
				case FileType.ExcelSheetTemplateX:
				case FileType.ExcelSheetMacroTemplateX:
					DoOpenExcelDocument(type, filename, true);
					break;

				case FileType.PowerPoint:
				case FileType.PowerPointX:
				case FileType.PowerPointMacroX:
				case FileType.PowerPointTemplateX:
				case FileType.PowerPointMacroTemplateX:
				case FileType.PowerPointShowX:
				case FileType.PowerPointMacroShowX:
					DoOpenPowerPointDocument(type, filename, true);
					break;

				case FileType.PDFDocument:
					System.Diagnostics.Process.Start(filename);
					break;
				}
			}
			catch (System.Exception ex)
			{
				Logger.LogError("Workshare.Policy.ClientManager.RequestManager.ViewDoc(): Failed to launch the document.\n\nNo application is associated with this filetype");
				Logger.LogError(ex);
			}
		}
		private Attachment GetAttachment(Redemption.Attachment redemptionAttachment, int bodyFormat)
		{
			string temp = LocalFileManager.GetLocalCopyOfFileTarget(redemptionAttachment.DisplayName);
			DeleteFile(temp);

			redemptionAttachment.SaveAsFile(temp);
			_unpackedTempCopies.Add(temp);

			// Attachment Content Type cannot be determined, whilst the Index will be set at a
			// higher level -> Flatten call
			// [09/07/09] DE9310 DZ: Prefer using FileName instead of DisplayName due for
			// this defect.

			// [01/09/09] DE9621 DZ: Redemption.Attachment.FileName/DisplayName couldn't correctly retrieve
			// the Unicode names when running on Office2003 with "Cached Exchanged Mode" turned on. Therefore
			// try raw attribute first.
			// RightClick send .msg, PR_ATTACH_LONG_FILENAME_W/PR_DISPLAY_NAME_W donot present.
			// Drag to attach .msg and send, PR_ATTACH_LONG_FILENAME_W does not present.
			string attname = redemptionAttachment.get_Fields(MapiDefines.PR_ATTACH_LONG_FILENAME_W) as string;
			if (string.IsNullOrEmpty(attname))
			{
				attname = redemptionAttachment.get_Fields(MapiDefines.PR_DISPLAY_NAME_W) as string;
				if (string.IsNullOrEmpty(attname))
				{
					// Redemption.Attachment.FileName should never return null/contain invalid file name characters
					// but can incorrectly decode Unicode characters, resulting underscores '____'.
					attname = redemptionAttachment.FileName;
				}
			}
			// Sanitize required due to filename retrieved from "get_fields()" may contain "????" for incorrectly
			// decoded Unicode character.
			attname = LocalCopyOfFileManager.GetValidFileName_excl_invalid_chars(attname);
			var attachment = new Attachment(new FCS.Lite.Interface.File(temp, attname),
												   string.Empty, Guid.NewGuid().ToString(), string.Empty, false)
										{
											Properties = new[] { new CustomProperty(PropertyNames.LocalFileName, temp) }
										};
			using (RWSAttachment rWSAttachment = new RWSAttachment(redemptionAttachment))
			{
				attachment.IsSignature = MapiSignatureInspector.IsSignature(rWSAttachment, (OlBodyFormat)bodyFormat);
			}

			return attachment;
		}
		/// <summary>
		/// Use seperate function to handle embedded message attachment, as 
		/// Redemption.Attachment.SaveAsFile will incorrectly save Unicode subject line and
		/// Unicode attachment file name into Ansi.
		/// </summary>
		/// <param name="embeddeditem"></param>
		/// <returns></returns>
		private Attachment GetAttachment(Redemption.MessageItem embeddeditem)
		{
			using (new ComRelease(embeddeditem))
			{
				string temp = LocalFileManager.GetLocalCopyOfFileTarget(embeddeditem.Subject);
				DeleteFile(temp);

				temp = Path.ChangeExtension(temp, MsgExtension);

				embeddeditem.SaveAs(temp, OlSaveAsType.olMSGUnicode);
				_unpackedTempCopies.Add(temp);

				// Use the subject field as the attachment name for embedded items.
				// NB this does NOT have a file extension, and this code should be kept
				// in line with that used to add attachments via the object model
				// for Office 2010 - see OOMWSMailAttachmentTransform.
				string attname = embeddeditem.Subject;

				attname = LocalCopyOfFileManager.GetValidFileName_excl_invalid_chars(attname);
				if (string.IsNullOrEmpty(attname) || string.IsNullOrEmpty(attname.Trim()))
				{
					attname = UntitledAttachmentTitle;
				}

				var attachment = new Attachment(new FCS.Lite.Interface.File(temp, attname), string.Empty,
													   Guid.NewGuid().ToString(), string.Empty, false)
											{
												Properties = new[] { new CustomProperty(PropertyNames.LocalFileName, temp) }
											};
				return attachment;
			}
		}
		// This is used for the Cryptzone Secure Email Action
		// We can only support one Action that has this property and still function
		// in a reasonable fashion since we are allowing the Action to remove all 
		// attachments and replace then with completely new ones. JE 19.10.2011
		public void ReplaceAttachments(dynamic mailItem, Attachment[] processedAttachments)
		{
			Attachments attachments = mailItem.Attachments;

			try
			{
				RemoveAllAttachment(attachments);
				mailItem.Save();

				foreach (Attachment attachment in processedAttachments)
				{
					string displayName = attachment.Name;
					if (string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(displayName.Trim()))
					{
						displayName = UntitledAttachmentTitle;
					}

					string fileName = attachment.FileName;

					Microsoft.Office.Interop.Outlook.Attachment newAttachment;
					if (fileName.EndsWith(".msg", StringComparison.InvariantCultureIgnoreCase))
					{
						// Attach .msg via "olEmbeddedItem" to avoid Unicode msg attachment being blocked by "Symantec anti-virus Outlook addin"
						newAttachment = attachments.Add(fileName, OlAttachmentType.olEmbeddeditem, Missing.Value, displayName);
					}
					else
					{
						newAttachment = attachments.Add(fileName, OlAttachmentType.olByValue, Missing.Value, displayName);
					}

					if (newAttachment != null)
					{
						if (!string.IsNullOrEmpty(attachment.Id))
						{
							newAttachment.PropertyAccessor.SetProperty(MAPIStringDefines.PR_ATTACH_CONTENT_ID, attachment.Id);
						}
					}
				}
			}
			finally
			{
				mailItem.Save();
			}
		}
		private bool GetAttachmentFileTimes(Attachment attachment,
											Dictionary<string, AttachmentProperties> dictAttachmentProps,
											ref DateTime creationTime, ref DateTime lastModificationTime)
		{
			string recordkey = GetPropertyValue(attachment.Properties, PropertyNames.RecordKey);
			if (dictAttachmentProps.ContainsKey(recordkey))
			{
				creationTime = dictAttachmentProps[recordkey].CreationTime;
				lastModificationTime = dictAttachmentProps[recordkey].LastModifiedtime;
				return true;
			}

			return false;
		}
예제 #15
0
        /// <summary>
		/// Re-encrypts an attachment that was built from a decrypted attachment (changes content bytes in-place)
		/// </summary>
		public abstract void ReEncryptInternal(Attachment attachment);
예제 #16
0
		private bool IsUnpackable(Attachment attachment)
		{
            FileType type = attachment.File.FileType;

            if ((type == FileType.Unknown && 
                !Workshare.FCS.Lite.Interface.File.IsOutlookMSGType(attachment.File.RawContents)) ||
                type != FileType.Email)
            {
                return false;
            }

            AtLeastOneEmail = true; // Else we dont get Secure File Transfer..

            if (Workshare.FCS.Lite.Interface.File.IsOutlookPostType(attachment.File.RawContents))
            {
                return false;
            }

            return true;
		}
예제 #17
0
		public void ReplaceProcessedAttachments(MsOutlook.MailItem mailItem, Attachment[] processedAttachments, ZipAllOptions zipAll)
		{
			m_mat.ReplaceProcessedAttachments(mailItem, processedAttachments, zipAll);
		}
예제 #18
0
		public void ReplaceAttachments(MsOutlook.MailItem mailItem, Attachment[] processedAttachments)
		{
			m_mat.ReplaceAttachments(mailItem, processedAttachments);
		}
		public List<Attachment> Unpack(IAttachmentNode child)
		{
			var positions = new List<int>();
			var unpackedItems = new List<Attachment>();
			var tempFile = child.Attachment.FileName;

			// store the msg file location and remove it if by chance it was being scheduled for deletion - case
			// of 2nd level nested msgs
			child.BackingByFile = tempFile;
			_msgFileBackingCopies.Add(tempFile);
			_unpackedTempCopies.Remove(tempFile);

            using (var mailitem = OutlookApp.CreateItemFromTemplate(tempFile))
            {
                if (mailitem == null)
                    return unpackedItems; // we end up in here for attached contacts, which aren't mail items

                OlBodyFormat bodyFormat = mailitem.BodyFormat;

                Interop.Logging.Logger.LogDebug("Mail Format:" + bodyFormat.ToString() +
                                                "Attachment container filename: " + tempFile);

                Attachments attachments = mailitem.Attachments;
                for (int i = 1; i <= attachments.Count; ++i)
                {
                    Microsoft.Office.Interop.Outlook.Attachment attachment = attachments[i];
                    if (bodyFormat == OlBodyFormat.olFormatRichText)
                    {
                        positions.Add(attachment.Position);
                    }
                    else
                    {
                        positions.Add(-1);
                    }

                    string attachmentName = attachment.FileName;
                    if (string.IsNullOrEmpty(attachmentName))
                    {
                        attachmentName = attachment.DisplayName;
                    }

                    string temp = LocalFileManager.GetLocalCopyOfFileTarget(attachmentName);
                    if (File.Exists(temp))
                    {
                        File.Delete(temp);
                    }

                    attachment.SaveAsFile(temp);
                    _unpackedTempCopies.Add(temp);

                    Interop.Logging.Logger.LogDebug("Unpacked attachment filename: " + temp);

                    string attname;
                    if ((attachment.Type == OlAttachmentType.olOLE) &&
                        (bodyFormat == OlBodyFormat.olFormatRichText))
                    {
                        attname = attachment.DisplayName;
                    }
                    else
                    {
                        attname = attachment.FileName;

                        // Remove the .msg extension for embedded messages.
                        // This code should be kept in line with that used to process the
                        // email via MAPI, for Office 2003/2007 - See RWSMailAttachmentTransform.
                        // (MAPI processing uses the subject field for the attachment name,
                        // so doesn't have a .msg extension)
                        if (attachment.Type == OlAttachmentType.olEmbeddeditem)
                        {
                            attname = RemoveMsgExtension(attname);
                        }
                    }

                    attname = LocalCopyOfFileManager.GetValidFileName_excl_invalid_chars(attname);
                    Attachment att = new Attachment(new FCS.Lite.Interface.File(temp, attname), string.Empty,
                                                    Guid.NewGuid().ToString(), string.Empty, false)
                                            {
                                                Properties =
                                                    new[]
                                                        {new CustomProperty(PropertyNames.LocalFileName, temp)},
                                                IsSignature =
                                                    OomSignatureInspector.IsSignature(attachment, bodyFormat)
                                            };
                    unpackedItems.Add(att);

                }
                mailitem.Close(OlInspectorClose.olDiscard);

                child.WasUnpacked = true;
                for (int i = 0; i < unpackedItems.Count; i++)
                {
                    _attachmentPositions.Add(unpackedItems[i].Id, positions[i]);
                }
                return unpackedItems;
            }
		}
		private void AddAttachmentToMsg(Attachment attachment, Attachments attachments, int index, bool isAnEmbeddedEmail)
		{
			string fileName = attachment.FileName;

			if (isAnEmbeddedEmail)
			{
				// A subject line like 
				// "test messed up subject line, invalid characters: /\/\ 29/04/2004\"
				// in an email is why LocalCopyOfFileManager.GetValidFileName() cant be used
				//
				// Change to replace invalid characters by underscore to avoid potential empty file name. e.g. '   .msg'

				// we need .msg extension to use Namespace.OpenSharedItem()
				if (!File.Exists(Path.ChangeExtension(fileName, MsgExtension)))
				{
					fileName = Path.ChangeExtension(fileName, MsgExtension);
					File.Copy(attachment.FileName, fileName);
				}
				_msgFileBackingCopies.Add(fileName);

                dynamic nameSpace = OutlookApp.GetNamespace("MAPI");
                var mitem = nameSpace.OpenSharedItem(fileName);
                using (new ComRelease(mitem))
                {
                    var mailItem = attachments.Parent;
                    using (new ComRelease(mailItem))
                    {
						if (mailItem != null && (Microsoft.Office.Interop.Outlook.OlBodyFormat)mailItem.BodyFormat != OlBodyFormat.olFormatRichText)
                        {
                            index = 1;
                        }
                        var newAttach = attachments.Add(mitem, OlAttachmentType.olEmbeddeditem, index,
													  attachment.Name);
                        using (new ComRelease(newAttach))
                        {
                            var propertyAccessor = newAttach.PropertyAccessor;
                            using (new ComRelease(propertyAccessor))
                            {
                                string displayname = mitem.Subject;
                                if (string.IsNullOrEmpty(displayname) || string.IsNullOrEmpty(displayname.Trim()))
                                {
                                    propertyAccessor.SetProperty(MAPIStringDefines.PR_DISPLAY_NAME_W,
                                                                            UntitledAttachmentTitle);
                                }
                                else
                                {
                                    propertyAccessor.SetProperty(MAPIStringDefines.PR_DISPLAY_NAME_W,
                                                                            mitem.Subject);
                                }
                            }
                        }
                    }
                }

			    // need to do this to ensure mitem does not hold onto file used to create it
				GC.Collect();
				GC.WaitForPendingFinalizers();
				///////////////////////////////////////////////////////////////////////////////	
			}
			else
			{
				if (!attachment.IsSignature)
				{
					var mailItem = attachments.Parent;
					if (mailItem != null && (Microsoft.Office.Interop.Outlook.OlBodyFormat)mailItem.BodyFormat != OlBodyFormat.olFormatRichText)
					{
						index = 1;
					}
					attachments.Add(fileName, OlAttachmentType.olByValue, index, attachment.Name);
				}
			}
		}
		private bool RemoveAttachment(Attachments attachments, Attachment attachment)
		{
			for (int index = attachments.Count; index > 0; --index)
			{
                dynamic safeAttachment = attachments[index];

                var wsAttachments = attachments as WsAttachments;

                foreach (CustomProperty cp in attachment.Properties)
				{
					if (cp.Name == "RecordKey")
					{
                        if (wsAttachments != null)
                        {
                            wsAttachments.Remove(cp.Value);
                            return true;
                        }
                        else
                        {
                            if (cp.Value == safeAttachment.RecordKey)
                            {
                                attachments.Remove(index);
                                return true;
                            }
                        }
                        
					}
				}
			}
			return false;
		}
예제 #22
0
		/// <summary>
		/// Determine if the attachment is significant enough to warrant showing the dynamic discovery box
		/// </summary>
		/// <param name="a"></param>
		/// <returns></returns>
		private bool IsSignificantAttachment(Attachment a)
		{
			if (a == null || a.ContentType == null)
				return true; // just in case of null objects

            if (a.IsSignature)
                return false;

			if (a.ContentType == "application/pdf")
				return false;

			return !a.ContentType.StartsWith("image"); // for instance image/png or image/gif etc
		}
예제 #23
0
        /// <summary>
        /// Re-encrypts an attachment that was built from a decrypted attachment and marks it as not decrypted
        /// </summary>
        public virtual void ReEncrypt(Attachment attachment)
	    {
	        ReEncryptInternal(attachment);
            IsDecrypted = false;
	    }
예제 #24
0
		public PDFEncryption(Attachment attachment, Workshare.FCS.Lite.Interface.File file)
            : base(attachment, file)
        {
        }
예제 #25
0
		/// <summary>
		/// Sets up this encryption object
		/// </summary>
		/// <param name="attachment">Original attachment</param>
		protected FileEncryption(Attachment attachment, File file)
		{		
			m_Attachment = attachment;
			m_AttachmentFile = file;
		}
		public void ReplaceProcessedAttachments(dynamic mailItem, Attachment[] processedAttachments, ZipAllOptions groupedZip)
		{
			Attachments attachments = mailItem.Attachments;

			if ((groupedZip != null) && groupedZip.ZipAll && attachments.Count > 0)
			{
				ZipAttachments(attachments, processedAttachments, groupedZip, mailItem.BodyFormat);
				return;
			}

			//AttachmentProperties
			Dictionary<string, AttachmentProperties> dictAttachmentProps = new Dictionary<string, AttachmentProperties>(attachments.Count);
			GetAttachmentProperties(attachments, dictAttachmentProps);

			// Use .ToArray() to ensure the attachments are removed first, before any re-additions.
			Attachment[] removedAttachments = processedAttachments.Where(a => RemoveAttachment(attachments, a)).ToArray();
			
			int renderingPosition = 1;
			foreach (Attachment attachment in removedAttachments)
			{
				string displayName = attachment.Name;
				if (string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(displayName.Trim()))
				{
					displayName = UntitledAttachmentTitle;
				}

				string fileName = attachment.FileName;

				DateTime creationTime = new DateTime();
				DateTime lastModificationTime = new DateTime();

				// For unmodified attachments we want to restore the timestamp so they appear as they were (ie unchanged!)
				// We need to set the file creation/modification correctly, removing/adding resets the timestamp
				if (!attachment.IsProcessed &&
					GetAttachmentFileTimes(attachment, dictAttachmentProps, ref creationTime, ref lastModificationTime))
				{
					File.SetCreationTime(fileName, creationTime);
					File.SetLastWriteTime(fileName, lastModificationTime);
				}

				int position = renderingPosition;
				string recordkey = GetPropertyValue(attachment.Properties, PropertyNames.RecordKey);
				AttachmentProperties attProps;
				bool bPropsAvailable = dictAttachmentProps.TryGetValue(recordkey, out attProps);
				if (bPropsAvailable)
				{
					if ((int) attProps.OPosition != -1)
					{
						position = (int) attProps.OPosition + 1;
					}
					else
					{
						position = -1;
					}
				}

				Microsoft.Office.Interop.Outlook.Attachment newAttachment;
				OlAttachmentType attachType = OlAttachmentType.olByValue;
				if (fileName.EndsWith(".msg", StringComparison.InvariantCultureIgnoreCase))
				{
					// Attach .msg via "olEmbeddedItem" to avoid Unicode msg attachment being blocked by "Symantec anti-virus Outlook addin"
					attachType = OlAttachmentType.olEmbeddeditem;
				}

				newAttachment = attachments.Add(fileName, attachType, Missing.Value, displayName);

				if (newAttachment != null)
				{
					if (bPropsAvailable)
					{
						List<string> lProperties = new List<string>();
						List<object> lValues = new List<object>();
						
						if (attProps.OHidden is bool)
						{
							lProperties.Add(MAPIStringDefines.PR_ATTACHMENT_HIDDEN);
							lValues.Add(attProps.OHidden);

							if ((attProps.OContentId is string) && (attProps.OContentId as string != string.Empty) && (bool)attProps.OHidden)
							{
								lProperties.Add(MAPIStringDefines.PR_ATTACH_CONTENT_ID);
								lValues.Add(attProps.OContentId);
							}
						}
						if ((attProps.OFlags is int) && ((int) attProps.OFlags >= 0))
						{
							lProperties.Add(MAPIStringDefines.PR_ATTACHMENT_FLAGS);
							lValues.Add(attProps.OFlags);
						}
						if ((attProps.OPosition is int) && ((int) attProps.OPosition >= -1))
						{
							lProperties.Add(MAPIStringDefines.PR_RENDERING_POSITION);
							lValues.Add(attProps.OPosition);
							if (position != -1)
								newAttachment.Position = position;
						}
						if (attProps.OContactPhoto is bool)
						{
							lProperties.Add(MAPIStringDefines.PR_ATTACHMENT_CONTACTPHOTO);
							lValues.Add(attProps.OContactPhoto);
						}

						newAttachment.PropertyAccessor.SetProperties(lProperties.ToArray(), lValues.ToArray());
					}
					else
					{
						//We have an attachment that was not in the original collection.
						//Dont have all the info but we at least know the attachment content id.
						if (!string.IsNullOrEmpty(attachment.Id))
						{
							newAttachment.PropertyAccessor.SetProperty(MAPIStringDefines.PR_ATTACH_CONTENT_ID, attachment.Id);
						}
					}
				}

				++renderingPosition;
			}
			mailItem.Save();
		}
예제 #27
0
		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;
		}
예제 #28
0
		public void PackMSG(Attachment msgAttachment)
		{
            if (IsUnpackable(msgAttachment))
            {
                m_mat.Repack(msgAttachment);
            }
		}
예제 #29
0
		// Functions used by the EncryptionManager to process .msg files inside .zip containers
		
		public List<Attachment> ExpandMSG(Attachment msgAttachment)
		{
			List<Attachment> flattenedList = new List<Attachment>();

			if (msgAttachment.File.FileType == FileType.Email && IsUnpackable(msgAttachment))
			{
                flattenedList = Unpack(new AttachmentNode(msgAttachment));
			}

			return flattenedList;
		}
예제 #30
0
		public static IContentItem GetIContentItem(Workshare.PolicyContent.ContentItem item, Attachment origAttachment)
		{
			if (null == item)
				throw new ArgumentException("item");

			if (null == origAttachment)
				throw new ArgumentException("origAttachment");

			IFile engineFile = FileAdaptor.GetIFile(origAttachment);

			Workshare.Policy.Engine.ContentItem ci = new Workshare.Policy.Engine.ContentItem(engineFile);

			ci.DisplayName = item.Name;
			ci.Encrypted = item.Encrypted;
			ci.Type = item.ContentType;
			ci.Size = item.Size;

			if ( item.Properties != null)
			{
				foreach (CustomProperty property in item.Properties)
				{
					ci.Properties[property.Name] = property.Value;
				}
			}

			if ( item.PolicySets != null)
			{
				foreach (PolicySet policySet in item.PolicySets)
				{
					ci.PolicySetCollection.Add( PolicySetAdaptor.GetIPolicySetResponse(policySet) );
				}
			}

			return ci;
		}