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
|
||||
|
||||
def localize
|
||||
logger.info "LOCALIZEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
|
||||
# We will use instance vars for the locale so we can make use of them in
|
||||
# the templates.
|
||||
@charset = 'utf-8'
|
||||
logger.info "Paso 1"
|
||||
headers['Content-Type'] = "text/html; charset=#{@charset}"
|
||||
# Here is a very simplified approach to extract the prefered language
|
||||
# from the request. If all fails, just use 'en_EN' as the default.
|
||||
temp = if request.env['HTTP_ACCEPT_LANGUAGE'].nil?
|
||||
logger.info "Paso 2"
|
||||
[]
|
||||
else
|
||||
logger.info "Paso 3"
|
||||
request.env['HTTP_ACCEPT_LANGUAGE'].split(',').first.split('-') rescue []
|
||||
end
|
||||
language = temp.slice(0)
|
||||
dialect = temp.slice(1)
|
||||
@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').
|
||||
@dialect = dialect.nil? ? @language.upcase : dialect
|
||||
# The complete locale string consists of
|
||||
|
|
|
@ -375,11 +375,22 @@ class IMAPFolder
|
|||
@mailbox.imap.expunge
|
||||
end
|
||||
|
||||
def synchronize_cache
|
||||
def synchronize_cache(offset=0, limit = 10)
|
||||
to = limit+offset
|
||||
startSync = Time.now
|
||||
activate
|
||||
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
|
||||
cached_messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name])
|
||||
|
@ -427,7 +438,7 @@ class IMAPFolder
|
|||
fetch_uids(slice)
|
||||
end
|
||||
end
|
||||
@mcached = true
|
||||
#FIX: @mcached = true
|
||||
logger.debug("Synchonization done for folder #{@name} in #{Time.now - startSync} ms.")
|
||||
end
|
||||
|
||||
|
@ -449,14 +460,14 @@ class IMAPFolder
|
|||
}
|
||||
end
|
||||
|
||||
def messages(offset = 0, limit = 10, sort = 'date desc')
|
||||
def messages(offset = 1, limit = 10, sort = 'date desc')
|
||||
# Synchronize first retrieval time
|
||||
synchronize_cache unless @mcached
|
||||
synchronize_cache(offset, limit) #unless @mcached
|
||||
|
||||
if limit == -1
|
||||
@messages = ImapMessage.find(:all, :conditions => ["username = ? and folder_name = ?", @username, @name], :order => sort)
|
||||
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
|
||||
|
||||
|
|
|
@ -140,7 +140,11 @@ module Mail2Screen
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def add_to_contact(addr, msg_id)
|
||||
|
|
Loading…
Reference in a new issue