Пример #1
0
        /// <summary>
        /// Save the attachment to the file.
        /// </summary>
        /// <param name="InFilePath"></param>
        public void SaveAs(string InFilePath)
        {
            // saveas depends on the ContentType of the attachment part.
            PartProperty.ContentType ct = mPart.Properties.ContentType;
            if ((ct.Type == "text") && (ct.SubType == "plain"))
            {
                StreamWriter sw = new StreamWriter(InFilePath, false);
                for (int Ix = 0; Ix < mPart.MessageLines.Length; ++Ix)
                {
                    string line = mPart.MessageLines[Ix];
                    sw.WriteLine(line);
                }
                sw.Close( );
            }

            else
            {
                MemoryStream ms = ToMemoryStream( );
                FileStream   fs = new FileStream(InFilePath, FileMode.Create);
                BinaryWriter w  = new BinaryWriter(fs);
                w.Write(ms.ToArray( ));
                w.Close( );
                fs.Close( );
            }
        }
Пример #2
0
        // ------------------------- ParseContentType ----------------------------
        public static PartProperty.ContentType ParseContentType(string InString)
        {
            TextTraits traits = new TextTraits()
                                .SetQuoteEncapsulation(QuoteEncapsulation.Escape);

            traits.DividerPatterns.Replace(
                new string[] { "/", ":", ";", " ", "\t", "=" }, DelimClassification.DividerSymbol);
            traits.WhitespacePatterns.Replace(" ", "\t", DelimClassification.Whitespace);
            PartProperty.ContentType results = new PartProperty.ContentType();

            WordCursor csr = Scanner.PositionBeginWord(InString, traits);

            while (true)
            {
                csr = Scanner.ScanNextWord(InString, csr);
                if (csr.IsEndOfString)
                {
                    break;
                }

                // content type
                if (csr.DelimValue == "/")
                {
                    results.Type = csr.Word.ToString( ).ToLower( );
                }

                // content sub type.
                else if (csr.DelimValue == ";")
                {
                    results.SubType = csr.Word.ToString( ).ToLower( );
                }

                // a kwd
                else if (csr.DelimValue == "=")
                {
                    WordCursor nxCsr = csr.NextWord( );
                    if ((nxCsr.DelimClass == DelimClassification.EndOfString) ||
                        (nxCsr.DelimClass == DelimClassification.Whitespace))
                    {
                        string kwd = csr.Word.ToString( ).ToLower( );
                        csr = nxCsr;
                        if (kwd == "charset")
                        {
                            results.CharSet = csr.Word.NonQuotedSimpleValue;
                        }
                        else if (kwd == "boundary")
                        {
                            results.Boundary = csr.Word.NonQuotedSimpleValue;
                        }
                        else if (kwd == "name")
                        {
                            results.Name = csr.Word.NonQuotedSimpleValue;
                        }
                    }
                }
            }
            return(results);
        }
Пример #3
0
        // ------------------------- ParseContentType ----------------------------
        public static PartProperty.ContentType ParseContentType(string InString)
        {
            TextTraits traits = new TextTraits( )
                                .SetDelimChars("/:; \t=")
                                .SetWhitespaceChars(" \t")
                                .SetQuoteEncapsulation(QuoteEncapsulation.Escape);

            PartProperty.ContentType results = new PartProperty.ContentType( );

            Scanner.WordCursor csr = Scanner.PositionBeginWord( );
            while (true)
            {
                csr = Scanner.ScanNextWord(InString, csr, traits);
                if (csr.IsEndOfString)
                {
                    break;
                }

                // content type
                if (csr.Delim == "/")
                {
                    results.Type = csr.Word.ToString( ).ToLower( );
                }

                // content sub type.
                else if (csr.Delim == ";")
                {
                    results.SubType = csr.Word.ToString( ).ToLower( );
                }

                // a kwd
                else if (csr.Delim == "=")
                {
                    Scanner.WordCursor nxCsr = csr.NextWord( );
                    if ((nxCsr.DelimClass == DelimClassification.End) ||
                        (nxCsr.DelimClass == DelimClassification.Whitespace))
                    {
                        string kwd = csr.Word.ToString( ).ToLower( );
                        csr = nxCsr;
                        if (kwd == "charset")
                        {
                            results.CharSet = csr.Word.NonQuotedWord;
                        }
                        else if (kwd == "boundary")
                        {
                            results.Boundary = csr.Word.NonQuotedWord;
                        }
                        else if (kwd == "name")
                        {
                            results.Name = csr.Word.NonQuotedWord;
                        }
                    }
                }
            }
            return(results);
        }