Example #1
0
        protected void DeleteClick(string msgID, string msgMessageID)
        {
            string PathTemplate;

            PathTemplate = Path.Combine(ConfigSettings.DataStoragePath, String.Format("webmail{1}{0}{1}mails", UC.UserId, Path.DirectorySeparatorChar));
            string NameOfFile = PathTemplate + Path.DirectorySeparatorChar + msgMessageID + ".tmsg";

            if (File.Exists(NameOfFile))
            {
                Message         msg     = new Message();
                FileStream      newfile = new FileStream(NameOfFile, FileMode.Open);
                BinaryFormatter bf      = new BinaryFormatter();
                msg = (Message)bf.Deserialize(newfile);
                newfile.Close();

                foreach (MessageAttach ma in msg.Attachment)
                {
                    string attpath;
                    attpath = Path.Combine(ConfigSettings.DataStoragePath, String.Format("webmail{2}{0}{2}{1}", UC.UserId, ma.Filename, Path.DirectorySeparatorChar));
                    if (File.Exists(attpath))
                    {
                        File.Delete(attpath);
                    }
                }
                File.Delete(NameOfFile);
            }


            DataRow dtpop3 = DatabaseConnection.CreateDataset("SELECT MAILSERVER,MAILUSER,MAILPASSWORD FROM ACCOUNT WHERE UID=" + UC.UserId).Tables[0].Rows[0];
            string  pop3   = dtpop3[0].ToString();
            bool    secure = false;

            if (pop3.StartsWith("!"))
            {
                pop3   = pop3.Substring(1);
                secure = true;
            }
            using (Pop3Client email = new Pop3Client(dtpop3[1].ToString(), dtpop3[2].ToString(), pop3, secure))
            {
                email.OpenInbox();
                email.NextEmail(Convert.ToInt32(msgID));
                bool result = email.DeleteEmail();
                if (!result)
                {
                    lblError.Text = Root.rm.GetString("Mailtxt26");
                }
                email.Quit();
                email.CloseConnection();
                FillMsgIn(true, false);
                dgmessages.Visible = false;
            }
        }
Example #2
0
        private void получитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <Config.Server> list = _config.GetPop3();

            foreach (Config.Server srv in list)
            {
                try
                {
                    Pop3Client email = new Pop3Client(srv.User, srv.Password, srv.Address);
                    email.OpenInbox();

                    while (email.NextEmail())
                    {
                        _inbox.Add(new Letter()
                        {
                            Subject = email.Subject,
                            From    = email.From,
                            To      = email.To
                        });
                        email.DeleteEmail();
                    }

                    email.CloseConnection();
                }
                catch (Pop3LoginException)
                {
                    string msg = "Сервер " + srv.Address + " не доступен";
                    MessageBox.Show(msg);
                }
                catch (Pop3ConnectException)
                {
                    string msg = "Сервер " + srv.Address + " не доступен";
                    MessageBox.Show(msg);
                }
            }
            UpdateInbox();
        }
