Exemplo n.º 1
0
        /// <summary>
        /// First phase: the complete list of the UIds is built.
        /// </summary>
        /// <returns></returns>
        public List <MessageUniqueId> RetrieveUIds()
        {
            List <Pop3Client.PopServerUniqueId> lstUId = null;
            List <MessageUniqueId> lstMUId             = null;
            int iMailHeader;


            // Create the object
            if (triggerChanges == null)
            {
                triggerChanges = new PostOfficeChangesTrigger(this);
            }

            // Restart the container (BUT without requesting reloading (recursive comes here again!)
            if (MailHeaderSyncCheck(true, false) < 0)
            {
                // Problems while connecting ...
                return(null);
            }

            // Get the full UIds list from PostOffice
            do
            {
                switch (InProtoGet())
                {
                case IncomingProtocols.POP3:
                    // Ask server
                    lstUId = this.Pop3.RetrieveUIds();
                    // Convert from one type to (an)other(s) ...
                    do
                    {
                        lstMUId     = new List <MessageUniqueId>();
                        iMailHeader = 0;
                        foreach (Pop3Client.PopServerUniqueId PSUId in lstUId)
                        {
                            // ------------------------------------------------------------ //
                            iMailHeader++;
                            if (iMailHeader != PSUId.Index)
                            {
                                // Unsynchronized lists (local vs. server)
                                iMailHeader = iMailHeader;
                            }
                            MailHeader mh = new MailHeader();
                            mh.Index    = PSUId.Index.ToString();
                            mh.UniqueId = PSUId.UniqueId;
                            mh.Date     = DateTime.MinValue;    // This value flags that the rest is not loaded yet.
                            aMailHeader[iMailHeader] = mh;
                            // ------------------------------------------------------------ //
                            MessageUniqueId muid = new MessageUniqueId();
                            muid.Ordinal = PSUId.Index;
                            muid.UId     = PSUId.UniqueId;
                            lstMUId.Add(muid);
                            // ------------------------------------------------------------ //
                        }
                        // The following line means: if it has changed in the meanwhile, please reload it!
                    } while (triggerChanges.StatisticsUpdate());
                    break;

                case IncomingProtocols.IMAP:
                    // doesn't yet exist! lstUId                          = this.imapController.RetrieveUIds( Constants.MAILBOX );
                    // Convert from one type to another ...
                    //lstMUId                         = new List<MessageUniqueId>();
                    //foreach( Pop3Client.PopServerUniqueId Puid in lstUId )
                    //    {
                    //    MessageUniqueId    muid         = new MessageUniqueId();
                    //    muid.Ordinal                    = Puid.Index;
                    //    muid.UId                        = Puid.UniqueId;
                    //    lstMUId.Add( muid );
                    //    }

                    //TASK: Allineamento log - Ciro
                    ManagedException mEx = new ManagedException("Imap not supported at all!",
                                                                "ERR_MAIL_0112", string.Empty,
                                                                string.Empty, null);
                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                    _log.Error(mEx);
                    throw mEx;
                    //throw new ManagedException("Imap not supported at all!", String.Empty, String.Empty, String.Empty, null);
                    break;

                default:
                    return(null);
                }
            } while ((this.Pop3.Pop3Client.IsConnected) && (triggerChanges.StatisticsUpdate() == true));

            return(lstMUId);
        } // List<MailUniqueId> RetrieveUIds()
Exemplo n.º 2
0
        /// <summary>
        /// Load a MailHeader segment
        /// </summary>
        /// <param name="piStart"></param>
        /// <param name="piCount"></param>
        /// <returns></returns>
        private MailHeader[] MailHeader_Fetch(int pidxStart, int piCount)
        {
            int idxStart;
            int idxStop;
            List <MailHeader> tmpListMailHeader = new List <MailHeader>();
            int i;
            int iMax;
            int iMin;
            int iDir;


            if (triggerChanges == null)
            {
                triggerChanges = new PostOfficeChangesTrigger(this);
            }

            if (ReloadForce || !triggerChanges.IsSynchronized())
            {
                // Reloads all the UIds (but NOT MailHeaders)
                if (MailHeaderSyncCheck(true, true) < 0)
                {
                    // Problems while connecting ...
                    return(null);
                }
            }

            iMax = aMailHeader.Length - 1;
            iMin = 1;
            if (false)
            {
                idxStart = pidxStart + iMin;
                idxStop  = idxStart + piCount - 1;
                iDir     = 1;
            }
            else
            {
                idxStart = aMailHeader.Length - pidxStart;
                idxStop  = idxStart - piCount + 1;
                iDir     = -1;
            }

            // Start is "Out of bound"? Zero included because the first item has index=1.
            if ((idxStart <= 0) || (idxStart >= aMailHeader.Length))
            {
                return(aMailHeader);      // Unchanged!
            }
            // Stop adjustment ...
            if ((idxStop <= 0) || (idxStop >= aMailHeader.Length))
            {
                idxStop = (iDir > 0) ? iMax : iMin;
            }

            // First I do check that requested elements has been already loaded ...
            for (i = idxStart; FetchScanCondition(iDir, i, idxStop); i += iDir)
            {
                // Is it loaded?
                if (IsMailHeaderNotLoaded(aMailHeader[i]))
                {
                    // No. I must load it now.
                    switch (InProtoGet())
                    {
                    case IncomingProtocols.POP3:
                        tmpListMailHeader = this.Pop3.RetrieveHeaders(i, 1);
                        break;

                    case IncomingProtocols.IMAP:
                        tmpListMailHeader = this.Imap.RetrieveHeaders(_MailBoxName, i, 1);
                        break;

                    default:
                        return(aMailHeader);       // Empty list ...

                        break;
                    }
                    // Starting from current position on ...
                    int cntInsert = 0;
                    foreach (MailHeader mh in tmpListMailHeader)
                    {
                        if (mh.UniqueId == "*")
                        { // Remove a no-more-valid item
                            int j = i + cntInsert;

                            if (mh.Index == aMailHeader[j].Index)   // It is the one to drop!
                            {
                                // ------------------------------------------------------------ //
                                // Be careful: now I remove the item ...
                                // ------------------------------------------------------------ //
                                for (; j < aMailHeader.Length - 1; j++)
                                {
                                    aMailHeader[j] = aMailHeader[j + 1];
                                }
                                // --- Size and Indexes bias ---------------------------------- //
                                iMax     = aMailHeader.Length - 1;
                                idxStop += iDir;
                                if (i == idxStart)
                                {
                                    idxStart += iDir;
                                }

                                if (idxStart <= 0)
                                {
                                    idxStart = 1;
                                }
                                if (idxStart >= aMailHeader.Length - 1)
                                {
                                    idxStart = aMailHeader.Length - 1;
                                }

                                if (idxStop <= 0)
                                {
                                    idxStop = 1;
                                }
                                if (idxStop >= aMailHeader.Length - 1)
                                {
                                    idxStop = aMailHeader.Length - 1;
                                }

                                // ------------------------------------------------------------ //
                                Array.Resize(ref aMailHeader, aMailHeader.Length - 1);
                            }
                        }
                        else
                        {
                            if (aMailHeader[i + cntInsert].UniqueId != mh.UniqueId)
                            {
                                // Unsynchronized lists!
                                if (MailHeaderLoad() < 0)
                                {
                                    //TASK: Allineamento log - Ciro
                                    ManagedException mEx = new ManagedException("Non posso leggere la casella postale",
                                                                                "ERR_MAIL_0107", string.Empty,
                                                                                string.Empty, null);
                                    ErrorLogInfo err = new ErrorLogInfo(mEx);
                                    _log.Error(mEx);
                                    throw mEx;
                                }
                                //throw new ManagedException("Non posso leggere la casella postale"
                                //                          , "ERR_MAIL_0007", "MailServerFacade.cs", "MailHeader_Fetch", "MailHeaderLoad", "", "", null
                                //                          );
                                return(MailHeader_Fetch(pidxStart, piCount));
                            }
                            else
                            {
                                aMailHeader[i + cntInsert] = mh;
                                cntInsert += iDir;
                            }
                        }
                    }
                }
            } // for ( i = idxStart ; ...

            ReloadForce = false;
            return(aMailHeader);
        } // MailHeader[] MailHeader_Fetch(...