Example #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);
                }
            }
        }
        public override void Authenticate()
        {
            Logger.Debug("Authenticating connection {0}", LogSource.Channel, UniqueId);

            if (channelState == ChannelState.Authenticated)
            {
                return;
            }

            if (channelState != ChannelState.Connected)
            {
                Logger.Error("Unable to authenticate in current channel state. ChannelState = {0}", LogSource.Channel, channelState);

                throw new ChannelException("Unable to authenticate in current channel state");
            }

            try
            {
                client.Capability();
                client.YahooImap();
                client.Authenticate(Username, Password);

                channelState = ChannelState.Authenticated;

                Logger.Debug("SUCCESS Authenticating connection {0}", LogSource.Channel, UniqueId);
            }
            catch (IMAP_ClientException ex)
            {
                channelState = ChannelState.Broken;

                Logger.Debug("FAILED Authenticating connection {0}. Server said {1}", LogSource.Channel, UniqueId, ex.ResponseText);

                throw new ChannelAuthenticationException(ex.ResponseText, ex);
            }
        }
Example #3
0
 public static void StoreMessage(string mailbox, string password, string folder, byte[] messageBytes)
 {
     using (var imapClient = new IMAP_Client()) {
         imapClient.Connect(Settings.Default.IMAPHost, Convert.ToInt32(Settings.Default.IMAPPort));
         imapClient.Authenticate(mailbox, password);
         imapClient.SelectFolder(Settings.Default.IMAPSourceFolder);
         imapClient.StoreMessage(folder, messageBytes);
     }
 }
Example #4
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>());
        }
Example #5
0
 public override void IMAPAuth(IMAP_Client client)
 {
     client.Authenticate(_imapUser, _imapPassword);
 }
 public virtual void IMAPAuth(IMAP_Client c)
 {
     c.Authenticate(Settings.Default.IMAPUser, Settings.Default.IMAPPass);
 }