mailr/lib/imap_session.rb

26 lines
599 B
Ruby
Raw Normal View History

2011-07-27 20:34:30 +02:00
require 'net/imap'
require 'imap_mailbox'
module ImapSessionModule
def open_imap_session
begin
2011-07-31 22:45:29 +02:00
@mailbox ||= ImapMailboxModule::IMAPMailbox.new(logger)
2011-07-27 20:34:30 +02:00
@mailbox.connect(@current_user.servers.primary,@current_user.email, @current_user.get_cached_password(session))
rescue Exception => ex
2011-07-29 20:05:47 +02:00
redirect_to :controller => 'internal', :action => 'loginfailure'
2011-07-27 20:34:30 +02:00
end
end
def close_imap_session
return if @mailbox.nil? or not(@mailbox.connected)
@mailbox.disconnect
@mailbox = nil
end
2011-08-16 20:05:58 +02:00
def select_imap_folder
@mailbox.set_folder(@current_folder.full_name) if not @current_folder.nil?
end
2011-07-27 20:34:30 +02:00
end