Пример #1
0
 /// <summary>
 /// Creates secure attachment object
 /// </summary>
 /// <param name="contentBytes">Attachment byte array</param>
 /// <param name="contentType">Attachment content type</param>
 /// <param name="name">Attachment name</param>
 public SecureAttachment(byte[] contentBytes, SecureContentType contentType, string?name = null)
 {
     RawBytes    = contentBytes ?? throw new ArgumentNullException(nameof(contentBytes));
     ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
     if (name != null)
     {
         ContentType.Name = name;
     }
 }
Пример #2
0
        /// <summary>
        /// Creates secure message content container
        /// </summary>
        /// <param name="body">Body byte array</param>
        /// <param name="contentType">Body content type</param>
        /// <param name="encoding">Transfer encoding</param>
        /// <param name="encodeBody">Encode body</param>
        public SecureMessageContent(byte[] body, SecureContentType contentType, TransferEncoding encoding,
                                    bool encodeBody)
        {
            Body = encodeBody && encoding == TransferEncoding.Base64
                ? Encoding.UTF8.GetBytes(body.ToBase64String())
                : body;

            TransferEncoding = encoding;
            ContentType      = contentType;
        }
Пример #3
0
        /// <summary>
        /// Creates secure attachment object
        /// </summary>
        /// <param name="contentStream">Attachment content stream</param>
        /// <param name="contentType">Attachment content type</param>
        /// <param name="name">Attachment name</param>
        /// <exception cref="ArgumentNullException">If contentStream is null.</exception>
        public SecureAttachment(Stream contentStream, SecureContentType contentType, string?name = null)
        {
            if (contentStream == null)
            {
                throw new ArgumentNullException(nameof(contentStream));
            }

            contentStream.Position = 0;
            var reader = new BinaryReader(contentStream);

            RawBytes    = reader.ReadBytes((int)contentStream.Length);
            ContentType = contentType;

            if (name != null)
            {
                ContentType.Name = name;
            }
        }
Пример #4
0
 /// <summary>
 /// Creates secure attachment object
 /// </summary>
 /// <param name="fileName">File path</param>
 /// <param name="contentType">Attachment content type</param>
 public SecureAttachment(string fileName, SecureContentType contentType)
     : this(File.ReadAllBytes(fileName), contentType, Path.GetFileName(fileName))
 {
 }