Replace simple function with a static string.

This commit is contained in:
Lefteris Chatzimparmpas 2012-02-22 18:55:38 +01:00
parent 3f1059b355
commit dda48edbab
3 changed files with 52 additions and 94 deletions

View File

@ -26,6 +26,7 @@ Account._mt.__call = function (self, arg)
object._account.ssl = arg.ssl or ''
object._account.session = nil
object._account.selected = nil
object._string = arg.username .. '@' .. arg.server
for key, value in pairs(Account) do
if type(value) == 'function' then object[key] = value end
@ -42,18 +43,9 @@ Account._mt.__call = function (self, arg)
end
function Account._get_details(self, mailbox)
if mailbox then
return self._account.username .. '@' .. self._account.server .. '/' ..
mailbox
else
return self._account.username .. '@' .. self._account.server
end
end
function Account._check_connection(self)
if not self._account.session then
error('not connected to ' .. self._get_details(self), 0)
error('not connected to ' .. self._string, 0)
end
end
@ -61,8 +53,7 @@ function Account._check_result(self, request, result)
if result == nil then
self._account.session = nil
self._account.selected = nil
error(request .. ' request to ' .. self._get_details(self) ..
'failed', 0)
error(request .. ' request to ' .. self._string .. ' failed', 0)
end
end
@ -70,7 +61,7 @@ end
function Account._login_user(self)
if self._account.password == nil then
self._account.password = get_password('Enter password for ' ..
self._get_details(self) .. ': ')
self._string .. ': ')
end
if self._account.session then return true end
@ -187,8 +178,7 @@ function Account.create_mailbox(self, name)
if r == false then return false end
if options.info == true then
print(string.format("Created mailbox %s.",
self._get_details(self, name)))
print('Created mailbox ' .. self._string .. '/' .. name .. '.')
end
return r
@ -203,8 +193,7 @@ function Account.delete_mailbox(self, name)
if r == false then return false end
if options.info == true then
print(string.format("Deleted mailbox %s.",
self._get_details(self, name)))
print('Deleted mailbox ' .. self._string .. '/' .. name .. '.')
end
return r
@ -220,9 +209,8 @@ function Account.rename_mailbox(self, oldname, newname)
if r == false then return false end
if options.info == true then
print(string.format("Renamed mailbox %s to %s.",
self._get_details(self, oldname),
self._get_details(self, newname)))
print('Renamed mailbox ' .. self._string .. '/' .. oldname .. ' to ' ..
self._string .. '/' .. newname .. '.')
end
return r
@ -237,8 +225,7 @@ function Account.subscribe_mailbox(self, name)
if r == false then return false end
if options.info == true then
print(string.format("Subscribed mailbox %s.",
self._get_details(self, name)))
print('Subscribed mailbox ' .. self._string .. '/' .. name .. '.')
end
return r
@ -253,8 +240,7 @@ function Account.unsubscribe_mailbox(self, name)
if r == false then return false end
if options.info == true then
print(string.format("Unsubscribed mailbox %s.",
self._get_details(self, name)))
print('Unsubscribed mailbox ' .. self._string .. '/' .. name .. '.')
end
return r

View File

