Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- userConfig = "RedMailCfg/user.config"
- modemConfig = "RedMailCfg/modem.config"
- listConfig = "RedMailCfg/list"
- user = ""
- side = ""
- list = {}
- local unreadM = nil
- local menu = nil
- if not fs.exists("GUI") then
- http.request("http://pastebin.com/raw/PmCUHuTr")
- local requesting = true
- while requesting do
- local event, url, sourceText = os.pullEvent()
- if event == "http_success" then
- local respondedText = sourceText.readAll()
- sourceText.close()
- local f = fs.open("GUI","w")
- f.write(respondedText)
- f.close()
- requesting = false
- elseif event == "http_failure" then
- print("Server didn't respond.")
- requesting = false
- end
- end
- end
- os.loadAPI("GUI")
- overlay = GUI.newOverlay()
- local function InBox(text)
- t = {}
- table.insert(t,text)
- local InBox = GUI.inpBox(t)
- return InBox
- end
- local function msgBox(text)
- local t = {}
- table.insert(t,text)
- local msgBox = GUI.msgBox(t)
- end
- local function readFile(path)
- local f = fs.open(path,"r")
- local data = f.readAll()
- f.close()
- return data
- end
- local function writeFile(path,text)
- local f = fs.open(path,"w")
- f.write(text)
- f.close()
- end
- local function newPage(title)
- term.clear()
- term.setCursorPos(1,1)
- overlay:setHeaderTitle(title)
- overlay:draw()
- end
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- local function printScreen(lines)
- local text = lines
- local len = #text
- x,y = term.getCursorPos()
- maxX,maxY = term.getSize()
- diff = maxX - (x+len)
- if diff > maxX then
- while diff > maxX do
- print(string.sub(text,0,maxX-x))
- diff = maxX - (x+#string.sub(text,maxX-x))
- text = string.sub(text,maxX-x)
- end
- else
- print(text)
- end
- end
- local function sendM()
- newPage("Send a mail - RedMail")
- term.setCursorPos(2,5)
- print("To : ")
- term.setCursorPos(7,5)
- to = read()
- print()
- term.setCursorPos(2,7)
- print("Subject : ")
- term.setCursorPos(12,7)
- subject = read()
- print()
- term.setCursorPos(2,9)
- print("Message : ")
- x,y = term.getCursorPos()
- term.setCursorPos(2,y+2)
- corpse = read()
- while true do
- confirm = InBox("Send ? (Y/N)")
- confirm = string.upper(confirm)
- if confirm == "Y" then
- rednet.open(side)
- rednet.send(53,"send|".. to .."|".. user .."|".. subject .."|".. corpse)
- rednet.close()
- break
- elseif confirm == "N" then
- break
- else
- end
- end
- end
- local function detailM(j)
- local detail = split(list[j],"|")
- local from = detail[2]
- local subject = detail[3]
- local corpse = detail[4]
- newPage(detail[3] .." - RedMail")
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.red)
- print("X")
- term.setCursorPos(2,5)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- print("From : ".. from)
- term.setCursorPos(2,7)
- print("Subject : ".. subject)
- term.setCursorPos(2,9)
- print("Message : ")
- x,y = term.getCursorPos()
- term.setCursorPos(2,y+2)
- printScreen(corpse)
- file = ""
- for i=1, #list do
- if i == j then
- else
- file = file .. list[i] .."ยง"
- end
- end
- writeFile(listConfig,file)
- exited = false
- while not exited do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if xPos == 1 and yPos == 1 then
- unreadM()
- menu()
- exited = true
- end
- end
- error("")
- end
- unreadM = function()
- newPage("Unread mails - RedMail")
- term.setCursorPos(2,5)
- rednet.open(side)
- rednet.send(53,"fetch|"..user)
- _,message = rednet.receive()
- rednet.close()
- if not fs.exists(listConfig) then
- writeFile(listConfig,"")
- end
- unread_all = readFile(listConfig)
- l = split(message,"ยง")
- l_s = ""
- for i=1,#l do
- l_s = l_s .. l[i] .."ยง"
- end
- writeFile(listConfig,unread_all .. l_s)
- local unread_mails = readFile(listConfig)
- if #unread_mails == 0 then
- print("You don't have unread mails")
- sleep(2)
- else
- unread_mails_t = split(unread_mails,"ยง")
- list = unread_mails_t
- for i=1, #list do
- detail = split(list[i],"|")
- print(i .." - ".. detail[3] .."|"..detail[2])
- term.setCursorPos(2,5+i)
- end
- while true do
- event, button, xPos, yPos = os.pullEvent("mouse_click")
- if xPos == 2 and yPos >= 5 then
- j = yPos - 4
- detailM(j)
- end
- end
- end
- end
- menu = function()
- exited = false
- while not exited do
- newPage("RedMail")
- local x,y = term.getSize()
- local send = "Send Mail"
- local send_y = 5
- local send_x = math.ceil((x-#send)/2)
- local unread = "Unread Mails"
- local unread_y = 7
- local unread_x = math.ceil((x-#unread)/2)
- local archive = "Archives"
- local archive_y = 9
- local archive_x = math.ceil((x-#archive)/2)
- local quit = "Quit"
- local quit_y = 11
- local quit_x = math.ceil((x-#quit)/2)
- term.setCursorPos(send_x,send_y)
- print(send)
- term.setCursorPos(unread_x,unread_y)
- print(unread)
- term.setCursorPos(archive_x,archive_y)
- print(archive)
- term.setCursorPos(quit_x,quit_y)
- print(quit)
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if (yPos == 5) and (xPos >= send_x and xPos <= (send_x + #send)) then
- sendM()
- elseif (yPos == 11) and (xPos >= quit_x and xPos <= (quit_x + #quit)) then
- term.clear()
- term.setCursorPos(1,0)
- exited = true
- elseif (yPos == 7) and (xPos >= unread_x and xPos <= (unread_x + #unread)) then
- unreadM()
- end
- end
- end
- overlay:setHeaderTitle("RedMail")
- overlay:setFooterText("")
- overlay:draw()
- if not fs.exists(userConfig) then
- while true do
- local userInBox = InBox("Enter your username")
- if #userInBox > 0 then
- user = userInBox
- writeFile(userConfig,userInBox)
- break
- end
- end
- else
- user = readFile(userConfig)
- end
- if not fs.exists(modemConfig) then
- while true do
- local modemInBox = InBox("Which side is the modem ?")
- if #modemInBox > 0 then
- if peripheral.isPresent(modemInBox) and peripheral.getType(modemInBox) == "modem" then
- writeFile(modemConfig,modemInBox)
- side = modemInBox
- break
- else
- msgBox("Can't find modem this side")
- term.clear()
- overlay:setHeaderTitle("RedMail")
- overlay:setFooterText("")
- overlay:draw()
- end
- end
- end
- else
- side = readFile(modemConfig)
- end
- menu()
- rednet.open(side)
- rednet.send(53,"fetch|Deathspreader")
- id, message = rednet.receive()
- print(message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement