Esempio n. 1
0
        protected internal override void Parse(ImapResponseReader reader)
        {
            var set = new List <int>();

            while (reader.IsUntagged)
            {
                var line  = reader.CurrentLine;
                var match = Regex.Match(line, @"\d+");

                if (!match.Success)
                {
                    Debug.WriteLine(FailureMessages.UnexpectedServerResponseMessage);
                    Debug.WriteLine(string.Format("EXPUNGE: {0}", line));
                    return;
                }

                var digit = int.Parse(match.Value);
                set.Add(digit);
                reader.ReadNextLine();

                if (reader.IsCompleted)
                {
                    TakeSnapshot(reader);
                }
            }

            SequenceSet = SequenceSet.CreateSet(set);
        }
Esempio n. 2
0
 /// <summary>
 /// Deletes the specified message.
 /// </summary>
 /// <param name="mailbox">The mailbox to delete from.</param>
 /// <param name="messagePaths">The message paths to delete.</param>
 /// <param name="response">The response.</param>
 /// <returns>The response type.</returns>
 protected override CommandResponseType DeleteMessageCommand(Mailbox mailbox, Dictionary <string, string> messagePaths, out string response)
 {
     try
     {
         // Email servers dont hav an outbox
         if (mailbox.Folder == MailboxFolders.Outbox)
         {
             response = string.Empty;
             return(CommandResponseType.Ok);
         }
         // Any other mailbox
         else
         {
             SequenceSet sequenceSet = new SequenceSet(messagePaths.Keys.Select(o => new SequenceNumber(uint.Parse(o))));
             _client.MarkAsDeleted(sequenceSet, mailbox);
             CompletionResponse deleteResponse = _client.Delete(sequenceSet, mailbox);
             response = deleteResponse.Message;
             return(GetCommandResponseType(deleteResponse.CompletionResult));
         }
     }
     catch (Exception ex)
     {
         response = ex.ToString();
         return(CommandResponseType.Bad);
     }
 }
Esempio n. 3
0
        protected internal override void Parse(ImapResponseReader reader)
        {
            var matches = Regex.Matches(reader.CurrentLine, @"\d+");
            var list = (from Match match in matches select int.Parse(match.Value)).ToList();

            var isUid = reader.CurrentLine.Contains("UID");
            while (true) {
                reader.ReadNextLine();
                if (reader.IsCompleted) {
                    TakeSnapshot(reader);
                    break;
                }
            }
            SequenceSet = isUid ? SequenceSet.CreateUidSet(list) : SequenceSet.CreateSet(list);
        }
Esempio n. 4
0
        public void Store()
        {
            using (var client = Context.CreateSaslClient()) {
                var host = Context.GetHost();
                var port = ImapPorts.Ssl;

                client.Connect(host, port);
                var credentials = Context.GetCredentials();
                client.Authenticate(credentials, SaslMechanics.Login);

                client.Select("INBOX");

                var set = SequenceSet.CreateSet(1, 1);
                client.Store(set, MessageFlags.Seen | MessageFlags.Flagged, StoreProcedures.Add);
            }
        }
Esempio n. 5
0
        public void Expunge()
        {
            using (var client = Context.CreateSaslClient()) {
                client.Security = SecurityPolicies.Explicit;
                var host = Context.GetHost();
                var port = ImapPorts.Ssl;

                client.Connect(host, port);
                var credentials = Context.GetCredentials();
                client.Authenticate(credentials, SaslMechanics.Login);
                client.Select("INBOX");
                client.Store(SequenceSet.CreateSet(1), MessageFlags.Deleted, StoreProcedures.Add);
                client.StatusUpdateReceived += (sender, e) => Debug.WriteLine("Status update received.");
                var response = client.Expunge();
                Assert.IsTrue(response.IsOk);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Moves a list of messages from it's current mailbox to a specified mailbox.
        /// </summary>
        /// <param name="sourceMailbox">The source mailbox.</param>
        /// <param name="destinationMailbox">The destination mailbox.</param>
        /// <param name="messagePaths">The message paths to move.</param>
        /// <param name="response">The response.</param>
        /// <param name="newUids">The new uids.</param>
        /// <returns>The response type.</returns>
        protected override CommandResponseType MoveMessageCommand(Mailbox sourceMailbox, Mailbox destinationMailbox, Dictionary <string, string> messagePaths, out string response, out Dictionary <string, string> newUids)
        {
            newUids = new Dictionary <string, string>();

            try
            {
                SequenceSet        sequenceSet         = new SequenceSet(messagePaths.Keys.Select(o => new SequenceNumber(uint.Parse(o))));
                CompletionResponse moveMessageResponse = _client.Move(sequenceSet, sourceMailbox, destinationMailbox, out newUids);
                response = moveMessageResponse.Message;
                return(GetCommandResponseType(moveMessageResponse.CompletionResult));
            }
            catch (Exception ex)
            {
                response = ex.ToString();
                return(CommandResponseType.Bad);
            }
        }
Esempio n. 7
0
        public void Fetch()
        {
            using (var client = Context.CreateSaslClient()) {
                var host = Context.GetHost();
                var port = ImapPorts.Ssl;

                client.Connect(host, port);
                var credentials = Context.GetCredentials();
                client.Authenticate(credentials, SaslMechanics.Login);

                client.Select("INBOX");

                var set      = SequenceSet.CreateSet(1);
                var response = client.Fetch(set, "FLAGS");
                Assert.IsTrue(response.IsOk);
                Assert.IsTrue(response.Text.Contains("FLAGS"));
            }
        }
        protected internal override void Parse(ImapResponseReader reader)
        {
            var matches = Regex.Matches(reader.CurrentLine, @"\d+");
            var list    = (from Match match in matches select int.Parse(match.Value)).ToList();

            var isUid = reader.CurrentLine.Contains("UID");

            while (true)
            {
                reader.ReadNextLine();
                if (reader.IsCompleted)
                {
                    TakeSnapshot(reader);
                    break;
                }
            }
            SequenceSet = isUid ? SequenceSet.CreateUidSet(list) : SequenceSet.CreateSet(list);
        }
Esempio n. 9
0
        protected internal override void Parse(ImapResponseReader reader)
        {
            var set = new List<int>();
            while (reader.IsUntagged) {
                var line = reader.CurrentLine;
                var match = Regex.Match(line, @"\d+");

                if (!match.Success) {
                    Debug.WriteLine(FailureMessages.UnexpectedServerResponseMessage);
                    Debug.WriteLine(string.Format("EXPUNGE: {0}", line));
                    return;
                }

                var digit = int.Parse(match.Value);
                set.Add(digit);
                reader.ReadNextLine();

                if (reader.IsCompleted) {
                    TakeSnapshot(reader);
                }
            }

            SequenceSet = SequenceSet.CreateSet(set);
        }
        public void ExecuteQueryFlagsUsingMemberInitTest()
        {
            using (var client = Context.CreateSaslClient()) {
                var host       = Context.GetHost();
                var port       = ImapPorts.Ssl;
                var credential = Context.GetCredentials();

                client.Connect(host, port);
                client.Authenticate(credential, SaslMechanics.Login);
                client.Select("INBOX");

                client.Store(SequenceSet.CreateSet(1), MessageFlags.Seen, StoreProcedures.Add);
                client.Store(SequenceSet.CreateSet(2), MessageFlags.Seen, StoreProcedures.Add);

                var query = from i in client.Messages where i.SequenceNumber >= 1 && i.SequenceNumber <= 2 select new SampleContainer {
                    MyFlags = i.Flags
                };

                var result = query.ToList();
                Assert.IsTrue(result.Count == 2);
                Assert.IsTrue(result[0].MyFlags.HasFlag(MessageFlags.Seen));
                Assert.IsTrue(result[1].MyFlags.HasFlag(MessageFlags.Seen));
            }
        }
Esempio n. 11
0
 public COPYCommand(ISequence sequence, string mailbox)
 {
     this.mailbox  = mailbox;
     this.sequence = new SequenceSet();
     this.sequence.Add(sequence);
 }
Esempio n. 12
0
        private void WriteSequences()
        {
            // Load from yaml
            var groupSequences = LoadGroupSetsFromFile();

            var sb = new StringBuilder();

            sb.AppendLine("## This file was generated by CreateSequencesCommand.");
            sb.AppendLine("## Don't modify it yourself unless you know what you're doing.");
            sb.AppendLine(string.Empty);

            var newActorRules = new Dictionary <string, ActorRule>();

            foreach (var groupSequence in groupSequences)
            {
                sb.AppendLine($"{groupSequence.Name}:");
                foreach (var groupSequenceSet in groupSequence.Sets)
                {
                    List <ImageGroup> groups;
                    if (groupSequenceSet.StartOffset > 0)
                    {
                        groups = prtFile.Groups
                                 .Skip(groupSequenceSet.Start + groupSequenceSet.StartOffset)
                                 .Take(groupSequenceSet.Length - groupSequenceSet.StartOffset)
                                 .ToList();

                        groups.AddRange(prtFile.Groups
                                        .Skip(groupSequenceSet.Start)
                                        .Take(groupSequenceSet.StartOffset));
                    }
                    else
                    {
                        groups = prtFile.Groups
                                 .Skip(groupSequenceSet.Start)
                                 .Take(groupSequenceSet.Length)
                                 .ToList();
                    }

                    var typeGroupedFrames = new List <SequenceSet>();
                    var frameCount        = groups.Max(x => x.FrameCount);

                    for (var frameIndex = 0; frameIndex < frameCount; frameIndex++)
                    {
                        var groupIndex = 0;
                        foreach (var group in groups)
                        {
                            Op2Frame frame;
                            if (frameIndex >= group.Frames.Length)
                            {
                                // Hack it - just repeat the first one
                                frame = group.Frames[0];
                            }
                            else
                            {
                                frame = group.Frames[frameIndex];
                            }

                            var pics = frame.Pictures.OrderBy(x => x.PicOrder);
                            foreach (var pic in pics)
                            {
                                var rawFrame   = prtFile.ImageHeader[pic.ImgNumber];
                                var halfWidth  = (int)Math.Ceiling(rawFrame.PaddedWidth / 2.0);
                                var halfHeight = (int)Math.Ceiling(rawFrame.Height / 2.0);
                                var relX       = (halfWidth - group.CenterX) + pic.PosX;
                                var relY       = (halfHeight - group.CenterY) + pic.PosY;

                                var matchingSequenceFrames = typeGroupedFrames
                                                             .Where(x => x.FrameType == rawFrame.ImageType &&
                                                                    x.Palette == rawFrame.Palette)
                                                             .ToList();

                                var setFrame = false;
                                foreach (var seqFrame in matchingSequenceFrames)
                                {
                                    if (seqFrame.AnimationFacings[groupIndex].Frames[frameIndex] == null)
                                    {
                                        var animation = new AnimationFrame()
                                        {
                                            Frame   = pic.ImgNumber,
                                            OffsetX = relX,
                                            OffsetY = relY,
                                        };

                                        var ourGroup = seqFrame.AnimationFacings[groupIndex];
                                        ourGroup.Frames[frameIndex] = animation;
                                        setFrame = true;
                                        break;
                                    }
                                }

                                if (!setFrame)
                                {
                                    // Need a new frameset for this image type and palette
                                    var seqFrame = new SequenceSet
                                    {
                                        Name             = groupSequenceSet.Sequence,
                                        AnimationFacings = new AnimationFacing[groupSequenceSet.Length],
                                        FrameType        = rawFrame.ImageType,
                                        Palette          = rawFrame.Palette,
                                        PicOrder         = pic.PicOrder,
                                        OffsetX          = groupSequenceSet.OffsetX,
                                        OffsetY          = groupSequenceSet.OffsetY,
                                    };

                                    for (var i = 0; i < groupSequenceSet.Length; i++)
                                    {
                                        seqFrame.AnimationFacings[i] = new AnimationFacing
                                        {
                                            Frames = new AnimationFrame[frameCount],
                                        };
                                    }

                                    // Populate it too
                                    var animation = new AnimationFrame()
                                    {
                                        Frame   = pic.ImgNumber,
                                        OffsetX = relX,
                                        OffsetY = relY,
                                    };

                                    var ourGroup = seqFrame.AnimationFacings[groupIndex];
                                    ourGroup.Frames[frameIndex] = animation;

                                    typeGroupedFrames.Add(seqFrame);
                                }
                            }

                            groupIndex++;
                        }
                    }

                    typeGroupedFrames = typeGroupedFrames.OrderByDescending(x => x.PicOrder).ToList();

                    // Put the non-shadow frames before the shadow frames
                    var shadowFrames =
                        typeGroupedFrames.Where(x => x.FrameType == 4 || x.FrameType == 5);
                    var nonShadowFrames =
                        typeGroupedFrames.Where(x => x.FrameType != 4 && x.FrameType != 5);

                    typeGroupedFrames = nonShadowFrames.ToList();
                    typeGroupedFrames.AddRange(shadowFrames);

                    Func <int, string> getTypeString = (inFrameType) =>
                    {
                        return(inFrameType switch
                        {
                            1 => "sprite",
                            4 => "shadow",
                            5 => "shadow",
                            _ => "unknown"
                        });
Esempio n. 13
0
        private void lstEnvelopes_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedMessage = (MessageContainer)lstEnvelopes.SelectedItem;
            var selectedMailbox = (Mailbox)lstMailboxes.SelectedItem;

            if (selectedMessage == null)
            {
                return;
            }

            App.Log.Info("Selected message: " + selectedMessage.Uid);

            // First check if there is already a thread running to do some work.
            if (thread_downloadMessage != null && thread_downloadMessage.IsAlive)
            {
                // Abort the thread if it is already running
                thread_downloadMessage.Abort();
            }

            if (selectedMessage.BodyStructure == null)
            {
                var param = new Collection <Object> {
                    selectedMailbox, selectedMessage
                };

                if (selectedMessage.HtmlView == null)
                {
                    thread_downloadMessage = new Thread(DownloadEmail);
                    // Finally start the thread with the parameters
                    thread_downloadMessage.Start(param);
                }
                else
                {
                    wbMailRenderer.LoadHTML(selectedMessage.HtmlView.Text);
                }
            }
            else
            {
                if (selectedMessage.HtmlView != null)
                {
                    wbMailRenderer.LoadHTML(selectedMessage.HtmlView.Text);
                }
                else // There is a bodystructure, but no view yet.
                {
                    var param = new Collection <Object>();
                    param.Add(selectedMailbox);
                    param.Add(selectedMessage);

                    if (selectedMessage.HtmlView == null)
                    {
                        thread_downloadMessage = new Thread(DownloadEmail);
                        // Finally start the thread with the parameters
                        thread_downloadMessage.Start(param);
                    }
                    else
                    {
                        wbMailRenderer.LoadHTML(selectedMessage.HtmlView.Text);
                    }
                    //App.Log.Error("Message " + selectedMessage.Uid + " has a BodyStructure, but no View!");
                }
            }

            // Set the mail to "Seen"
            var set = SequenceSet.CreateUidSet(selectedMessage.Uid);

            Imap.Client.Store(set, MessageFlags.Seen, StoreProcedures.Add);

            App.Log.Debug("Message " + selectedMessage.Uid + " set to 'seen'.");
        }
Esempio n. 14
0
 public UIDEXPUNGECommand(ISequence sequence)
 {
     this.sequence = new SequenceSet();
     this.sequence.Add(sequence);
 }