Advertisement
dannysmc95

Blaze Email Client

Dec 17th, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 47.22 KB | None | 0 0
  1. -- Blaze Email Client
  2. -- Created By DannySMc
  3. -- Platform: Lua Virtual Machine
  4.  
  5. -- API Functions (Internal)
  6. function saveConfig(table, file)
  7.   fConfig = fs.open(file, "w") or error("Cannot open file "..file, 2)
  8.   fConfig.write(textutils.serialize(table))
  9.   fConfig.close()
  10. end
  11.  
  12. function loadConfig(file)
  13.   fConfig = fs.open(file, "r")
  14.   ret = textutils.unserialize(fConfig.readAll())
  15.   return ret
  16. end
  17.  
  18. function findPeripheral(Perihp) --Returns side of first matching peripheral matching passed string  
  19.   for _,s in ipairs(rs.getSides()) do
  20.     if peripheral.isPresent(s) and peripheral.getType(s) == Perihp then
  21.       return s  
  22.     end
  23.   end
  24.   return false
  25. end
  26.  
  27. -- Common Draw Functions
  28. function cs()
  29.   term.clear()
  30.   term.setCursorPos(1,1)
  31.   return
  32. end
  33.  
  34. function setCol(textColour, backgroundColour)
  35.   if textColour and backgroundColour then
  36.     if term.isColour() then
  37.       term.setTextColour(colours[textColour])
  38.       term.setBackgroundColour(colours[backgroundColour])
  39.       return true
  40.     else
  41.       return false
  42.     end
  43.   else
  44.     return false
  45.   end
  46. end
  47.  
  48. function resetCol()
  49.   if term.isColour then
  50.     term.setTextColour(colours.white)
  51.     term.setBackgroundColour(colours.black)
  52.     return true
  53.   else
  54.     return false
  55.   end
  56. end
  57.  
  58. function printC(Text, Line, NextLine, Color, BkgColor) -- print centered
  59.   local x, y = term.getSize()
  60.   x = x/2 - #Text/2
  61.   term.setCursorPos(x, Line)
  62.   if Color then setCol(Color, BkgColor) end
  63.   term.write(Text)
  64.   if NextLine then
  65.     term.setCursorPos(1, NextLine)
  66.   end
  67.   if Color then resetCol(Color, BkgColor) end
  68.   return true  
  69. end
  70.  
  71. function printL(Text, Line, NextLine, Color, BkgColor) -- print line
  72.  
  73.  
  74.   local x, y = term.getSize()
  75.   if ((term.isColor) and (term.isColor() == false) and (Text == " ")) then Text = "-" end
  76.   for i = 1, x do
  77.     term.setCursorPos(i, Line)
  78.     if Color then setCol(Color, BkgColor) end
  79.     term.write(Text)
  80.   end
  81.   if NextLine then  
  82.     term.setCursorPos(1, NextLine)
  83.   end
  84.   if Color then resetCol(Color, BkgColor) end
  85.   return true  
  86. end
  87.  
  88. function printA(Text, xx, yy, NextLine, Color, BkgColor) -- print anywhere
  89.   term.setCursorPos(xx,yy)
  90.   if Color then setCol(Color, BkgColor) end
  91.   term.write(Text)
  92.   if NextLine then  
  93.     term.setCursorPos(1, NextLine)
  94.   end
  95.   if Color then resetCol(Color, BkgColor) end
  96.   return true  
  97. end
  98.  
  99. function clearLine(Line, NextLine) -- May seem a bit odd, but it may be usefull sometimes
  100.   local x, y = term.getSize()
  101.   for i = 1, x do
  102.     term.setCursorPos(i, Line)
  103.     term.write(" ")
  104.   end  
  105.   if not NextLine then  
  106.     x, y = term.getCursorPos()
  107.     term.setCursorPos(1, y+1)
  108.   end
  109.   return true  
  110. end
  111.  
  112. function drawBox(StartX, lengthX, StartY, lengthY, Text, Color, BkgColor) -- does what is says on the tin.
  113.   local x, y = term.getSize()
  114.   if Color then setCol(Color, BkgColor) end
  115.   if not Text then Text = "*" end
  116.   lengthX = lengthX - 1
  117.   lengthY = lengthY - 1
  118.   EndX = StartX + lengthX  
  119.   EndY = StartY + lengthY
  120.   term.setCursorPos(StartX, StartY)
  121.   term.write(string.rep(Text, lengthX))
  122.   term.setCursorPos(StartX, EndY)
  123.   term.write(string.rep(Text, lengthX))
  124.   for i = StartY, EndY do
  125.     term.setCursorPos(StartX, i)
  126.     term.write(Text)
  127.     term.setCursorPos(EndX, i)    
  128.     term.write(Text)
  129.   end
  130.   resetCol(Color, BkgColor)
  131.   return true  
  132. end
  133.  
  134. db = {}
  135. db.__index = db
  136.  
  137. function db.delete(Filename)
  138.   if fs.exists(Filename) then
  139.     fs.delete(Filename)
  140.     return true
  141.   end
  142.   return false
  143. end
  144.  
  145. function db.load(Filename)
  146.   if not fs.exists(Filename) then
  147.     local F = fs.open(Filename, "w")
  148.     F.write("{}")
  149.     F.close()
  150.   end
  151.   local F = fs.open(Filename, "r")
  152.   local Data = F.readAll()
  153.   F.close()
  154.   Data = textutils.unserialize(Data)
  155.   return Data
  156. end
  157.  
  158. function db.save(Filename, ATable)
  159.   local Data = textutils.serialize(ATable)
  160.   local F = fs.open(Filename, "w")
  161.   F.write(Data)
  162.   F.close()
  163.   return true
  164. end
  165.  
  166. function db.search(searchstring, ATable)
  167.   for i, V in pairs(ATable) do
  168.     if tostring(ATable[i]) == tostring(searchstring) then
  169.       return i
  170.     end
  171.   end
  172.   return 0
  173. end
  174.  
  175. function db.removeString(Filename, AString)
  176.   local TempT = db.load(Filename)
  177.   if type(TempT) ~= "table" then return false end
  178.   local Pos = db.search(AString, TempT)
  179.   if Pos > 0 then
  180.     table.remove(TempT, Pos)
  181.     db.save(Filename, TempT)
  182.     return true
  183.   else
  184.     return false
  185.   end
  186. end
  187.  
  188. function db.insertString(Filename, AString)
  189.   local TempT = db.load(Filename)
  190.   if type(TempT) ~= "table" then TempT = {} end
  191.   table.insert(TempT, AString)
  192.   db.save(Filename, TempT)
  193.   return true
  194. end
  195.  
  196. function serialGen(digits)
  197.  
  198.   local serial
  199.   for i = 1, digits do
  200.     if i == 1 then
  201.       serial = math.random(9)
  202.     else
  203.       serial = serial.. math.random(9)
  204.     end
  205.   end
  206.   serial = tonumber(serial)
  207.   return serial
  208. end
  209.  
  210. function wordwrap(str, limit)
  211.   limit = limit or 72
  212.   local here = 1
  213.   local buf = ""
  214.   local t = {}
  215.   str:gsub("(%s*)()(%S+)()",
  216.   function(sp, st, word, fi)
  217.         if fi-here > limit then
  218.            --# Break the line
  219.            here = st
  220.            table.insert(t, buf)
  221.            buf = word
  222.         else
  223.            buf = buf..sp..word  --# Append
  224.         end
  225.   end)
  226.   --# Tack on any leftovers
  227.   if(buf ~= "") then
  228.         table.insert(t, buf)
  229.   end
  230.   return t
  231. end
  232.  
  233. function time()
  234.   local nTime = textutils.formatTime(os.time(), true)
  235.   os.startTimer(1)
  236.   return nTime
  237. end
  238.  
  239. -- SHA256 Hashing Algorithm:
  240. local MOD = 2^32
  241. local MODM = MOD-1
  242. local function memoize(f)
  243.   local mt = {}
  244.   local t = setmetatable({}, mt)
  245.   function mt:__index(k)
  246.     local v = f(k)
  247.     t[k] = v
  248.     return v
  249.   end
  250.   return t
  251. end
  252. local function make_bitop_uncached(t, m)
  253.   local function bitop(a, b)
  254.     local res,p = 0,1
  255.     while a ~= 0 and b ~= 0 do
  256.       local am, bm = a % m, b % m
  257.       res = res + t[am][bm] * p
  258.       a = (a - am) / m
  259.       b = (b - bm) / m
  260.       p = p*m
  261.     end
  262.     res = res + (a + b) * p
  263.     return res
  264.   end
  265.   return bitop
  266. end
  267. local function make_bitop(t)
  268.   local op1 = make_bitop_uncached(t,2^1)
  269.   local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)
  270.   return make_bitop_uncached(op2, 2 ^ (t.n or 1))
  271. end
  272. local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})
  273. local function bxor(a, b, c, ...)
  274.   local z = nil
  275.   if b then
  276.     a = a % MOD
  277.     b = b % MOD
  278.     z = bxor1(a, b)
  279.     if c then z = bxor(z, c, ...) end
  280.     return z
  281.   elseif a then return a % MOD
  282.   else return 0 end
  283. end
  284. local function band(a, b, c, ...)
  285.   local z
  286.   if b then
  287.     a = a % MOD
  288.     b = b % MOD
  289.     z = ((a + b) - bxor1(a,b)) / 2
  290.     if c then z = bit32_band(z, c, ...) end
  291.     return z
  292.   elseif a then return a % MOD
  293.   else return MODM end
  294. end
  295. local function bnot(x) return (-1 - x) % MOD end
  296. local function rshift1(a, disp)
  297.   if disp < 0 then return lshift(a,-disp) end
  298.   return math.floor(a % 2 ^ 32 / 2 ^ disp)
  299. end
  300. local function rshift(x, disp)
  301.   if disp > 31 or disp < -31 then return 0 end
  302.   return rshift1(x % MOD, disp)
  303. end
  304. local function lshift(a, disp)
  305.   if disp < 0 then return rshift(a,-disp) end
  306.   return (a * 2 ^ disp) % 2 ^ 32
  307. end
  308. local function rrotate(x, disp)
  309.     x = x % MOD
  310.     disp = disp % 32
  311.     local low = band(x, 2 ^ disp - 1)
  312.     return rshift(x, disp) + lshift(low, 32 - disp)
  313. end
  314. local k = {
  315.   0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  316.   0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  317.   0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  318.   0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  319.   0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  320.   0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  321.   0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  322.   0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  323.   0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  324.   0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  325.   0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  326.   0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  327.   0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  328.   0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  329.   0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  330.   0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
  331. }
  332. local function str2hexa(s)
  333.   return (string.gsub(s, ".", function(c) return string.format("%02x", string.byte(c)) end))
  334. end
  335. local function num2s(l, n)
  336.   local s = ""
  337.   for i = 1, n do
  338.     local rem = l % 256
  339.     s = string.char(rem) .. s
  340.     l = (l - rem) / 256
  341.   end
  342.   return s
  343. end
  344. local function s232num(s, i)
  345.   local n = 0
  346.   for i = i, i + 3 do n = n*256 + string.byte(s, i) end
  347.   return n
  348. end
  349. local function preproc(msg, len)
  350.   local extra = 64 - ((len + 9) % 64)
  351.   len = num2s(8 * len, 8)
  352.   msg = msg .. "\128" .. string.rep("\0", extra) .. len
  353.   assert(#msg % 64 == 0)
  354.   return msg
  355. end
  356. local function initH256(H)
  357.   H[1] = 0x6a09e667
  358.   H[2] = 0xbb67ae85
  359.   H[3] = 0x3c6ef372
  360.   H[4] = 0xa54ff53a
  361.   H[5] = 0x510e527f
  362.   H[6] = 0x9b05688c
  363.   H[7] = 0x1f83d9ab
  364.   H[8] = 0x5be0cd19
  365.   return H
  366. end
  367. local function digestblock(msg, i, H)
  368.   local w = {}
  369.   for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end
  370.   for j = 17, 64 do
  371.     local v = w[j - 15]
  372.     local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))
  373.     v = w[j - 2]
  374.     w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))
  375.   end
  376.   local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]
  377.   for i = 1, 64 do
  378.     local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))
  379.     local maj = bxor(band(a, b), band(a, c), band(b, c))
  380.     local t2 = s0 + maj
  381.     local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))
  382.     local ch = bxor (band(e, f), band(bnot(e), g))
  383.     local t1 = h + s1 + ch + k[i] + w[i]
  384.     h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2
  385.   end
  386.   H[1] = band(H[1] + a)
  387.   H[2] = band(H[2] + b)
  388.   H[3] = band(H[3] + c)
  389.   H[4] = band(H[4] + d)
  390.   H[5] = band(H[5] + e)
  391.   H[6] = band(H[6] + f)
  392.   H[7] = band(H[7] + g)
  393.   H[8] = band(H[8] + h)
  394. end
  395. function sha256(msg)
  396.   msg = preproc(msg, #msg)
  397.   local H = initH256({})
  398.   for i = 1, #msg, 64 do digestblock(msg, i, H) end
  399.   return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..
  400.     num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))
  401. end
  402.  
  403. function colourScreen()
  404.   term.setCursorPos(1,1)
  405.   setCol("white", "white")
  406.   count1 = 1
  407.   repeat
  408.     term.setCursorPos(1, count1)
  409.     write("                                                   ")
  410.     count1 = count1 + 1
  411.   until count1 == 20
  412. end
  413.  
  414. -- End API Functions
  415.  
  416.  
  417. --[[
  418. #
  419. #
  420. #
  421. #
  422. #
  423. #
  424. #
  425. #
  426. #
  427. #
  428. #
  429. ]]
  430.  
  431.  
  432. -- Set Globals, Variables and Placeholders
  433. _BLAZEUSER = nil
  434. _BLAZEPASS = nil
  435. _BLAZECMDS = {"login", "getInbox", "register", "delete", "send",}
  436. _BLAZEURLS = {"http://dannysmc.com/files/php/emailsystem.php",}
  437. -- Set Defaults
  438. tc = "black"
  439. bc = "lightGrey"
  440. nVer = 1.1
  441.  
  442. -- BLAZE API
  443. function BlazeLogin(username, password)
  444.   local req = http.post(_BLAZEURLS[1], "command="..textutils.urlEncode(tostring(_BLAZECMDS[1])).."&".."username="..textutils.urlEncode(tostring(username)).."&".."password="..textutils.urlEncode(tostring(password)))
  445.   return req
  446. end
  447.  
  448. function BlazeInbox(username, password)
  449.   local req = http.post(_BLAZEURLS[1], "command="..textutils.urlEncode(tostring(_BLAZECMDS[2])).."&".."username="..textutils.urlEncode(tostring(username)).."&".."password="..textutils.urlEncode(tostring(password)))
  450.   return req
  451. end
  452.  
  453. function BlazeSend(username, password, recipient, subject, message)
  454.   local req = http.post(_BLAZEURLS[1], "command="..textutils.urlEncode(tostring(_BLAZECMDS[5])).."&".."username="..textutils.urlEncode(tostring(username)).."&".."password="..textutils.urlEncode(tostring(password)).."&".."recipient="..textutils.urlEncode(tostring(recipient)).."&".."subject="..textutils.urlEncode(tostring(subject)).."&".."message="..textutils.urlEncode(tostring(message)))
  455.   return req
  456. end
  457.  
  458. function BlazeDelete(username, password, msgid)
  459.   local req = http.post(_BLAZEURLS[1], "command="..textutils.urlEncode(tostring(_BLAZECMDS[4])).."&".."username="..textutils.urlEncode(tostring(username)).."&".."password="..textutils.urlEncode(tostring(password)).."&".."messageid="..textutils.urlEncode(tostring(msgid)))
  460.   return req
  461. end
  462.  
  463. function BlazeRegister(username, password, email)
  464.   local req = http.post(_BLAZEURLS[1], "command="..textutils.urlEncode(tostring(_BLAZECMDS[3])).."&".."username="..textutils.urlEncode(tostring(username)).."&".."password="..textutils.urlEncode(tostring(password)).."&".."email="..textutils.urlEncode(tostring(email)))
  465.   return req
  466. end
  467.  
  468. -- Main Code
  469. function blaze_main()
  470.   if term.isColor() then
  471.     blaze_login()
  472.   end
  473. end
  474.  
  475. function drawPopup(sText)
  476.   drawBox(1, 51, 7, 1, " ", "lime", "red")
  477.   printC(">> "..sText.." <<", 7, false, "lime", "red")
  478. end
  479.  
  480. function blaze_login()
  481.   -- Start Login
  482.   local tInfo = {"Welcome to the new Blaze Email Client", "The pocket, turtle editions are on their way!",}
  483.   cs()
  484.   colourScreen()
  485.   drawBox(1, 51, 1, 2, " ", tc, bc)
  486.   printA("Blaze Email Client", 1, 1, false, tc, bc)
  487.   printA(time(), 47, 1, false, tc, bc)
  488.   printC(">> Login <<", 2, false, tc, bc)
  489.   -- Login Boxes
  490.   drawBox(1, 51, 3, 1, " ", tc, "grey")
  491.   printC("       REGISTER        < - >         [ LOGIN ]     ", 3, false, "white", "grey")
  492.   drawBox(8, 35, 5, 3, " ", tc, bc)
  493.   drawBox(8, 35, 9, 3, " ", tc, bc)
  494.   printC(">> Username <<", 5, false, tc, bc)
  495.   printC(">> Password <<", 9, false, tc, bc)
  496.   term.setCursorPos(1, 17)
  497.   setCol("black", "white")
  498.   printA("Please use your username and password to login to", 1, 17, false, "black", "white")
  499.   printA(" the email client. Don't have an account? Simple ", 1, 18, false, "black", "white")
  500.   printA("press 'REGISTER' to get an email account!", 1, 19, false, "black", "white")
  501.   term.setCursorPos(1,1)
  502.   drawBox(1, 51, 16, 1, " ", tc, bc)
  503.   printC(">> Help <<", 16, false, tc, bc)
  504.   drawBox(19, 13, 13, 1, " ", tc, bc)
  505.   printC(">> LOGIN <<", 13, false, tc, bc)
  506.  
  507.  
  508.  
  509.   while true do
  510.     local args = { os.pullEvent() }
  511.     if args[1] == "timer" then
  512.       clearLine(1, false)
  513.       drawBox(1, 51, 1, 2, " ", tc, bc)
  514.       printA("Blaze Email Client", 1, 1, false, tc, bc)
  515.       printA(time(), 47, 1, false, tc, bc)
  516.       printC(">> Login <<", 2, false, tc, bc)
  517.     elseif args[1] == "mouse_click" then
  518.       if (args[3] >= 9 and args[3] <= 42) and (args[4] == 6) then
  519.         term.setCursorPos(9, 6)
  520.         setCol("lime", "white")
  521.         write(": ")
  522.         username = tostring(read())
  523.       elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 10) then
  524.         term.setCursorPos(9, 10)
  525.         setCol("lime", "white")
  526.         write(": ")
  527.         password = tostring(read("*"))
  528.         password = sha256(password)
  529.       elseif (args[3] >= 20 and args[3] <= 31) and (args[4] == 13) then
  530.         local status = BlazeLogin(username, password)
  531.         if status.readAll() == '"true"' then
  532.           drawPopup("This action was successful")
  533.           sleep(1.5)
  534.           blaze_inbox(1)
  535.         else
  536.           drawPopup("Login Failed!")
  537.           sleep(1.5)
  538.           blaze_login()
  539.         end
  540.       elseif (args[3] >= 1 and args[3] <= 25) and (args[4] == 3) then
  541.         blaze_register()
  542.       end
  543.     elseif args[1] == "char" then
  544.       if args[2] == "u" then
  545.         term.setCursorPos(9, 6)
  546.         setCol("lime", "white")
  547.         write(": ")
  548.         username = tostring(read())
  549.       elseif args[2] == "p" then
  550.         term.setCursorPos(9, 10)
  551.         setCol("lime", "white")
  552.         write(": ")
  553.         password = tostring(read("*"))
  554.         password = sha256(password)
  555.       elseif args[2] == "r" then
  556.         blaze_register()
  557.         break
  558.       elseif args[2] == "l" then
  559.         local status = BlazeLogin(username, password)
  560.         if status.readAll() == '"true"' then
  561.           drawPopup("This action was successful")
  562.           sleep(1.5)
  563.           blaze_inbox(1)
  564.         else
  565.           drawPopup("Login Failed!")
  566.           sleep(1.5)
  567.           blaze_login()
  568.         end
  569.       end
  570.     end
  571.   end
  572. end
  573.  
  574. function addressBook(pageNumber)
  575.   local texttc = "black"
  576.   local textbc = "white"
  577.   local gridtc = "white"
  578.   local gridbc = "grey"
  579.   local menutc = "blue"
  580.   local menubc = "lightGrey"
  581.   fs.makeDir("blazeCore/")
  582.   abPath = "blazeCore/addresses"
  583.   if fs.exists(abPath) then
  584.     addresses = db.load(abPath)
  585.   else
  586.     aTable = {
  587.       {
  588.         "Creator",
  589.       },
  590.       {
  591.         "dannysmc95",
  592.       }
  593.     }
  594.     saveConfig(aTable, abPath)
  595.     addresses = loadConfig(abPath)
  596.   end
  597.   cs()
  598.   colourScreen()
  599.   drawMenuBar()
  600.   -- Views all users on the database
  601.   drawBox(1, 51, 2, 18, " ", "black", "black")
  602.   drawBox(2, 49, 3, 16, " ", gridtc, gridbc)
  603.   drawBox(2, 49, 5, 1, " ", gridtc, gridbc)
  604.   drawBox(26, 1, 3, 16, " ", gridtc, gridbc)
  605.   drawBox(3, 23, 4, 1, " ", menutc, menubc)
  606.   drawBox(27, 23, 4, 1, " ", menutc, menubc)
  607.   printA("Custom Name", 4, 4, false, menutc, menubc)
  608.   printA("Username Address", 28, 4, false, menutc, menubc)
  609.   drawBox(4, 5, 18, 1, " ", menutc, menubc)
  610.   printA("ADD", 5, 18, false, menutc, menubc)
  611.   drawBox(28, 21, 18, 1, " ", menutc, menubc)
  612.   printA("Right-Click Deletes", 29, 18, false, menutc, menubc)
  613.   countY = 6
  614.  
  615.   for k, v in ipairs(addresses[1]) do
  616.     printA(v, 3, countY, false, texttc, textbc)
  617.     countY = countY + 1
  618.   end
  619.  
  620.   countY = 6
  621.   for k, v in ipairs(addresses[2]) do
  622.     printA(v, 27, countY, false, texttc, textbc)
  623.     countY = countY + 1
  624.   end
  625.  
  626.   while true do
  627.     local args = { os.pullEvent() }
  628.     if args[1] == "timer" then
  629.       drawMenuBar()
  630.     end
  631.     if args[1] == "mouse_click" then
  632.       if (args[3] >= 2 and args[3] <= 6) and (args[4] == 1) then
  633.         drawDropdown("new")
  634.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 2) then
  635.         blaze_send()
  636.         break
  637.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 3) then
  638.         addressBook("view")
  639.         break
  640.       elseif (args[3] >= 8 and args[3] <= 14) and (args[4] == 1) then
  641.         blaze_inbox(1)
  642.         break
  643.       elseif (args[3] >= 16 and args[3] <= 25) and (args[4] == 1) then
  644.         blaze_options()
  645.         break
  646.       elseif (args[3] >= 27 and args[3] <= 32) and (args[4] == 1) then
  647.         blaze_help()
  648.         break
  649.       end
  650.       if args[2] == 1 then
  651.         -- Do touch buttons here
  652.         if (args[3] >= 3 and args[3] <= 49) and (args[4] >= 6 and args[4] <= 17) then
  653.           -- Option 1
  654.           intPos = args[4] - 5
  655.           if #addresses[2] == intPos then
  656.             sendRecipient = addresses[2][intPos]
  657.             blaze_send()
  658.             break
  659.           end
  660.         elseif (args[3] >= 4 and args[3] <= 9) and (args[4] == 18) then
  661.           cs()
  662.           colourScreen()
  663.           term.setCursorPos(1,1)
  664.           setCol(texttc, textbc)
  665.           print("Address Book -> Add User")
  666.           print(" ")
  667.           print("> Custom Name: ")
  668.           write(": ")
  669.           local customName = tostring(read())
  670.           print("> Address Name: ")
  671.           write(": ")
  672.           local addressName = tostring(read())
  673.           table.insert(addresses[1], customName)
  674.           table.insert(addresses[2], addressName)
  675.           saveConfig(addresses, abPath)
  676.           addressBook()
  677.         end
  678.       elseif args[2] == 2 then
  679.         if (args[3] >= 4 and args[3] <= 8) and (args[4] >= 6 and args[4] <= 17) then
  680.          intPos = args[4] - 5
  681.          if #addresses[2] == intPos then
  682.             table.remove(addresses[1], intPos)
  683.             table.remove(addresses[2], intPos)
  684.             saveConfig(addresses, abPath)
  685.             addressBook()
  686.           end
  687.         end
  688.       end
  689.     end
  690.   end
  691. end
  692.  
  693. function blaze_register()
  694.   -- Draws register menu
  695.   cs()
  696.   colourScreen()
  697.   drawBox(1, 51, 1, 2, " ", tc, bc)
  698.   printA("Blaze Email Client", 1, 1, false, tc, bc)
  699.   printA(time(), 47, 1, false, tc, bc)
  700.   printC(">> Register <<", 2, false, tc, bc)
  701.   -- Login Boxes
  702.   drawBox(1, 51, 3, 1, " ", tc, "grey")
  703.   printC("     [ REGISTER ]      < - >           LOGIN       ", 3, false, "white", "grey")
  704.   drawBox(8, 35, 5, 7, " ", tc, bc)
  705.   printC(">> Username <<", 5, false, tc, bc)
  706.   drawBox(8, 35, 7, 1, " ", tc, bc)
  707.   printC(">> Password <<", 7, false, tc, bc)
  708.   drawBox(8, 35, 9, 1, " ", tc, bc)
  709.   printC(">> Email Address <<", 9, false, tc, bc)
  710.   drawBox(15, 21, 13, 1, " ", tc, bc)
  711.   printC(" >> REGISTER <<", 13, false, tc, bc)
  712.   drawBox(1, 51, 17, 1, " ", tc, bc)
  713.   printC(">> Information <<", 17, false, tc, bc)
  714.   printA("Your email address is stored so you can recover", 1, 18, false, tc, "white")
  715.   printA("your account!", 1, 19, false, tc, "white")
  716.  
  717.   while true do
  718.     local args = { os.pullEvent() }
  719.     if args[1] == "timer" then
  720.       drawBox(1, 51, 1, 2, " ", tc, bc)
  721.       printA("Blaze Email Client", 1, 1, false, tc, bc)
  722.       printA(time(), 47, 1, false, tc, bc)
  723.       printC(">> Register <<", 2, false, tc, bc)
  724.     elseif args[1] == "mouse_click" then
  725.       if (args[3] >= 9 and args[3] <= 42) and (args[4] == 6) then
  726.         setCol("lime", "white")
  727.         term.setCursorPos(9, 6)
  728.         write(": ")
  729.         username = tostring(read())
  730.       elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 8) then
  731.         setCol("lime", "white")
  732.         term.setCursorPos(9, 8)
  733.         write(": ")
  734.         password = tostring(read("*"))
  735.         password = sha256(password)
  736.       elseif (args[3] >= 9 and args[3] <= 42) and (args[4] == 10) then
  737.         setCol("lime", "white")
  738.         term.setCursorPos(9, 10)
  739.         write(": ")
  740.         email = tostring(read())
  741.       elseif (args[3] >= 18 and args[3] <= 33) and (args[4] == 13) then
  742.         local status = BlazeRegister(username, password, email)
  743.         if status.readAll() == '"true"' then
  744.           drawPopup("This action was successful")
  745.           sleep(1.5)
  746.           _BLAZEUSER = username
  747.           _BLAZEPASS = password
  748.           blaze_login()
  749.         else
  750.           drawPopup("Login Failed!")
  751.           sleep(1.5)
  752.           blaze_login()
  753.         end
  754.       elseif (args[3] >= 28 and args[3] <= 51) and (args[4] == 3) then
  755.         blaze_login()
  756.       end
  757.     elseif args[1] == "char" then
  758.       if args[2] == "l" then
  759.         blaze_login()
  760.         break
  761.       elseif args[2] == "u" then
  762.         setCol("lime", "white")
  763.         term.setCursorPos(9, 6)
  764.         write(": ")
  765.         username = tostring(read())
  766.       elseif args[2] == "p" then
  767.         setCol("lime", "white")
  768.         term.setCursorPos(9, 8)
  769.         write(": ")
  770.         password = tostring(read("*"))
  771.         password = sha256(password)
  772.       elseif args[2] == "e" then
  773.         setCol("lime", "white")
  774.         term.setCursorPos(9, 10)
  775.         write(": ")
  776.         email = tostring(read())
  777.       elseif args[2] == "r" then
  778.         local status = BlazeRegister(username, password, email)
  779.         if status.readAll() == '"true"' then
  780.           drawPopup("This action was successful")
  781.           sleep(1.5)
  782.           _BLAZEUSER = username
  783.           _BLAZEPASS = password
  784.           blaze_login()
  785.         else
  786.           drawPopup("Login Failed!")
  787.           sleep(1.5)
  788.           blaze_login()
  789.         end
  790.       end
  791.     end
  792.   end
  793. end
  794.  
  795. function drawMenuBar()
  796.   menutc = "blue"
  797.   menubc = "lightGrey"
  798.   selectedtc = "lime"
  799.   inboxbc = "white"
  800.   gridbc = "grey"
  801.   drawBox(1, 51, 1, 1, " ", tc, gridbc)
  802.   drawBox(2, 5, 1, 1, " ", menutc, menubc)
  803.   printA("NEW", 3, 1, false, menutc, menubc)
  804.   drawBox(8, 7, 1, 1, " ", menutc, menubc)
  805.   printA("INBOX", 9, 1, false, menutc, menubc)
  806.   drawBox(16, 10, 1, 1, " ", menutc, menubc)
  807.   printA("SETTINGS", 17, 1, false, menutc, menubc)
  808.   drawBox(27, 6, 1, 1, " ", menutc, menubc)
  809.   printA("HELP", 28, 1, false, menutc, menubc)
  810.   drawBox(44, 7, 1, 1, " ", menutc, menubc)
  811.   printA(time(), 45, 1, false, menutc, menubc)
  812. end
  813.  
  814. function blaze_inbox(inboxNumber)
  815.   refreshCount = 300
  816.   menutc = "blue"
  817.   menubc = "lightGrey"
  818.   selectedtc = "lime"
  819.   inboxbc = "white"
  820.   gridbc = "grey"
  821.   cs()
  822.   colourScreen()
  823.   printA("No Message Selected!", 28, 11, false, "black", "white")
  824.   drawMenuBar()
  825.   drawBox(8, 7, 1, 1, " ", menutc, menubc)
  826.   printA("INBOX", 9, 1, false, selectedtc, menubc)
  827.  
  828.   -- Attempt to grab the users inbox:
  829.   local tData = BlazeInbox(username, password)
  830.   inbox = tData
  831.   inbox = inbox.readAll()
  832.   inbox = textutils.unserialize(inbox)
  833.   local status, err = pcall(function() test123 = #inbox end)
  834.   if status then
  835.     inboxEmpty = false
  836.   else
  837.     inboxEmpty = true
  838.   end
  839.  
  840.   -- Draw Inbox Grid
  841.   drawBox(20, 1, 2, 18, " ", tc, gridbc)
  842.   drawBox(1, 20, 2, 1, " ", tc, gridbc)
  843.   drawBox(1, 20, 6, 1, " ", tc, gridbc)
  844.   drawBox(1, 20, 10, 1, " ", tc, gridbc)
  845.   drawBox(1, 20, 14, 1, " ", tc, gridbc)
  846.   drawBox(1, 20, 18, 1, " ", tc, gridbc)
  847.   drawBox(1, 20, 19, 1, " ", tc, gridbc)
  848.   drawBox(2, 4, 19, 1, " ", menutc, menubc)
  849.   drawBox(16, 4, 19, 1, " ", menutc, menubc)
  850.   printA("<-", 3, 19, false, menutc, menubc)
  851.   printA("->", 17, 19, false, menutc, menubc)
  852.  
  853.   -- Draw refresh timer
  854.   drawBox(34, 5, 1, 1, " ", menutc, menubc)
  855.   printA(tostring(refreshCount), 35, 1, false, menutc, menubc)
  856.  
  857.   -- Page Logic Counter
  858.   if inboxEmpty == false then
  859.     inboxCount = #inbox
  860.     if inboxCount >= 1 then
  861.       inboxPages = 1
  862.     elseif inboxCount > 4 and inboxCount <= 8 then
  863.       inboxPages = 2
  864.     elseif inboxCount > 8 and inboxCount <= 12 then
  865.       inboxPages = 3
  866.     elseif inboxCount > 12 and inboxCount <= 16 then
  867.       inboxPages = 4
  868.     elseif inboxCount > 16 and inboxCount <= 20 then
  869.       inboxPages = 5
  870.     end
  871.  
  872.     if inboxNumber == 1 then
  873.       if inboxCount == 1 then
  874.         printA(inbox[1][1], 1, 3, false, selectedtc, inboxbc)
  875.         printA(inbox[1][3], 1, 4, false, menutc, inboxbc)
  876.         printA(inbox[1][4], 1, 5, false, menutc, inboxbc)
  877.       end
  878.       if inboxCount >= 2 then
  879.         printA(inbox[2][1], 1, 7, false, selectedtc, inboxbc)
  880.         printA(inbox[2][3], 1, 8, false, menutc, inboxbc)
  881.         printA(inbox[2][4], 1, 9, false, menutc, inboxbc)
  882.       end
  883.       if inboxCount >= 3 then
  884.         printA(inbox[3][1], 1, 11, false, selectedtc, inboxbc)
  885.         printA(inbox[3][3], 1, 12, false, menutc, inboxbc)
  886.         printA(inbox[3][4], 1, 13, false, menutc, inboxbc)
  887.       end
  888.       if inboxCount >= 4 then
  889.         printA(inbox[4][1], 1, 15, false, selectedtc, inboxbc)
  890.         printA(inbox[4][3], 1, 16, false, menutc, inboxbc)
  891.         printA(inbox[4][4], 1, 17, false, menutc, inboxbc)
  892.       end
  893.     elseif inboxNumber == 2 then
  894.       -- Draw Page 1
  895.       if inboxCount >= 5 then
  896.         printA(inbox[5][1], 1, 3, false, selectedtc, inboxbc)
  897.         printA(inbox[5][3], 5, 4, false, menutc, inboxbc)
  898.         printA(inbox[5][4], 5, 5, false, menutc, inboxbc)
  899.       end
  900.       if inboxCount >= 6 then
  901.         printA(inbox[6][1], 1, 7, false, selectedtc, inboxbc)
  902.         printA(inbox[6][3], 1, 8, false, menutc, inboxbc)
  903.         printA(inbox[6][4], 1, 9, false, menutc, inboxbc)
  904.       end
  905.       if inboxCount >= 7 then
  906.         printA(inbox[7][1], 1, 11, false, selectedtc, inboxbc)
  907.         printA(inbox[7][3], 1, 12, false, menutc, inboxbc)
  908.         printA(inbox[7][4], 1, 13, false, menutc, inboxbc)
  909.       end
  910.       if inboxCount >= 8 then
  911.         printA(inbox[8][1], 1, 15, false, selectedtc, inboxbc)
  912.         printA(inbox[8][3], 1, 16, false, menutc, inboxbc)
  913.         printA(inbox[8][4], 1, 17, false, menutc, inboxbc)
  914.       end
  915.     elseif inboxNumber == 3 then
  916.       -- Draw Page 1
  917.       if inboxCount >= 9 then
  918.         printA(inbox[9][1], 1, 3, false, selectedtc, inboxbc)
  919.         printA(inbox[9][3], 5, 4, false, menutc, inboxbc)
  920.         printA(inbox[9][4], 5, 5, false, menutc, inboxbc)
  921.       end
  922.       if inboxCount >= 10 then
  923.         printA(inbox[10][1], 1, 7, false, selectedtc, inboxbc)
  924.         printA(inbox[10][3], 1, 8, false, menutc, inboxbc)
  925.         printA(inbox[10][4], 1, 9, false, menutc, inboxbc)
  926.       end
  927.       if inboxCount >= 11 then
  928.         printA(inbox[11][1], 1, 11, false, selectedtc, inboxbc)
  929.         printA(inbox[11][3], 1, 12, false, menutc, inboxbc)
  930.         printA(inbox[11][4], 1, 13, false, menutc, inboxbc)
  931.       end
  932.       if inboxCount >= 12 then
  933.         printA(inbox[12][1], 1, 15, false, selectedtc, inboxbc)
  934.         printA(inbox[12][3], 1, 16, false, menutc, inboxbc)
  935.         printA(inbox[12][4], 1, 17, false, menutc, inboxbc)
  936.       end
  937.     elseif inboxNumber == 4 then
  938.       -- Draw Page 1
  939.       if inboxCount >= 13 then
  940.         printA(inbox[13][1], 1, 3, false, selectedtc, inboxbc)
  941.         printA(inbox[13][3], 5, 4, false, menutc, inboxbc)
  942.         printA(inbox[13][4], 5, 5, false, menutc, inboxbc)
  943.       end
  944.       if inboxCount >= 14 then
  945.         printA(inbox[14][1], 1, 7, false, selectedtc, inboxbc)
  946.         printA(inbox[14][3], 1, 8, false, menutc, inboxbc)
  947.         printA(inbox[14][4], 1, 9, false, menutc, inboxbc)
  948.       end
  949.       if inboxCount >= 15 then
  950.         printA(inbox[15][1], 1, 11, false, selectedtc, inboxbc)
  951.         printA(inbox[15][3], 1, 12, false, menutc, inboxbc)
  952.         printA(inbox[15][4], 1, 13, false, menutc, inboxbc)
  953.       end
  954.       if inboxCount >= 16 then
  955.         printA(inbox[16][1], 1, 15, false, selectedtc, inboxbc)
  956.         printA(inbox[16][3], 1, 16, false, menutc, inboxbc)
  957.         printA(inbox[16][4], 1, 17, false, menutc, inboxbc)
  958.       end
  959.     elseif inboxNumber == 5 then
  960.       -- Draw Page 1
  961.       if inboxCount >= 17 then
  962.         printA(inbox[17][1], 1, 3, false, selectedtc, inboxbc)
  963.         printA(inbox[17][3], 5, 4, false, menutc, inboxbc)
  964.         printA(inbox[17][4], 5, 5, false, menutc, inboxbc)
  965.       end
  966.       if inboxCount >= 18 then
  967.         printA(inbox[18][1], 1, 7, false, selectedtc, inboxbc)
  968.         printA(inbox[18][3], 1, 8, false, menutc, inboxbc)
  969.         printA(inbox[18][4], 1, 9, false, menutc, inboxbc)
  970.       end
  971.       if inboxCount >= 19 then
  972.         printA(inbox[19][1], 1, 11, false, selectedtc, inboxbc)
  973.         printA(inbox[19][3], 1, 12, false, menutc, inboxbc)
  974.         printA(inbox[19][4], 1, 13, false, menutc, inboxbc)
  975.       end
  976.       if inboxCount >= 20 then
  977.         printA(inbox[20][1], 1, 15, false, selectedtc, inboxbc)
  978.         printA(inbox[20][3], 1, 16, false, menutc, inboxbc)
  979.         printA(inbox[20][4], 1, 17, false, menutc, inboxbc)
  980.       end
  981.     end
  982.   end
  983.   drawBox(8, 6, 19, 1, " ", menutc, menubc)
  984.   printA(inboxNumber.."/5", 9, 19, false, menutc, menubc)
  985.   while true do
  986.     local args = { os.pullEvent() }
  987.     if args[1] == "timer" then
  988.       drawBox(44, 7, 1, 1, " ", menutc, menubc)
  989.       printA(time(), 45, 1, false, menutc, menubc)
  990.       drawBox(34, 5, 1, 1, " ", menutc, menubc)
  991.       printA(tostring(refreshCount), 35, 1, false, menutc, menubc)
  992.       refreshCount = refreshCount - 1
  993.       if refreshCount == 0 then
  994.         refreshCount = 300
  995.         blaze_inbox(1)
  996.       end
  997.     elseif args[1] == "mouse_click" then
  998.       if (args[3] >= 2 and args[3] <= 6) and (args[4] == 1) then
  999.         drawDropdown("new")
  1000.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 2) then
  1001.         blaze_send()
  1002.         break
  1003.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 3) then
  1004.         addressBook("view")
  1005.         break
  1006.       elseif (args[3] >= 8 and args[3] <= 14) and (args[4] == 1) then
  1007.         blaze_inbox(1)
  1008.         break
  1009.       elseif (args[3] >= 16 and args[3] <= 25) and (args[4] == 1) then
  1010.         blaze_options()
  1011.         break
  1012.       elseif (args[3] >= 27 and args[3] <= 32) and (args[4] == 1) then
  1013.         blaze_help()
  1014.         break
  1015.       elseif (args[3] >= 3 and args[3] <= 48) and (args[4] == 7) then
  1016.         -- Do Update
  1017.         blaze_update()
  1018.         break
  1019.       elseif (args[3] >= 16 and args[3] <= 19) and (args[4] == 19) then
  1020.         if inboxNumber <= 4 then
  1021.           blaze_inbox(inboxNumber + 1)
  1022.         end
  1023.       elseif (args[3] >= 2 and args[3] <= 5) and (args[4] == 19) then
  1024.         if inboxNumber >= 2 then
  1025.           blaze_inbox(inboxNumber - 1)
  1026.         end
  1027.       elseif (args[3] >= 23 and args[3] <= 29) and (args[4] == 18) then
  1028.         sendRecipient = inbox[msgID1][3]
  1029.         blaze_send()
  1030.         break
  1031.       elseif (args[3] >= 42 and args[3] <= 48) and (args[4] == 18) then
  1032.         BlazeDelete(username, password, msgID)
  1033.         blaze_inbox(1)
  1034.         break
  1035.       end  
  1036.       -- Do Inbox Logic
  1037.       if inboxNumber == 1 then
  1038.         if (args[3] >= 1 and args[3] <= 19) and (args[4] >= 3 and args[4] <= 5) then
  1039.           openMessage(1)
  1040.           msgID = inbox[1][1]
  1041.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 7 and args[4] <= 9) then
  1042.           openMessage(2)
  1043.           msgID = inbox[2][1]
  1044.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 11 and args[4] <= 13) then
  1045.           openMessage(3)
  1046.           msgID = inbox[3][1]
  1047.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 15 and args[4] <= 17) then
  1048.           openMessage(4)
  1049.           msgID = inbox[4][1]
  1050.         end
  1051.       elseif inboxNumber == 2 then
  1052.         -- Allow Message Choosing for Page 2
  1053.         if (args[3] >= 1 and args[3] <= 19) and (args[4] >= 3 and args[4] <= 5) then
  1054.           openMessage(5)
  1055.           msgID = inbox[5][1]
  1056.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 7 and args[4] <= 9) then
  1057.           openMessage(6)
  1058.           msgID = inbox[6][1]
  1059.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 11 and args[4] <= 13) then
  1060.           openMessage(7)
  1061.           msgID = inbox[7][1]
  1062.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 15 and args[4] <= 17) then
  1063.           openMessage(8)
  1064.           msgID = inbox[8][1]
  1065.         end
  1066.       elseif inboxNumber == 3 then
  1067.         -- Allow Message Choosing for Page 3
  1068.         if (args[3] >= 1 and args[3] <= 19) and (args[4] >= 3 and args[4] <= 5) then
  1069.           openMessage(9)
  1070.           msgID = inbox[9][1]
  1071.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 7 and args[4] <= 9) then
  1072.           openMessage(10)
  1073.           msgID = inbox[10][1]
  1074.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 11 and args[4] <= 13) then
  1075.           openMessage(11)
  1076.           msgID = inbox[11][1]
  1077.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 15 and args[4] <= 17) then
  1078.           openMessage(12)
  1079.           msgID = inbox[12][1]
  1080.         end
  1081.       elseif inboxNumber == 4 then
  1082.         -- Allow Message Choosing for Page 4
  1083.         if (args[3] >= 1 and args[3] <= 19) and (args[4] >= 3 and args[4] <= 5) then
  1084.           openMessage(13)
  1085.           msgID = inbox[13][1]
  1086.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 7 and args[4] <= 9) then
  1087.           openMessage(14)
  1088.           msgID = inbox[14][1]
  1089.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 11 and args[4] <= 13) then
  1090.           openMessage(15)
  1091.           msgID = inbox[15][1]
  1092.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 15 and args[4] <= 17) then
  1093.           openMessage(16)
  1094.           msgID = inbox[16][1]
  1095.         end
  1096.       elseif inboxNumber == 5 then
  1097.         -- Allow Message Choosing for Page 5
  1098.         if (args[3] >= 1 and args[3] <= 19) and (args[4] >= 3 and args[4] <= 5) then
  1099.           openMessage(17)
  1100.           msgID = inbox[17][1]
  1101.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 7 and args[4] <= 9) then
  1102.           openMessage(18)
  1103.           msgID = inbox[18][1]
  1104.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 11 and args[4] <= 13) then
  1105.           openMessage(19)
  1106.           msgID = inbox[19][1]
  1107.         elseif (args[3] >= 1 and args[3] <= 19) and (args[4] >= 15 and args[4] <= 17) then
  1108.           openMessage(20)
  1109.           msgID = inbox[20][1]
  1110.         end
  1111.       end
  1112.     end
  1113.   end
  1114. end
  1115.  
  1116. function openMessage(intID)
  1117.   msgID1 = intID
  1118.   local texttc = "black"
  1119.   local textbc = "white"
  1120.   local gridtc = "white"
  1121.   local gridbc = "grey"
  1122.   local menutc = "blue"
  1123.   local menubc = "lightGrey"
  1124.   setCol(texttc, textbc)
  1125.   local count1 = 2
  1126.   repeat
  1127.     term.setCursorPos(21, count1)
  1128.     write("                               ")
  1129.     count1 = count1 + 1
  1130.   until count1 == 19
  1131.   drawBox(21, 31, 2, 18, " ", "black", "black")
  1132.   drawBox(22, 29, 3, 16, " ", gridtc, gridbc)
  1133.   drawBox(22, 29, 7, 1, " ", gridtc, gridbc)
  1134.   drawBox(22, 29, 18, 1, " ", gridtc, gridbc)
  1135.   drawBox(23, 7, 18, 1, " ", menutc, menubc)
  1136.   drawBox(42, 8, 18, 1, " ", menutc, menubc)
  1137.   drawBox(31, 1, 4, 3, " ", gridtc, gridbc)
  1138.   printA("REPLY", 24, 18, false, menutc, menubc)
  1139.   printA("DELETE", 43, 18, false, menutc, menubc)
  1140.   printA("Sender:", 23, 4, false, texttc, textbc)
  1141.   printA("Subject:", 23, 5, false, texttc, textbc)
  1142.   printA(inbox[intID][3], 32, 4, false, texttc, textbc)
  1143.   local count1 = 5
  1144.   local tSubject = wordwrap(inbox[intID][4], 18)
  1145.   for _, v in ipairs(tSubject) do
  1146.     term.setCursorPos(32, count1)
  1147.     write(v)
  1148.     count1 = count1 + 1
  1149.   end
  1150.   printA(inbox[intID][4], 32, 5, false, texttc, textbc)
  1151.   setCol(texttc, textbc)
  1152.   local count1 = 8
  1153.   local tMessage = wordwrap(inbox[intID][5], 27)
  1154.   for _,v in ipairs(tMessage) do
  1155.     term.setCursorPos(23, count1)
  1156.     write(v)
  1157.     count1 = count1 + 1
  1158.   end
  1159.   printA("Message ID: "..inbox[intID][1], 23, 3, false, "lime", gridbc)
  1160. end
  1161.  
  1162. function drawDropdown(sMenu, intY)
  1163.   if sMenu == "new" then
  1164.     drawBox(2, 9, 2, 2, " ", menutc, menubc)
  1165.     printA("Message", 3, 2, false, menutc, menubc)
  1166.     printA("Contact", 3, 3, false, menutc, menubc)
  1167.   end
  1168. end
  1169.  
  1170. function blaze_send()
  1171.   gridtc = "white"
  1172.   gridbc = "grey"
  1173.   texttc = "black"
  1174.   textbc = "white"
  1175.   menutc = "blue"
  1176.   menubc = "lightgrey"
  1177.   cs()
  1178.   colourScreen()
  1179.   drawMenuBar()
  1180.   printA("NEW", 3, 1, false, selectedtc, menubc)
  1181.   drawBox(1, 51, 4, 1, " ", gridtc, gridbc)
  1182.   drawBox(12, 1, 2, 3, " ", gridtc, gridbc)
  1183.   printA("To:", 1, 2, false, texttc, textbc)
  1184.   if sendRecipient then
  1185.     printA(sendRecipient, 14, 2, false, texttc, textbc)
  1186.   end
  1187.   sendSubject = nil
  1188.   printA("Subject:", 1, 3, false, texttc, textbc)
  1189.   printC("Message Contents (MAX 200 CHARS)", 4, false, gridtc, gridbc)
  1190.   drawBox(46, 1, 2, 3, " ", gridtc, gridbc)
  1191.   printA("MAX:1", 47, 2, false, texttc, textbc)
  1192.   printA("<= 16", 47, 3, false, texttc, textbc)
  1193.  
  1194.   drawBox(1, 51, 19, 1, " ", gridtc, gridbc)
  1195.   drawBox(2, 6, 19, 1, " ", menutc, menubc)
  1196.   printA("SEND", 3, 19, false, menutc, menubc)
  1197.   drawBox(10, 7, 19, 1, " ", menutc, menubc)
  1198.   printA("CLEAR", 11, 19, false, menutc, menubc)
  1199.   drawBox(42, 8, 19, 1, " ", menutc, menubc)
  1200.   printA("CANCEL", 43, 19, false, menutc, menubc)
  1201.  
  1202.   while true do
  1203.     local args = { os.pullEvent() }
  1204.     if args[1] == "timer" then
  1205.       drawMenuBar()
  1206.       printA("NEW", 3, 1, false, selectedtc, menubc)
  1207.     elseif args[1] == "mouse_click" then
  1208.       if (args[3] >= 42 and args[3] <= 50) and (args[4] == 19) then
  1209.         blaze_inbox(1)
  1210.         break
  1211.       elseif (args[3] >= 2 and args[3] <= 8) and (args[4] == 19) then
  1212.         BlazeSend(username, password, sendRecipient, sendSubject, sendMessage)
  1213.         drawPopup("Message Sent")
  1214.         sleep(1.5)
  1215.         blaze_inbox(1)
  1216.         break
  1217.       elseif args[1] == "mouse_click" then
  1218.         if (args[3] >= 2 and args[3] <= 6) and (args[4] == 1) then
  1219.         drawDropdown("new")
  1220.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 2) then
  1221.         blaze_send()
  1222.         break
  1223.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 3) then
  1224.         addressBook("view")
  1225.         break
  1226.       elseif (args[3] >= 8 and args[3] <= 14) and (args[4] == 1) then
  1227.         blaze_inbox(1)
  1228.         break
  1229.       elseif (args[3] >= 16 and args[3] <= 25) and (args[4] == 1) then
  1230.         blaze_options()
  1231.         break
  1232.       elseif (args[3] >= 27 and args[3] <= 32) and (args[4] == 1) then
  1233.         blaze_help()
  1234.         break
  1235.       elseif (args[3] >= 3 and args[3] <= 48) and (args[4] == 7) then
  1236.         -- Do Update
  1237.         blaze_update()
  1238.         break
  1239.       elseif (args[3] >= 23 and args[3] <= 29) and (args[4] == 18) then
  1240.         -- Do Back button
  1241.         blaze_inbox(1)
  1242.         break
  1243.         elseif (args[3] >= 13 and args[3] <= 45) and (args[4] == 2) then
  1244.           -- Start Recipient Input
  1245.           if sendRecipientExist then
  1246.             setCol(texttc, textbc)
  1247.             term.setCursorPos(13,2)
  1248.             write("                                 ")
  1249.           end
  1250.           setCol(texttc, textbc)
  1251.           term.setCursorPos(14,2)
  1252.           sendRecipient = read()
  1253.           sendRecipientExist = true        
  1254.         elseif (args[3] >= 13 and args[3] <= 45) and (args[4] == 3) then
  1255.           -- Start Subject Input
  1256.           if sendSubjectExist then
  1257.             setCol(texttc, textbc)
  1258.             term.setCursorPos(13,3)
  1259.             write("                                 ")
  1260.           end
  1261.           setCol(texttc, textbc)
  1262.           term.setCursorPos(14,3)
  1263.           sendSubject = read()
  1264.           sendSubjectExist = true  
  1265.         elseif (args[3] >= 1 and args[3] <= 51) and (args[4] >= 5 and args[4] <= 18) then
  1266.           -- Start Message Input
  1267.           if sendMessageExist then
  1268.             count2 = 5
  1269.             repeat
  1270.               term.setCursorPos(1, count2)
  1271.               setCol("white", "white")
  1272.               write("                                                   ")
  1273.               count2 = count2 + 1
  1274.             until count2 == 19
  1275.           end
  1276.           setCol("black", "white")
  1277.           term.setCursorPos(1, 5)
  1278.           sendMessage = read()
  1279.           sendMessageExist = true
  1280.           term.setCursorPos(1, 5)
  1281.           for _, v in ipairs(wordwrap(sendMessage)) do
  1282.             print(v)
  1283.           end
  1284.         end
  1285.       end
  1286.     end
  1287.   end
  1288. end
  1289.  
  1290. function blaze_options()
  1291.   texttc = "black"
  1292.   textbc = "white"
  1293.   selectedtc = "lime"
  1294.   gridtc = "white"
  1295.   gridbc = "grey"
  1296.   menutc = "blue"
  1297.   menubc = "lightGrey"
  1298.   cs()
  1299.   colourScreen()
  1300.   drawMenuBar()
  1301.   drawBox(16, 10, 1, 1, " ", menutc, menubc)
  1302.   printA("SETTINGS", 17, 1, false, selectedtc, menubc)
  1303.   local tOptions = {"1. Register New User", "2. Update Blaze"}
  1304.   drawBox(1, 51, 2, 18, " ", "black", "black")
  1305.   drawBox(2, 49, 3, 16, " ", gridtc, gridbc)
  1306.   drawBox(35, 1, 3, 13, " ", gridtc, gridbc)
  1307.   drawBox(2, 49, 15, 1, " ", gridtc, gridbc)
  1308.   drawBox(2, 49, 5, 1, " ", gridtc, gridbc)
  1309.   drawBox(3, 32, 4, 1, " ", menutc, menubc)
  1310.   drawBox(36, 14, 4, 1, " ", menutc, menubc)
  1311.   printA("OPTION/FUNCTION NAME", 4, 4, false, menutc, menubc)
  1312.   printA("VALUE", 37, 4, false, menutc, menubc)
  1313.   printA(tOptions[1], 4, 6, false, menubc, textbc)
  1314.   printA(tOptions[2], 4, 7, false, texttc, textbc)
  1315.   printA("N/A", 37, 6, false, texttc, textbc)
  1316.   printA("N/A", 37, 7, false, texttc, textbc)
  1317.   printA("Greyed out options are not yet functional.", 3, 16, false, texttc, textbc)
  1318.   printA("N/A applies to functions that can't be changed.", 3, 17, false, texttc, textbc)
  1319.   printA(" BACK ", 23, 18, false, menutc, menubc)
  1320.  
  1321.   while true do
  1322.     local args = { os.pullEvent() }
  1323.     if args[1] == "timer" then
  1324.       drawMenuBar()
  1325.       drawBox(16, 10, 1, 1, " ", menutc, menubc)
  1326.       printA("SETTINGS", 17, 1, false, selectedtc, menubc)
  1327.       settings1 = true
  1328.     elseif args[1] == "mouse_click" then
  1329.       if (args[3] >= 2 and args[3] <= 6) and (args[4] == 1) then
  1330.         if settings1 then
  1331.           settings1 = false
  1332.           drawDropdown("new")
  1333.         end
  1334.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 2) then
  1335.         if settings1 then
  1336.           settings1 = false
  1337.           blaze_send()
  1338.           break
  1339.         end
  1340.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 3) then
  1341.         if settings1 then
  1342.           settings1 = false
  1343.           addressBook("view")
  1344.           break
  1345.         end
  1346.       elseif (args[3] >= 8 and args[3] <= 14) and (args[4] == 1) then
  1347.         if settings1 then
  1348.           settings1 = false
  1349.           blaze_inbox(1)
  1350.           break
  1351.         end
  1352.       elseif (args[3] >= 16 and args[3] <= 25) and (args[4] == 1) then
  1353.         if settings1 then
  1354.           settings1 = false
  1355.           blaze_options()
  1356.           break
  1357.         end
  1358.       elseif (args[3] >= 27 and args[3] <= 32) and (args[4] == 1) then
  1359.         if settings1 then
  1360.           settings1 = false
  1361.           blaze_help()
  1362.           break
  1363.         end
  1364.       elseif (args[3] >= 3 and args[3] <= 48) and (args[4] == 7) then
  1365.         -- Do Update
  1366.         if settings1 then
  1367.           settings1 = false
  1368.           blaze_update()
  1369.           break
  1370.         end
  1371.       elseif (args[3] >= 23 and args[3] <= 29) and (args[4] == 18) then
  1372.         -- Do Back button
  1373.         if settings1 then
  1374.           settings1 = false
  1375.           blaze_inbox(1)
  1376.           break
  1377.         end
  1378.       end
  1379.     end
  1380.   end
  1381. end
  1382.  
  1383. function blaze_update()
  1384.   cs()
  1385.   colourScreen()
  1386.   -- Do Update Stuff Here
  1387.   bartc = "blue"
  1388.   barbc = "lightGrey"
  1389.   texttc = "black"
  1390.   textbc = "white"
  1391.   drawBox(1, 51, 1, 2, " ", bartc, barbc)
  1392.   printA("Blaze Email Client", 1, 1, false, bartc, barbc)
  1393.   printC("UPDATING BLAZE", 2, false, bartc, barbc)
  1394.   term.setCursorPos(1,4)
  1395.   setCol(texttc, textbc)
  1396.   print("> Update in progress, please wait")
  1397.   sleep(1)
  1398.   print("> Grabbing Blaze")
  1399.   shell.run("pastebin get VehDCxwR updateBlaze")
  1400.   print("> Deleting old file")
  1401.   fs.delete("blaze")
  1402.   print("> Saving new file")
  1403.   shell.run("mv updateBlaze blaze")
  1404.   print("> Restarting...")
  1405.   sleep(1.5)
  1406.   os.reboot()
  1407. end
  1408.  
  1409. function blaze_help()
  1410.   texttc = "black"
  1411.   textbc = "white"
  1412.   selectedtc = "lime"
  1413.   gridtc = "white"
  1414.   gridbc = "grey"
  1415.   menutc = "blue"
  1416.   menubc = "lightGrey"
  1417.   cs()
  1418.   colourScreen()
  1419.   drawMenuBar()
  1420.   drawBox(27, 6, 1, 1, " ", menutc, menubc)
  1421.   printA("HELP", 28, 1, false, selectedtc, menubc)
  1422.   drawBox(1, 51, 2, 18, " ", "black", "black")
  1423.   drawBox(2, 49, 3, 16, " ", gridtc, gridbc)
  1424.   local sHelp1 = "Created and hosted by DannySMc, Contacts: danny.smc95@gmail.com, Website: http://dannysmc.com. Questions? Contact Danny! Want to use the API? Check on my blog to when it is published. Passwords are secured with SHA265 Hashing algorithm for extra security. This is a beta, so there will likely be many bugs! Please submit them on the ComputerCraft Forums post in the comments."
  1425.   local tHelp1 = wordwrap(sHelp1, 47)
  1426.   drawBox(22, 6, 3, 1, " ", menutc, menubc)
  1427.   printA("HELP", 23, 3, false, menutc, menubc)
  1428.   setCol(texttc, textbc)
  1429.   local count1 = 4
  1430.   for _,v in ipairs(tHelp1) do
  1431.     term.setCursorPos(3, count1)
  1432.     write(v)
  1433.     count1 = count1 + 1
  1434.   end
  1435.  
  1436.   while true do
  1437.     local args = { os.pullEvent() }
  1438.     if args[1] == "timer" then
  1439.       drawMenuBar()
  1440.       drawBox(27, 6, 1, 1, " ", menutc, menubc)
  1441.       printA("HELP", 28, 1, false, selectedtc, menubc)
  1442.     elseif args[1] == "mouse_click" then
  1443.       if (args[3] >= 2 and args[3] <= 6) and (args[4] == 1) then
  1444.         drawDropdown("new")
  1445.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 2) then
  1446.         blaze_send()
  1447.         break
  1448.       elseif (args[3] >= 2 and args[3] <= 11) and (args[4] == 3) then
  1449.         addressBook("view")
  1450.         break
  1451.       elseif (args[3] >= 8 and args[3] <= 14) and (args[4] == 1) then
  1452.         blaze_inbox(1)
  1453.         break
  1454.       elseif (args[3] >= 16 and args[3] <= 25) and (args[4] == 1) then
  1455.         blaze_options()
  1456.         break
  1457.       elseif (args[3] >= 27 and args[3] <= 32) and (args[4] == 1) then
  1458.         blaze_help()
  1459.         break
  1460.       elseif (args[3] >= 3 and args[3] <= 48) and (args[4] == 7) then
  1461.         -- Do Update
  1462.         blaze_update()
  1463.         break
  1464.       elseif (args[3] >= 23 and args[3] <= 29) and (args[4] == 18) then
  1465.         -- Do Back button
  1466.         blaze_inbox(1)
  1467.         break
  1468.       end
  1469.     end
  1470.   end
  1471. end
  1472.  
  1473. blaze_login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement