From 87c2b318756fc4d84f42f47e5d22ce8982dcd56d Mon Sep 17 00:00:00 2001 From: Mark Longair Date: Mon, 10 Jun 2013 13:42:10 +0100 Subject: Add a rake task to re-extract any missing attachments You can see the number of emails that would be reparsed by doing: bundle exec rake temp:reextract_missing_attachments To actually reparse the incoming emails and rextract attachments for any that were missing, you would do: bundle exec rake temp:reextract_missing_attachments[commit] (In fact, the 'commit' can be any non-empty string.) --- lib/tasks/temp.rake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/tasks/temp.rake') diff --git a/lib/tasks/temp.rake b/lib/tasks/temp.rake index 35ae442c7..fcabb23de 100644 --- a/lib/tasks/temp.rake +++ b/lib/tasks/temp.rake @@ -7,6 +7,28 @@ namespace :temp do user.save! unless dryrun end + desc "Re-extract any missing cached attachments" + task :reextract_missing_attachments, [:commit] => :environment do |t, args| + dry_run = args.commit.nil? || args.commit.empty? + total_messages = 0 + messages_to_reparse = 0 + IncomingMessage.find_each :include => :foi_attachments do |im| + reparse = im.foi_attachments.any? { |fa| ! File.exists? fa.filepath } + total_messages += 1 + messages_to_reparse += 1 if reparse + if total_messages % 1000 == 0 + puts "Considered #{total_messages} received emails." + end + unless dry_run + im.parse_raw_email! true if reparse + sleep 2 + end + end + message = dry_run ? "Would reparse" : "Reparsed" + message += " #{messages_to_reparse} out of #{total_messages} received emails." + puts message + end + desc 'Cleanup accounts with a space in the email address' task :clean_up_emails_with_spaces => :environment do dryrun = ENV['DRYRUN'] == '0' ? false : true -- cgit v1.2.3