Permalink
Browse files

Speed up maildir processing

1. Only process messages when emails are added (not when they are
changed or removed).
2. Only process the messages that were added, not the entire maildir
  • Loading branch information...
kjg committed Sep 17, 2012
1 parent 610fa8e commit 327bf782efa25b41a519914acc11f178dea53757
Showing with 9 additions and 12 deletions.
  1. +9 −12 lib/mailman/application.rb
View
@@ -79,31 +79,28 @@ def run
Mailman.logger.info "Maildir receiver enabled (#{Mailman.config.maildir})."
- process_maildir
+ Mailman.logger.debug "Processing new message queue..."
+ @maildir.list(:new).each do |message|
+ @processor.process_maildir_message(message)
+ end
if Mailman.config.watch_maildir
require 'listen'
Mailman.logger.debug "Monitoring the Maildir for new messages..."
callback = Proc.new do |modified, added, removed|
- process_maildir
+ added.each do |new_file|
+ message = Maildir::Message.new(@maildir, "new/#{new_file}")
+ @processor.process_maildir_message(message)
+ end
end
- @listener = Listen.to(File.join(Mailman.config.maildir, 'new')).change(&callback)
+ @listener = Listen.to(File.join(@maildir.path, 'new'), :relative_paths => true).change(&callback)
@listener.start
end
end
end
- # List all message in Maildir new directory and process it
- def process_maildir
- # Process messages queued in the new directory
- Mailman.logger.debug "Processing new message queue..."
- @maildir.list(:new).each do |message|
- @processor.process_maildir_message(message)
- end
- end
-
private
# Run the polling loop for the email inbox connection

0 comments on commit 327bf78

Please sign in to comment.