close() 개인적인 메소드

private close ( ) : void
리턴 void
예제 #1
0
        protected static void POP3_POP3command(POP3connection POP3, string command, string[] args, string raw)
        {
            lock (POP3)
            {
                Console.WriteLine(raw);
                switch (command)
                {
                    case "USER":
                        if (P3S.userOK || P3S.passOK)
                        {
                            POP3.err("YOU ALREADY SET THE USERNAME STUPID BITCH!", false);
                        }
                        else
                        {
                            P3S.userOK = true;
                            POP3.ok("Obviously you need to send the password now");
                        }
                        break;
                    case "PASS":
                        if (P3S.userOK)
                        {
                            if (P3S.passOK)
                            {
                                POP3.err("WE F*****G DID THIS ALREADY!", false);
                            }
                            else
                            {
                                P3S.passOK = true;
                                var allMsg = Bitmessage.getMessages(BitAPIserver.BA);
                                if (allMsg == null)
                                {
                                    NFI.ShowBalloonTip(5000, "API Error", "POP3: Cannot retreive Messages.\r\nVerify Bitmessage runs and the API Parameters are correct", ToolTipIcon.Error);
                                    POP3.err("CONFIGURE ME PROPERLY!",true);
                                    break;
                                }
                                else
                                {
                                    myAddr=Bitmessage.getAddresses(BitAPIserver.BA);
                                    POP3msg = new POP3message[allMsg.Length];
                                    for (int i = 0; i < POP3msg.Length; i++)
                                    {
                                        POP3msg[i] = new POP3message(i + 1, allMsg[i],myAddr);
                                    }
                                    POP3.ok("Thanks. next time do it faster");
                                }
                            }
                        }
                        else
                        {
                            POP3.err("I NEED YOUR NAME ASSHOLE!", false);
                        }
                        break;
                    case "CAPA":
                        POP3.sendRaw(@"+OK I don't know why I am so nice to you...
            USER
            PASS
            TOP
            STAT
            RETR
            UIDL
            NOOP
            AYRA
            CAPA
            LIST
            DELE
            HELP
            RSET
            QUIT
            .
            ");
                        break;
                    case "STAT":
                        if (P3S.passOK && P3S.userOK)
                        {
                            long size = 0;
                            int count = 0;
                            int i = 0;
                            for (i = 0; i < POP3msg.Length; i++)
                            {
                                if (!POP3msg[i].Deleted)
                                {
                                    count++;
                                    size += POP3msg[i].Body.Length;
                                }
                            }
                            for (i = 0; i < AuxMessages.Count; i++)
                            {
                                if (!AuxMessages[i].Deleted)
                                {
                                    count++;
                                    size += AuxMessages[i].Body.Length;
                                }
                            }
                            POP3.ok(string.Format("{0} {1}", POP3msg.Length+AuxMessages.Count, size));
                        }
                        break;
                    case "LIST":
                        if (P3S.passOK && P3S.userOK)
                        {
                            POP3.ok("INCOMMING MAILS! BITCH");
                            int i = 0;
                            int j = 0;
                            for (i = 0; i < POP3msg.Length; i++)
                            {
                                if (!POP3msg[i].Deleted)
                                {
                                    POP3.sendRaw(string.Format("{0} {1}\r\n", i + 1, POP3msg[i].Body.Length));
                                }
                                j++;
                            }
                            for (i = 0; i < AuxMessages.Count; i++)
                            {
                                if (!AuxMessages[i].Deleted)
                                {
                                    POP3.sendRaw(string.Format("{0} {1}\r\n", j + 1, AuxMessages[i].Body.Length));
                                }
                                j++;
                            }
                            POP3.sendRaw(".\r\n");
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    case "TOP":
                        if (P3S.passOK && P3S.userOK)
                        {
                            if (args.Length >= 1)
                            {
                                int linesHeader = 0;
                                int i = 0;

                                if (args.Length == 2 && !int.TryParse(args[1], out linesHeader))
                                {
                                    POP3.err("WRONG ARGUMENT ASSHOLE!", false);
                                    return;
                                }

                                if (int.TryParse(args[0], out i) && i > 0 && i <= POP3msg.Length && !POP3msg[i - 1].Deleted)
                                {
                                    POP3.ok("listen carefully!");
                                    bool countlines = false;
                                    foreach (string s in POP3msg[i - 1].Body.Split('\n'))
                                    {
                                        if (s.Trim() == string.Empty && !countlines)
                                        {
                                            countlines = true;
                                            POP3.sendRaw("\r\n");
                                        }
                                        else
                                        {
                                            if (!countlines)
                                            {
                                                POP3.sendRaw(s.TrimEnd() + "\r\n");
                                            }
                                            else if (linesHeader > 0)
                                            {
                                                linesHeader--;
                                                POP3.sendRaw(s.TrimEnd() + "\r\n");
                                            }
                                        }
                                    }
                                    POP3.sendRaw("\r\n.\r\n");
                                }
                                else if (int.TryParse(args[0], out i) && i > 0 && i-POP3msg.Length <= AuxMessages.Count)
                                {
                                    i -= POP3msg.Length;
                                    POP3.ok("listen carefully!");
                                    bool countlines = false;
                                    foreach (string s in AuxMessages[i - 1].Body.Split('\n'))
                                    {
                                        if (s.Trim() == string.Empty && !countlines)
                                        {
                                            countlines = true;
                                            POP3.sendRaw("\r\n");
                                        }
                                        else
                                        {
                                            if (!countlines)
                                            {
                                                POP3.sendRaw(s.TrimEnd() + "\r\n");
                                            }
                                            else if (linesHeader > 0)
                                            {
                                                linesHeader--;
                                                POP3.sendRaw(s.TrimEnd() + "\r\n");
                                            }
                                        }
                                    }
                                    POP3.sendRaw("\r\n.\r\n");
                                }
                                else
                                {
                                    POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                                }
                            }
                            else
                            {
                                POP3.err("LEARN COMMANDS BITCH!", false);
                            }
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    case "DELE":
                        if (P3S.passOK && P3S.userOK)
                        {
                            int ID = 0;
                            if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length && !POP3msg[ID - 1].Deleted)
                            {
                                POP3.ok("I will take care of it!");
                                POP3msg[ID - 1].MarkDelete();
                            }
                            else if(int.TryParse(args[0], out ID))
                            {
                                //shifts the Message ID
                                ID -= POP3msg.Length;
                                if (ID <= AuxMessages.Count)
                                {
                                    for (int i = 0; i < AuxMessages.Count; i++)
                                    {
                                        POP3.ok("I will take care of it!");
                                        AuxMessages[ID - 1].MarkDelete();
                                    }
                                }
                                else
                                {
                                    POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                                }
                            }
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    case "HELP":
                        POP3.ok("WHAT THE F**K YOU WANT? see RFC 1939 you douchebag");
                        break;
                    case "AYRA":
                        POP3.ok("I still hate you");
                        break;
                    case "RETR":
                        if (P3S.passOK && P3S.userOK)
                        {
                            int ID = 0;
                            if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length && !POP3msg[ID - 1].Deleted)
                            {
                                POP3.ok("listen carefully!");
                                POP3.sendRaw(POP3msg[ID - 1].Body + "\r\n.\r\n");
                            }
                            else if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length + AuxMessages.Count && !AuxMessages[ID - 1 - (POP3msg.Length)].Deleted)
                            {
                                ID -= POP3msg.Length;
                                POP3.ok("listen carefully!");
                                POP3.sendRaw(AuxMessages[ID - 1].Body + "\r\n.\r\n");
                            }
                            else
                            {
                                POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                            }
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    case "QUIT":
                        POP3.ok("It's about time you go already");
                        if (POP3msg != null)
                        {
                            foreach (var P in POP3msg)
                            {
                                if (P.Deleted)
                                {
                                    BitAPIserver.BA.trashMessage(P.UID);
                                }
                            }
                            for (int i = 0; i < AuxMessages.Count; i++)
                            {
                                if (AuxMessages[i].Deleted)
                                {
                                    AuxMessages.RemoveAt(i--);
                                }
                            }
                        }
                        POP3.close();
                        break;
                    case "NOOP":
                        POP3.ok("Bitch Please, stop it!");
                        break;
                    case "RSET":
                        if (P3S.passOK && P3S.userOK)
                        {
                            foreach (var P in POP3msg)
                            {
                                if (P.Deleted)
                                {
                                    P.Reset();
                                }
                            }
                            for (int i = 0; i < AuxMessages.Count; i++)
                            {
                                AuxMessages[i].Reset();
                            }
                            POP3.ok("Don't make mistakes in the future!");
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    case "UIDL":
                        if (P3S.passOK && P3S.userOK)
                        {
                            int ID = 0;
                            if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length)
                            {
                                POP3.ok(string.Format("{0} {1}", ID, POP3msg[ID - 1].UID));
                            }
                            else
                            {
                                POP3.ok("Here you go!");
                                int i = 0;
                                int j = 0;
                                for (i = 0; i < POP3msg.Length; i++)
                                {
                                    j++;
                                    POP3.sendRaw(string.Format("{0} {1}\r\n", j, POP3msg[i].UID));
                                }
                                for (i = 0; i < AuxMessages.Count; i++)
                                {
                                    j++;
                                    POP3.sendRaw(string.Format("{0} {1}\r\n", j, AuxMessages[i].UID));
                                }
                                POP3.sendRaw(".\r\n");
                            }
                        }
                        else
                        {
                            POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                        }
                        break;
                    default:
                        POP3.err("Watch your language!", false);
                        break;
                }
            }
        }
예제 #2
0
        protected static void POP3_POP3command(POP3connection POP3, string command, string[] args, string raw)
        {
            lock (POP3)
            {
                Console.WriteLine(raw);
                switch (command)
                {
                case "USER":
                    if (P3S.userOK || P3S.passOK)
                    {
                        POP3.err("YOU ALREADY SET THE USERNAME STUPID BITCH!", false);
                    }
                    else
                    {
                        P3S.userOK = true;
                        POP3.ok("Obviously you need to send the password now");
                    }
                    break;

                case "PASS":
                    if (P3S.userOK)
                    {
                        if (P3S.passOK)
                        {
                            POP3.err("WE F*****G DID THIS ALREADY!", false);
                        }
                        else
                        {
                            P3S.passOK = true;
                            var allMsg = Bitmessage.getMessages(BitAPIserver.BA);
                            if (allMsg == null)
                            {
                                NFI.ShowBalloonTip(5000, "API Error", "POP3: Cannot retreive Messages.\r\nVerify Bitmessage runs and the API Parameters are correct", ToolTipIcon.Error);
                                POP3.err("CONFIGURE ME PROPERLY!", true);
                                break;
                            }
                            else
                            {
                                myAddr  = Bitmessage.getAddresses(BitAPIserver.BA);
                                POP3msg = new POP3message[allMsg.Length];
                                for (int i = 0; i < POP3msg.Length; i++)
                                {
                                    POP3msg[i] = new POP3message(i + 1, allMsg[i], myAddr);
                                }
                                POP3.ok("Thanks. next time do it faster");
                            }
                        }
                    }
                    else
                    {
                        POP3.err("I NEED YOUR NAME ASSHOLE!", false);
                    }
                    break;

                case "CAPA":
                    POP3.sendRaw(@"+OK I don't know why I am so nice to you...
USER
PASS
TOP
STAT
RETR
UIDL
NOOP
AYRA
CAPA
LIST
DELE
HELP
RSET
QUIT
.
");
                    break;

                case "STAT":
                    if (P3S.passOK && P3S.userOK)
                    {
                        long size  = 0;
                        int  count = 0;
                        int  i     = 0;
                        for (i = 0; i < POP3msg.Length; i++)
                        {
                            if (!POP3msg[i].Deleted)
                            {
                                count++;
                                size += POP3msg[i].Body.Length;
                            }
                        }
                        for (i = 0; i < AuxMessages.Count; i++)
                        {
                            if (!AuxMessages[i].Deleted)
                            {
                                count++;
                                size += AuxMessages[i].Body.Length;
                            }
                        }
                        POP3.ok(string.Format("{0} {1}", POP3msg.Length + AuxMessages.Count, size));
                    }
                    break;

                case "LIST":
                    if (P3S.passOK && P3S.userOK)
                    {
                        POP3.ok("INCOMMING MAILS! BITCH");
                        int i = 0;
                        int j = 0;
                        for (i = 0; i < POP3msg.Length; i++)
                        {
                            if (!POP3msg[i].Deleted)
                            {
                                POP3.sendRaw(string.Format("{0} {1}\r\n", i + 1, POP3msg[i].Body.Length));
                            }
                            j++;
                        }
                        for (i = 0; i < AuxMessages.Count; i++)
                        {
                            if (!AuxMessages[i].Deleted)
                            {
                                POP3.sendRaw(string.Format("{0} {1}\r\n", j + 1, AuxMessages[i].Body.Length));
                            }
                            j++;
                        }
                        POP3.sendRaw(".\r\n");
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                case "TOP":
                    if (P3S.passOK && P3S.userOK)
                    {
                        if (args.Length >= 1)
                        {
                            int linesHeader = 0;
                            int i           = 0;

                            if (args.Length == 2 && !int.TryParse(args[1], out linesHeader))
                            {
                                POP3.err("WRONG ARGUMENT ASSHOLE!", false);
                                return;
                            }

                            if (int.TryParse(args[0], out i) && i > 0 && i <= POP3msg.Length && !POP3msg[i - 1].Deleted)
                            {
                                POP3.ok("listen carefully!");
                                bool countlines = false;
                                foreach (string s in POP3msg[i - 1].Body.Split('\n'))
                                {
                                    if (s.Trim() == string.Empty && !countlines)
                                    {
                                        countlines = true;
                                        POP3.sendRaw("\r\n");
                                    }
                                    else
                                    {
                                        if (!countlines)
                                        {
                                            POP3.sendRaw(s.TrimEnd() + "\r\n");
                                        }
                                        else if (linesHeader > 0)
                                        {
                                            linesHeader--;
                                            POP3.sendRaw(s.TrimEnd() + "\r\n");
                                        }
                                    }
                                }
                                POP3.sendRaw("\r\n.\r\n");
                            }
                            else if (int.TryParse(args[0], out i) && i > 0 && i - POP3msg.Length <= AuxMessages.Count)
                            {
                                i -= POP3msg.Length;
                                POP3.ok("listen carefully!");
                                bool countlines = false;
                                foreach (string s in AuxMessages[i - 1].Body.Split('\n'))
                                {
                                    if (s.Trim() == string.Empty && !countlines)
                                    {
                                        countlines = true;
                                        POP3.sendRaw("\r\n");
                                    }
                                    else
                                    {
                                        if (!countlines)
                                        {
                                            POP3.sendRaw(s.TrimEnd() + "\r\n");
                                        }
                                        else if (linesHeader > 0)
                                        {
                                            linesHeader--;
                                            POP3.sendRaw(s.TrimEnd() + "\r\n");
                                        }
                                    }
                                }
                                POP3.sendRaw("\r\n.\r\n");
                            }
                            else
                            {
                                POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                            }
                        }
                        else
                        {
                            POP3.err("LEARN COMMANDS BITCH!", false);
                        }
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                case "DELE":
                    if (P3S.passOK && P3S.userOK)
                    {
                        int ID = 0;
                        if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length && !POP3msg[ID - 1].Deleted)
                        {
                            POP3.ok("I will take care of it!");
                            POP3msg[ID - 1].MarkDelete();
                        }
                        else if (int.TryParse(args[0], out ID))
                        {
                            //shifts the Message ID
                            ID -= POP3msg.Length;
                            if (ID <= AuxMessages.Count)
                            {
                                for (int i = 0; i < AuxMessages.Count; i++)
                                {
                                    POP3.ok("I will take care of it!");
                                    AuxMessages[ID - 1].MarkDelete();
                                }
                            }
                            else
                            {
                                POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                            }
                        }
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                case "HELP":
                    POP3.ok("WHAT THE F**K YOU WANT? see RFC 1939 you douchebag");
                    break;

                case "AYRA":
                    POP3.ok("I still hate you");
                    break;

                case "RETR":
                    if (P3S.passOK && P3S.userOK)
                    {
                        int ID = 0;
                        if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length && !POP3msg[ID - 1].Deleted)
                        {
                            POP3.ok("listen carefully!");
                            POP3.sendRaw(POP3msg[ID - 1].Body + "\r\n.\r\n");
                        }
                        else if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length + AuxMessages.Count && !AuxMessages[ID - 1 - (POP3msg.Length)].Deleted)
                        {
                            ID -= POP3msg.Length;
                            POP3.ok("listen carefully!");
                            POP3.sendRaw(AuxMessages[ID - 1].Body + "\r\n.\r\n");
                        }
                        else
                        {
                            POP3.err("I DO NOT HAVE YOUR STUFF!", false);
                        }
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                case "QUIT":
                    POP3.ok("It's about time you go already");
                    if (POP3msg != null)
                    {
                        foreach (var P in POP3msg)
                        {
                            if (P.Deleted)
                            {
                                BitAPIserver.BA.trashMessage(P.UID);
                            }
                        }
                        for (int i = 0; i < AuxMessages.Count; i++)
                        {
                            if (AuxMessages[i].Deleted)
                            {
                                AuxMessages.RemoveAt(i--);
                            }
                        }
                    }
                    POP3.close();
                    break;

                case "NOOP":
                    POP3.ok("Bitch Please, stop it!");
                    break;

                case "RSET":
                    if (P3S.passOK && P3S.userOK)
                    {
                        foreach (var P in POP3msg)
                        {
                            if (P.Deleted)
                            {
                                P.Reset();
                            }
                        }
                        for (int i = 0; i < AuxMessages.Count; i++)
                        {
                            AuxMessages[i].Reset();
                        }
                        POP3.ok("Don't make mistakes in the future!");
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                case "UIDL":
                    if (P3S.passOK && P3S.userOK)
                    {
                        int ID = 0;
                        if (args.Length == 1 && int.TryParse(args[0], out ID) && ID > 0 && ID <= POP3msg.Length)
                        {
                            POP3.ok(string.Format("{0} {1}", ID, POP3msg[ID - 1].UID));
                        }
                        else
                        {
                            POP3.ok("Here you go!");
                            int i = 0;
                            int j = 0;
                            for (i = 0; i < POP3msg.Length; i++)
                            {
                                j++;
                                POP3.sendRaw(string.Format("{0} {1}\r\n", j, POP3msg[i].UID));
                            }
                            for (i = 0; i < AuxMessages.Count; i++)
                            {
                                j++;
                                POP3.sendRaw(string.Format("{0} {1}\r\n", j, AuxMessages[i].UID));
                            }
                            POP3.sendRaw(".\r\n");
                        }
                    }
                    else
                    {
                        POP3.err("LOGIN FIRST YOU SON OF A BITCH", false);
                    }
                    break;

                default:
                    POP3.err("Watch your language!", false);
                    break;
                }
            }
        }