imap_archiver 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -9,7 +9,7 @@ module ImapArchiver
9
9
  @logger.level = Logger::WARN
10
10
  if debug
11
11
  @logger.level = Logger::DEBUG
12
- @Logger.debug "Debugging enabled."
12
+ @logger.debug "Debugging enabled."
13
13
  end
14
14
  @logger.debug "Loading config"
15
15
  self.load_config(config_file)
@@ -74,9 +74,11 @@ module ImapArchiver
74
74
  connection.select(folder)
75
75
  # puts "will search 1"
76
76
  msgs_to_archive = connection.search(conditions)
77
+ @logger.debug "#{msgs_to_archive.size} msgs to archive"
77
78
  if msgs_to_archive.size > 0
78
79
  @logger.debug "will archive #{msgs_to_archive.size} messages"
79
80
  if connection.list("",current_archive_folder).nil?
81
+ @logger.debug "creating archive folder #{current_archive_folder}"
80
82
  connection.create(current_archive_folder)
81
83
  if connection.capability.include?("ACL")
82
84
  self.archive_folder_acl.each do |key,value|
@@ -84,9 +86,11 @@ module ImapArchiver
84
86
  end
85
87
  end
86
88
  end
87
- connection.copy(msgs_to_archive, current_archive_folder)
88
- connection.store(msgs_to_archive, "+FLAGS",[:Deleted])
89
- @msg_count += msgs_to_archive.size
89
+ while !msgs_to_archive.empty? && (msgs = msgs_to_archive.slice!(0,100))
90
+ connection.copy(msgs, current_archive_folder)
91
+ connection.store(msgs, "+FLAGS",[:Deleted])
92
+ @msg_count += msgs.size
93
+ end
90
94
  connection.expunge
91
95
  end
92
96
  if connection.search(["BEFORE", since_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).size > 0
@@ -118,7 +122,7 @@ module ImapArchiver
118
122
  end
119
123
 
120
124
  def self.run(config_file,debug=false)
121
- self.new(config_file).start
125
+ self.new(config_file,debug).start
122
126
  end
123
127
  end
124
128
  end
@@ -108,4 +108,48 @@ describe ImapArchiver::Archiver do
108
108
  @archiver.folder_list.should == [mock1]
109
109
  end
110
110
  end
111
- end
111
+
112
+ describe "copying mails" do
113
+ before do
114
+ ImapArchiver::Config.expects(:load_config)
115
+ ImapArchiver::Archiver.any_instance.expects(:config_valid?)
116
+ @archiver = ImapArchiver::Archiver.new("configfile")
117
+ @archiver.imap_server = "mailserver"
118
+ @archiver.username = "user"
119
+ @archiver.password = "password"
120
+ @archiver.auth_mech = 'CRAM-MD5'
121
+ @archiver.archive_folder = 'archive'
122
+ @archiver.base_folder = 'Public Folders'
123
+ # @archiver.expects(:connect)
124
+ @archiver.connection = mock
125
+ @archiver.connection.stubs(:capability).returns([])
126
+ @archiver.connection.stubs(:list).returns(mock)
127
+ @archiver.connection.stubs(:select)
128
+ @archiver.connection.stubs(:store)
129
+ @archiver.connection.stubs(:expunge)
130
+ @archiver.instance_variable_set("@msg_count",0)
131
+ end
132
+
133
+ it "should copy archivable msgs in chunks" do
134
+ #@archiver.folders_to_archive = ["Public Folders/test1"]
135
+ #@archiver.connection.expects(:list).with('',"Public Folders/test1").returns([mock1 = mock(:name => "Public Folders/test1")])
136
+ since_date = Date.today.months_ago(3).beginning_of_month
137
+ before_date= Date.today.months_ago(2).beginning_of_month
138
+ conditions = ["SINCE", since_date.strftime("%d-%b-%Y"), "BEFORE", before_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]
139
+ @archiver.connection.expects(:search).with(conditions).returns((1..996).to_a)
140
+ @archiver.connection.expects(:search).with(["BEFORE", since_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([])
141
+ @archiver.connection.expects(:copy).with((1..100).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
142
+ @archiver.connection.expects(:copy).with((101..200).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
143
+ @archiver.connection.expects(:copy).with((201..300).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
144
+ @archiver.connection.expects(:copy).with((301..400).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
145
+ @archiver.connection.expects(:copy).with((401..500).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
146
+ @archiver.connection.expects(:copy).with((501..600).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
147
+ @archiver.connection.expects(:copy).with((601..700).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
148
+ @archiver.connection.expects(:copy).with((701..800).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
149
+ @archiver.connection.expects(:copy).with((801..900).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
150
+ @archiver.connection.expects(:copy).with((901..996).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
151
+ @archiver.archive_folder_between_dates("Public Folders/test1",since_date,before_date) #if folder.name =~ /^Public Folders\/Team\//
152
+ @archiver.instance_variable_get("@msg_count").should == 996
153
+ end
154
+ end
155
+ end
@@ -2,6 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "ImapArchiver" do
4
4
  it "should read the correct version" do
5
- ImapArchiver::Version.should == "0.0.5"
5
+ ImapArchiver::Version.should == "0.0.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap_archiver
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jelle Helsen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-05 00:00:00 +01:00
18
+ date: 2011-02-06 00:00:00 +01:00
19
19
  default_executable: imap_archiver
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency