Open main menu
Posts
Gists
Guilds
Users
Decipher
Docs
Open user menu
Log in
Sign up
Create a new gist
Posts
Gists
Guilds
Users
Decipher
Docs
Files
mail.src
mail.src
Mission = {}
// type : enum [academic_record]
// is_completed : boolean
// info : map
Mission.attrs = ["type", "is_completed"]
Mission.init = function(mail)
self.mail = mail
self.inbox = mail.inbox
self.meta_mail = mail.inbox.meta_mail
self.is_completed = false
if self.mail.content.indexOf("customer is satisfied") then
self.is_completed = true
end if
self.set_type
end function
Mission.set_type = function
// also code smell
if self.mail.content.indexOf("academic record") then
self.type = "academic_record"
else if self.mail.content.indexOf("police record") then
self.type = "police_record"
end if
end function
Mission.info = function
// code smell
if self.type == "academic_record" then
return self.get_academic_record_info
else if self.type == "police_record" then
return self.get_police_record_info
end if
end function
Mission.get_academic_record_info = function
info = {}
info.remote_ip = self.mail.content[self.mail.content.indexOf("remote ip of the victim is"):][27:].split(char(10))[0][3:-4]
info.database_ip = self.mail.content[self.mail.content.indexOf("database is located is"):][23:].split(char(10))[0][3:-4]
info.student = self.mail.content[self.mail.content.indexOf("modify belongs to"):][19:].split(char(10))[0][3:-5]
info.subject = self.mail.content[self.mail.content.indexOf("modify the subject"):][19:].split(" ")[0][3:-4]
info.skip = false
info.database_port = null
router = get_router(info.remote_ip)
for port in router.used_ports
if router.port_info(port).indexOf("students") != null then
info.database_port = port.port_number
if port.is_closed == true then
info.skip = true
end if
end if
end for
if info.database_port == null then
info.skip = true
end if
return info
end function
Mission.get_police_record_info = function
info = {}
info.remote_ip = self.mail.content[self.mail.content.indexOf("remote ip of the victim is"):][27:].split(char(10))[0][3:-4]
info.convicted = self.mail.content[self.mail.content.indexOf("modify belongs to"):][19:].split(char(10))[0][3:-5]
info.skip = false
info.database_port = null
if self.mail.content.indexOf("client wants to delete the charge") then
info.type = "delete"
info.charge = self.mail.content[self.mail.content.indexOf("delete the charge of"):][21:].split(" ")[0][3:-5]
else if self.mail.content.indexOf("client wants to add the charge") then
info.type = "add"
info.charge = self.mail.content[self.mail.content.indexOf("add the charge of"):][18:].split(" ")[0][3:-4]
info.year = self.mail.content[self.mail.content.indexOf("in the year"):][12:].split(" ")[0][:-1]
else
info.type = "edit"
info.charge = self.mail.content[self.mail.content.indexOf("modify the charge of"):][21:].split(" ")[0][3:-4]
info.change = self.mail.content[self.mail.content.indexOf("date of the crime is"):][21:].split(char(10))[0]
end if
router = get_router(info.remote_ip)
for port in router.used_ports
if router.port_info(port).indexOf("criminals") != null then
info.database_port = port.port_number
if port.is_closed == true then
info.skip = true
end if
end if
end for
if info.database_port == null then
info.skip = true
end if
return info
end function
Mail = {}
// id : string
// from : string
// subject : string
// content : string
Mail.attrs = ["id", "from", "subject"]
Mail.init = function(inbox, str)
self.inbox = inbox
self.meta_mail = inbox.meta_mail
self.id = str[str.indexOf("MailID: "):][8:].split(char(10))[0]
self.from = str[str.indexOf("From: "):][6:].split(char(10))[0]
self.subject = str[str.indexOf("Subject: "):][9:].split(char(10))[0]
self.content = self.meta_mail.read(self.id)
self.content = self.content[self.content.indexOf("Subject: "):].split(char(10))[1:].join(char(10))
if self.is_mission == true then
self.mission = new Mission
self.mission.init(self)
end if
end function
Mail.is_mission = function
return self.subject == "Mission Contract"
end function
Inbox = {}
Inbox.init = function(email, password)
self.meta_mail = mail_login(email, password)
if self.meta_mail isa string then exit(self.meta_mail)
end function
Inbox.list = function
mails = self.meta_mail.fetch()
for i in mails.indexes
m = new Mail
m.init(self, mails[i])
mails[i] = m
end for
return mails
end function
Inbox.missions = function
f = function(o)
return o.is_mission == true
end function
missions = self.list.select(@f)
f = function(o)
return o.mission
end function
missions = missions.map(@f)
f = function(o)
return o.type
end function
missions = missions.lsort(@f)
return missions
end function
Inbox.grouped_missions = function()
missions = {}
for m in self.missions
if missions.hasIndex(m.type) == false then
missions[m.type] = []
end if
missions[m.type].push m
end for
return missions
end function