imap_archiver 0.0.6 → 0.0.7

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -73,7 +73,7 @@ module ImapArchiver
73
73
  begin
74
74
  connection.select(folder)
75
75
  # puts "will search 1"
76
- msgs_to_archive = connection.search(conditions)
76
+ msgs_to_archive = connection.uid_search(conditions)
77
77
  @logger.debug "#{msgs_to_archive.size} msgs to archive"
78
78
  if msgs_to_archive.size > 0
79
79
  @logger.debug "will archive #{msgs_to_archive.size} messages"
@@ -87,9 +87,10 @@ module ImapArchiver
87
87
  end
88
88
  end
89
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])
90
+ connection.uid_copy(msgs, current_archive_folder)
91
+ connection.uid_store(msgs, "+FLAGS",[:Deleted])
92
92
  @msg_count += msgs.size
93
+ @logger.info "archived #{msg_count} messages"
93
94
  end
94
95
  connection.expunge
95
96
  end
@@ -41,11 +41,12 @@ describe ImapArchiver::Archiver do
41
41
  it "should reconnect when an IOError is raised during archiving" do
42
42
  @archiver.instance_variable_set(:@msg_count, 0)
43
43
  @archiver.connection.expects(:select).times(2)
44
- @archiver.connection.expects(:search).times(3).returns([1],[1],[])
44
+ @archiver.connection.expects(:uid_search).times(2).returns([1],[1])
45
+ @archiver.connection.expects(:search).returns([])
45
46
  @archiver.connection.expects(:list).times(2).returns(true)
46
- @archiver.connection.stubs(:copy).raises(IOError).then.returns(nil)
47
+ @archiver.connection.stubs(:uid_copy).raises(IOError).then.returns(nil)
47
48
  @archiver.expects(:reconnect).times(1)
48
- @archiver.connection.expects(:store)
49
+ @archiver.connection.expects(:uid_store)
49
50
  @archiver.connection.expects(:expunge)
50
51
  @archiver.archive_folder_between_dates('Public Folders/test',Date.today,Date.today)
51
52
  end
@@ -78,7 +79,8 @@ describe ImapArchiver::Archiver do
78
79
  @archiver.folders_to_archive = ["Public Folders/test1", "test2"]
79
80
  @archiver.connection.expects(:list).with('',"Public Folders/test1").returns([stub(:name => 'Public Folders/test1')])
80
81
  @archiver.connection.expects(:list).with('',"test2").returns([stub(:name => 'test2')])
81
- @archiver.connection.expects(:search).times(4).returns([])
82
+ @archiver.connection.expects(:search).times(2).returns([])
83
+ @archiver.connection.expects(:uid_search).times(2).returns([])
82
84
  @archiver.start
83
85
  end
84
86
 
@@ -125,7 +127,7 @@ describe ImapArchiver::Archiver do
125
127
  @archiver.connection.stubs(:capability).returns([])
126
128
  @archiver.connection.stubs(:list).returns(mock)
127
129
  @archiver.connection.stubs(:select)
128
- @archiver.connection.stubs(:store)
130
+ #@archiver.connection.stubs(:store)
129
131
  @archiver.connection.stubs(:expunge)
130
132
  @archiver.instance_variable_set("@msg_count",0)
131
133
  end
@@ -136,18 +138,30 @@ describe ImapArchiver::Archiver do
136
138
  since_date = Date.today.months_ago(3).beginning_of_month
137
139
  before_date= Date.today.months_ago(2).beginning_of_month
138
140
  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)
141
+ @archiver.connection.expects(:uid_search).with(conditions).returns((1..996).to_a)
140
142
  @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")}")
