コード例 #1
0
ファイル: MimeCodeManager.cs プロジェクト: dblock/sncore
		private void InitialCode()
		{
			MimeCode aFieldCode = new MimeFieldCodeBase();
			SetCode("Subject", aFieldCode);
			SetCode("Comments", aFieldCode);
			SetCode("Content-Description", aFieldCode);

			aFieldCode = new MimeFieldCodeAddress();
			SetCode("From", aFieldCode);
			SetCode("To", aFieldCode);
			SetCode("Resent-To", aFieldCode);
			SetCode("Cc", aFieldCode);
			SetCode("Resent-Cc", aFieldCode);
			SetCode("Bcc", aFieldCode);
			SetCode("Resent-Bcc", aFieldCode);
			SetCode("Reply-To", aFieldCode);
			SetCode("Resent-Reply-To", aFieldCode);
			
			aFieldCode = new MimeFieldCodeParameter();
			SetCode("Content-Type", aFieldCode);
			SetCode("Content-Disposition", aFieldCode);

			MimeCode aCode = new MimeCode();
			SetCode("7bit", aCode);
			
			SetCode("8bit", aCode);

			aCode = new MimeCodeBase64();
			SetCode("base64", aCode);

			aCode = new MimeCodeQP();
			SetCode("quoted-printable", aCode);

		}
コード例 #2
0
        public void WriteToFile(string filePathName)
        {
            if (filePathName == null)
            {
                throw new ArgumentNullException();
            }

            StreamWriter sw = new StreamWriter(filePathName);
            Stream       bs = sw.BaseStream;

            string encoding = GetTransferEncoding();

            if (encoding == null)
            {
                encoding = MimeConst.Encoding7Bit;
            }

            MimeCode aCode = MimeCodeManager.Instance.GetCode(encoding);

            aCode.Charset = GetCharset();
            byte[] b = aCode.DecodeToBytes(mContent);

            bs.Write(b, 0, b.Length);

            sw.Close();
            sw = null;
        }
コード例 #3
0
ファイル: MimeFieldCodeBase.cs プロジェクト: qwdf1615/sncore
        protected void EncodeNoDelimeter(string s, StringBuilder sb)
        {
            if (Charset == null)
            {
                Charset = System.Text.Encoding.Default.BodyName;
            }

            switch (SelectEncoding(s).ToLower())
            {
            case "non": sb.Append(s); break;

            case "quoted-printable":
            {
                MimeCode aCode = MimeCodeManager.Instance.GetCode("quoted-printable");
                aCode.Charset = Charset;
                sb.AppendFormat("=?{0}?Q?{1}?=", Charset, aCode.EncodeFromString(s));
                break;
            }

            case "base64":
            {
                MimeCode aCode = MimeCodeManager.Instance.GetCode("base64");
                aCode.Charset = Charset;
                sb.AppendFormat("=?{0}?B?{1}?=", Charset, aCode.EncodeFromString(s));
                break;
            }
            }
        }
コード例 #4
0
ファイル: MimeCodeManager.cs プロジェクト: qwdf1615/sncore
        private void InitialCode()
        {
            MimeCode aFieldCode = new MimeFieldCodeBase();

            SetCode("Subject", aFieldCode);
            SetCode("Comments", aFieldCode);
            SetCode("Content-Description", aFieldCode);

            aFieldCode = new MimeFieldCodeAddress();
            SetCode("From", aFieldCode);
            SetCode("To", aFieldCode);
            SetCode("Resent-To", aFieldCode);
            SetCode("Cc", aFieldCode);
            SetCode("Resent-Cc", aFieldCode);
            SetCode("Bcc", aFieldCode);
            SetCode("Resent-Bcc", aFieldCode);
            SetCode("Reply-To", aFieldCode);
            SetCode("Resent-Reply-To", aFieldCode);

            aFieldCode = new MimeFieldCodeParameter();
            SetCode("Content-Type", aFieldCode);
            SetCode("Content-Disposition", aFieldCode);

            MimeCode aCode = new MimeCode();

            SetCode("7bit", aCode);

            SetCode("8bit", aCode);

            aCode = new MimeCodeBase64();
            SetCode("base64", aCode);

            aCode = new MimeCodeQP();
            SetCode("quoted-printable", aCode);
        }
コード例 #5
0
ファイル: MimeField.cs プロジェクト: qwdf1615/sncore
        //load a field from a string buffer
        public void LoadField(string strData)
        {
            if (strData == null)
            {
                throw new ArgumentNullException();
            }

            int colonIndex = strData.IndexOf(':');

            if (colonIndex != -1)
            {
                m_strName = strData.Substring(0, colonIndex);
            }
            else
            {
                m_strName = "";
            }

            colonIndex++;
            m_strValue = strData.Substring(colonIndex, strData.Length - colonIndex).Trim();
            //need decode!!! and m_strCharset
            MimeCode aFieldCode = MimeCodeManager.Instance.GetCode(GetName());

            if (aFieldCode != null)
            {
                m_strValue   = aFieldCode.DecodeToString(m_strValue);
                m_strCharset = aFieldCode.Charset;
            }
        }
コード例 #6
0
ファイル: MimeFieldCodeBase.cs プロジェクト: qwdf1615/sncore
        public override string DecodeToString(string s)
        {
            string dString = "";
            int    start   = 0;

            while (start < s.Length)
            {
                int i = s.IndexOf("=?", start);
                if (i != -1)
                {
                    dString += s.Substring(start, i - start);
                    int j = s.IndexOf("?=", i + 2);
                    if (j != -1)
                    {
                        i += 2;
                        int k = s.IndexOf('?', i);
                        if (k != -1 && s[k + 2] == '?')
                        {
                            Charset = s.Substring(i, k - i);
                            string decString = s.Substring(k + 3, j - k - 3);
                            if (s[k + 1] == 'Q')
                            {
                                MimeCode aCode = MimeCodeManager.Instance.GetCode("quoted-printable");
                                aCode.Charset = Charset;
                                dString      += aCode.DecodeToString(decString);
                            }
                            else if (s[k + 1] == 'B')
                            {
                                MimeCode aCode = MimeCodeManager.Instance.GetCode("base64");
                                aCode.Charset = Charset;
                                dString      += aCode.DecodeToString(decString);
                            }
                            else
                            {
                                dString += decString;
                            }
                        }
                        else
                        {
                            dString += s.Substring(k, j - k);
                        }
                        start = j + 2;
                    }
                    else
                    {
                        dString += s.Substring(i, s.Length - i);
                        break;
                    }
                }
                else
                {
                    dString += s.Substring(start, s.Length - start);
                    break;
                }
            }
            return(dString);
        }
コード例 #7
0
        public string GetText()
        {
            string encoding = GetTransferEncoding();

            if (encoding == null)
            {
                encoding = MimeConst.Encoding7Bit;
            }
            MimeCode aCode = MimeCodeManager.Instance.GetCode(encoding);

            aCode.Charset = GetCharset();
            return(aCode.DecodeToString(mContent));
        }
コード例 #8
0
ファイル: MimeFieldCodeBase.cs プロジェクト: qwdf1615/sncore
        protected void EncodeDelimeter(string s, StringBuilder sb)
        {
            char[]   filter      = GetDelimeterChars();
            string[] strArr      = s.Split(filter);
            int      filterIndex = 0;

            for (int i = 0; i < strArr.Length; i++)
            {
                filterIndex += strArr[i].Length;
                if (strArr[i] != null)
                {
                    if (Charset == null)
                    {
                        Charset = System.Text.Encoding.Default.BodyName;
                    }

                    switch (SelectEncoding(strArr[i]).ToLower())
                    {
                    case "non": sb.Append(strArr[i]); break;

                    case "quoted-printable":
                    {
                        MimeCode aCode = MimeCodeManager.Instance.GetCode("quoted-printable");
                        aCode.Charset = Charset;
                        sb.AppendFormat("=?{0}?Q?{1}?=", Charset, aCode.EncodeFromString(strArr[i]));
                        break;
                    }

                    case "base64":
                    {
                        MimeCode aCode = MimeCodeManager.Instance.GetCode("base64");
                        aCode.Charset = Charset;
                        sb.AppendFormat("=?{0}?B?{1}?=", Charset, aCode.EncodeFromString(strArr[i]));
                        break;
                    }
                    }
                }
                if (filterIndex < s.Length)
                {
                    sb.Append(s.Substring(filterIndex, 1));
                }
                filterIndex += 1;
            }
        }
コード例 #9
0
ファイル: MimeField.cs プロジェクト: qwdf1615/sncore
        //store a field content to a string buffer
        public void Store(StringBuilder sb)
        {
            if (sb == null)
            {
                throw new ArgumentNullException();
            }

            MimeCode aFieldCode = MimeCodeManager.Instance.GetCode(GetName());

            if (aFieldCode != null)
            {
                aFieldCode.Charset = m_strCharset;
                sb.AppendFormat("{0}: {1}\r\n", m_strName, aFieldCode.EncodeFromString(m_strValue));
            }
            else
            {
                sb.AppendFormat("{0}: {1}\r\n", m_strName, m_strValue);
            }
        }
コード例 #10
0
        public void ReadFromFile(string filePathName)
        {
            if (filePathName == null)
            {
                throw new ArgumentNullException();
            }

            StreamReader sr = new StreamReader(filePathName);
            Stream       bs = sr.BaseStream;

            byte[] b = new byte[bs.Length];
            bs.Read(b, 0, (int)bs.Length);

            string encoding = GetTransferEncoding();

            if (encoding == null)
            {
                encoding = MimeConst.EncodingBase64;
                SetTransferEncoding(encoding);
            }

            MimeCode aCode = MimeCodeManager.Instance.GetCode(encoding);

            aCode.Charset = GetCharset();
            mContent      = aCode.EncodeFromBytes(b) + "\r\n";

            string filename;
            int    index = filePathName.LastIndexOf('\\');

            if (index != -1)
            {
                filename = filePathName.Substring(index + 1, filePathName.Length - index - 1);
            }
            else
            {
                filename = filePathName;
            }
            SetName(filename);

            sr.Close();
            sr = null;
        }
コード例 #11
0
        public void SetText(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException();
            }

            string encoding = GetTransferEncoding();

            if (encoding == null)
            {
                encoding = MimeConst.Encoding7Bit;
                SetTransferEncoding(encoding);
            }
            MimeCode aCode = MimeCodeManager.Instance.GetCode(encoding);

            aCode.Charset = GetCharset();
            mContent      = aCode.EncodeFromString(text) + "\r\n";

            SetContentType("text/plain");
            SetCharset(aCode.Charset);
        }
コード例 #12
0
ファイル: MimeCodeManager.cs プロジェクト: dblock/sncore
		public void SetCode(string name, MimeCode code)
		{
			codeHT.Add(name.ToLower(), code);
		}
コード例 #13
0
ファイル: MimeCodeManager.cs プロジェクト: qwdf1615/sncore
 public void SetCode(string name, MimeCode code)
 {
     codeHT.Add(name.ToLower(), code);
 }