コード例 #1
0
		/// <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;
			}
		}