Skip to content

Commit

Permalink
Import email
Browse files Browse the repository at this point in the history
MailerDaemon was not working properly on production, so we're switching to a simple script to be called from cron.
  • Loading branch information
Pablo Villalba committed Jan 25, 2010
1 parent b94ee6e commit 0d58776
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion config/teambox.yml
Expand Up @@ -28,7 +28,7 @@ defaults: &DEFAULTS
# When set to true, "reply above this line" notice will be displayed where relevant and accept emails.
# You will need to:
# * Setup catch-all address for email received for any username of the incoming mail server.
# * Run './script/inbox start' to start the receiving email daemon.
# * Run './script/inbox' periodically from cron to process incoming emails.
allow_incoming_email: false
incoming:
type: pop
Expand Down
38 changes: 18 additions & 20 deletions script/inbox
@@ -1,30 +1,28 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../config/environment.rb'
require 'net/pop'
require File.dirname(__FILE__) + '/../config/environment'

logger = RAILS_DEFAULT_LOGGER

class MailerDaemonFetcherDaemon < Daemon::Base

@config = APP_CONFIG['incoming'].to_options

@sleep_time = @config.delete(:sleep_time) || 30
@fetcher = Fetcher.create({:receiver => Emailer}.merge(@config))

def self.start
puts "Starting MailerDaemonFetcherDaemon"
@fetcher = Fetcher.create({:receiver => Emailer}.merge(@config))
puts 'Running Mail Importer...'

loop do
@fetcher.fetch
sleep(@sleep_time)
@config = APP_CONFIG['incoming']

Net::POP3.start(@config['server'], nil, @config['username'], @config['password']) do |pop|
if pop.mails.empty?
puts 'No mail.'
else
pop.mails.each do |email|
begin
puts 'Receiving mail...'
Emailer.receive(email.pop)
rescue Exception => e
puts 'Error receiving email at ' + Time.current.to_s + '::: ' + e.message
end
email.delete
end
end

def self.stop
puts "Stopping MailerDaemonFetcherDaemon"
end

end
puts 'Finished Mail Importer.'

MailerDaemonFetcherDaemon.daemonize

0 comments on commit 0d58776

Please sign in to comment.