@ -12,6 +12,8 @@ Mailbox._mt.__call = function (self, account, mailbox)
object._type = 'mailbox'
object._account = account
object._mailbox = mailbox
object._string = account._account.username .. '@' ..
account._account.server .. '/' .. mailbox
for key, value in pairs(Mailbox) do
if type(value) == 'function' then object[key] = value end
@ -25,15 +27,9 @@ Mailbox._mt.__call = function (self, account, mailbox)
end
function Mailbox._get_details(self)
return self._account._account.username .. '@' ..
self._account._account.server .. '/' .. self._mailbox
end
function Mailbox._check_connection(self)
if not self._account._account.session then
error('not connected to ' ..
self._account._get_details(self._account), 0)
error('not connected to ' .. self._account._string, 0)
end
end
@ -41,8 +37,8 @@ function Mailbox._check_result(self, request, result)
if result == nil then
self._account._account.session = nil
self._account._account.selected = nil
error(request .. ' request to ' ..
self._account._get_details(self._account) .. 'failed', 0)
error(request .. ' request to ' .. self._account._string ..
' failed', 0)
end
end
@ -491,8 +487,8 @@ function Mailbox.check_status(self)
if r == false then return false end
if options.info == true then
print(string.format("%d messages, %d recent, %d unseen, in %s.",
exist, recent, unseen, self._get_details(self)))
print(exist .. ' messages, ' .. recent .. ' recent, ' .. unseen ..
' unseen, in ' .. self._string .. '.')
end
return exist, recent, unseen, uidnext
@ -515,8 +511,7 @@ function Mailbox.add_flags(self, flags, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', flags, mesgs)
if options.info == true and r == true then
print(string.format("%d messages flagged in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages flagged in ' .. self._string .. '.')
end
return r
@ -529,8 +524,7 @@ function Mailbox.remove_flags(self, flags, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', flags, mesgs)
if options.info == true and r == true then
print(string.format("%d messages flagged in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages flagged in ' .. self._string .. '.')
end
return r
@ -543,8 +537,7 @@ function Mailbox.replace_flags(self, flags, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'replace', flags, mesgs)
if options.info == true and r == true then
print(string.format("%d messages flagged in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages flagged in ' .. self._string .. '.')
end
return r
@ -557,8 +550,7 @@ function Mailbox.mark_answered(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Answered' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages marked answered in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages marked answered in ' .. self._string .. '.')
end
return r
@ -571,8 +563,7 @@ function Mailbox.mark_deleted(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Deleted' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages marked deleted in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages marked deleted in ' .. self._string .. '.')
end
return r
@ -584,8 +575,7 @@ function Mailbox.mark_draft(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Draft' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages marked draft in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages marked draft in ' .. self._string .. '.')
end
return r
@ -597,8 +587,7 @@ function Mailbox.mark_flagged(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Flagged' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages marked flagged in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages marked flagged in ' .. self._string .. '.')
end
return r
@ -610,8 +599,7 @@ function Mailbox.mark_seen(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Seen' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages marked seen in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages marked seen in ' .. self._string .. '.')
end
return r
@ -623,8 +611,8 @@ function Mailbox.unmark_answered(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', { '\\Answered' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages unmarked answered in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages unmarked answered in ' .. self._string ..
'.')
end
return r
@ -636,8 +624,7 @@ function Mailbox.unmark_deleted(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', { '\\Deleted' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages unmarked deleted in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages unmarked deleted in ' .. self._string .. '.')
end
return r
@ -649,8 +636,7 @@ function Mailbox.unmark_draft(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', { '\\Draft' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages unmarked draft in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages unmarked draft in ' .. self._string .. '.')
end
return r
@ -662,8 +648,7 @@ function Mailbox.unmark_flagged(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', { '\\Flagged' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages unmarked flagged in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages unmarked flagged in ' .. self._string .. '.')
end
return r
@ -675,8 +660,7 @@ function Mailbox.unmark_seen(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'remove', { '\\Seen' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages unmarked seen in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages unmarked seen in ' .. self._string .. '.')
end
return r
@ -689,8 +673,7 @@ function Mailbox.delete_messages(self, messages)
local mesgs = _extract_messages(self, messages)
local r = self._flag_messages(self, 'add', { '\\Deleted' }, mesgs)
if options.info == true and r == true then
print(string.format("%d messages deleted in %s.", #mesgs,
self._get_details(self)))
print(#mesgs .. ' messages deleted in ' .. self._string .. '.')
end
return r
@ -704,8 +687,8 @@ function Mailbox.copy_messages(self, dest, messages)
local mesgs = _extract_messages(self, messages)
local r = self._copy_messages(self, dest, mesgs)
if options.info == true and r == true then
print(string.format("%d messages copied from %s to %s.", #mesgs,
self._get_details(self), self._get_details(dest)))
print(#mesgs .. ' messages copied from ' .. self._string .. ' to ' ..
dest._string .. '.')
end
return r
@ -722,10 +705,9 @@ function Mailbox.move_messages(self, dest, messages)
if rc == true then
rf = self._flag_messages(self, 'add', { '\\Deleted' }, mesgs)
end
if options.info == true and
rc == true and rf == true then
print(string.format("%d messages moved from %s to %s.", #mesgs,
self._get_details(self), self._get_details(dest)))
if options.info == true and rc == true and rf == true then
print(#mesgs .. ' messages moved from ' .. self._string .. ' to ' ..
dest._string .. '.')
end
return rc == true and rf == true
@ -793,8 +775,8 @@ function Mailbox.append_message(self, message, flags, date)
if r == false then return false end
if options.info == true and r == true then
print(string.format("Appended message of %d octets to %s.", #message,
self._get_details(self)))
print('Appended message of ' .. #message .. ' octets to ' ..
self._string .. '.')
end
return true

View File

@ -13,6 +13,9 @@ Message._mt.__call = function (self, account, mailbox, uid)
object._account = account
object._mailbox = mailbox
object._uid = uid
object._string = account._account.username .. '@' ..
account._account.server .. '/' .. mailbox._mailbox ..
'[' .. uid .. ']'
object._structure = nil
object._header = nil
@ -33,19 +36,11 @@ Message._mt.__call = function (self, account, mailbox, uid)
end
function Message._get_details(self)
return self._account._account.username .. '@' ..
self._account._account.server .. '/' .. self._mailbox._mailbox ..
'[' .. self._uid .. ']'
end
function Message.fetch_structure(self)
local r = self._mailbox._fetch_structure(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the structure of %s.",
self._get_details(self)))
print('Fetched the structure of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -54,8 +49,7 @@ function Message.fetch_header(self)
local r = self._mailbox._fetch_header(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the header of %s.",
self._get_details(self)))
print('Fetched the header of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -64,7 +58,7 @@ function Message.fetch_body(self)
local r = self._mailbox._fetch_body(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the body of %s.", self._get_details(self)))
print('Fetched the body of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -73,7 +67,7 @@ function Message.fetch_message(self)
local r = self._mailbox._fetch_message(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched message %s.", self._get_details(self)))
print('Fetched message ' .. self._string .. '.')
end
return r[self._uid]
end
@ -83,8 +77,7 @@ function Message.fetch_field(self, field)
{ self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched field \"%s\" of %s.", field,
self._get_details(self)))
print('Fetched field "' .. field .. '" of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -93,8 +86,7 @@ function Message.fetch_fields(self, fields)
local r = self._mailbox._fetch_fields(self._mailbox, fields, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched some of the fields of %s.",
self._get_details(self)))
print('Fetched some of the fields of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -103,8 +95,7 @@ function Message.fetch_part(self, part)
local r = self._mailbox._fetch_parts(self._mailbox, { part }, self._uid)
if not r or not r[part] then return end
if options.info == true then
print(string.format("Fetched part \"%s\" of %s.", part,
self._get_details(self)))
print('Fetched part "' .. part .. '" of ' .. self._string .. '.')
end
return r[part]
end
@ -113,7 +104,7 @@ function Message.fetch_size(self)
local r = self._mailbox._fetch_size(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the size of %s.", self._get_details(self)))
print('Fetched the size of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -122,7 +113,7 @@ function Message.fetch_date(self)
local r = self._mailbox._fetch_date(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the date of %s.", self._get_details(self)))
print('Fetched the date of ' .. self._string .. '.')
end
return r[self._uid]
end
@ -131,8 +122,7 @@ function Message.fetch_flags(self)
local r = self._mailbox._fetch_flags(self._mailbox, { self._uid })
if not r or not r[self._uid] then return end
if options.info == true then
print(string.format("Fetched the flags of %s.",
self._get_details(self)))
print('Fetched the flags of ' .. self._string .. '.')
end
return r[self._uid]
end