swallow 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,6 @@ require "swallow"
4
4
 
5
5
  admin = Swallow::Admin.new
6
6
  admin.process_junk
7
- admin.process_inbox
7
+ admin.process_inbox
8
+ admin.process_innocent
9
+ admin.age
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'time_extentions'
4
+ require 'ftools'
4
5
 
5
6
  module Swallow
6
7
  class Email
@@ -34,9 +35,14 @@ module Swallow
34
35
  # modify filename to "S" on end
35
36
  end
36
37
 
38
+ def move_to(folder)
39
+ File.move(@filename, folder, true)
40
+ end
41
+
37
42
  def to_s
38
43
  File.open(@filename).read
39
44
  end
45
+
40
46
  def delete
41
47
  File.delete(@filename)
42
48
  end
@@ -36,11 +36,11 @@ module Swallow
36
36
  end
37
37
 
38
38
  def unread_count
39
- length("new")
39
+ emails.find_all{ |e| e.read == false }.length
40
40
  end
41
41
 
42
42
  def read_count
43
- length("cur")
43
+ emails.find_all{ |e| e.read == true }.length
44
44
  end
45
45
 
46
46
  def unknown_count
@@ -49,23 +49,23 @@ module Swallow
49
49
 
50
50
  def length(sub_path)
51
51
  length = 0
52
- Dir.open(File.join(@folder_path,sub_path)).each { |filename|
52
+ Dir.open(File.join(@folder_path,sub_path)).each do |filename|
53
53
  next if filename == "." or filename == ".."
54
54
  length += 1
55
- }
55
+ end
56
56
  length
57
57
  end
58
58
 
59
59
  def emails
60
60
  list = Array.new
61
- @sub_folders.each { |sub_path|
61
+ @sub_folders.each do |sub_path|
62
62
  path = File.join(@folder_path, sub_path)
63
- Dir.open(path).each { |f|
63
+ Dir.open(path).each do |f|
64
64
  filename = File.join(path,f)
65
65
  next if File.directory?(filename)
66
66
  list << Email.new(filename)
67
- }
68
- }
67
+ end
68
+ end
69
69
  return list
70
70
  end
71
71
 
@@ -75,6 +75,13 @@ module Swallow
75
75
  puts "Deleted #{count} emails"
76
76
  end
77
77
 
78
+ def add(emails)
79
+ # We'll take these emails from some other location and add them to our "cur" folder.
80
+ emails.each do |email|
81
+ email.move_to(File.join(@folder_path,"cur"))
82
+ end
83
+ end
84
+
78
85
  def emails_newer_than(limit)
79
86
  emails.find_all { |e| e.newer_than?(limit) }
80
87
  end
@@ -85,25 +92,16 @@ module Swallow
85
92
 
86
93
  def sweep!(limit)
87
94
  if limit.kind_of? Integer then
88
- @sub_folder.each { |sub_path|
95
+ @sub_folder.each do |sub_path|
89
96
  Dir.open(File.join(@folder_path,sub_path)).sweep!(limit)
90
- }
97
+ end
91
98
  end
92
99
  end
100
+ def status
101
+ "#{@folder_path} has #{unread_count} unread messages and #{read_count} read messages (#{unknown_count})."
102
+ end
93
103
  def to_s
94
- "#{@folder_path} has #{unread_count} unread messages and #{read_count} read messages (#{unknown_count})."
104
+ "#{@folder_path}"
95
105
  end
96
106
  end
97
107
  end
98
-
99
- if $0 == __FILE__ then
100
- include Swallow
101
- root = "/home/#{ENV['USER']}/Maildir/"
102
- m = MailDirFolder.new(root)
103
- puts m.to_s
104
- m.enum.each { |folder|
105
- n = MailDirFolder.new(m.path+folder)
106
- puts n.to_s
107
- puts n.enum
108
- }
109
- end
@@ -20,11 +20,9 @@ module Swallow
20
20
  def process_junk
21
21
  # Create Folder Objects
22
22
  junk = MailDirFolder.new(@config[:maildir] + @config[:junk])
23
- corpus = MailDirFolder.new(@config[:maildir] + @config[:corpus])
24
23
 
25
24
  # Clean out the Junk Folder
26
25
  @dspam.train_and_clean_folder(junk)
27
- @dspam.train_and_clean_folder(corpus)
28
26
  end
29
27
 
30
28
  def process_inbox
@@ -33,12 +31,41 @@ module Swallow
33
31
  # Feed new messages under the limit in the inbox to the filter as innocent corpus
34
32
  @dspam.train_emails_as_innocent(inbox.emails_newer_than(@config[:limit]))
35
33
  end
36
- end
37
- end
38
34
 