143
+ @archiver.connection.expects(:uid_copy).with((1..100).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
144
+ @archiver.connection.expects(:uid_copy).with((101..200).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
145
+ @archiver.connection.expects(:uid_copy).with((201..300).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
146
+ @archiver.connection.expects(:uid_copy).with((301..400).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
147
+ @archiver.connection.expects(:uid_copy).with((401..500).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
148
+ @archiver.connection.expects(:uid_copy).with((501..600).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
149
+ @archiver.connection.expects(:uid_copy).with((601..700).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
150
+ @archiver.connection.expects(:uid_copy).with((701..800).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
151
+ @archiver.connection.expects(:uid_copy).with((801..900).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
152
+ @archiver.connection.expects(:uid_copy).with((901..996).to_a, "archive/test1/#{since_date.strftime("%b %Y")}")
153
+
154
+ @archiver.connection.expects(:uid_store).with((1..100).to_a, "+FLAGS",[:Deleted])
155
+ @archiver.connection.expects(:uid_store).with((101..200).to_a, "+FLAGS",[:Deleted])
156
+ @archiver.connection.expects(:uid_store).with((201..300).to_a, "+FLAGS",[:Deleted])
157
+ @archiver.connection.expects(:uid_store).with((301..400).to_a, "+FLAGS",[:Deleted])
158
+ @archiver.connection.expects(:uid_store).with((401..500).to_a, "+FLAGS",[:Deleted])
159
+ @archiver.connection.expects(:uid_store).with((501..600).to_a, "+FLAGS",[:Deleted])
160
+ @archiver.connection.expects(:uid_store).with((601..700).to_a, "+FLAGS",[:Deleted])
161
+ @archiver.connection.expects(:uid_store).with((701..800).to_a, "+FLAGS",[:Deleted])
162
+ @archiver.connection.expects(:uid_store).with((801..900).to_a, "+FLAGS",[:Deleted])
163
+ @archiver.connection.expects(:uid_store).with((901..996).to_a, "+FLAGS",[:Deleted])
164
+
151
165
  @archiver.archive_folder_between_dates("Public Folders/test1",since_date,before_date) #if folder.name =~ /^Public Folders\/Team\//
152
166
  @archiver.instance_variable_get("@msg_count").should == 996
153
167
  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.6"
5
+ ImapArchiver::Version.should == "0.0.7"
6
6
  end
7
7
  end
@@ -37,14 +37,16 @@ describe "imap_archiver" do
37
37
  it "should select and search the matching mailboxes" do
38
38
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
39
39
  @connection.expects(:select).with('testfolder')
40
- @connection.expects(:search).twice.returns([]) #search current range and before
40
+ @connection.expects(:search).returns([])
41
+ @connection.expects(:uid_search).returns([])
41
42
  ImapArchiver::CLI.execute(STDOUT,STDIN,["-F",@config_file.path])
42
43
  end
43
44
 
44
45
  it "should create a mailbox for archiving if it does not exist" do
45
46
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
46
47
  @connection.expects(:select).with('testfolder')
47
- @connection.expects(:search).twice.returns([1,2],[])
48
+ @connection.expects(:search).returns([])
49
+ @connection.expects(:uid_search).returns([1,2])
48
50
  @connection.expects(:list).with('',"/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
49
51
  @connection.expects(:create).with("/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
50
52
 
@@ -54,7 +56,8 @@ describe "imap_archiver" do
54
56
  it "should not create a mailbox for archiving if it does exist" do
55
57
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
56
58
  @connection.expects(:select).with('testfolder')
57
- @connection.expects(:search).twice.returns([1,2],[])
59
+ @connection.expects(:search).returns([])
60
+ @connection.expects(:uid_search).returns([1,2])
58
61
  @connection.expects(:list).with('',"/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}").returns(stub_everything('archive folder'))
59
62
  @connection.expects(:create).never
60
63
 
@@ -65,10 +68,10 @@ describe "imap_archiver" do
65
68
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
66
69
  @connection.expects(:select).with('testfolder')
67
70
  # @connection.expects(:search).twice.returns([1,2],[])
68
- @connection.expects(:search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
71
+ @connection.expects(:uid_search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
69
72
  @connection.expects(:search).with(["BEFORE", @archive_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([])
70
73
 
71
- @connection.expects(:copy).with([1,2],"/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
74
+ @connection.expects(:uid_copy).with([1,2],"/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
72
75
 
73
76
  ImapArchiver::CLI.execute(STDOUT,STDIN,["-F",@config_file.path])
74
77
 
@@ -77,8 +80,9 @@ describe "imap_archiver" do
77
80
  it "should delete the copied messages" do
78
81
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
79
82
  @connection.expects(:select).with('testfolder')
80
- @connection.expects(:search).twice.returns([1,2],[])
81
- @connection.expects(:store).with([1,2],"+FLAGS",[:Deleted])
83
+ @connection.expects(:search).returns([])
84
+ @connection.expects(:uid_search).returns([1,2])
85
+ @connection.expects(:uid_store).with([1,2],"+FLAGS",[:Deleted])
82
86
  @connection.expects(:expunge)
83
87
  ImapArchiver::CLI.execute(STDOUT,STDIN,["-F",@config_file.path])
84
88
 
@@ -87,10 +91,10 @@ describe "imap_archiver" do
87
91
  it "should search for messages older then the archiving period" do
88
92
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
89
93
  @connection.expects(:select).with('testfolder').twice
90
- @connection.expects(:search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
94
+ @connection.expects(:uid_search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
91
95
  @connection.expects(:search).with(["BEFORE", @archive_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([3,4])
92
96
  @archive_date = @archive_date.prev_month
93
- @connection.expects(:search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
97
+ @connection.expects(:uid_search).with(["SINCE", @archive_date.strftime("%d-%b-%Y"), "BEFORE", @archive_date.next_month.beginning_of_month.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([1,2])
94
98
  @connection.expects(:search).with(["BEFORE", @archive_date.strftime("%d-%b-%Y"), "SEEN", "NOT", "FLAGGED"]).returns([])
95
99
 
96
100
  ImapArchiver::CLI.execute(STDOUT,STDIN,["-F",@config_file.path])
@@ -99,7 +103,8 @@ describe "imap_archiver" do
99
103
  it "should set the correct acl on newly created archive folders" do
100
104
  @connection.expects(:list).with("","*").returns([mock1=stub(:name=>'testfolder'),mock2=stub(:name=>'foldertest')])
101
105
  @connection.expects(:select).with('testfolder')
102
- @connection.expects(:search).twice.returns([1,2],[])
106
+ @connection.expects(:search).returns([])
107
+ @connection.expects(:uid_search).returns([1,2])
103
108
  @connection.expects(:list).with('',"/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
104
109
  @connection.expects(:create).with("/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}")
105
110
  @connection.expects(:setacl).with("/Archive/test/testfolder/#{@archive_date.strftime("%b %Y")}",'jhelsen','lrswpcda')
@@ -133,7 +138,8 @@ describe "imap_archiver" do
133
138
  it "should select and search the matching mailboxes" do
134
139
  @connection.expects(:list).with("","test1").returns([mock1=stub(:name=>'test1')])
135
140
  @connection.expects(:select).with('test1')
136
- @connection.expects(:search).twice.returns([]) #search current range and before
141
+ @connection.expects(:uid_search).returns([]) #search current range
142
+ @connection.expects(:search).returns([]) #and before
137
143
  ImapArchiver::CLI.execute(STDOUT,STDIN,["-F",@config_file.path])
138
144
  end
139
145
  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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jelle Helsen