Esempio n. 1
0
        /// <summary>
        /// Gets the POP3 box list.
        /// </summary>
        /// <returns></returns>
        public Pop3Box[] GetPop3BoxList()
        {
            ArrayList list = new ArrayList();

            using (IDataReader reader = DBPop3Box.GetList())
            {
                Pop3Box box   = null;
                int     boxId = -1;
                while (reader.Read())
                {
                    if (boxId != (int)reader["Pop3BoxId"])
                    {
                        if (box != null)
                        {
                            box.Handlers.ResetModified();
                        }

                        box = new Pop3Box(reader);
                        list.Add(box);
                    }
                    if (reader["HandlerName"] != DBNull.Value)
                    {
                        box.AddHandler(_config.Handlers[(string)reader["HandlerName"]]);
                    }
                }
            }
            return((Pop3Box[])list.ToArray(typeof(Pop3Box)));
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the POP3 box.
        /// </summary>
        /// <param name="box">The box.</param>
        /// <returns></returns>
        public Pop3Box UpdatePop3Box(Pop3Box box)
        {
            if (box.IsBoxModified())
            {
                using (DbTransaction tra = DbTransaction.Begin())
                {
                    int BoxId = box.Id;

                    if (box.Modified)
                    {
                        if (BoxId == -1)
                        {
                            using (IDataReader reader = DBPop3Box.Create(box.Name, box.Server,
                                                                         box.Port, box.Login, box.Password, box.IsActive,
                                                                         box.Interval, box.LastRequest, box.LastSuccessfulRequest,
                                                                         box.LastErrorText, box.AutoKillForRead))
                            {
                                if (reader.Read())
                                {
                                    BoxId = (int)reader["Pop3BoxId"];
                                }
                            }
                        }
                        else
                        {
                            DBPop3Box.Update(BoxId, box.Name, box.Server,
                                             box.Port, box.Login, box.Password, box.IsActive,
                                             box.Interval, box.LastRequest, box.LastSuccessfulRequest,
                                             box.LastErrorText, box.AutoKillForRead);
                        }

                        box.ResetModified();
                    }

                    if (box.Handlers.IsModified)
                    {
                        DBPop3Box.DeleteHandlers(BoxId);

                        foreach (Pop3MessageHandlerInfo info in box.Handlers)
                        {
                            DBPop3Box.CreateHandler(BoxId, info.Name);
                        }
                        box.Handlers.ResetModified();
                    }
                    if (box.Parameters.IsModified)
                    {
                        DBPop3Box.DeleteParameters(BoxId);

                        foreach (string name in box.Parameters.Keys)
                        {
                            DBPop3Box.AddParameter(BoxId, name, box.Parameters[name]);
                        }
                    }

                    tra.Commit();
                }
            }
            return(box);
        }
Esempio n. 3
0
        public Pop3Parameters(Pop3Box pop3Box)
        {
            _ownerPop3Box = pop3Box;

            using (IDataReader reader = DBPop3Box.GetParameterList(pop3Box.Id))
            {
                while (reader.Read())
                {
                    string name  = (string)reader["Name"];
                    string value = (reader["Value"] == DBNull.Value) ? string.Empty : (string)reader["Value"];

                    Add(name, value);
                }
            }

            _modified = false;
        }
Esempio n. 4
0
        public void Request()
        {
            System.Diagnostics.Trace.WriteLine("Pop3Box.Request()");

            _lastRequest   = DateTime.Now;
            _lastErrorText = String.Empty;

            try
            {
                System.Diagnostics.Trace.WriteLine(string.Format("Dns.GetHostByName({0})", _server));

                //IPHostEntry hostInfo = Dns.GetHostEntry(_server);
                IPAddress[] addresses = Dns.GetHostAddresses(_server);

                if (addresses.Length > 0)
                {
                    IPEndPoint pop3ServerEndPoint = new IPEndPoint(addresses[0], _port);

                    Pop3Connection pop3Connection = new Pop3Connection();

                    pop3Connection.Open(pop3ServerEndPoint);
                    System.Diagnostics.Trace.WriteLine(string.Format("pop3Connection.Open - OK"));

                    pop3Connection.User(_login);
                    System.Diagnostics.Trace.WriteLine(string.Format("pop3Connection.Login - OK"));

                    pop3Connection.Pass(_password);
                    System.Diagnostics.Trace.WriteLine(string.Format("pop3Connection.Password - OK"));

                    Pop3Stat stat = pop3Connection.Stat();
                    System.Diagnostics.Trace.WriteLine(string.Format("Message Count = {0}", stat.MessageCout));

                    Exception innerException = null;

                    if (stat.MessageCout > 0)
                    {
                        Pop3UIDInfoList messageList = pop3Connection.Uidl();
                        foreach (Pop3UIDInfo mi in messageList)
                        {
                            System.Diagnostics.Trace.WriteLine(string.Format("Message ID = {0}, UID = {1}", mi.ID, mi.UID));

                            if (!_AutoKillForRead && DBPop3Box.CheckMessageUId(_id, mi.UID))
                            {
                                continue;
                            }

                            Pop3Message message = pop3Connection.Retr(mi.ID);

                            System.Diagnostics.Trace.WriteLine(string.Format("pop3Connection.Retr - OK"));

                            foreach (Pop3MessageHandlerInfo handlerInfo in _handlers)
                            {
                                try
                                {
                                    handlerInfo.Handler.ProcessPop3Message(this, message);

                                    if (_AutoKillForRead)
                                    {
                                        pop3Connection.Dele(mi.ID);
                                    }
                                    else
                                    {
                                        DBPop3Box.AddMessageUId(_id, mi.UID);
                                    }

                                    System.Diagnostics.Trace.WriteLine(string.Format("Handler.ProcessPop3Message - OK"));
                                }
                                catch (Exception ex)
                                {
                                    System.Diagnostics.Trace.WriteLine(ex);
                                    innerException = ex;
                                }
                            }
                        }
                    }

                    pop3Connection.Quit();

                    if (innerException != null)
                    {
                        throw innerException;
                    }

                    System.Diagnostics.Trace.WriteLine("Quit - OK");
                }
                else
                {
                    throw new ArgumentException(string.Format("Could not find server {0}.", _server));
                }

                _lastSuccessfulRequest = _lastRequest;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                _lastErrorText = ex.Message;
            }

            System.Diagnostics.Trace.WriteLine(string.Format("DBPop3Box.UpdateTime(id = {0}, lastRequest = {1}, lastSuccessfulRequest = {2}, lastErrorText = {3})", _id, _lastRequest, _lastSuccessfulRequest, _lastErrorText));
            DBPop3Box.UpdateTime(_id, _lastRequest, _lastSuccessfulRequest, _lastErrorText);
        }
Esempio n. 5
0
 /// <summary>
 /// Removes the POP3 box.
 /// </summary>
 /// <param name="Pop3BoxId">The POP3 box id.</param>
 public void RemovePop3Box(int Pop3BoxId)
 {
     DBPop3Box.Delete(Pop3BoxId);
 }