예제 #1
0
        /// <summary>
        /// Удаляет все сообщения из IMAP папки по фильтру subject
        /// </summary>
        public static void ClearImapFolder(string mailbox, string password, string folder, string subject)
        {
            using (var imapClient = new IMAP_Client()) {
                imapClient.Connect(Settings.Default.IMAPHost, Convert.ToInt32(Settings.Default.IMAPPort));
                imapClient.Authenticate(mailbox, password);
                imapClient.SelectFolder(folder);
                var sequenceSet = new IMAP_SequenceSet();
                sequenceSet.Parse("1:*", Int64.MaxValue);
                var items = String.IsNullOrEmpty(subject)
                                        ? imapClient.FetchMessages(sequenceSet, IMAP_FetchItem_Flags.UID, false, false)
                                        : imapClient.FetchMessages(sequenceSet, IMAP_FetchItem_Flags.UID | IMAP_FetchItem_Flags.Envelope, false, false);

                //производим фильтрацию, если параметр subject установлен
                if (!String.IsNullOrEmpty(subject) && items != null && items.Length > 0)
                {
                    items = items
                            .Where(i => i.Envelope.Subject?.Equals(subject, StringComparison.CurrentCultureIgnoreCase) == true)
                            .ToArray();
                }

                if ((items != null) && (items.Length > 0))
                {
                    var sequenceMessages = new IMAP_SequenceSet();
                    sequenceMessages.Parse(String.Join(",", items.Select(i => i.UID.ToString()).ToArray()), long.MaxValue);
                    imapClient.DeleteMessages(sequenceMessages, true);
                }
            }
        }
예제 #2
0
        public IMAP_FetchItem[] FetchUIDs()
        {
            var sequenceUids = new IMAP_SequenceSet();

            sequenceUids.Parse("1:*", long.MaxValue);
            return(_imapClient.FetchMessages(sequenceUids, IMAP_FetchItem_Flags.UID, false, false)
                   ?? Enumerable.Empty <IMAP_FetchItem>().ToArray());
        }
예제 #3
0
        public static List <IMAP_FetchItem> CheckImapFolder(string mailbox, string password, string folder)
        {
            using (var imapClient = new IMAP_Client()) {
                imapClient.Connect(Settings.Default.IMAPHost, Convert.ToInt32(Settings.Default.IMAPPort));
                imapClient.Authenticate(mailbox, password);
                imapClient.SelectFolder(folder);
                var sequenceSet = new IMAP_SequenceSet();
                sequenceSet.Parse("1:*", Int64.MaxValue);
                var items = imapClient.FetchMessages(sequenceSet, IMAP_FetchItem_Flags.UID | IMAP_FetchItem_Flags.Envelope, false, false);
                if ((items != null) && (items.Length > 0))
                {
                    return(items.ToList());
                }
            }

            return(new List <IMAP_FetchItem>());
        }