protected static void Ssrv_SMTPincomming(System.Net.Sockets.TcpClient c) { if (SMTP == null) { myAddr = Bitmessage.getAddresses(BitAPIserver.BA); SMS = new SMTPstate(); SMTP = new SMTPconnection(c); SMTP.SMTPcommand += new SMTPcommandHandler(SMTP_SMTPcommand); SMTP.SMTPdropped += new SMTPdroppedHandler(SMTP_SMTPdropped); SMTP.msg(220, "WAKE UP BITCH! I'M READY TO KICK ASS, AND IT BETTER BE IMPORTANT"); } else { SMTPconnection temp = new SMTPconnection(c); temp.msg(421, "Try again later you fool!"); temp.close(); } }
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; } } }
protected static void SMTP_SMTPcommand(SMTPconnection SMTP, string command, string[] args, string raw) { lock (SMTP) { if (SMS.onData) { if (raw == ".") { SMS.onData = false; SMTP.dataMode = false; if (SMS.spam) { SMTP.msg(521, "Someone gets nasty!"); //spam protection to be implemented } else { if (SMS.isCommand) { switch (SMS.subject.ToLower().Split(' ')[0]) { case "help": adminMsg("OK: BMS Help", Troll.ADMINHELP); break; case "status": if (SMS.subject.Split(' ').Length > 1) { BitAPIserver.BA.statusBar(SMS.subject.Split(new char[] { ' ' }, 2)[1]); adminMsg("OK: status", "status set to " + SMS.subject.Split(new char[] { ' ' }, 2)[1]); } else { adminMsg("ERR: status", "cannot set status. You need to specify the value for it"); } break; case "killall": foreach (BitMsg m in Bitmessage.getMessages(BitAPIserver.BA)) { BitAPIserver.BA.trashMessage(m.msgid); } adminMsg("OK: killall", "All messages deleted."); break; case "createaddr": if (SMS.subject.Split(' ').Length == 2) { adminMsg("OK: Address generation", Bitmessage.generateAddress(BitAPIserver.BA, SMS.subject.Split(new char[] { ' ' }, 2)[1], "B2M generated addr")); } else { adminMsg("OK: Address generation", Bitmessage.generateAddress(BitAPIserver.BA, "B2M generated addr")); } break; case "listsub": string sublist = string.Format("{0} {1} Enabled\r\n", size("Address", 38), size("Label", 20)); foreach (Subscription s in Bitmessage.getSubscriptions(BitAPIserver.BA)) { sublist += string.Format("{0} {1} {2}\r\n", size(s.address, 38), size(s.label, 20), size(s.enabled.ToString(), 7)); } adminMsg("OK: Subscription list", sublist); break; case "list": string addrlist = string.Format("{0} {1} Enabled Stream\r\n", size("Address", 38), size("Label", 20)); foreach (BitAddr a in Bitmessage.getAddresses(BitAPIserver.BA)) { addrlist += string.Format("{0} {1} {2} {3}\r\n", size(a.address, 38), size(a.label, 20), size(a.enabled.ToString(), 7), size(a.stream.ToString(), 6)); } adminMsg("OK: Address list", addrlist); break; case "subscribe": case "sub": if (SMS.subject.Split(' ').Length >= 2) { if (SMS.subject.Split(' ').Length > 2) { BitAPIserver.BA.addSubscription(SMS.subject.Split(' ')[1], B64e(SMS.subject.Split(new char[] { ' ' }, 3)[2])); } else { BitAPIserver.BA.addSubscription(SMS.subject.Split(' ')[1], B64e("--NO NAME--")); } adminMsg("OK: subscribe", "subscribed to " + SMS.subject.Split(' ')[1]); } else { adminMsg("ERR: subscribe", "You need to specify an address"); } break; case "unsubscribe": case "usub": if (SMS.subject.Split(' ').Length == 2) { BitAPIserver.BA.deleteSubscription(SMS.subject.Split(' ')[1]); adminMsg("OK: unsubscribe", string.Format("Subscription for {0} deleted", SMS.subject.Split(' ')[1])); } else { adminMsg("ERR: unsubscribe", "You need to specify an address"); } break; default: adminMsg("ERR: unknown command", string.Format(@"The command you used is not valid. To get a list of valid commands, use the 'help' command. Your command line: {0}", SMS.subject)); break; } } else { if (BS.StripHdr) { SMS.message = FilterHeaders(SMS.message); } foreach (string s in SMS.to) { if (s.ToUpper() == "BROADCAST") { AckMessage.Add(BitAPIserver.BA.sendBroadcast(SMS.from, B64e(SMS.subject), B64e(SMS.message))); } else { AckMessage.Add(BitAPIserver.BA.sendMessage(s, SMS.from, B64e(SMS.subject), B64e(SMS.message))); } } } SMTP.msg(250, "This better not be spam!"); } SMS = new SMTPstate(); } else { if (raw.ToLower().StartsWith("subject: ") && string.IsNullOrEmpty(SMS.subject)) { if (BS.StripHdr) { SMS.subject = stripQuoted(raw.Substring(9).Trim()); } else { SMS.subject = raw.Substring(9).Trim(); } } //MIME from field, if the address exists set this. if (raw.ToLower().StartsWith("from: ")) { string fromAddr = getAddress(raw); if (!string.IsNullOrEmpty(fromAddr)) { foreach (BitAddr a in myAddr) { if (a.address.ToLower() == fromAddr.ToLower()) { SMS.from = a.address; } } } } if (BS.StripHdr) { SMS.message += stripQuoted(raw + "\r\n"); } else { SMS.message += raw + "\r\n"; } } } else { switch (command) { case "EHLO": case "HELO": SMTP.msg(250, "I am busy stealing your secrets, it better be important"); break; case "MAIL": if (args.Length > 0 && args[0].ToUpper().StartsWith("FROM:")) { string addr; if (!string.IsNullOrEmpty(addr = check(raw))) { if (addr == RANDOM.Split('@')[0] && BS.Random) { SMS.from = Bitmessage.generateAddress(BitAPIserver.BA, "RANDOM"); SMTP.msg(250, "Generated your address: " + SMS.from); } else { bool found = false; foreach (var Addr in myAddr) { if (Addr.address.ToLower() == addr.ToLower() || Addr.label.ToLower() == addr.ToLower()) { SMS.from = Addr.address; found = true; } } if (found) { SMTP.msg(250, "At least it is your address"); } else { SMTP.msg(530, "Fuckoff"); } } } else { SMTP.msg(500, "HOW DUMB ARE YOU? THIS IS NOT EVEN A CORRECT BITMESSAGE ADDRESS..."); } } else { SMTP.msg(500, "WRONG!!!!"); } break; case "RCPT": if (args.Length > 0 && args[0].ToUpper().StartsWith("TO:")) { string addr = check(raw); if (!string.IsNullOrEmpty(addr)) { if (addr == COMMAND.Split('@')[0]) { SMS.isCommand = true; SMTP.msg(250, "Give me the damn subject line already"); } else { SMS.to.Add(addr); SMTP.msg(250, "I added the address"); } } else { SMTP.msg(551, "TRY A F*****G EXTERNAL SERVER OR USE <BITMESSAGE.CH>"); } } else { SMTP.msg(500, "WRONG!!!!"); } break; case "DATA": if (!string.IsNullOrEmpty(SMS.from) && (SMS.to.Count > 0 || SMS.isCommand)) { SMS.onData = true; SMTP.dataMode = true; //As a Mail Server we add this SMS.message = "Return-Path: <" + SMS.from + "@bitmessage.ch>\r\n"; SMTP.msg(354, "I am waiting..."); } else { SMTP.msg(500, "DEFINE MAIL AND RCPT YOU IDIOT"); } break; case "HELP": SMTP.msg(241, "THERE IS NO F*****G HELP FOR YOUR PROBLEM. JUST LIVE WITH IT!"); break; case "NOOP": SMTP.msg(Troll.Trollface); break; case "QUIT": if (string.IsNullOrEmpty(SMS.from) || SMS.to.Count == 0) { SMTP.msg(221, "NEXT TIME SEND A MAIL YOU STOOPID BITCH"); } else { SMTP.msg(221, "I relay your message, but only because it's you!"); } SMTP.close(); break; case "RSET": SMS = new SMTPstate(); SMTP.msg(250, new string[] { "Who is too stupid to write a message without errors?", "You are too stupid to write a message!" }); break; case "VRFY": case "EXPN": case "TURN": case "AUTH": SMTP.msg(502, "I HAVE NO F*****G TIME FOR THIS. SCREW THIS COMMAND"); break; default: SMTP.msg(500, "STOP DOING THIS!"); break; } } } }