2012-04-10 14:06:46 +00:00
|
|
|
require 'net/imap'
|
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
class Channel::IMAP < Channel::EmailParser
|
2012-04-10 14:06:46 +00:00
|
|
|
include UserInfo
|
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
def fetch (channel)
|
2012-04-10 14:06:46 +00:00
|
|
|
puts 'fetching imap'
|
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
imap = Net::IMAP.new(channel[:options][:host], 993, true )
|
|
|
|
imap.authenticate('LOGIN', channel[:options][:user], channel[:options][:password])
|
2012-04-10 14:06:46 +00:00
|
|
|
imap.select('INBOX')
|
2012-04-13 16:42:25 +00:00
|
|
|
count = 0
|
2012-04-10 14:06:46 +00:00
|
|
|
imap.search(['ALL']).each do |message_id|
|
|
|
|
msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
|
|
|
|
# puts msg.to_s
|
|
|
|
|
2012-04-13 16:42:25 +00:00
|
|
|
# delete email from server after article was created
|
|
|
|
if parse(channel, msg)
|
|
|
|
imap.store(message_id, "+FLAGS", [:Deleted])
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2012-04-13 16:42:25 +00:00
|
|
|
count += 1
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
imap.expunge()
|
|
|
|
imap.disconnect()
|
2012-04-13 16:42:25 +00:00
|
|
|
puts "#{count.to_s} mails fetched. done."
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
2012-04-13 13:51:10 +00:00
|
|
|
def send(attr, notification = false)
|
|
|
|
channel = Channel.where( :area => 'Email::Outbound', :active => true ).first
|
|
|
|
begin
|
|
|
|
c = eval 'Channel::' + channel[:adapter] + '.new'
|
|
|
|
c.send(attr, channel, notification)
|
|
|
|
rescue Exception => e
|
|
|
|
puts "can't use " + 'Channel::' + channel[:adapter]
|
|
|
|
puts e.inspect
|
2012-04-10 14:06:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|