Example #3
0
        /// <summary>
        /// Execute() implementation
        /// </summary>
        /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public void Execute(XmlNode testConfig, Context context)
        {
            int    delayBeforeCheck = context.ReadConfigAsInt32(testConfig, "DelayBeforeCheck", true);
            string server           = context.ReadConfigAsString(testConfig, "Server");
            string user             = context.ReadConfigAsString(testConfig, "User");
            string password         = context.ReadConfigAsString(testConfig, "Password");
            string from             = null;
            bool   showBody         = false;
            string subject          = null;
            int    attachments      = -1;
            bool   found            = false;

            if (testConfig.SelectSingleNode("ShowBody") != null)
            {
                showBody = context.ReadConfigAsBool(testConfig, "ShowBody");
            }

            if (testConfig.SelectSingleNode("From") != null)
            {
                from = context.ReadConfigAsString(testConfig, "From");
            }

            if (testConfig.SelectSingleNode("Subject") != null)
            {
                subject = context.ReadConfigAsString(testConfig, "Subject");
            }

            if (testConfig.SelectSingleNode("Attachments") != null)
            {
                attachments = context.ReadConfigAsInt32(testConfig, "Attachments");
            }

            if (delayBeforeCheck > 0)
            {
                context.LogInfo("Waiting for {0} seconds before checking the mail.", delayBeforeCheck);
                System.Threading.Thread.Sleep(delayBeforeCheck * 1000);
            }

            var email = new Pop3Client(user, password, server);

            email.OpenInbox();

            try
            {
                while (email.NextEmail())
                {
                    if (email.To == user && (email.From == from || from == null) && (email.Subject == subject || subject == null))
                    {
                        if (attachments > 0 && email.IsMultipart)
                        {
                            int         a          = 0;
                            IEnumerator enumerator = email.MultipartEnumerator;
                            while (enumerator.MoveNext())
                            {
                                var multipart = (Pop3Component)
                                                enumerator.Current;
                                if (multipart.IsBody)
                                {
                                    if (showBody)
                                    {
                                        context.LogData("Multipart body", multipart.Data);
                                    }
                                }
                                else
                                {
                                    context.LogData("Attachment name", multipart.Name);
                                    a++;
                                }
                            }
                            if (attachments == a)
                            {
                                found = true;
                                break;
                            }
                        }
                        else
                        {
                            if (showBody)
                            {
                                context.LogData("Single body", email.Body);
                            }
                            found = true;
                            break;
                        }
                    }
                }


                if (!found)
                {
                    throw new Exception("Failed to find email message");
                }
                else
                {
                    email.DeleteEmail();
                }
            }
            finally
            {
                email.CloseConnection();
            }
        }
Example #4
0
        private static void ReceiveMail()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load((string)cfg.GetValue("game.xml", typeof(string)));

            Pop3Client pop3 = new Pop3Client(
                (string)cfg.GetValue("pop3.username", typeof(string)),
                (string)cfg.GetValue("pop3.password", typeof(string)),
                (string)cfg.GetValue("pop3.server", typeof(string)));

            pop3.OpenInbox();

            while (pop3.NextEmail())
            {
                Log("Receiving \"" + pop3.Subject + "\" from " + pop3.From);

                string body;
                if (pop3.Charset == "koi8-r")
                {
                    body = KoiToWin(pop3.Body);
                }
                else
                {
                    body = pop3.Body;
                }

                string filename = "";
                bool   checker  = false;
                bool   save     = true;
                string folder   = (string)cfg.GetValue("mailbox", typeof(string));
                if (pop3.Subject.ToLower() == "request")
                {
                    int i = 1;
                    while (File.Exists(Path.Combine(folder, "request." + i.ToString())))
                    {
                        i++;
                    }
                    filename = "request." + i.ToString();
                    Log("..this is a request :)");

                    TextWriter tw = new StreamWriter(Path.Combine(folder, filename + ".confirm"), false,
                                                     Encoding.GetEncoding(1251));
                    tw.WriteLine("To: " + pop3.From);
                    tw.WriteLine("Subject: [Wasteland] Request confirmation");
                    tw.WriteLine("");
                    tw.WriteLine("Request accepted. Wait for next turn please.");
                    tw.Close();
                }
                else
                {
                    string[] ss = body.Split('\n');
                    int      i  = 0;
                    for (i = 0; i < ss.Length; i++)
                    {
                        string s = ss[i];
                        Regex  re;

                        // Orders
                        re = new Regex(@"#orders (\d+) ""(.*?)""");
                        if (re.IsMatch(s))
                        {
                            Match  m        = re.Match(s);
                            string faction  = m.Groups[1].Value;
                            string password = m.Groups[2].Value;

                            XmlElement elFaction = (XmlElement)doc.SelectSingleNode(
                                String.Format("/game/faction[@num='{0}']",
                                              faction.Replace("'", "")));
                            if (elFaction == null)
                            {
                                Log("..faction " + faction + " not found");
                            }
                            else if (elFaction.GetAttribute("password") != password)
                            {
                                Log("..wrong password for " + faction);
                            }
                            else
                            {
                                Log("..found orders for " + faction);
                                filename = "order." + faction;
                                checker  = true;
                                break;
                            }
                        }

                        // Report resend
                        re = new Regex(@"#resend (\d+) ""(.*?)""");
                        if (re.IsMatch(s))
                        {
                            Match  m        = re.Match(s);
                            string faction  = m.Groups[1].Value;
                            string password = m.Groups[2].Value;

                            XmlElement elFaction = (XmlElement)doc.SelectSingleNode(
                                String.Format("/game/faction[@num='{0}']",
                                              faction.Replace("'", "")));
                            if (elFaction == null)
                            {
                                Log("..faction " + faction + " not found");
                            }
                            else if (elFaction.GetAttribute("password") != password)
                            {
                                Log("..wrong password for " + faction);
                            }
                            else
                            {
                                Log("..found resend request for " + faction);

                                string   gamedir  = (string)cfg.GetValue("gamedir", typeof(string));
                                int      turnnum  = Convert.ToInt32(doc.SelectSingleNode("game/@turn").Value);
                                string   turnname = "turn." + (turnnum - 1).ToString();
                                FileInfo fi       = new FileInfo(Path.Combine(Path.Combine(gamedir, turnname),
                                                                              "report." + faction));
                                if (fi.Exists)
                                {
                                    fi.CopyTo(Path.Combine(folder, fi.Name), false);
                                }

                                checker  = false;
                                save     = false;
                                filename = "resend";
                                break;
                            }
                        }

                        // Mail
                        re = new Regex(@"#mail (person )?(\d+)( (\d+) ""(.*?)"")?");
                        if (re.IsMatch(s))
                        {
                            Match  m        = re.Match(s);
                            string person   = m.Groups[1].Value;
                            string to       = m.Groups[2].Value;
                            string faction  = m.Groups[4].Value;
                            string password = m.Groups[5].Value;

                            XmlElement elFaction = (XmlElement)doc.SelectSingleNode(
                                String.Format("/game/faction[@num='{0}']",
                                              faction.Replace("'", "")));

                            XmlElement elRecipient = null;
                            XmlElement elPerson    = null;
                            if (person != "person ")
                            {
                                elRecipient = (XmlElement)doc.SelectSingleNode(
                                    String.Format("/game/faction[@num='{0}']",
                                                  to.Replace("'", "")));
                            }
                            else
                            {
                                elPerson = (XmlElement)doc.SelectSingleNode(
                                    String.Format("//person[@num='{0}']", to.Replace("'", "")));
                                if (elPerson != null)
                                {
                                    elRecipient = (XmlElement)doc.SelectSingleNode(
                                        String.Format("/game/faction[@num='{0}']",
                                                      elPerson.GetAttribute("faction")));
                                }
                            }

                            if (elFaction != null && elFaction.GetAttribute("password") != password)
                            {
                                Log("..wrong password for " + faction);
                            }
                            else if (elRecipient == null || elRecipient.GetAttribute("email") == "")
                            {
                                Log("..recipient " + to + " not found");
                            }
                            else
                            {
                                Log("..found mail from " + faction);

                                filename = "mail." + faction + "-" + to + "." + DateTime.Now.ToString("HHmmssfff");
                                TextWriter tw = new StreamWriter(Path.Combine(folder, filename), false,
                                                                 Encoding.GetEncoding(1251));
                                tw.WriteLine("To: " + elRecipient.GetAttribute("email"));
                                string subj = "Subject: [Wasteland] Private message";
                                if (elFaction != null)
                                {
                                    subj += " from " + elFaction.GetAttribute("name") + " (" +
                                            elFaction.GetAttribute("num") + ")";
                                }
                                tw.WriteLine(subj);
                                tw.WriteLine("");
                                if (elPerson != null)
                                {
                                    tw.WriteLine("Message received by " + Translit(elPerson.GetAttribute("name")) +
                                                 " (" + to + ").");
                                }
                                for (int j = i + 1; j < ss.Length; j++)
                                {
                                    if (ss[j].Trim() == "#end")
                                    {
                                        break;
                                    }
                                    tw.WriteLine(ss[j]);
                                }
                                tw.Close();

                                filename = "confirm." + faction + "-" + to + "." + DateTime.Now.ToString("HHmmssfff");
                                tw       = new StreamWriter(Path.Combine(folder, filename), false,
                                                            Encoding.GetEncoding(1251));
                                tw.WriteLine("To: " + pop3.From);
                                tw.WriteLine("Subject: [Wasteland] Mail confirmation");
                                tw.WriteLine("");
                                if (elPerson == null)
                                {
                                    tw.WriteLine("Message to " + elRecipient.GetAttribute("name") +
                                                 " (" + to + ") sent.");
                                }
                                else
                                {
                                    tw.WriteLine("Message to " + Translit(elPerson.GetAttribute("name")) +
                                                 " (" + to + ") sent.");
                                }
                                tw.Close();

                                checker = false;
                                save    = false;
                                break;
                            }
                        }
                    }

                    if (filename == "")
                    {
                        int j = 1;
                        while (File.Exists(Path.Combine(folder, "spam." + j.ToString())))
                        {
                            j++;
                        }
                        filename = "spam." + j.ToString();
                        Log("..this should be spam :/");
                    }
                }

                if (save)
                {
                    TextWriter tw = new StreamWriter(Path.Combine(folder, filename), false,
                                                     Encoding.GetEncoding(1251));
                    tw.WriteLine("From: " + pop3.From);
                    tw.WriteLine("Subject: " + pop3.Subject);
                    tw.WriteLine("");
                    tw.WriteLine(body);
                    tw.Close();
                }

                if (checker)
                {
                    Log("Checking " + filename);
                    RunEngine("/check " + Path.Combine(folder, filename));
                }

                pop3.DeleteEmail();
            }

            pop3.CloseConnection();
        }
        public static string FindAndRecordEmailBounces()
        {
            Pop3Client email   = null;
            string     message = string.Empty;

            try
            {
                email = new Pop3Client("*****@*****.**", "deadFax186", "mail.thebirthdayregister.com");
                email.OpenInbox();

                // only process x amount of messages at a time because deleting is not really done until the session is closed
                const long nMaxProcess = 2;
                long       nTotalCount = Math.Min(nMaxProcess, email.MessageCount);
                long       nMaxEmail   = email.MessageCount;
                long       nMinEmail   = Math.Max(0, email.MessageCount - nMaxProcess);
                for (long i = nMaxEmail - 1; i >= nMinEmail; i--)
                {
                    email.NextEmail(i);
                    if (0 != string.Compare(email.To, "*****@*****.**", true))
                    {
                        continue;
                    }
                    // check the subject, delete items as appropriate
                    if (email.Subject.ToLower().Contains("delay"))
                    {
                        email.DeleteEmail();
                    }
                    string szRecipient = "", szAction = "", szStatus = "", szTo = "", szFrom = "", szSubject = "", szDate = "", szReply_to = "";
                    if (email.Subject.ToLower().Contains("failure notice") || email.Subject.ToLower().Contains("Delivery Status Notification (Failure)") || email.Subject.ToLower().Contains("Mail Delivery Failure") || email.Subject.ToLower().Contains("Mail System Error - Returned Mail"))
                    {
                        if (!email.IsMultipart)
                        {
                            szTo        = GetEmailFromValue(GetValueFromKey(email.Body, "To:"));
                            szFrom      = GetEmailFromValue(GetValueFromKey(email.Body, "From:"));
                            szSubject   = CleanSubject(GetValueFromKey(email.Body, "Subject:"));
                            szDate      = GetValueFromKey(email.Body, "Date:");
                            szRecipient = GetEmailFromValue(GetValueFromKey(email.Body, "Final-Recipient:"));
                            szAction    = GetValueFromKey(email.Body, "Action:");
                            szStatus    = GetValueFromKey(email.Body, "Status:");
                            szReply_to  = GetEmailFromValue(GetValueFromKey(email.Body, "Reply-To:"));
                        }
                        else
                        {
                            System.Collections.IEnumerator enumerator = email.MultipartEnumerator;
                            while (enumerator.MoveNext())
                            {
                                Pop3Component multipart = (Pop3Component)enumerator.Current;

                                if (string.IsNullOrEmpty(szTo))
                                {
                                    szTo = GetEmailFromValue(GetValueFromKey(multipart.Data, "To:"));
                                }
                                if (string.IsNullOrEmpty(szTo))
                                {
                                    szTo = GetEmailFromValue(GetValueFromKey(multipart.Data, "Original-Recipient:"));
                                }
                                if (string.IsNullOrEmpty(szFrom))
                                {
                                    szFrom = GetEmailFromValue(GetValueFromKey(multipart.Data, "From:"));
                                }
                                if (string.IsNullOrEmpty(szSubject))
                                {
                                    szSubject = CleanSubject(GetValueFromKey(multipart.Data, "Subject:"));
                                }
                                if (string.IsNullOrEmpty(szDate))
                                {
                                    szDate = GetValueFromKey(multipart.Data, "Date:");
                                }
                                if (string.IsNullOrEmpty(szDate))
                                {
                                    szDate = GetValueFromKey(multipart.Data, "Arrival-Date:");
                                }
                                if (string.IsNullOrEmpty(szRecipient))
                                {
                                    szRecipient = GetEmailFromValue(GetValueFromKey(multipart.Data, "Final-Recipient:"));
                                }
                                if (string.IsNullOrEmpty(szAction))
                                {
                                    szAction = GetValueFromKey(multipart.Data, "Action:");
                                }
                                if (string.IsNullOrEmpty(szStatus))
                                {
                                    szStatus = GetValueFromKey(multipart.Data, "Status:");
                                }
                                if (string.IsNullOrEmpty(szReply_to))
                                {
                                    szReply_to = GetEmailFromValue(GetValueFromKey(multipart.Data, "Reply-To:"));
                                }
                            }
                        }
                        message = message + szTo + " | " + szFrom + " | " + szReply_to + " | " + szSubject + " | " + szDate + " <br/>";
                        email.DeleteEmail();
                    }
                }
                message = message + string.Format("Total message count: {0}, Process message count: {1}", email.MessageCount.ToString(), nTotalCount.ToString());
                email.CloseConnection();
            }
            catch (Exception ex)
            {
                if (null != email)
                {
                    try
                    {
                        email.CloseConnection();
                    }
                    catch
                    {
                    }
                }
                message = "Exception thrown in FindAndRecordEmailBounces.  Message: " + ex.Message;
            }
            return(message);
        }
