public void EncodeHeaders_WithCustomUnicodeHeaders_ShouldEncodeHeaders()
        {
            _headers.Add("X-Custom", CustomUnicodeHeaderValue);
            _message.EncodeHeaders(_headers, false);

            string encodedHeader = _headers.Get("X-Custom");

            Assert.True(encodedHeader.StartsWith("="));
            Assert.True(encodedHeader.EndsWith("="));
            //should contain no unicode
            Assert.False(ContainsNonAscii(encodedHeader), encodedHeader);

            Assert.Equal(Encoding.UTF8, _message.HeadersEncoding);

            // Allow Unicode
            _headers.Clear();
            _headers.Add("X-Custom", CustomUnicodeHeaderValue);
            _message.EncodeHeaders(_headers, true);

            encodedHeader = _headers.Get("X-Custom");
            Assert.False(encodedHeader.StartsWith("="));
            Assert.False(encodedHeader.EndsWith("="));
            //should contain unicode
            Assert.True(ContainsNonAscii(encodedHeader), encodedHeader);
        }
        public static void Run()
        {
            // ExStart:RetrievingEmailHeaders
            // Create an instance of the Pop3Client class
            Pop3Client client = new Pop3Client();

            // Specify host, username. password, Port and SecurityOptions for your client
            client.Host            = "pop.gmail.com";
            client.Username        = "******";
            client.Password        = "******";
            client.Port            = 995;
            client.SecurityOptions = SecurityOptions.Auto;
            try
            {
                HeaderCollection headers = client.GetMessageHeaders(1);
                for (int i = 0; i < headers.Count; i++)
                {
                    // Display key and value in the header collection
                    Console.Write(headers.Keys[i]);
                    Console.Write(" : ");
                    Console.WriteLine(headers.Get(i));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                client.Dispose();
            }
            // ExEnd:RetrievingEmailHeaders
            Console.WriteLine(Environment.NewLine + "Displayed header information from emails using POP3 ");
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir  = RunExamples.GetDataDir_POP3();
            string dstEmail = dataDir + "message.msg";

            //Create an instance of the Pop3Client class
            Pop3Client client = new Pop3Client();

            //Specify host, username and password for your client
            client.Host = "pop.gmail.com";

            // Set username
            client.Username = "******";

            // Set password
            client.Password = "******";

            // Set the port to 995. This is the SSL port of POP3 server
            client.Port = 995;

            // Enable SSL
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                HeaderCollection headers = client.GetMessageHeaders(1);

                for (int i = 0; i < headers.Count; i++)
                {
                    // Display key and value in the header collection
                    Console.Write(headers.Keys[i]);
                    Console.Write(" : ");
                    Console.WriteLine(headers.Get(i));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                client.Disconnect();
            }

            Console.WriteLine(Environment.NewLine + "Displayed header information from emails using POP3 ");
        }
Example #4
0
        public static IDictionary <string, IEnumerable <string> > ToDictionary(this HeaderCollection headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            var result = new Dictionary <string, IEnumerable <string> >();

            if (headers.Any)
            {
                foreach (var key in headers.Keys)
                {
                    var values = headers.Get(key);
                    result.Add(key, values.ToArray());
                }
            }

            return(result);
        }
Example #5
0
        public static IHeaderDictionary ToHeaderDictionary(this HeaderCollection headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            var result = new HeaderDictionary();

            if (headers.Any)
            {
                foreach (var key in headers.Keys)
                {
                    var values = headers.Get(key);
                    result.Add(key, new StringValues(values.ToArray()));
                }
            }

            return(result);
        }
        /// <summary>
        /// When converting a list of headers to an <see cref="ExtensibleObject"/>, this
        /// method sets the common attributes on the object.
        /// </summary>
        /// <param name="obj">The <see cref="ExtensibleObject"/> to be populated</param>
        /// <param name="headers">The <see cref="HeaderCollection"/> containing the list of headers</param>
        protected static void SetCommonAttributesFromHeaders(ExtensibleObject obj, HeaderCollection headers)
        {
            if (obj != null && headers != null)
            {
                Header hMachineName = headers.Get(Header.ORIGIN_MACHINE_NAME);
                if (hMachineName != null && !String.IsNullOrEmpty(hMachineName.Value)) obj.machineName = hMachineName.Value;

                Header hSoftwareName = headers.Get(Header.ORIGIN_SOFTWARE_NAME);
                if (hSoftwareName != null && !String.IsNullOrEmpty(hSoftwareName.Value)) obj.softwareName = hSoftwareName.Value;

                Header hSoftwareVersion = headers.Get(Header.ORIGIN_SOFTWARE_VERSION);
                if (hSoftwareVersion != null && !String.IsNullOrEmpty(hSoftwareVersion.Value)) obj.softwareVersion = hSoftwareVersion.Value;

                Header hPlatformName = headers.Get(Header.ORIGIN_PLATFORM_NAME);
                if (hPlatformName != null && !String.IsNullOrEmpty(hPlatformName.Value)) obj.platformName = hPlatformName.Value;

                Header hPlatoformVersion = headers.Get(Header.ORIGIN_PLATFORM_VERSION);
                if (hPlatoformVersion != null && !String.IsNullOrEmpty(hPlatoformVersion.Value)) obj.platformVersion = hPlatoformVersion.Value;
            }
        }
Example #7
0
 /// <summary>
 /// Get a header
 /// </summary>
 /// <typeparam name="T">Type that it should be cast to</typeparam>
 /// <param name="headerName">Name of header</param>
 /// <returns>Header if found and casted properly; otherwise <c>null</c>.</returns>
 public T Get <T>(string headerName) where T : class, IHeader
 {
     return(_headers.Get <T>(headerName));
 }