Advertisement
shadowkat1010

mail

Mar 30th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. local component = require "component"
  2. local event = require "event"
  3. local computer = require "computer"
  4. local shell = require "shell"
  5. local fs = require "filesystem"
  6. local modem = component.modem
  7.  
  8. local filesPath = "/usr/mail/"
  9. local users = {}
  10. local tArgs = {...}
  11.  
  12. local function extractStr(path)
  13. if path:find("!") ~= nil then
  14. return path:sub(1,path:find("!")-1), path:sub(path:find("!")+1,path:len())
  15. else return path,path
  16. end
  17. end
  18.  
  19. local function mailEventListener(_,message)
  20. local frag1, ufrag = extractStr(message)
  21. print(message)
  22. print(frag1)
  23. print(ufrag)
  24. if message:sub(1,3) == "put" then --put!subject!content
  25. local subject, content = extractStr(ufrag)
  26. print(subject)
  27. print(content)
  28. local path = filesPath..subject
  29. print(path)
  30. if fs.exists(path) then
  31. local fObj = io.open(path,"a")
  32. fObj:write(content)
  33. fObj:close()
  34. else
  35. local f = io.open(path,"w")
  36. f:write(content)
  37. f:close()
  38. end
  39. end
  40. end
  41.  
  42. mailEventListener(nil,"put!derp!derp")
  43.  
  44. event.listen("relay_message",mailEventListener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement