Пример #1
0
 /// <summary>
 /// Fetches a single attachment from the requested message.
 /// </summary>
 /// <param name="info">The associated info object, this token can be obtained from the messages body structure.</param>
 /// <returns>The requested attachment.</returns>
 public Attachment FetchAttachment(AttachmentInfo info)
 {
     var base64String = FetchEntityText(info);
     if (string.IsNullOrEmpty(base64String)) {
         return null;
     }
     var bytes = Convert.FromBase64String(base64String);
     return Attachment.FromBytes(info.Name, bytes, info.MediaType);
 }
Пример #2
0
        private static void AddAttachment(MessageInfo message, BodyPart child, string token, int sn)
        {
            var attachment = new AttachmentInfo {
                ContentTransferEncoding = string.IsNullOrEmpty(child.BodyEncoding) ? string.Empty : child.BodyEncoding.ToLower(),
                MediaType = (child.BodyType + "/" + child.SubType).ToLower(),
                Token = token,
                SequenceNumber = sn
            };

            int size;
            var success = int.TryParse(child.BodySize, out size);
            if (success) {
                attachment.SizeEncoded = Size.FromBytes(size);
            } else {
                Debug.WriteLine(string.Format("Unable to parse body size. Value is not numeric: '{0}'", child.BodySize));
            }

            if (child.Parameters.ContainsKey("name")) {
                attachment.Name = child.Parameters["name"];
            }

            ((ParameterDictionary) attachment.Parameters).AddRange(child.Parameters);
            ((IList<AttachmentInfo>) message.Attachments).Add(attachment);
        }