Exemple #1
0
        private void DecodeData()
        {
            if (m_contentDisposition != null)
            {
                if (!Directory.Exists(Pop3Statics.DataFolder))
                {
                    Directory.CreateDirectory(Pop3Statics.DataFolder);
                }

                m_filepath = Pop3Statics.DataFolder + @"\" + m_filename;

                //if base-64 data
                if ((m_contentDisposition.Equals("attachment;")) && (m_contentTransferEncoding.ToUpper().Equals("BASE64")))
                {
                    //convert from base-64
                    m_binaryData = Convert.FromBase64String(m_data.Replace("\n", ""));

                    BinaryWriter bw = new BinaryWriter(new FileStream(m_filepath, FileMode.Create));

                    bw.Write(m_binaryData);
                    bw.Flush();
                    bw.Close();
                }
                else if ((m_contentDisposition.Equals("attachment;")) && (m_contentTransferEncoding.ToUpper().Equals("QUOTED-PRINTABLE")))
                {
                    //if printable
                    using (StreamWriter sw = File.CreateText(m_filepath))
                    {
                        sw.Write(Pop3Statics.FromQuotedPrintable(m_data));
                        sw.Flush();
                        sw.Close();
                    }
                }
            }
        }
Exemple #2
0
        private void DecodeData()
        {
            // if this data is an attachment ...
            if (m_contentDisposition != null)
            {
                // create data folder if it doesn't exist ...
                if (!Directory.Exists(Pop3Statics.DataFolder))
                {
                    Directory.CreateDirectory(Pop3Statics.DataFolder);
                }
                var searchText = "; filename=";
                if (m_filename == null && m_contentDisposition.Contains(searchText))                 //look in  filename=\"import example file.csv\"
                {
                    //below three lines could be easier using regular expression
                    int    startIndex      = m_contentDisposition.IndexOf(searchText) + searchText.Length;
                    string startOfFileName = m_contentDisposition.Remove(0, startIndex + 1);             //remove start
                    m_filename = startOfFileName.Remove(startOfFileName.Length - 2);                     //remove end
                    if (m_filename.Contains("\""))
                    {
                        m_filename = m_filename.Substring(0, m_filename.IndexOf('"'));
                    }

                    m_filePath = Pop3Statics.DataFolder + @"\" + Beweb.FileSystem.GetUniqueFilename(Pop3Statics.DataFolder + @"\", m_filename);
                    //m_filePath = Pop3Statics.DataFolder + @"\" + m_filename;
                }


                // if BASE-64 data ...
                if ((m_contentDisposition.Contains("attachment;")) &&
                    (m_contentTransferEncoding.ToUpper()
                     .Equals("BASE64")))
                {
                    // convert attachment from BASE64 ...
                    m_binaryData =
                        Convert.FromBase64String(m_data.Replace("\n", ""));

                    BinaryWriter bw = new BinaryWriter(
                        new FileStream(m_filePath, FileMode.Create));

                    bw.Write(m_binaryData);
                    bw.Flush();
                    bw.Close();
                }
                else if ((m_contentDisposition.Contains("attachment;")) &&                  // if PRINTABLE ...
                         (m_contentTransferEncoding.ToUpper()
                          .Equals("QUOTED-PRINTABLE")))
                {
                    using (StreamWriter sw = File.CreateText(m_filePath)) {
                        sw.Write(Pop3Statics.FromQuotedPrintable(m_data));
                        sw.Flush();
                        sw.Close();
                    }
                }
                else
                {
                    //Unknown type
                }
            }
        }