/// <summary>
        /// Forwards the eml file to the recepient that is determined from the folder of the eml file.
        /// </summary>
        /// <param name="destinationIp">The destinationIp.</param>
        /// <param name="destinationHostname">The destinationHostname.</param>
        /// <returns>True if the mail was forwarded. False otherwise.</returns>
        public static Boolean Forward(FileInfo file, String destinationIp, String destinationHostname)
        {
            Boolean result = false;

            try
            {
                LumiSoft.Net.Mime.Mime mimemessage   = LumiSoft.Net.Mime.Mime.Parse(file.FullName);
                MemoryStream           messageStream = new MemoryStream();
                mimemessage.ToStream(messageStream);
                messageStream.Position = 0;

                LumiSoft.Net.SMTP.Client.SmtpClientEx smtpClient = new LumiSoft.Net.SMTP.Client.SmtpClientEx();
                smtpClient.Connect(destinationIp, 25);
                smtpClient.Ehlo(destinationHostname);
                smtpClient.SetSender(EmlFile.GetSender(mimemessage), messageStream.Length);
                smtpClient.AddRecipient(EmlFile.GetRecepient(file));
                smtpClient.SendMessage(messageStream);
                smtpClient.Disconnect();

                messageStream.Close();
                result = true;
            }
            catch (Exception ex)
            {
                throw new Exception("Forwarding failed", ex);
            }

            return(result);
        }
        private static String GetSender(LumiSoft.Net.Mime.Mime mimemessage)
        {
            String messageInMime = null;

            try
            {
                messageInMime = (mimemessage.MainEntity.From[0] as LumiSoft.Net.Mime.MailboxAddress).EmailAddress;
                messageInMime = new System.Net.Mail.MailAddress(messageInMime).Address;
            }
            catch
            {
                messageInMime = "*****@*****.**";
            }

            messageInMime = String.Format("<{0}>", messageInMime);

            return(messageInMime);
        }
        /// <summary>
        /// Gets if specified message matches with this class search-key.
        /// </summary>
        /// <param name="no">IMAP message sequence number.</param>
        /// <param name="uid">IMAP message UID.</param>
        /// <param name="size">IMAP message size in bytes.</param>
        /// <param name="internalDate">IMAP message INTERNALDATE (dateTime when server stored message).</param>
        /// <param name="flags">IMAP message flags.</param>
        /// <param name="mime">Mime message main header only.</param>
        /// <param name="bodyText">Message body text.</param>
        /// <returns></returns>
        public bool Match(long no, long uid, long size, DateTime internalDate, IMAP_MessageFlags flags, LumiSoft.Net.Mime.Mime mime, string bodyText)
        {
            // We must match all keys, if one fails, no need to check others

            foreach (object searckKey in m_pSearchKeys)
            {
                if (!Match_Key_Value(searckKey, no, uid, size, internalDate, flags, mime, bodyText))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Gets if specified message matches to specified search key.
        /// </summary>
        /// <param name="searchKey">SearchKey or SearchGroup.</param>
        /// <param name="no">IMAP message sequence number.</param>
        /// <param name="uid">IMAP message UID.</param>
        /// <param name="size">IMAP message size in bytes.</param>
        /// <param name="internalDate">IMAP message INTERNALDATE (dateTime when server stored message).</param>
        /// <param name="flags">IMAP message flags.</param>
        /// <param name="mime">Mime message main header only.</param>
        /// <param name="bodyText">Message body text.</param>
        /// <returns></returns>
        internal static bool Match_Key_Value(object searchKey, long no, long uid, long size, DateTime internalDate, IMAP_MessageFlags flags, LumiSoft.Net.Mime.Mime mime, string bodyText)
        {
            if (searchKey.GetType() == typeof(SearchKey))
            {
                if (!((SearchKey)searchKey).Match(no, uid, size, internalDate, flags, mime, bodyText))
                {
                    return(false);
                }
            }
            else if (searchKey.GetType() == typeof(SearchGroup))
            {
                if (!((SearchGroup)searchKey).Match(no, uid, size, internalDate, flags, mime, bodyText))
                {
                    return(false);
                }
            }

            return(true);
        }