2011-03-06 06:58:58 -05:00
|
|
|
-- The Message class that represents messages inside a mailbox.
|
|
|
|
|
|
|
|
Message = {}
|
|
|
|
|
|
|
|
Message._mt = {}
|
|
|
|
setmetatable(Message, Message._mt)
|
|
|
|
|
|
|
|
|
|
|
|
Message._mt.__call = function (self, account, mailbox, uid)
|
|
|
|
local object = {}
|
|
|
|
|
|
|
|
object._type = 'message'
|
|
|
|
object._account = account
|
|
|
|
object._mailbox = mailbox
|
|
|
|
object._uid = uid
|
2012-02-22 12:55:38 -05:00
|
|
|
object._string = account._account.username .. '@' ..
|
|
|
|
account._account.server .. '/' .. mailbox._mailbox ..
|
|
|
|
'[' .. uid .. ']'
|
2011-03-06 06:58:58 -05:00
|
|
|
|
|
|
|
object._structure = nil
|
|
|
|
object._header = nil
|
|
|
|
object._body = nil
|
|
|
|
object._fields = {}
|
|
|
|
object._parts = {}
|
|
|
|
object._size = nil
|
|
|
|
object._date = nil
|
|
|
|
|
2012-02-14 16:13:15 -05:00
|
|
|
for key, value in pairs(Message) do
|
|
|
|
if type(value) == 'function' then object[key] = value end
|
|
|
|
end
|
|
|
|
|
|
|
|
object._mt = {}
|
|
|
|
setmetatable(object, object._mt)
|
|
|
|
|
2011-03-06 06:58:58 -05:00
|
|
|
return object
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function Message.fetch_structure(self)
|
|
|
|
local r = self._mailbox._fetch_structure(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the structure of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_header(self)
|
|
|
|
local r = self._mailbox._fetch_header(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the header of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_body(self)
|
|
|
|
local r = self._mailbox._fetch_body(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the body of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_message(self)
|
|
|
|
local r = self._mailbox._fetch_message(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched message ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_field(self, field)
|
|
|
|
local r = self._mailbox._fetch_fields(self._mailbox, { field },
|
|
|
|
{ self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched field "' .. field .. '" of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_fields(self, fields)
|
|
|
|
local r = self._mailbox._fetch_fields(self._mailbox, fields, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched some of the fields of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_part(self, part)
|
|
|
|
local r = self._mailbox._fetch_parts(self._mailbox, { part }, self._uid)
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[part] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched part "' .. part .. '" of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[part]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_size(self)
|
|
|
|
local r = self._mailbox._fetch_size(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the size of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_date(self)
|
|
|
|
local r = self._mailbox._fetch_date(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the date of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
function Message.fetch_flags(self)
|
|
|
|
local r = self._mailbox._fetch_flags(self._mailbox, { self._uid })
|
2012-02-19 17:56:54 -05:00
|
|
|
if not r or not r[self._uid] then return end
|
|
|
|
if options.info == true then
|
2012-02-22 12:55:38 -05:00
|
|
|
print('Fetched the flags of ' .. self._string .. '.')
|
2012-02-19 17:56:54 -05:00
|
|
|
end
|
2011-03-06 06:58:58 -05:00
|
|
|
return r[self._uid]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
Message._mt.__index = function () end
|
|
|
|
Message._mt.__newindex = function () end
|