コード例 #1
0
        /// <summary>
        /// Handels the STAT command.
        /// </summary>
        private void Stat(Pop3Context context)
        {
            // TODO: wrong implementation, should only return unread messages
            if (context.LastCommand >= COMMAND_PASS)
            {
                Pop3MessageInfo[] list = new Pop3MessageInfo[0];

                if (_storage != null)
                {
                    list = _storage.GetMessageOverview(context.Username);
                }

                long mailboxSize = 0;

                foreach (Pop3MessageInfo l in list)
                {
                    mailboxSize += l.Size;
                }

                context.WriteLine(String.Format(MESSAGE_STAT, list.Length, mailboxSize));
                context.LastCommand = COMMAND_STAT;
            }
            else
            {
                context.WriteLine(MESSAGE_INVALID_COMMAND_ORDER);
            }
        }
コード例 #2
0
        /// <summary>
        /// Handels the UIDL command.
        /// </summary>
        private void Uidl(Pop3Context context, String[] inputs)
        {
            if (context.LastCommand >= COMMAND_PASS)
            {
                if (inputs.Length > 2)
                {
                    context.WriteLine(MESSAGE_INVALID_ARGUMENT_COUNT);
                }
                else
                {
                    int idx = 0;

                    if (inputs.Length == 2)
                    {
                        idx = Convert.ToInt32(inputs[1]);
                    }

                    Pop3MessageInfo[] list = new Pop3MessageInfo[0];

                    if (_storage != null)
                    {
                        list = _storage.GetMessageOverview(context.Username);
                    }

                    if (inputs.Length == 1)
                    {
                        context.WriteLine(String.Format(MESSAGE_LIST, list.Length));

                        int id = 1;
                        foreach (Pop3MessageInfo l in list)
                        {
                            context.WriteLine(id + " " + l.UniqueIdentifier);
                            id++;
                        }

                        context.WriteLine(MESSAGE_EOF);
                    }
                    else
                    {
                        context.WriteLine(string.Format(MESSAGE_STAT, idx, list[idx - 1].UniqueIdentifier));
                    }

                    context.LastCommand = COMMAND_LIST;
                }
            }
            else
            {
                context.WriteLine(MESSAGE_INVALID_COMMAND_ORDER);
            }
        }