imap_tickler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in imap_tickler.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ imap_tickler (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ chronic (0.3.0)
10
+ delorean (0.2.1)
11
+ chronic
12
+ diff-lcs (1.1.2)
13
+ mocha (0.9.11)
14
+ rake
15
+ rake (0.8.7)
16
+ rspec (2.5.0)
17
+ rspec-core (~> 2.5.0)
18
+ rspec-expectations (~> 2.5.0)
19
+ rspec-mocks (~> 2.5.0)
20
+ rspec-core (2.5.1)
21
+ rspec-expectations (2.5.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ delorean
30
+ imap_tickler!
31
+ mocha
32
+ rspec
data/README.markdown ADDED
@@ -0,0 +1,57 @@
1
+ imap\_tickler
2
+ ===========
3
+
4
+ imap\_tickler is a utility that ticklers your _43 folders_ style mailfolders. It expects the following folderstructure in your mail.
5
+
6
+ @Tickler
7
+ Month
8
+ 01 Jan
9
+ 02 Feb
10
+ 03 Mar
11
+ 04 Apr
12
+ 05 May
13
+ 06 Jun
14
+ 07 Jul
15
+ 08 Aug
16
+ 09 Sep
17
+ 10 Oct
18
+ 11 Nov
19
+ 12 Dec
20
+ Week 1
21
+ 1
22
+ 2
23
+ 3
24
+ 4
25
+ 5
26
+ 6
27
+ 7
28
+ Week 2
29
+ 8
30
+ 9
31
+ 10
32
+ 11
33
+ 12
34
+ 13
35
+ 14
36
+ Week 3
37
+ 15
38
+ 16
39
+ 17
40
+ 18
41
+ 19
42
+ 20
43
+ 21
44
+ Week 4
45
+ 22
46
+ 23
47
+ 24
48
+ 25
49
+ 26
50
+ 27
51
+ 28
52
+ Week 5
53
+ 29
54
+ 30
55
+ 31
56
+
57
+ It will move all mail from today's mailbox and this month's mailbox into your inbox.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler'
2
+ require "rspec/core/rake_task"
3
+ Bundler::GemHelper.install_tasks
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1 @@
1
+ Autotest.add_discovery {"rspec2"}
data/bin/imap_tickler ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+ require "imap_tickler/cli"
5
+ exit ImapTickler::CLI.execute(STDIN,STDOUT,ARGV)
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "imap_tickler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "imap_tickler"
7
+ s.version = ImapTickler::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jelle Helsen"]
10
+ s.email = ["jelle.helsen@hcode.be"]
11
+ s.homepage = "http://rubygems.org/gems/imap_tickler"
12
+ s.summary = %q{an imap tickler}
13
+ s.description = %q{imap_tickler is a utility that ticklers your 43 folders style mailfolders. It expects the following folderstructure in your mail.}
14
+
15
+ s.rubyforge_project = "imap_tickler"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "delorean"
24
+ s.add_development_dependency "mocha"
25
+ end
@@ -0,0 +1,24 @@
1
+ require 'optparse'
2
+ require "yaml"
3
+ require "imap_tickler/tickler"
4
+ module ImapTickler
5
+ class CLI
6
+ def self.execute(input,output,arguments=[])
7
+ options = {:config_file => "~/.imap_tickler.conf"}
8
+ parser = OptionParser.new do |opts|
9
+ opts.banner = <<-BANNER.gsub(/^ /,'')
10
+ Usage: #{File.basename($0)} [options]
11
+
12
+ Options are:
13
+ BANNER
14
+ opts.on( "-F path", "", String,
15
+ "Load an alternate config file") do |opt|
16
+ options[:config_file] = opt
17
+ end
18
+ end
19
+ parser.parse(arguments)
20
+ config = YAML.load_file(File.expand_path(options[:config_file]))
21
+ Tickler.new(config).start
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require "date"
2
+ require "net/imap"
3
+ module ImapTickler
4
+ class Tickler
5
+ attr_reader :config, :connection
6
+ def initialize(config)
7
+ @day_list = ["Week 1/1", "Week 1/2", "Week 1/3", "Week 1/4", "Week 1/5", "Week 1/6", "Week 1/7", "Week 2/8", "Week 2/9",
8
+ "Week 2/10", "Week 2/11", "Week 2/12", "Week 2/13", "Week 2/14", "Week 3/15", "Week 3/16", "Week 3/17", "Week 3/18",
9
+ "Week 3/19", "Week 3/20", "Week 3/21", "Week 4/22", "Week 4/23", "Week 4/24", "Week 4/25", "Week 4/26", "Week 4/27",
10
+ "Week 4/28", "Week 5/29", "Week 5/30", "Week 5/31"]
11
+
12
+ @month_list = ["Month/01 Jan", "Month/02 Feb", "Month/03 Mar", "Month/04 Apr", "Month/05 May", "Month/06 Jun",
13
+ "Month/07 Jul", "Month/08 Aug", "Month/09 Sep", "Month/10 Oct", "Month/11 Nov", "Month/12 Dec"]
14
+
15
+ @config = config
16
+ end
17
+
18
+ def connect
19
+ @connection = Net::IMAP.new(config[:mailserver], 993, true) if config[:use_ssl]
20
+ @connection ||= Net::IMAP.new(config[:mailserver])
21
+ if @connection
22
+ @connection.login(config[:username],config[:password])
23
+ end
24
+ end
25
+
26
+ def this_months_mailbox
27
+ @month_list[Date.today.month - 1]
28
+ end
29
+
30
+ def todays_mailbox
31
+ @day_list[Date.today.day - 1]
32
+ end
33
+
34
+ def tickle_mailbox mailbox
35
+ connection.select("@Tickler/#{mailbox}")
36
+ messages = connection.responses["EXISTS"][-1]
37
+ if messages > 0
38
+ connection.copy(1..messages,"INBOX")
39
+ connection.store(1..messages,"+FLAGS", [:Deleted])
40
+ end
41
+ end
42
+
43
+ def start
44
+ connect
45
+ [todays_mailbox, this_months_mailbox].each do |mailbox|
46
+ tickle_mailbox(mailbox)
47
+ end
48
+ return 0
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module ImapTickler
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ module ImapTickler
2
+ require "imap_tickler/version"
3
+ require "imap_tickler/tickler"
4
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ require "imap_tickler/cli"
3
+ describe ImapTickler::CLI do
4
+ it "should load the default config file" do
5
+ YAML.expects(:load_file).with(File.expand_path('~/.imap_tickler.conf')).returns(config = mock)
6
+ ImapTickler::Tickler.expects(:new).with(config).returns(tickler = mock(:start => nil))
7
+ ImapTickler::CLI.execute(STDIN,STDOUT,[])
8
+ end
9
+
10
+ it "should load the given config file" do
11
+ YAML.expects(:load_file).with(File.expand_path('/tmp/imap_tickler.conf')).returns(config = mock)
12
+ ImapTickler::Tickler.expects(:new).with(config).returns(tickler = mock(:start => nil))
13
+ ImapTickler::CLI.execute(STDIN,STDOUT,%w(-F /tmp/imap_tickler.conf))
14
+ end
15
+
16
+ it "should start the tickler" do
17
+ YAML.expects(:load_file).with(File.expand_path('/tmp/imap_tickler.conf')).returns(config = mock)
18
+ ImapTickler::Tickler.expects(:new).with(config).returns(tickler = mock)
19
+ tickler.expects(:start).returns(0)
20
+ ImapTickler::CLI.execute(STDIN,STDOUT,%w(-F /tmp/imap_tickler.conf)).should == 0
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ require "spec_helper"
2
+ describe ImapTickler::Tickler do
3
+ before do
4
+ @tickler = ImapTickler::Tickler.new({:mailserver => 'imap.example.com', :username => "user@domain", :password => "secret"})
5
+ end
6
+ it "should get the correct mailbox for this month" do
7
+ Delorean.time_travel_to "5 Jan 2011"
8
+ @tickler.this_months_mailbox.should == "Month/01 Jan"
9
+ Delorean.time_travel_to "5 Feb 2011"
10
+ @tickler.this_months_mailbox.should == "Month/02 Feb"
11
+ Delorean.time_travel_to "5 Dec 2011"
12
+ @tickler.this_months_mailbox.should == "Month/12 Dec"
13
+ Delorean.back_to_the_present
14
+ end
15
+
16
+ it "should get the correct mailbox for today" do
17
+ Delorean.time_travel_to "5 Jan 2011"
18
+ @tickler.todays_mailbox.should == "Week 1/5"
19
+ Delorean.time_travel_to "15 Feb 2011"
20
+ @tickler.todays_mailbox.should == "Week 3/15"
21
+ Delorean.time_travel_to "25 Dec 2011"
22
+ @tickler.todays_mailbox.should == "Week 4/25"
23
+ Delorean.back_to_the_present
24
+ end
25
+
26
+ it "should conect to the mailserver" do
27
+ Net::IMAP.expects(:new).with('imap.example.com').returns(connection = mock)
28
+ connection.expects(:login).with("user@domain","secret")
29
+ @tickler.connect
30
+ end
31
+
32
+ it "should select the mailbox" do
33
+ @tickler.expects(:connection).times(2).returns(connection = mock)
34
+ connection.expects(:select).with("@Tickler/Week 1/5")
35
+ connection.expects(:responses).returns({"EXISTS" => [0]})
36
+ @tickler.tickle_mailbox("Week 1/5")
37
+ end
38
+
39
+ it "should copy and delete all mails in the mailbox" do
40
+ @tickler.expects(:connection).times(4).returns(connection ||= mock)
41
+ connection.expects(:select).with("@Tickler/Week 1/5")
42
+ connection.expects(:responses).returns({"EXISTS" => [21]})
43
+ connection.expects(:copy).with(1..21,"INBOX")
44
+ connection.expects(:store).with(1..21, "+FLAGS", [:Deleted] )
45
+ @tickler.tickle_mailbox("Week 1/5")
46
+ end
47
+
48
+ it "should use ssl if instructed" do
49
+ @tickler = ImapTickler::Tickler.new({:mailserver => 'imap.example.com', :username => "user@domain", :password => "secret",:use_ssl => true})
50
+ Net::IMAP.expects(:new).with('imap.example.com', 993, true).returns(connection = mock)
51
+ connection.expects(:login).with("user@domain","secret")
52
+ @tickler.connect
53
+ end
54
+
55
+ it "should connect and tickle todays and this months mailbox" do
56
+ Delorean.time_travel_to "5 Jan 2011"
57
+ @tickler.expects(:connect)
58
+ @tickler.expects(:tickle_mailbox).with("Week 1/5")
59
+ @tickler.expects(:tickle_mailbox).with("Month/01 Jan")
60
+ @tickler.start
61
+ end
62
+
63
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+ describe "version" do
3
+ it "equals 0.0.1" do
4
+ ImapTickler::VERSION.should == "0.0.1"
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","lib"))
3
+ require "imap_tickler"
4
+ require "delorean"
5
+
6
+ RSpec.configure do |c|
7
+ c.color_enabled = true
8
+ c.mock_framework = :mocha
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imap_tickler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jelle Helsen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-10 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: delorean
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: mocha
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: imap_tickler is a utility that ticklers your 43 folders style mailfolders. It expects the following folderstructure in your mail.
64
+ email:
65
+ - jelle.helsen@hcode.be
66
+ executables:
67
+ - imap_tickler
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - README.markdown
77
+ - Rakefile
78
+ - autotest/discover.rb
79
+ - bin/imap_tickler
80
+ - imap_tickler.gemspec
81
+ - lib/imap_tickler.rb
82
+ - lib/imap_tickler/cli.rb
83
+ - lib/imap_tickler/tickler.rb
84
+ - lib/imap_tickler/version.rb
85
+ - spec/lib/cli_spec.rb
86
+ - spec/lib/ticker_spec.rb
87
+ - spec/lib/version_spec.rb
88
+ - spec/spec_helper.rb
89
+ has_rdoc: true
90
+ homepage: http://rubygems.org/gems/imap_tickler
91
+ licenses: []
92
+
93
+ post_install_message:
94
+ rdoc_options: []
95
+
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ requirements: []
117
+
118
+ rubyforge_project: imap_tickler
119
+ rubygems_version: 1.4.2
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: an imap tickler
123
+ test_files:
124
+ - spec/lib/cli_spec.rb
125
+ - spec/lib/ticker_spec.rb
126
+ - spec/lib/version_spec.rb
127
+ - spec/spec_helper.rb