Example #6
0
        /// <summary>
        ///     Execute() implementation
        /// </summary>
        /// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
        /// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
        public void Execute(XmlNode testConfig, Context context)
        {
            var    delayBeforeCheck = context.ReadConfigAsInt32(testConfig, "DelayBeforeCheck", true);
            var    server           = context.ReadConfigAsString(testConfig, "Server");
            var    user             = context.ReadConfigAsString(testConfig, "User");
            var    password         = context.ReadConfigAsString(testConfig, "Password");
            string from             = null;
            var    showBody         = false;
            string subject          = null;
            var    attachments      = -1;
            var    found            = false;

            if (testConfig.SelectSingleNode("ShowBody") != null)
            {
                showBody = context.ReadConfigAsBool(testConfig, "ShowBody");
            }

            if (testConfig.SelectSingleNode("From") != null)
            {
                from = context.ReadConfigAsString(testConfig, "From");
            }

            if (testConfig.SelectSingleNode("Subject") != null)
            {
                subject = context.ReadConfigAsString(testConfig, "Subject");
            }

            if (testConfig.SelectSingleNode("Attachments") != null)
            {
                attachments = context.ReadConfigAsInt32(testConfig, "Attachments");
            }

            if (delayBeforeCheck > 0)
            {
                context.LogInfo("Waiting for {0} seconds before checking the mail.", delayBeforeCheck);
                Thread.Sleep(delayBeforeCheck * 1000);
            }

            using (var email = new Pop3Client(user, password, server))
            {
                email.OpenInbox();

                while (email.NextEmail())
                {
                    if (email.To == user && (email.From == @from || @from == null) &&
                        (email.Subject == subject || subject == null))
                    {
                        if (attachments > 0 && email.IsMultipart)
                        {
                            var a = 0;
                            foreach (var multipart in email)
                            {
                                if (multipart.IsBody)
                                {
                                    if (showBody)
                                    {
                                        context.LogData("Multipart body", multipart.Data);
                                    }
                                }
                                else
                                {
                                    context.LogData("Attachment name", multipart.Name);
                                    a++;
                                }
                            }
                            if (attachments == a)
                            {
                                found = true;
                                break;
                            }
                        }
                        else
                        {
                            if (showBody)
                            {
                                context.LogData("Single body", email.Body);
                            }
                            found = true;
                            break;
                        }
                    }
                }


                if (!found)
                {
                    throw new InvalidOperationException("Failed to find email message");
                }
                email.DeleteEmail();
            }
        }