maildir 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -4
- data/lib/maildir.rb +1 -0
- data/lib/maildir/message.rb +3 -2
- data/lib/maildir/version.rb +1 -1
- data/test/test_helper.rb +1 -4
- data/test/test_maildir.rb +10 -0
- data/test/test_message.rb +17 -0
- metadata +11 -9
data/README.rdoc
CHANGED
@@ -16,12 +16,13 @@ While the maildir format was created for email, it works well for arbitrary data
|
|
16
16
|
|
17
17
|
== Install
|
18
18
|
|
19
|
-
|
19
|
+
gem install maildir
|
20
20
|
|
21
21
|
== Usage
|
22
22
|
|
23
23
|
Create a maildir in /home/aaron/mail
|
24
24
|
|
25
|
+
require 'maildir'
|
25
26
|
maildir = Maildir.new("/home/aaron/mail") # creates tmp, new, and cur dirs
|
26
27
|
# call Maildir.new("/home/aaron/mail", false) to skip directory creation.
|
27
28
|
|
@@ -67,6 +68,19 @@ Delete the message from disk
|
|
67
68
|
message.destroy # => returns the frozen message
|
68
69
|
maildir.list(:cur) # => []
|
69
70
|
|
71
|
+
=== Cleaning up from orphaned messages
|
72
|
+
|
73
|
+
An expected (though rare) behavior is for partially-written messages to be
|
74
|
+
orphaned in the tmp folder (when clients fail before fully writing a message).
|
75
|
+
|
76
|
+
Find messages in tmp that haven't been changed in 36 hours:
|
77
|
+
|
78
|
+
maildir.get_stale_tmp
|
79
|
+
|
80
|
+
Clean them up:
|
81
|
+
|
82
|
+
maildir.get_stale_tmp.each{|msg| msg.destroy}
|
83
|
+
|
70
84
|
== Pluggable serializers
|
71
85
|
|
72
86
|
By default, message data are written and read from disk as a string. It's often desirable to process the string into a useful object. Maildir supports configurable serializers to convert message data into a useful object.
|
@@ -85,7 +99,7 @@ Maildir::Serializer::Base simply reads and writes strings to disk.
|
|
85
99
|
message = maildir.add("Hello World!") # writes "Hello World!" to disk
|
86
100
|
message.data # => "Hello World!"
|
87
101
|
|
88
|
-
As of version 0.
|
102
|
+
As of version 1.0.0, the Maildir::Serializer::Base can write IO streams as well as strings. For example:
|
89
103
|
|
90
104
|
message.add(STDIN)
|
91
105
|
|
@@ -115,8 +129,11 @@ It's trivial to create a custom serializer. Implement the following two methods:
|
|
115
129
|
|
116
130
|
== Contributors
|
117
131
|
|
118
|
-
|
119
|
-
|
132
|
+
* Aaron Suggs (github[http://github.com/ktheory]) Primary author
|
133
|
+
* Niklas E. Cathor (github[http://github.com/nilclass]) added subdir & courierimapkeywords support
|
134
|
+
* Ali Polatel (github[http://github.com/alip]) for suggesting IO.copy_stream
|
135
|
+
* Harry Vangberg (github[http://github.com/vangberg]) for fixing tests in ruby 1.9
|
136
|
+
* Alexander Flatter (github[http://github.com/aflatter]) for improving serializers
|
120
137
|
|
121
138
|
== Copyright
|
122
139
|
|
data/lib/maildir.rb
CHANGED
data/lib/maildir/message.rb
CHANGED
@@ -70,9 +70,10 @@ class Maildir::Message
|
|
70
70
|
"#<#{self.class} key=#{key} maildir=#{@maildir.inspect}>"
|
71
71
|
end
|
72
72
|
|
73
|
-
#
|
73
|
+
# Determines the serializer by first trying the maildir and then falling
|
74
|
+
# back to the default serializer.
|
74
75
|
def serializer
|
75
|
-
@@serializer
|
76
|
+
@maildir.serializer || @@serializer
|
76
77
|
end
|
77
78
|
|
78
79
|
# Writes data to disk. Can only be called on messages instantiated without
|
data/lib/maildir/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -3,14 +3,11 @@ require 'shoulda'
|
|
3
3
|
require 'maildir'
|
4
4
|
|
5
5
|
# Require all the serializers
|
6
|
-
serializers = File.
|
6
|
+
serializers = File.expand_path('../../lib/maildir/serializer/*.rb', __FILE__)
|
7
7
|
Dir.glob(serializers).each do |serializer|
|
8
8
|
require serializer
|
9
9
|
end
|
10
10
|
|
11
|
-
# Require 'ktheory-fakefs' until issues 28, 29, and 30 are resolved in
|
12
|
-
# defunkt/fakefs. See http://github.com/defunkt/fakefs/issues
|
13
|
-
gem "ktheory-fakefs"
|
14
11
|
require 'fakefs'
|
15
12
|
|
16
13
|
# Create a reusable maildir that's cleaned up when the tests are done
|
data/test/test_maildir.rb
CHANGED
@@ -17,6 +17,16 @@ class TestMaildir < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
should "have no serializer" do
|
21
|
+
assert temp_maildir.serializer.nil?
|
22
|
+
end
|
23
|
+
|
24
|
+
should "set serializer" do
|
25
|
+
maildir = temp_maildir
|
26
|
+
maildir.serializer = :test
|
27
|
+
assert_equal maildir.serializer, :test
|
28
|
+
end
|
29
|
+
|
20
30
|
should "expand paths" do
|
21
31
|
maildir = Maildir.new("~/test_maildir/")
|
22
32
|
expanded_path = File.expand_path("~/test_maildir")
|
data/test/test_message.rb
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
class TestMessage < Test::Unit::TestCase
|
3
3
|
|
4
|
+
context "A message" do
|
5
|
+
setup do
|
6
|
+
FakeFS::FileSystem.clear
|
7
|
+
@maildir = temp_maildir
|
8
|
+
@message = Maildir::Message.new(@maildir)
|
9
|
+
end
|
10
|
+
|
11
|
+
should "use default serializer" do
|
12
|
+
assert_equal @message.serializer, Maildir::Message.serializer
|
13
|
+
end
|
14
|
+
|
15
|
+
should "prefer serializer of its maildir" do
|
16
|
+
@maildir.serializer = :foo
|
17
|
+
assert_equal @message.serializer, :foo
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
4
21
|
context "An new, unwritten message" do
|
5
22
|
setup do
|
6
23
|
FakeFS::FileSystem.clear
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maildir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aaron Suggs
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-05-08 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -76,17 +76,19 @@ dependencies:
|
|
76
76
|
type: :development
|
77
77
|
version_requirements: *id004
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: fakefs
|
80
80
|
prerelease: false
|
81
81
|
requirement: &id005 !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
hash:
|
86
|
+
hash: 23
|
87
87
|
segments:
|
88
88
|
- 0
|
89
|
-
|
89
|
+
- 3
|
90
|
+
- 2
|
91
|
+
version: 0.3.2
|
90
92
|
type: :development
|
91
93
|
version_requirements: *id005
|
92
94
|
description: A ruby library for reading and writing arbitrary messages in DJB's maildir format
|
@@ -151,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
requirements: []
|
152
154
|
|
153
155
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.
|
156
|
+
rubygems_version: 1.6.2
|
155
157
|
signing_key:
|
156
158
|
specification_version: 3
|
157
159
|
summary: Read & write messages in the maildir format
|