39
- if $0 == __FILE__ then
40
- admin = Swallow::Admin.new
41
- admin.process_junk
42
- admin.process_inbox
43
- end
35
+ def process_innocent
36
+ innocent = MailDirFolder.new(@config[:maildir] + @config[:innocent])
37
+ inbox = MailDirFolder.new(@config[:maildir] + @config[:inbox])
38
+ @dspam.train_emails_as_innocent(innocent.emails)
39
+ inbox.add(innocent.emails)
40
+ end
41
+
42
+ def process_folder(folder_name, is_spam)
43
+ folder = MailDirFolder.new(@config[:maildir] + folder_name)
44
+ if is_spam == true then
45
+ @dspam.train_and_clean_folder(folder)
46
+ else
47
+ @dspam.train_emails_as_innocent(folder.emails)
48
+ end
49
+ end
44
50
 
51
+ def age_to_folder(src, dst, limit)
52
+ dst.add(src.emails_older_than(limit))
53
+ end
54
+
55
+ def age
56
+ puts "Aging folders..."
57
+ trash = MailDirFolder.new(@config[:maildir] + @config[:trash])
58
+ ruleset = RuleSet.new(@config[:files] + @config[:ruleset])
59
+ ruleset.rules.each do |rule|
60
+ if rule[:folder] != nil and rule[:day_limit] != nil then
61
+ puts "Folder #{rule[:folder]} has a limit of #{rule[:day_limit]}"
62
+ src = MailDirFolder.new(@config[:maildir] + "." + rule[:folder])
63
+ emails = src.emails_older_than(rule[:day_limit])
64
+ puts "Moved #{emails.length} emails"
65
+ trash.add(emails)
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'swallow'
5
+ maildir = "#{ENV['HOME']}/Maildir/"
6
+
7
+ case ARGV.length
8
+ when 3
9
+ src = Swallow::MailDirFolder.new(maildir + ARGV[0])
10
+ dst = Swallow::MailDirFolder.new(maildir + ARGV[1])
11
+ limit = Integer(ARGV[2])
12
+ admin = Swallow::Admin.new
13
+ admin.age_to_folder(src,dst,limit)
14
+ else
15
+ admin = Swallow::Admin.new
16
+ admin.age
17
+ end
18
+
19
+
20
+
21
+
22
+
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'swallow'
5
+
6
+ maildir = "#{ENV['HOME']}/Maildir/"
7
+ m = Swallow::MailDirFolder.new(maildir)
8
+ puts m.to_s
9
+ puts m.status
10
+ m.enum.each do |folder|
11
+ n = Swallow::MailDirFolder.new(m.path+folder)
12
+ puts n.to_s
13
+ puts n.status
14
+ puts n.enum
15
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'swallow'
5
+
6
+ exit(1) unless ARGV.length > 1
7
+ maildir = "#{ENV['HOME']}/Maildir/"
8
+ src = Swallow::MailDirFolder.new(maildir + ARGV[0])
9
+ dst = Swallow::MailDirFolder.new(maildir + ARGV[1])
10
+
11
+ dst.add(src.emails)
metadata CHANGED
@@ -1,33 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: swallow
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2007-10-29 00:00:00 -05:00
8
- summary: A backend IMAP/Maildir Email Sorting/Routing/Cleanup system
9
- require_paths:
10
- - lib
11
- email: swallow-dev@erik.rainey.name
12
- homepage: http://erik.rainey.name/swallow
13
- rubyforge_project:
14
- description:
15
- autorequire: swallow
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.0.2
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Erik Rainey
8
+ autorequire: swallow
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-26 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: gurgitate-mail
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.5
23
+ version:
24
+ description:
25
+ email: swallow-dev@erik.rainey.name
26
+ executables:
27
+ - swallow
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - README
31
32
  files:
32
33
  - bin/swallow
33
34
  - lib/time_extentions.rb
@@ -37,27 +38,36 @@ files:
37
38
  - lib/swallow.rb
38
39
  - lib/spamdetector.rb
39
40
  - README
40
- test_files:
41
- - test/test_spam.rb
42
- - test/test_ruleset.rb
43
- - test/test_folder.rb
41
+ has_rdoc: false
42
+ homepage: http://erik.rainey.name/swallow
43
+ post_install_message:
44
44
  rdoc_options: []
45
45
 
46
- extra_rdoc_files:
47
- - README
48
- executables:
49
- - swallow
50
- extensions: []
51
-
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
52
60
  requirements: []
53
61
 
54
- dependencies:
55
- - !ruby/object:Gem::Dependency
56
- name: gurgitate-mail
57
- version_requirement:
58
- version_requirements: !ruby/object:Gem::Version::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.8.5
63
- version:
62
+ rubyforge_project:
63
+ rubygems_version: 0.9.5
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: A backend IMAP/Maildir Email Sorting/Routing/Cleanup system
67
+ test_files:
68
+ - test/test_spam.rb
69
+ - test/test_ruleset.rb
70
+ - test/test_folder.rb
71
+ - test/test_move.rb
72
+ - test/test_age.rb
73
+ - test/test_dir.rb