Beispiel #1
0
        /// <summary>
        /// Examples:
        ///		2        -> seq-number (2)
        ///		2:4      -> seq-range  (from 2 - 4)
        ///		2:*      -> seq-range  (from 2 to last)
        ///		2,3,10:* -> sequence-set (seq-number,seq-number,seq-range)
        ///		                       (2,3, 10 - last)
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void LoadMessages(String start, String end)
        {
            Messages.Clear();
            if (!_IsConnected)
            {
                throw new EMailException {
                          ExceptionType = EMAIL_EXCEPTION_TYPE.NOT_CONNECTED
                }
            }
            ;
            if (!String.IsNullOrWhiteSpace(_CurrentFolder))
            {
                Client.Fetch(
                    false,

                    IMAP_t_SeqSet.Parse(start + ":" + end),
                    new IMAP_t_Fetch_i[]
                {
                    new IMAP_t_Fetch_i_Envelope(),
                    new IMAP_t_Fetch_i_Flags(),
                    new IMAP_t_Fetch_i_InternalDate(),
                    new IMAP_t_Fetch_i_Rfc822Size(),
                    new IMAP_t_Fetch_i_Uid()
                },
                    (s, e) =>
                {
                    try
                    {
                        IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;

                        string from = "";
                        if (fetchResp.Envelope.From != null)
                        {
                            for (int i = 0; i < fetchResp.Envelope.From.Length; i++)
                            {
                                // Don't add ; for last item
                                if (i == fetchResp.Envelope.From.Length - 1)
                                {
                                    from += fetchResp.Envelope.From[i].ToString();
                                }
                                else
                                {
                                    from += fetchResp.Envelope.From[i].ToString() + ";";
                                }
                            }
                        }
                        else
                        {
                            from = "<none>";
                        }
                        string Subject = fetchResp.Envelope.Subject != null ? fetchResp.Envelope.Subject : "<none>";
                        string Date    = fetchResp.InternalDate.Date.ToString("dd.MM.yyyy HH:mm");
                        string size    = ((decimal)(fetchResp.Rfc822Size.Size / (decimal)1000)).ToString("f2") + " kb";

                        Mail_t_Address[] froms = fetchResp.Envelope.From;

                        string Tag = fetchResp.UID.UID.ToString();

                        IMAP_Message_Wrapper wr = new IMAP_Message_Wrapper {
                            Client = Client, SequenceNumber = (int)fetchResp.UID.UID, UID = Tag, Date = fetchResp.InternalDate.Date, Size = fetchResp.Rfc822Size.Size, Subject = Subject
                        };
                        foreach (var item in froms)
                        {
                            if (item is Mail_t_Mailbox)
                            {
                                wr.From.Add(((Mail_t_Mailbox)item).Address);
                            }
                        }
                        //var F = fetchResp.Flags.Flags;
                        //if(!F.Contains("\\Deleted"))
                        _Messages.Add(wr);
                    }
                    catch (Exception exe)
                    {
                        throw new EMailException
                        {
                            ExceptionType  = EMAIL_EXCEPTION_TYPE.ERROR_ON_GET_MESSAGE,
                            InnerException = exe
                        };
                    }
                }
                    );
                if (OnMessagesLoaded != null)
                {
                    OnMessagesLoaded(this);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Examples:
        ///		2        -> seq-number (2)
        ///		2:4      -> seq-range  (from 2 - 4)
        ///		2:*      -> seq-range  (from 2 to last)
        ///		2,3,10:* -> sequence-set (seq-number,seq-number,seq-range)
        ///		                       (2,3, 10 - last)
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void LoadMessages(String start, String end)
        {
            if (!_IsConnected) throw new EMailException { ExceptionType = EMAIL_EXCEPTION_TYPE.NOT_CONNECTED };
            if (!String.IsNullOrWhiteSpace(_CurrentFolder))
            {
                Client.Fetch(
                    false,

                    IMAP_t_SeqSet.Parse(start + ":" + end),
                    new IMAP_t_Fetch_i[]
                    {
                        new IMAP_t_Fetch_i_Envelope(),
                        new IMAP_t_Fetch_i_Flags(),
                        new IMAP_t_Fetch_i_InternalDate(),
                        new IMAP_t_Fetch_i_Rfc822Size(),
                        new IMAP_t_Fetch_i_Uid()
                    },
                    (s, e) =>
                    {
                        try
                        {
                            IMAP_r_u_Fetch fetchResp = (IMAP_r_u_Fetch)e.Value;

                            string from = "";
                            if (fetchResp.Envelope.From != null)
                            {
                                for (int i = 0; i < fetchResp.Envelope.From.Length; i++)
                                {
                                    // Don't add ; for last item
                                    if (i == fetchResp.Envelope.From.Length - 1)
                                    {
                                        from += fetchResp.Envelope.From[i].ToString();
                                    }
                                    else
                                    {
                                        from += fetchResp.Envelope.From[i].ToString() + ";";
                                    }
                                }
                            }
                            else
                            {
                                from = "<none>";
                            }
                            string Subject = fetchResp.Envelope.Subject != null ? fetchResp.Envelope.Subject : "<none>";
                            string Date = fetchResp.InternalDate.Date.ToString("dd.MM.yyyy HH:mm");
                            string size = ((decimal)(fetchResp.Rfc822Size.Size / (decimal)1000)).ToString("f2") + " kb";

                            Mail_t_Address[] froms = fetchResp.Envelope.From;

                            string Tag = fetchResp.UID.UID.ToString();

                            IMAP_Message_Wrapper wr = new IMAP_Message_Wrapper { Client = Client, SequenceNumber = (int)fetchResp.UID.UID, UID = Tag, Date = fetchResp.InternalDate.Date, Size = fetchResp.Rfc822Size.Size, Subject = Subject };
                            foreach (var item in froms)
                            {
                                if (item is Mail_t_Mailbox)
                                {
                                    wr.From.Add(((Mail_t_Mailbox)item).Address);
                                }
                            }
                            _Messages.Add(wr);

                        }
                        catch (Exception exe)
                        {
                            throw new EMailException
                            {
                                ExceptionType = EMAIL_EXCEPTION_TYPE.ERROR_ON_GET_MESSAGE,
                                InnerException = exe
                            };
                        }
                    }
                );
                if (OnMessagesLoaded != null) OnMessagesLoaded(this);
            }
        }