Exemple #1
0
        internal void CheckForStatusUpdates(ImapResponseReader reader)
        {
            StatusUpdateReceivedEventArgs e = null;

            while (true)
            {
                if (!reader.IsStatusUpdate)
                {
                    break;
                }

                if (e == null)
                {
                    e = new StatusUpdateReceivedEventArgs(SelectedMailbox);
                }

                e.MailboxInfo.InjectLine(reader.CurrentLine);
                reader.ReadNextLine();
                continue;
            }

            if (e != null)
            {
                InvokeStatusUpdateReceived(e);
            }
        }
Exemple #2
0
        internal void InvokeStatusUpdateReceived(StatusUpdateReceivedEventArgs e)
        {
            var handler = StatusUpdateReceived;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #3
0
        internal void InvokeStatusUpdateReceived(string line)
        {
            var handler = StatusUpdateReceived;

            if (handler != null)
            {
                var e = new StatusUpdateReceivedEventArgs(SelectedMailbox);
                e.MailboxInfo.InjectLine(line);
                handler(this, e);
            }
        }
Exemple #4
0
        internal void ReceiveIdleStatusUpdates(ImapResponseReader reader)
        {
            reader.ReadNextLine();

            if (reader.IsCompleted)
            {
                return;
            }

            StopIdleAsync();

            var e = new StatusUpdateReceivedEventArgs(SelectedMailbox)
            {
                IsIdleUpdate = true
            };

            while (true)
            {
                if (reader.IsCompleted)
                {
                    InvokeStatusUpdateReceived(e);
                    break;
                }

                if (reader.IsStatusUpdate)
                {
                    e.MailboxInfo.InjectLine(reader.CurrentLine);
                }

                // We must check seperately for FETCH updates since we cannot include them into regular status update checks.
                // If included they would be processed as a status update and not as a FETCH response, thus corrupting the stack.
                // We can only check for this kind of update inside the IDLE loop, since we know here that no previous FETCH command has been issued and
                // it is therefor safe to process a FETCH update response.
                if (reader.CurrentLine.Contains("FETCH"))
                {
                    if (e.MailboxInfo.MessageStateChanges == null)
                    {
                        e.MailboxInfo.MessageStateChanges = new List <MessageState>();
                    }
                    var state = new MessageState();
                    state.InjectLine(reader.CurrentLine);
                    ((IList <MessageState>)e.MailboxInfo.MessageStateChanges).Add(state);
                }

                reader.ReadNextLine();
            }

            if (!e.IsIdleCancelled)
            {
                StartIdle();
            }
        }
        private static void OnStatusUpdateReceived(object sender, StatusUpdateReceivedEventArgs e)
        {
            var client = sender as ImapClient;
            if (client == null)
            {
                return;
            }

            // Respond to change notifications
            // i.E. client.Messages.Where(x.Uid > myLastKnownHighestUid).Select(x => x.Envelope) ...
            MessageBox.Show("New email");

            if (e.IsIdleUpdate)
            {
                e.IsIdleCancelled = false; // cancel IDLE session (false default)
            }
        }
        internal void ReceiveIdleStatusUpdates(ImapResponseReader reader)
        {
            reader.ReadNextLine();

            if (reader.IsCompleted) {
                return;
            }

            StopIdleAsync();

            var e = new StatusUpdateReceivedEventArgs(SelectedMailbox) {IsIdleUpdate = true};
            while (true) {
                if (reader.IsCompleted) {
                    InvokeStatusUpdateReceived(e);
                    break;
                }

                if (reader.IsStatusUpdate) {
                    e.MailboxInfo.InjectLine(reader.CurrentLine);
                }

                // We must check seperately for FETCH updates since we cannot include them into regular status update checks.
                // If included they would be processed as a status update and not as a FETCH response, thus corrupting the stack.
                // We can only check for this kind of update inside the IDLE loop, since we know here that no previous FETCH command has been issued and
                // it is therefor safe to process a FETCH update response.
                if (reader.CurrentLine.Contains("FETCH")) {
                    if (e.MailboxInfo.MessageStateChanges == null) {
                        e.MailboxInfo.MessageStateChanges = new List<MessageState>();
                    }
                    var state = new MessageState();
                    state.InjectLine(reader.CurrentLine);
                    ((IList<MessageState>) e.MailboxInfo.MessageStateChanges).Add(state);
                }

                reader.ReadNextLine();
            }

            if (!e.IsIdleCancelled) {
                StartIdle();
            }
        }
 internal void InvokeStatusUpdateReceived(StatusUpdateReceivedEventArgs e)
 {
     var handler = StatusUpdateReceived;
     if (handler != null) {
         handler(this, e);
     }
 }
 internal void InvokeStatusUpdateReceived(string line)
 {
     var handler = StatusUpdateReceived;
     if (handler != null) {
         var e = new StatusUpdateReceivedEventArgs(SelectedMailbox);
         e.MailboxInfo.InjectLine(line);
         handler(this, e);
     }
 }
        internal void CheckForStatusUpdates(ImapResponseReader reader)
        {
            StatusUpdateReceivedEventArgs e = null;
            while (true) {
                if (!reader.IsStatusUpdate) {
                    break;
                }

                if (e == null) {
                    e = new StatusUpdateReceivedEventArgs(SelectedMailbox);
                }

                e.MailboxInfo.InjectLine(reader.CurrentLine);
                reader.ReadNextLine();
                continue;
            }

            if (e != null) {
                InvokeStatusUpdateReceived(e);
            }
        }
Exemple #10
0
        // Respond to change notifications
        private void onStatusUpdateReceived(object sender, StatusUpdateReceivedEventArgs e)
        {
            var client = sender as ImapClient;
            if (client == null)
            {
                return;
            }

            var since = DateTime.Now.AddDays(-7);
            var query = client.Messages.
                        Where(x => x.InternalDate > since && x.Uid >= uidNext).
                        Select(x => new InitialResponseFields {
                                Uid = x.Uid,
                                Envelope = x.Envelope,
                                Size = x.Size,
                                InternalDate = x.InternalDate,
                                BodyStructure = x.BodyStructure});

            foreach (var msg in query)
            {
                uidNext = msg.Uid + 1;
                if (msg.Envelope.Subject.Contains("bot") && msg.Envelope.Subject.Contains("[id="))
                {
                    try
                    {
                        // get the text/html view
                        ViewInfo htmlViewInfo = msg.BodyStructure.Views.Where(x => x.MediaType == "text/html").First<ViewInfo>();
                        if (null != htmlViewInfo) {
                            // back to the server to retrieve the text/html body part
                            Crystalbyte.Equinox.View htmlView = client.FetchView(htmlViewInfo);
                            if (null != htmlView) {
                                callbackFn(msg.Envelope.Subject, htmlView.Text);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            /** Keep the IDLE state going, so that it is always reading new mail....
            if (e.IsIdleUpdate)
            {
                e.IsIdleCancelled = true; // cancel IDLE session (false default)
            }
             * ***/
        }