Exemple #1
0
        public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile)
        {
            string text  = Guid.NewGuid().ToString().Replace("-", "");
            string text2 = "";
            int    num   = 0;

            try
            {
                Mail_Message entity = Mail_Message.ParseFromFile(messageFile);
                text2 = IMAP_Envelope.ConstructEnvelope(entity);
                num   = (int)new FileInfo(messageFile).Length;
            }
            catch
            {
            }
            if (!Directory.Exists(RecycleBinManager.m_RecycleBinPath))
            {
                try
                {
                    Directory.CreateDirectory(RecycleBinManager.m_RecycleBinPath);
                }
                catch
                {
                }
            }
            File.Copy(messageFile, RecycleBinManager.m_RecycleBinPath + text + ".eml");
            using (FileStream file = RecycleBinManager.GetFile())
            {
                file.Position = file.Length;
                byte[] bytes = Encoding.UTF8.GetBytes(string.Concat(new object[]
                {
                    text,
                    " ",
                    DateTime.Now.ToString("yyyyMMddHHmmss"),
                    " ",
                    folderOwner,
                    " ",
                    TextUtils.QuoteString(folder),
                    " ",
                    num,
                    " ",
                    TextUtils.QuoteString(text2),
                    "\r\n"
                }));
                file.Write(bytes, 0, bytes.Length);
            }
        }
        /// <summary>
        /// Stores specified message to recycle bin.
        /// </summary>
        /// <param name="folderOwner">Folder woner user.</param>
        /// <param name="folder">Folder what message it is.</param>
        /// <param name="messageFile">Message file name with path.</param>
        public static void StoreToRecycleBin(string folderOwner, string folder, string messageFile)
        {
            string messageID = Guid.NewGuid().ToString().Replace("-", "");
            string envelope  = "";
            int    size      = 0;

            try{
                // Parse message
                Mail_Message m = Mail_Message.ParseFromFile(messageFile);

                // Construct envelope
                envelope = IMAP_Envelope.ConstructEnvelope(m);

                size = (int)new FileInfo(messageFile).Length;
            }
            catch {
            }

            if (!Directory.Exists(m_RecycleBinPath))
            {
                try{
                    Directory.CreateDirectory(m_RecycleBinPath);
                }
                catch {
                }
            }

            // Store recycle bin copy of message
            File.Copy(messageFile, m_RecycleBinPath + messageID + ".eml");

            // Update index file
            using (FileStream fs = GetFile()){
                fs.Position = fs.Length;

                // MessageID DeleteDate UserName Folder InternalDate Flags Subject
                byte[] record = System.Text.Encoding.ASCII.GetBytes(
                    messageID + " " +
                    DateTime.Now.ToString("yyyyMMddHHmmss") + " " +
                    folderOwner + " " +
                    TextUtils.QuoteString(folder) + " " +
                    size + " " +
                    TextUtils.QuoteString(envelope) + "\r\n"
                    );
                fs.Write(record, 0, record.Length);
            }
        }