示例#1
0
		private void AddAttachment(string fileName, string displayName, AttachmentProperties aprops)
		{
			File.SetCreationTime(fileName, aprops.CreationTime);
			File.SetLastWriteTime(fileName, aprops.LastModifiedTime);

			int position;
			if ((int) aprops.Position != -1)
			{
				position = (int) aprops.Position + 1;
			}
			else
			{
				position = -1;
			}

			Attachment newAttachment = position == -1
										? _mailItem.Attachments.Add(fileName, OlAttachmentType.olByValue, 1, displayName)
										: _mailItem.Attachments.Add(fileName, OlAttachmentType.olByValue, position, displayName);

			_mailItem.Save();

			if (newAttachment != null)
			{
				List<string> properties = new List<string>();
				List<object> values = new List<object>();
				if (!String.IsNullOrEmpty(aprops.ContentId as string))
				{
					properties.Add(MAPIStringDefines.PR_ATTACH_CONTENT_ID);
					values.Add(aprops.ContentId);
				}
				if (aprops.Hidden is bool)
				{
					properties.Add(MAPIStringDefines.PR_ATTACHMENT_HIDDEN);
					values.Add(aprops.Hidden);
				}
				if ((aprops.Flags is int) && ((int) aprops.Flags >= 0))
				{
					properties.Add(MAPIStringDefines.PR_ATTACHMENT_FLAGS);
					values.Add(aprops.Flags);
				}
				if (((int) aprops.Position >= -1))
				{
					properties.Add(MAPIStringDefines.PR_RENDERING_POSITION);
					values.Add(aprops.Position);
				}
				if (aprops.ContactPhoto is bool)
				{
					properties.Add(MAPIStringDefines.PR_ATTACHMENT_CONTACTPHOTO);
					values.Add(aprops.ContactPhoto);
				}

				newAttachment.PropertyAccessor.SetProperties(properties.ToArray(), values.ToArray());
			}
		}
示例#2
0
		private void GetAttachmentProperties()
		{
			if (_attachment.Type == OlAttachmentType.olOLE)
			{
				// OLE attachments are currently not processed like the rest
				// (removed, processed, then added back to the mail item)
				return;
			}

			string[] properties = {
			                      	MAPIStringDefines.PR_RECORD_KEY,
			                      	MAPIStringDefines.PR_ATTACH_CONTENT_ID,
			                      	MAPIStringDefines.PR_ATTACHMENT_HIDDEN,
			                      	MAPIStringDefines.PR_ATTACHMENT_FLAGS,
			                      	MAPIStringDefines.PR_RENDERING_POSITION,
			                      	MAPIStringDefines.PR_ATTACHMENT_CONTACTPHOTO,
			                      	MAPIStringDefines.PR_CREATION_TIME,
			                      	MAPIStringDefines.PR_LAST_MODIFICATION_TIME
			                      };

			object[] propertyValues = _attachment.PropertyAccessor.GetProperties(properties);

			_attachProperties = new AttachmentProperties
									{
										RecordKey = Utilities.GetStringFromBytes(propertyValues[0] as byte[]),
										ContentId = propertyValues[1],
										Hidden = propertyValues[2],
										Flags = propertyValues[3],
										Position = propertyValues[4],
										ContactPhoto = propertyValues[5]
									};

			if (propertyValues[6] is DateTime)
			{
				_attachProperties.CreationTime = (DateTime) propertyValues[6];
			}
			else
			{
				_attachProperties.CreationTime = DateTime.Now;
			}

			if (propertyValues[7] is DateTime)
			{
				_attachProperties.LastModifiedTime = (DateTime) propertyValues[7];
			}
			else
			{
				_attachProperties.LastModifiedTime = DateTime.Now;
			}
		}