nilclass-maildir 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -6,7 +6,9 @@ A ruby library for reading and writing messages in the maildir format.
6
6
 
7
7
  See http://cr.yp.to/proto/maildir.html and http://en.wikipedia.org/wiki/Maildir
8
8
 
9
- As Daniel J. Berstein puts it: "Two words: no locks." The maildir format allows multiple processes to read and write arbitrary messages without file locks.
9
+ "Two words: no locks." -- Daniel J. Berstein
10
+
11
+ The maildir format allows multiple processes to read and write arbitrary messages without file locks.
10
12
 
11
13
  New messages are initially written to a "tmp" directory with an automatically-generated unique filename. After the message is written, it's moved to the "new" directory where other processes may read it.
12
14
 
@@ -104,9 +106,9 @@ It's trivial to create a custom serializer. Implement the following two methods:
104
106
  load(path)
105
107
  dump(data, path)
106
108
 
107
- == Credits
109
+ == Contributors
108
110
 
109
- niklas | brueckenschlaeger, http://github.com/nilclass added subdir & courierimapkeywords support
111
+ Niklas E. Cathor (http://github.com/nilclass) added subdir & courierimapkeywords support
110
112
 
111
113
  == Copyright
112
114
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ task :default => :test
10
10
  begin
11
11
  require 'jeweler'
12
12
  Jeweler::Tasks.new do |gemspec|
13
- gemspec.name = "nilclass-maildir"
13
+ gemspec.name = "maildir"
14
14
  gemspec.summary = "Read & write messages in the maildir format"
15
15
  gemspec.description = "A ruby library for reading and writing arbitrary messages in DJB's maildir format"
16
16
  gemspec.email = "aaron@ktheory.com"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
data/lib/maildir.rb CHANGED
@@ -2,7 +2,6 @@ require 'fileutils' # For create_directories
2
2
  class Maildir
3
3
 
4
4
  SUBDIRS = [:tmp, :new, :cur].freeze
5
- READABLE_DIRS = SUBDIRS.reject{|s| :tmp == s}.freeze
6
5
 
7
6
  include Comparable
8
7
 
@@ -86,6 +85,17 @@ class Maildir
86
85
  Maildir::Message.new(self, key)
87
86
  end
88
87
 
88
+ # Returns a message object for the given unique name.
89
+ # This allows retrieving messages where the flags may have changed,
90
+ # but obviously is slower than getting it by key.
91
+ def find(unique_name)
92
+ get_dir_listing(:cur).each do |key|
93
+ # NOTE: I used split(File::SEPARATOR) and split(':') here first,
94
+ # but when benchmarking it turned out this is 2 times faster.
95
+ return get(key) if key.match(/cur\/(.*):.*$/)[1] == unique_name
96
+ end
97
+ end
98
+
89
99
  # Deletes the message for key by calling destroy() on the message.
90
100
  def delete(key)
91
101
  get(key).destroy
@@ -112,4 +122,4 @@ class Maildir
112
122
  end
113
123
  require 'maildir/unique_name'
114
124
  require 'maildir/serializer/base'
115
- require 'maildir/message'
125
+ require 'maildir/message'
data/maildir.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{maildir}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Suggs", "Niklas E. Cathor"]
@@ -48,13 +48,13 @@ Gem::Specification.new do |s|
48
48
  s.rubygems_version = %q{1.3.5}
49
49
  s.summary = %q{Read & write messages in the maildir format}
50
50
  s.test_files = [
51
- "test/test_serializers.rb",
51
+ "test/test_helper.rb",
52
52
  "test/test_keywords.rb",
53
- "test/test_helper.rb",
54
- "test/test_subdirs.rb",
53
+ "test/test_maildir.rb",
55
54
  "test/test_message.rb",
56
- "test/test_unique_name.rb",
57
- "test/test_maildir.rb"
55
+ "test/test_serializers.rb",
56
+ "test/test_subdirs.rb",
57
+ "test/test_unique_name.rb"
58
58
  ]
59
59
 
60
60
  if s.respond_to? :specification_version then
@@ -79,3 +79,4 @@ Gem::Specification.new do |s|
79
79
  s.add_dependency(%q<ktheory-fakefs>, [">= 0"])
80
80
  end
81
81
  end
82
+
data/test/test_helper.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'rubygems'
2
1
  require 'test/unit'
2
+ require 'rubygems'
3
3
  require 'shoulda'
4
- require 'fileutils'
5
4
  require 'maildir'
6
5
 
7
6
  # Require all the serializers
@@ -17,7 +16,7 @@ require 'fakefs'
17
16
 
18
17
  # Create a reusable maildir that's cleaned up when the tests are done
19
18
  def temp_maildir
20
- Maildir.new("/tmp/maildir_test")
19
+ Maildir.new("/tmp/maildir_test")
21
20
  end
22
21
 
23
22
  # create the subdir tree:
@@ -32,7 +31,7 @@ def setup_subdirs(maildir)
32
31
  end
33
32
  end
34
33
 
35
- # Useful for testing that strings defined & not empty
34
+ # Test that objects are neither nil nor empty
36
35
  def assert_not_empty(obj, msg='')
37
36
  assert !obj.nil? && !obj.empty?, msg
38
37
  end
@@ -1,13 +1,13 @@
1
1
  require 'test_helper'
2
2
  require 'maildir/keywords'
3
3
  class TestKeywords < Test::Unit::TestCase
4
- context "A message" do
5
- setup do
4
+ context "A message" do
5
+ setup do
6
6
  @data = "foo\n"
7
7
  @msg = Maildir::Message.create(temp_maildir, @data)
8
8
  end
9
9
 
10
- should "remember keywords" do
10
+ should "remember keywords" do
11
11
  kw = %w(Junk Seen)
12
12
  @msg.keywords = kw
13
13
  assert (@msg.keywords & kw).size == 2
data/test/test_maildir.rb CHANGED
@@ -41,14 +41,20 @@ class TestMaildir < Test::Unit::TestCase
41
41
  should "list a new message" do
42
42
  @message = temp_maildir.add("")
43
43
  messages = temp_maildir.list(:new)
44
- assert messages.include?(@message)
44
+ assert_equal messages, [@message]
45
45
  end
46
46
 
47
47
  should "list a cur message" do
48
48
  @message = temp_maildir.add("")
49
49
  @message.process
50
50
  messages = temp_maildir.list(:cur)
51
- assert messages.include?(@message)
51
+ assert_equal messages, [@message]
52
+ end
53
+
54
+ should "find a message by unique name" do
55
+ @message = temp_maildir.add("")
56
+ @message.process
57
+ assert_equal temp_maildir.find(@message.unique_name), @message
52
58
  end
53
59
  end
54
60
 
@@ -16,7 +16,7 @@ class TestSerializers < Test::Unit::TestCase
16
16
  when Maildir::Serializer::Mail
17
17
  Mail.new
18
18
  else
19
- # Test a few common data structures
19
+ # Test a few common types
20
20
  [1, nil, {"foo" => true}]
21
21
  end
22
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nilclass-maildir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Suggs
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-24 00:00:00 +01:00
13
+ date: 2010-01-25 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency