예제 #1
0
    }     // List<Message> RetrieveMessages(...

    /// <summary>
    /// This method retrieves the mail messages using the IMAP protocol.
    /// </summary>
    /// <param name="psMailBoxName"></param>
    /// <param name="piStart"></param>
    /// <param name="piCount"></param>
    /// <returns>A list of Header object(s)</returns>
    public List <MailHeader> RetrieveHeaders(String psMailBoxName, int piStart, int piCount)
    {
        int iCount;
        List <MailHeader> lstRetVal;


        do
        {
            ErrorMessage = "";
            lstRetVal    = new List <MailHeader>();
            try
            {
                Mailbox inbox        = this._imap4Client.SelectMailbox(psMailBoxName);
                Fetch   fetch        = inbox.Fetch;
                int     messageCount = inbox.MessageCount;

                iCount = 0;
                for (int i = piStart; ((i <= messageCount) && (iCount <= piCount)); i++)
                {
                    MailHeader mailHeader = new MailHeader();
                    Header     header     = fetch.HeaderObject(i);
                    String     uid        = fetch.Uid(i).ToString();
                    mailHeader.Index = i.ToString();
                    mailHeader.FillHeader(header);
                    mailHeader.UniqueId = uid;
                    lstRetVal.Add(mailHeader);
                    if (++iCount >= piCount)
                    {
                        break;
                    }
                }

                fetch = inbox.Fetch;
                if (messageCount == this._imap4Client.SelectMailbox(psMailBoxName).MessageCount)
                {
                    break;
                }
            }
            catch (Exception ex)
            {
                log.Error("ImapController Metodo: RetrieveHeaders: ", ex);
                ErrorMessage = ex.Message;
                lstRetVal.Clear();
                return(lstRetVal);
            }
        } while (true);

        return(lstRetVal);
    }
예제 #2
0
    /// <summary>
    /// Method for retrieve the mail headers for POP protocol.
    /// </summary>
    /// <returns>The mail headers</returns>
    public List <MailHeader> RetrieveHeaders()
    {
        this.ListMessageInbox.Clear();

        int messageCount = this._pop3Client.MessageCount;

        for (int i = 1; i <= messageCount; i = i + 1)
        {
            MailHeader mailHeader = new MailHeader();
            Header     header     = new Header();
            header           = this._pop3Client.RetrieveHeaderObject(i);
            mailHeader.Index = i.ToString();
            mailHeader.FillHeader(header);
            this._listHeaderInbox.Add(mailHeader);
        }

        return(this.ListHeaderInbox);
    }
예제 #3
0
    /// <summary>
    /// Method for retrieve the mail headers for IMAP protocol.
    /// </summary>
    /// <param name="mailBox">The mail box</param>
    /// <returns>The mail headers</returns>
    public List <MailHeader> RetrieveHeaders(string mailBox)
    {
        Mailbox inbox        = this._imap4Client.SelectMailbox(mailBox);
        Fetch   fetch        = inbox.Fetch;
        int     messageCount = inbox.MessageCount;

        this._listMessageInbox.Clear();

        for (int i = 1; i <= messageCount; i++)
        {
            MailHeader mailHeader = new MailHeader();
            Header     header     = fetch.HeaderObject(i);
            mailHeader.Index = i.ToString();
            mailHeader.FillHeader(header);
            this._listHeaderInbox.Add(mailHeader);
        }
        return(this._listHeaderInbox);
    }
예제 #4
0
    public List <MailHeader> GetSentMailList()
    {
        string            path = Path.Combine(Path.GetTempPath(), Constants.SENT_MAILS_FOLDER);
        List <MailHeader> ret  = null;

        if (Directory.Exists(path))
        {
            string[] arquivos = Directory.GetFiles(path);
            ret = new List <MailHeader>();

            foreach (string name in arquivos)
            {
                Message    msg    = Parser.ParseMessageFromFile(Path.Combine(path, name));
                MailHeader header = new MailHeader();
                header.FillHeader(msg, name);
                ret.Add(header);
            }
        }

        return(ret);
    }
예제 #5
0
    public List<MailHeader> GetSentMailList()
    {

        string path = Path.Combine(Path.GetTempPath(), Constants.SENT_MAILS_FOLDER);
        List<MailHeader> ret = null;

        if (Directory.Exists(path))
        {
            string[] arquivos = Directory.GetFiles(path);
            ret = new List<MailHeader>();

            foreach (string name in arquivos)
            {
                Message msg = Parser.ParseMessageFromFile(Path.Combine(path, name));
                MailHeader header = new MailHeader();
                header.FillHeader(msg, name);
                ret.Add(header);
            }
        }

        return ret;
    }
예제 #6
0
    /// <summary>
    /// Method for retrieve the mail headers for POP protocol.
    /// </summary>   
    /// <returns>The mail headers</returns>
    public List<MailHeader> RetrieveHeaders()
    {       
        this.ListMessageInbox.Clear();
        
        int messageCount = this._pop3Client.MessageCount;        

        for (int i = 1; i <= messageCount; i = i + 1)
        {
            MailHeader mailHeader = new MailHeader();
            Header header = new Header();
            header = this._pop3Client.RetrieveHeaderObject(i);
            mailHeader.Index = i.ToString();
            mailHeader.FillHeader(header);
            this._listHeaderInbox.Add(mailHeader);
        }

        return this.ListHeaderInbox;
    }
예제 #7
0
    /// <summary>
    /// Method for retrieve the mail headers for IMAP protocol.
    /// </summary>
    /// <param name="mailBox">The mail box</param>
    /// <returns>The mail headers</returns>
    public List<MailHeader> RetrieveHeaders(string mailBox)
    {
        Mailbox inbox = this._imap4Client.SelectMailbox(mailBox);
        Fetch fetch = inbox.Fetch;
        int messageCount = inbox.MessageCount;
        this._listMessageInbox.Clear();       

        for (int i = 1; i <= messageCount; i++)
        {
            MailHeader mailHeader = new MailHeader();
            Header header = fetch.HeaderObject(i);
            mailHeader.Index = i.ToString();
            mailHeader.FillHeader(header);
            this._listHeaderInbox.Add(mailHeader);            
        }
        return this._listHeaderInbox;
    }
예제 #8
0
    /// <summary>
    /// Retrieves the mail headers for POP protocol.
    /// </summary>
    /// <returns>The mail headers. If a MailHeader has uid="*", that element is no more available in te server.</returns>
    public List <MailHeader> RetrieveHeaders(int pidxStart, int piCount)
    {
        int MessageCount;
        int MessageSize;
        int iCount;
        List <MailHeader> lstRetVal;


        ErrorMessage = "";
        try
        {
            do
            {
                if (!IsMailServerReady())
                {
                    return(new List <MailHeader>());
                }

                MessageCount = this._pop3Client.MessageCount;
                MessageSize  = this._pop3Client.TotalSize;

                iCount    = 0;
                lstRetVal = new List <MailHeader>();
                for (int i = pidxStart; i <= MessageCount; i = i + 1)
                {
                    Header header;

                    header = this._pop3Client.RetrieveHeaderObject(i);
                    if (header != null)
                    {
                        MailHeader mailHeader = new MailHeader();

                        mailHeader.Index = i.ToString();
                        mailHeader.FillHeader(header);
                        mailHeader.UniqueId = this._pop3Client.GetUniqueId(i);
                        lstRetVal.Add(mailHeader);
                        if (++iCount >= piCount)
                        {
                            break;
                        }
                    }
                    else
                    {
                        MailHeader mailHeader = new MailHeader();

                        mailHeader.Index    = i.ToString();
                        mailHeader.UniqueId = "*";
                        lstRetVal.Add(mailHeader);
                    }
                }

                this._pop3Client.UpdateStats();
                if (MessageCount == this._pop3Client.MessageCount)
                {
                    if (MessageSize == this._pop3Client.TotalSize)
                    {
                        return(lstRetVal);
                    }
                }
            } while (true);
        }
        catch (Exception ex)
        {
            //Allienamento log - Ciro
            if (ex.GetType() != typeof(ManagedException))
            {
                ManagedException mEx = new ManagedException(
                    "Errore durante la lettura degli headers dal server",
                    "POP3_ERR_004",
                    string.Empty,
                    "Casella mail: " + ((AccountInfo.LoginId != null) ? AccountInfo.LoginId : " vuoto. "), //EnanchedInfo
                    ex.InnerException);
                ErrorLogInfo err = new ErrorLogInfo(mEx);
                log.Error(err);
            }
            ErrorMessage = ex.Message;
            //ManagedException mEx = new ManagedException(
            //    "Errore durante la lettura degli headers dal server",
            //    "POP3_ERR_004",
            //    "Pop3Controller",
            //    "RetrieveHeaders(int pidxStart, int piCount)",
            //    "Scarica gli headers dal server",
            //    (AccountInfo == null) ? "" : AccountInfo.LoginId,
            //    null,
            //    ex);
            //ErrorLogInfo err = new ErrorLogInfo(APP_CODE, mEx);
            //log.Error(err);
            //ErrorMessage = ex.Message;
        }

        return(null);
    } // List<MailHeader> RetrieveHeaders(...