Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] Created By: Redxone
- --]] MC Ign: trainerred2000
- local mailpath = "cozy/programs/email/"
- local mailList = {}
- local bgcolor = colors.white
- local inEmail = false
- local mType = "inbox"
- local opMail = ""
- local mailSender= ""
- local id = os.getComputerID()
- local accMngr = true
- local username = ""
- foundMail = false
- local inInbox=false
- local dodyPar = {}
- local inbody = false
- local bt_str = ""
- local w,h = term.getSize()
- local parnum = 0
- function fadeScreen(delay)
- local cols = {colors.black,colors.gray,colors.lightGray,colors.white};
- for i = 1, #cols do
- term.setBackgroundColor(cols[i])
- sleep(delay)
- term.clear()
- end
- end
- os.loadAPI("ea")
- os.loadAPI("cozy_string")
- local sides = {"up","down","left","right","bottom","back"}
- for i = 1, #sides do if(peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == "modem")then rednet.open(sides[i]) end end
- function start()
- ea.stc(colors.white)
- ea.sbc(colors.white)
- term.clear()
- ea.scp(1,1)
- ea.sbc(colors.blue)
- term.clearLine()
- ea.scp(1,2)
- term.clearLine()
- ea.scp(1,3)
- term.clearLine()
- ea.scp(1,1)
- print("Kosy Mail Checking For Updates...")
- ea.scp(2,10)
- ea.sbc(colors.white)
- ea.stc(colors.green)
- shell.run("pastebin","get","516EUVX2",".temp")
- print("Reading...")
- f = fs.open(".temp","r")
- con = f.readAll()
- f.close()
- fs.delete(".temp")
- print("Comparing Code...")
- f = fs.open(shell.getRunningProgram(),"r")
- ccon = f.readAll()
- f.close()
- if(con == ccon)then print("KosyMail Is Up To Date :)") accountMngr() else print("KosyMail Update Available!")
- print("Update? (Y) or (N)")
- s = {os.pullEvent("key")}
- if(s[2] == keys.y)then
- fs.delete(shell.getRunningProgram())
- shell.run("pastebin","get","516EUVX2",shell.getRunningProgram())
- print("File Received, Restarting Kosy Mail..")
- sleep(2)
- shell.run(shell.getRunningProgram())
- else
- print("Update Canceled..")
- sleep(2)
- accountMngr()
- end
- end
- end
- function accountMngr()
- ea.stc(colors.white)
- ea.sbc(colors.white)
- term.clear()
- ea.scp(1,1)
- ea.sbc(colors.blue)
- term.clearLine()
- ea.scp(1,2)
- term.clearLine()
- ea.scp(1,3)
- term.clearLine()
- ea.scp(1,1)
- print("Kosy Mail Login Options")
- ea.scp(2,10)
- ea.sbc(colors.white)
- ea.stc(colors.green)
- print("<- Or -> Arrow Keys To Select Enter To Continue")
- slop = 1
- local accOp = {
- [" Create User "] = {offset = 1,x = 3, y = 18, bcol = colors.gray, scol = colors.blue, action = function() accMngr = false; createUser() end};
- [" Sign In "] = {offset = 2,x = 30, y = 18, bcol = colors.gray, scol = colors.blue,action = function() accMngr = false; getUser() end};
- }
- function prntAcc()
- ea.stc(colors.white)
- for k , v in pairs(accOp) do
- ea.scp(v.x,v.y)
- if(v.offset == slop)then
- ea.sbc(v.scol)
- else
- ea.sbc(v.bcol)
- end
- print(k)
- end
- end
- function updateAcc()
- a = {os.pullEvent("key")}
- if(a[2] == keys.left and slop > 1 )then slop = slop - 1 end
- if(a[2] == keys.right and slop <= 1 )then slop = slop + 1 end
- if(a[2] == keys.enter)then for k, v in pairs(accOp) do if(v.offset == slop)then v.action() end end end
- end
- while not inEmail and accMngr do
- prntAcc()
- updateAcc()
- end
- end
- function clearLineLength(x,y,l)
- ea.scp(x,y)
- ea.sbc(colors.gray)
- print(" ")
- end
- function getUser()
- ea.stc(colors.white)
- ea.sbc(colors.white)
- term.clear()
- ea.scp(1,1)
- ea.sbc(colors.blue)
- term.clearLine()
- ea.scp(1,2)
- term.clearLine()
- ea.scp(1,3)
- term.clearLine()
- ea.scp(1,1)
- print("Kosy Mail - Login")
- ea.scp(1,10)
- ea.stc(colors.black)
- ea.sbc(colors.white)
- print("Username: ")
- print("Password: ")
- ea.scp(10,10)
- us = read()
- ea.scp(10,11)
- up = read("*")
- rednet.broadcast("COZY_GETUSER")
- local id, msg = rednet.receive(2)
- if(msg == nil)then error("Connection to server failed!") end
- rednet.send(id,us)
- local id, valid = rednet.receive()
- if(valid)then
- local id, cpass = rednet.receive()
- if(up == cpass)then corpass=true else corpass = false end
- end
- if(valid and corpass)then fadeScreen(0.2) inEmail = true; username = us; updateEmailFiles(); clear(); CMail() end
- if(not valid)then ea.sp("Username Invalid") getUser() end
- if(not corpass)then ea.sp("Password Invalid") getUser() end
- end
- function createUser()
- ea.stc(colors.white)
- ea.sbc(colors.white)
- term.clear()
- ea.scp(1,1)
- ea.sbc(colors.blue)
- term.clearLine()
- ea.scp(1,2)
- term.clearLine()
- ea.scp(1,3)
- term.clearLine()
- ea.scp(1,1)
- print("Kosy Mail - Create Login")
- ea.scp(1,10)
- ea.stc(colors.black)
- ea.sbc(colors.white)
- print("Username: ")
- print("Password: ")
- print("Repeat Password: ")
- ea.scp(10,10)
- us = read()
- ea.scp(10,11)
- up = read()
- ea.scp(18,12)
- up2=read()
- if(up ~= up2)then ea.sp("Password's Do Not Match!") createUser() end
- rednet.broadcast("COZY_CREATEUSER")
- local id, got = rednet.receive(2)
- if(got ~= nil)then
- rednet.send(tonumber(id),us)
- local id, valid = rednet.receive()
- if(valid)then
- rednet.send(tonumber(id),up)
- ea.sp("User Created!")
- f = fs.open("cozy/programs/email/login/.user","w")
- f.writeLine("--]] Has Login [[--")
- f.writeLine("true")
- f.close()
- accMngr = true
- accountMngr()
- else
- ea.sp("Username Unavailable!")
- end
- else
- error("Server Connection Failed!")
- end
- end
- function clear()
- ea.sbc(bgcolor);
- term.clear();
- ea.scp(1,1)
- ea.sbc(colors.blue)
- term.clearLine()
- ea.scp(1,1)
- ea.stc(colors.white)
- print("COZYMAIL")
- ea.scp(w-((#username)+2), 1)
- print("["..username.."]")
- ea.sbc(colors.blue)
- for i = 3, 15 do
- ea.scp(1,i)
- print(string.rep(" ",12))
- end
- ea.sbc(colors.gray)
- for i = 3, 17 do
- ea.scp(15,i)
- print(string.rep(" ",36))
- end
- ea.scp(15,3)
- ea.stc(colors.white)
- print("INBOX")
- ea.scp(15,4)
- ea.scp(1,3)
- ea.stc(colors.white)
- ea.sbc(colors.blue)
- print(" ")
- print(" Inbox ")
- print(" Swap User")
- print(" Compose ")
- --print("|NO[Block]|")
- --print("|NO[Chat] |")
- --print("|---------|")
- end
- function printEmail(type)
- for k,v in pairs(mailList) do
- if(v.type == type)then
- ea.sbc(colors.gray)
- ea.scp(15,v.offset+4)
- if(v.sender == nil or v.disc == nil)then ea.stc(colors.red); print("CORRUPED EMAIL") else ea.stc(colors.white); print(v.sender.." - "..v.disc) end
- end
- end
- end
- function openMail(mail)
- i = 0
- xod = 0
- clear()
- ea.scp(15,4)
- ea.scp(15,17)
- ea.sbc(colors.gray)
- print(" REPLY ")
- ea.stc(colors.red)
- ea.scp(43,17)
- print(" DELETE ")
- ea.stc(colors.white)
- ea.sbc(colors.gray)
- f = io.open(mail,"r")
- for line in f:lines() do
- ea.scp(15+xod,i+5)
- if(i == 0)then print("Sender: "..line) end
- if(i == 1)then print("Subject: "..line) end
- if(i ~= 0 and i ~= 1)then print(line) end
- if(i >= 2)then xod = 1 else xod = 0 end
- i = i + 1
- end
- ea.scp(15,7)
- print("Body: ")
- end
- function updateEmail()
- if(inbody)then
- term.setCursorPos(15,parnum+8)
- write(string.rep(" ",33))
- term.setCursorPos(15,parnum+8)
- --term.clearLine()
- write(bt_str)
- term.setCursorBlink(true)
- end
- m = {os.pullEvent()}
- --]] Read Body Mngr [[ --
- if(inbody)then
- if(m[1] == "char")then
- if(#bt_str <= 32)then
- term.setCursorPos(15,#bodyPar+8)
- bt_str = bt_str .. m[2]
- else
- if(#bodyPar < 8)then table.insert(bodyPar,bt_str) term.setCursorPos(15,#bodyPar+8) bt_str = "" parnum = parnum + 1 end
- end
- end
- if(m[1] == "key")then
- if(m[2] == keys.backspace)then
- if(parnum > 0 and #bt_str == 0)then
- bt_str = bodyPar[parnum]
- parnum = parnum - 1
- end
- bt_str = bt_str:sub(1,-2)
- end -- returns string beginging until last letter before end [[--
- if(m[2] == keys.enter)then if(#bodyPar < 8)then table.insert(bodyPar,bt_str) bt_str = "" parnum = parnum + 1 end end
- end
- end
- if(m[1] == "mouse_click" and m[2] == 1)then
- if(m[3] >= 3 and m[3] <= 8 and m[4] == 4 and not inInbox)then
- --mType = "inbox"
- ea.scp(1,4)
- ea.sbc(colors.gray)
- print(" Inbox ")
- inbody=false
- sleep(0.2)
- clear()
- ea.scp(15,4)
- updateEmailFiles()
- if(readingMail)then readingMail = false end
- if(sending)then sending = false end
- --inInbox=true
- end
- if(m[3] >= 3 and m[3] <= 8 and m[4] == 5)then
- ea.scp(1,5)
- ea.sbc(colors.gray)
- print(" Swap User")
- inbody=false
- sleep(0.2)
- if(readingMail)then readingMail = false end
- if(sending)then sending = false end
- clear()
- inEmail = false
- accMngr = true
- accountMngr()
- end
- if(m[3] >= 3 and m[3] <= 8 and m[4] == 6)then
- ea.scp(1,6)
- ea.sbc(colors.gray)
- print(" Compose ")
- sleep(0.2)
- clear()
- rcr=nil
- rcsub=nil
- inbody = false
- bodyPar = {}
- sendEmail()
- t = 0;
- sending=true
- parnum = 0
- end
- if(not readingMail and not sending)then
- for k,v in pairs(mailList) do
- if(m[3] >= 15 and m[3] <= #v.sender+15 and m[4] == v.offset+4)then
- ea.sbc(colors.gray)
- readingMail = true
- print(v.path.." "..v.offset)
- openMail(v.path)
- opMail = v.path
- mailSender = v.sender
- opName = k
- mType = v.type
- end
- end
- else
- if(not sending)then
- if(m[3] >= 16 and m[3] <= 21 and m[4] == 17)then
- clear()
- rcr=mailSender
- sendEmail()
- sending=true
- readingMail=false
- end
- if(m[3] >= 43 and m[3] <= 50 and m[4] == 17)then
- rednet.broadcast("COZY_REMOVE")
- local id, m =rednet.receive(2)
- if(m == nil)then error("Server Connect Failed!") end
- rednet.send(tonumber(id),opName)
- rednet.send(tonumber(id),username)
- if(mType == "inbox")then
- clear()
- ea.scp(15,4)
- updateEmailFiles()
- mybody = false
- parnum = 0
- readingMail = false
- end
- if(mType == "spam")then
- clear()
- ea.scp(15,4)
- readingMail = false
- end
- end
- end
- if(sending and not readingMail)then
- if(m[3] >= 16 and m[4] == 4)then
- clearLineLength(19,4,15)
- ea.scp(19,4)
- rcr=read()
- end
- if(m[3] >= 16 and m[4] == 5)then
- clearLineLength(24,5,10)
- ea.scp(24,5)
- rcsub=read()
- end
- if(m[3] >= 16 and m[4] >= 8 and m[4] <= 16)then
- --]] -=- Body Code Par -=- [[--
- inbody=true
- parnum=0
- end
- if(m[3] >= 43 and m[3] <= 49 and m[4] == 17)then
- if(rcr ~= nil and rcsub ~= nil)then
- sendCozyMail(rcr,rcsub,bodyPar)
- rcr=nil
- rcsub=nil
- bodyPar={}
- end
- end
- end
- end
- end
- end
- function sendCozyMail(to,subject,bodytable)
- term.setCursorBlink(false)
- inbody=false
- parnum = 0
- f = fs.open(".tempcozymail","w")
- f.writeLine(username)
- f.writeLine(subject)
- f.writeLine(" ")
- for i = 1, #bodyPar do f.writeLine(bodyPar[i]) end
- f.close()
- f = fs.open(".tempcozymail","r")
- sendm = f.readAll()
- f.close()
- fs.delete(".tempcozymail")
- rednet.broadcast("COZY_EMAIL")
- id, m1 = rednet.receive(1)
- if(m1 ~= nil)then
- rednet.send(id,to);
- local id, usr = rednet.receive()
- if(usr)then
- rednet.send(id,sendm)
- local id, isOK = rednet.receive(2)
- if(isOK ~= nil)then
- ea.scp(15,17)
- ea.stc(colors.green)
- ea.sp("Mail Sent!")
- else
- error("[SEVER] Server Crashed! Please Contact Server Admin RIGHT NOW!!")
- end
- else
- ea.scp(15,17)
- ea.sp("No such user!")
- end
- end
- if(m1 == nil)then ea.scp(15,17); ea.sp("Connection With Server Failed :(") end
- end
- function sendEmail()
- clear()
- ea.stc(colors.white)
- ea.sbc(colors.gray)
- ea.scp(15,3)
- print("|==================================|")
- ea.scp(15,4)
- print(" To: ")
- ea.scp(15,5)
- print(" Subject: ")
- ea.scp(15,6)
- print("|==================================|")
- ea.scp(15,7)
- print("[Body]")
- ea.scp(45,17)
- ea.sbc(colors.green)
- print(" SEND ")
- ea.sbc(colors.gray)
- ea.stc(colors.white)
- if(rcr ~= nil)then ea.scp(19,4); print(rcr) end
- end
- function receiveEmailedFile()
- amm = math.random(1,9999999)
- rednet.send(senID,"FILE")
- id, dehfile = rednet.receive(1)
- f = fs.open("cozy/programs/email/inbox/cozymailID_"..amm,"w")
- f.write(dehfile)
- f.close()
- end
- function updateEmailFiles()
- for k, v in pairs(fs.list("cozy/programs/email/inbox")) do
- fs.delete("cozy/programs/email/inbox/"..v)
- end
- rednet.broadcast("COZY_EMAIL_UPDATE")
- local id, m = rednet.receive(2)
- rednet.send(tonumber(id),username)
- if(m == nil)then ea.scp(1,1) ea.sbc(colors.red) term.clearLine() ea.stc(colors.white); print("Connection With Server Failed!") end
- if(m ~= nil)then
- local id, amount = rednet.receive()
- for i = 0, amount do
- if(i > 0 )then
- ti=(i-1)
- id, file = rednet.receive();
- id, fileN = rednet.receive();
- f = fs.open("cozy/programs/email/inbox/"..fileN,"w")
- f.write(file)
- f.close()
- end
- end
- mailList = {}
- for k,v in pairs(fs.list(mailpath.."inbox")) do
- if(mailList[v] == nil and not fs.isDir(mailpath.."inbox"..v))then
- f = fs.open(mailpath.."inbox".."/"..v,"r")
- conl = f.readLine()
- cDisc = f.readLine()
- f.close()
- mailList[v] = {type="inbox",sender=conl,disc = cDisc,offset = k,path=mailpath.."inbox".."/"..v}
- end
- end
- clear()
- printEmail("inbox")
- end
- end
- function sendMailEnter()
- a = {os.pullEvent("key")}
- if(a[2] == keys.enter and sending)then
- b = {os.pullEvent("key")}
- if(b[2] == keys.enter)then
- term.setCursorBlink(false)
- sendCozyMail(rcr,rcsub,bp1,bp2,bp3,bp4,bp5,bp6,bp7)
- rcr=nil
- rcsub=nil
- bodyPar={}
- inbody=false
- clear()
- else
- sendMailEnter()
- end
- else
- sendMailEnter()
- end
- end
- function para()
- --parallel.waitForAny(updateEmail, sendMailEnter)
- para()
- end
- function CMail()
- while inEmail do
- updateEmail()
- --para()
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement