Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 10
- Log:
Checking in HEAD from RForum's SVN of 22-Jul-2006, 8pm (revision 906).
- Author:
- adh
- Date:
- Sat Jul 22 20:02:44 +0100 2006
- Size:
- 2423 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | unless maildir = ARGV[0] |
4 | puts 'Usage: script/process_mails directory [time between checks in minutes]' |
5 | puts 'Example: script/process_mails Maildir/.Rails/new 5' |
6 | exit |
7 | end |
8 | |
9 | sleeptime = ARGV[1].to_i |
10 | |
11 | require File.dirname(__FILE__) + '/../config/environment' |
12 | require 'fileutils' |
13 | require 'breakpoint' |
14 | |
15 | def do_update |
16 | puts "Reading last update time from last_update.yaml... " |
17 | begin |
18 | from = YAML.load(File.read(RAILS_ROOT + '/last_update.yaml')) |
19 | puts "done." |
20 | rescue |
21 | puts "could not load file. Using default (1 day ago)." |
22 | from = 1.day.ago |
23 | end |
24 | |
25 | puts "Updating index starting from #{from.to_s}..." |
26 | last_update = Time.now |
27 | number = Post.search_handler.rebuild_index(from).size |
28 | puts "done (#{number} posts)." |
29 | |
30 | puts "Saving last update time to last_update.yaml... " |
31 | File.open(RAILS_ROOT + '/last_update.yaml', 'w') do |file| |
32 | file.write(last_update.to_yaml) |
33 | end |
34 | puts "done." |
35 | end |
36 | |
37 | def do_import(maildir) |
38 | puts "Checking for new mails" |
39 | Dir[File.join(maildir, '*')].each do |file| |
40 | begin |
41 | if Mailer.process_email(File.read(file)) |
42 | puts "Imported #{file}" |
43 | File.delete(file) |
44 | else |
45 | puts "Could not import #{file}" |
46 | end |
47 | rescue => e |
48 | if e.is_a? Iconv::InvalidEncoding |
49 | puts "Skipped file #{file} (invalid encoding)" |
50 | FileUtils.move(file, RAILS_ROOT + '/mails/rejected/invalid_encoding/') rescue ArgumentError |
51 | elsif e.message['messageid : has already been taken'] |
52 | puts "Skipped & deleted file #{file} (messageid already in database)" |
53 | File.delete(file) rescue ArgumentError |
54 | elsif e.is_a? RForum::ValidationError |
55 | puts "Skipped file #{file} (ValidationError): #{e.inspect}" |
56 | FileUtils.move(file, RAILS_ROOT + '/mails/rejected/validation_error/') rescue ArgumentError |
57 | elsif e.message['parent not found'] |
58 | puts "Skipped file #{file} (parent not found): #{e.inspect}" |
59 | FileUtils.move(file, RAILS_ROOT + '/mails/rejected/parent_not_found/') rescue ArgumentError |
60 | else |
61 | puts "Skipped file #{file} (unknown error): #{e.inspect}" |
62 | FileUtils.move(file, RAILS_ROOT + '/mails/rejected/unknown_error/') rescue ArgumentError |
63 | end |
64 | end |
65 | end |
66 | end |
67 | |
68 | if sleeptime == 0 |
69 | do_import(maildir) |
70 | else |
71 | loop do |
72 | do_import(maildir) |
73 | GC.start |
74 | do_update() |
75 | GC.start |
76 | puts "sleeping for #{sleeptime} minutes..." |
77 | sleep sleeptime * 60 |
78 | end |
79 | end |