Attempt to fix long messages list on synchronize
This commit is contained in:
parent
b3d16dcac8
commit
f2388c1fd4
|
@ -38,25 +38,20 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def localize
|
def localize
|
||||||
logger.info "LOCALIZEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
|
|
||||||
# We will use instance vars for the locale so we can make use of them in
|
# We will use instance vars for the locale so we can make use of them in
|
||||||
# the templates.
|
# the templates.
|
||||||
@charset = 'utf-8'
|
@charset = 'utf-8'
|
||||||
logger.info "Paso 1"
|
|
||||||
headers['Content-Type'] = "text/html; charset=#{@charset}"
|
headers['Content-Type'] = "text/html; charset=#{@charset}"
|
||||||
# Here is a very simplified approach to extract the prefered language
|
# Here is a very simplified approach to extract the prefered language
|
||||||
# from the request. If all fails, just use 'en_EN' as the default.
|
# from the request. If all fails, just use 'en_EN' as the default.
|
||||||
temp = if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
temp = if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
||||||
logger.info "Paso 2"
|
|
||||||
[]
|
[]
|
||||||
else
|
else
|
||||||
logger.info "Paso 3"
|
|
||||||
request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
|
request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
|
||||||
end
|
end
|
||||||
language = temp.slice(0)
|
language = temp.slice(0)
|
||||||
dialect = temp.slice(1)
|
dialect = temp.slice(1)
|
||||||
@language = language.nil? ? 'en' : language.downcase # default is en
|
@language = language.nil? ? 'en' : language.downcase # default is en
|
||||||
logger.info @language
|
|
||||||
# If there is no dialect use the language code ('en' becomes 'en_EN').
|
# If there is no dialect use the language code ('en' becomes 'en_EN').
|
||||||
@dialect = dialect.nil? ? @language.upcase : dialect
|
@dialect = dialect.nil? ? @language.upcase : dialect
|
||||||
# The complete locale string consists of
|
# The complete locale string consists of
|
||||||
|
|
|
@ -375,11 +375,22 @@ class IMAPFolder
|
||||||
@mailbox.imap.expunge
|
@mailbox.imap.expunge
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize_cache
|
def synchronize_cache(offset=0, limit = 10)
|
||||||
|
to = limit+offset
|
||||||
startSync = Time.now
|
startSync = Time.now
|
||||||
activate
|
activate
|
||||||
startUidFetch = Time.now
|
startUidFetch = Time.now
|
||||||
server_messages = @mailbox.imap.uid_fetch(1..-1, ['UID', 'FLAGS'])
|
|
||||||
|
#Count all messages
|
||||||
|
count = @mailbox.imap.fetch(1..-1, "UID")
|
||||||
|
to = count.size if count.size < to
|
||||||
|
|
||||||
|
|
||||||
|
range = (offset..to)
|
||||||
|
logger.info range.inspect
|
||||||
|
|
||||||
|
server_messages = @mailbox.imap.fetch(range, "(UID FLAGS)")
|
||||||
|
#server_messages = @mailbox.imap.uid_fetch(sequence_uids, ["UID", "FLAGS"])
|
||||||
|
|
||||||
startDbFetch = Time.now
|
startDbFetch = Time.now
|
||||||
cached_messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name])
|
cached_messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name])
|
||||||
|
@ -427,7 +438,7 @@ class IMAPFolder
|
||||||
fetch_uids(slice)
|
fetch_uids(slice)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@mcached = true
|
#FIX: @mcached = true
|
||||||
logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.")
|
logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -449,14 +460,14 @@ class IMAPFolder
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def messages(offset = 0, limit = 10, sort = 'date desc')
|
def messages(offset = 1, limit = 10, sort = 'date desc')
|
||||||
# Synchronize first retrieval time
|
# Synchronize first retrieval time
|
||||||
synchronize_cache unless @mcached
|
synchronize_cache(offset, limit) #unless @mcached
|
||||||
|
|
||||||
if limit == -1
|
if limit == -1
|
||||||
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort)
|
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort)
|
||||||
else
|
else
|
||||||
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort, :limit => limit, :offset => offset )
|
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,11 @@ module Mail2Screen
|
||||||
end
|
end
|
||||||
|
|
||||||
def friendly_address_or_name(addr)
|
def friendly_address_or_name(addr)
|
||||||
addr.kind_of?(Net::IMAP::Address) ? ((addr.name.nil? or addr.name.to_s == "") ? "#{addr.mailbox}@#{addr.host}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s)) : ((addr.name.nil? or addr.name.to_s == "") ? "#{addr.spec}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s))
|
if addr.kind_of?(Net::IMAP::Address)
|
||||||
|
((addr.name.nil? or addr.name.to_s == "") ? "#{addr.mailbox}@#{addr.host}" : (mime_encoded?(addr.name.to_s) ? mime_decode(addr.name.to_s): addr.name.to_s))
|
||||||
|
else
|
||||||
|
((addr.nil? or addr.to_s == "") ? "#{addr.to_s}" : (mime_encoded?(addr.to_s) ? mime_decode(addr.to_s): addr.to_s))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_contact(addr, msg_id)
|
def add_to_contact(addr, msg_id)
|
||||||
|
|
Loading…
Reference in a new issue