Exemplo n.º 1
0
        /// <summary>
        /// Fetches a single view 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 view.</returns>
        public View FetchView2(ViewInfo info)
        {
            var text = FetchEntityBody(info);
            if (string.IsNullOrEmpty(text))
            {
                return null;
            }
            var paramDictionary = ((IDictionary<string, string>)info.Parameters);
            var hasValidCharset = paramDictionary.ContainsKey("charset");
            var charset = hasValidCharset ? paramDictionary["charset"] : Charsets.Utf8;
            var decoded = TransferEncoder.Decode(text, info.ContentTransferEncoding, charset);

            return new View { MediaType = info.MediaType, Text = decoded };
        }
Exemplo n.º 2
0
        private static void AddView(MessageInfo message, BodyPart child, string token, int sn)
        {
            var mediaType = (child.BodyType + "/" + child.SubType).ToLower();
            var view = new ViewInfo {
                Description = child.BodyDescription.ToUpper() == "NIL" ? string.Empty : child.BodyDescription, Id = child.BodyId.ToUpper() == "NIL" ? string.Empty : child.BodyId,
                ContentTransferEncoding = string.IsNullOrEmpty(child.BodyEncoding) ? string.Empty : child.BodyEncoding.ToLower(),
                MediaType = mediaType,
                Token = token,
                SequenceNumber = sn
            };

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

            int lines;
            success = int.TryParse(child.TextLines, out lines);
            if (success) {
                view.TextLinesEncoded = lines;
            }

            var paramDictionary = (ParameterDictionary)view.Parameters;
            paramDictionary.AddRange(child.Parameters);
            ((IList<ViewInfo>) message.Views).Add(view);
        }