maildir 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -1
- data/Rakefile +1 -20
- data/lib/maildir/serializer/base.rb +16 -0
- data/lib/maildir/serializer/json.rb +17 -9
- data/lib/maildir/unique_name.rb +0 -13
- data/lib/maildir/version.rb +3 -0
- data/test/test_serializers.rb +16 -3
- metadata +73 -33
- data/.gitignore +0 -3
- data/VERSION +0 -1
- data/benchmarks/runner +0 -30
- data/maildir.gemspec +0 -82
data/README.rdoc
CHANGED
@@ -73,7 +73,7 @@ By default, message data are written and read from disk as a string. It's often
|
|
73
73
|
|
74
74
|
The following serializers are included:
|
75
75
|
|
76
|
-
* Maildir::Serializer::Base (
|
76
|
+
* Maildir::Serializer::Base (default)
|
77
77
|
* Maildir::Serializer::Mail
|
78
78
|
* Maildir::Serializer::Marshal
|
79
79
|
* Maildir::Serializer::JSON
|
@@ -85,6 +85,13 @@ Maildir::Serializer::Base simply reads and writes strings to disk.
|
|
85
85
|
message = maildir.add("Hello World!") # writes "Hello World!" to disk
|
86
86
|
message.data # => "Hello World!"
|
87
87
|
|
88
|
+
As of version 0.7, the Maildir::Serializer::Base can write IO streams as well as strings. For example:
|
89
|
+
|
90
|
+
message.add(STDIN)
|
91
|
+
|
92
|
+
This will use Ruby 1.9's more efficient IO.copy_stream method if available,
|
93
|
+
and degrade gracefully in Ruby 1.8.
|
94
|
+
|
88
95
|
The Mail serializer takes a ruby Mail object (http://github.com/mikel/mail) and writes RFC2822 email messages.
|
89
96
|
|
90
97
|
require 'maildir/serializer/mail'
|
@@ -109,6 +116,7 @@ It's trivial to create a custom serializer. Implement the following two methods:
|
|
109
116
|
== Contributors
|
110
117
|
|
111
118
|
Niklas E. Cathor (http://github.com/nilclass) added subdir & courierimapkeywords support
|
119
|
+
Ali Polatel (http://github.com/alip) for suggesting IO.copy_stream
|
112
120
|
|
113
121
|
== Copyright
|
114
122
|
|
data/Rakefile
CHANGED
@@ -7,25 +7,6 @@ end
|
|
7
7
|
|
8
8
|
task :default => :test
|
9
9
|
|
10
|
-
begin
|
11
|
-
require 'jeweler'
|
12
|
-
Jeweler::Tasks.new do |gemspec|
|
13
|
-
gemspec.name = "maildir"
|
14
|
-
gemspec.summary = "Read & write messages in the maildir format"
|
15
|
-
gemspec.description = "A ruby library for reading and writing arbitrary messages in DJB's maildir format"
|
16
|
-
gemspec.email = "aaron@ktheory.com"
|
17
|
-
gemspec.homepage = "http://github.com/ktheory/maildir"
|
18
|
-
gemspec.authors = ["Aaron Suggs", "Niklas E. Cathor"]
|
19
|
-
gemspec.add_development_dependency "shoulda", ">= 0"
|
20
|
-
gemspec.add_development_dependency "mail", ">= 0"
|
21
|
-
gemspec.add_development_dependency "json", ">= 0"
|
22
|
-
gemspec.add_development_dependency "ktheory-fakefs", ">= 0"
|
23
|
-
end
|
24
|
-
Jeweler::GemcutterTasks.new
|
25
|
-
rescue LoadError
|
26
|
-
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
27
|
-
end
|
28
|
-
|
29
10
|
desc "Run benchmarks"
|
30
11
|
task :bench do
|
31
12
|
load File.join(File.dirname(__FILE__), "benchmarks", "runner")
|
@@ -34,4 +15,4 @@ end
|
|
34
15
|
desc "Remove trailing whitespace"
|
35
16
|
task :whitespace do
|
36
17
|
sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
|
37
|
-
end
|
18
|
+
end
|
@@ -13,7 +13,23 @@ module Maildir::Serializer
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Writes data to path. Returns number of bytes written.
|
16
|
+
# If data acts like an IO object (i.e., data responds to the read method),
|
17
|
+
# we call data.read or the more efficient IO.copy_stream available in
|
18
|
+
# ruby 1.9.1.
|
16
19
|
def dump(data, path)
|
20
|
+
if data.respond_to?(:read)
|
21
|
+
if IO.respond_to?(:copy_stream)
|
22
|
+
IO.copy_stream(data, path)
|
23
|
+
else
|
24
|
+
write(data.read, path)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
write(data, path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def write(data, path)
|
17
33
|
File.open(path, "w") {|file| file.write(data)}
|
18
34
|
end
|
19
35
|
end
|
@@ -1,13 +1,21 @@
|
|
1
|
-
|
1
|
+
# Prefer yajl JSON library
|
2
|
+
begin
|
3
|
+
require 'yajl/json_gem'
|
4
|
+
rescue LoadError
|
5
|
+
require 'json'
|
6
|
+
end
|
7
|
+
|
2
8
|
# Serialize messages as JSON
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
9
|
+
module Maildir::Serializer
|
10
|
+
class JSON < Base
|
11
|
+
# Read data from path and parse it as JSON.
|
12
|
+
def load(path)
|
13
|
+
::JSON.load(super(path))
|
14
|
+
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
# Dump data as JSON and writes it to path.
|
17
|
+
def dump(data, path)
|
18
|
+
super(data.to_json, path)
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/maildir/unique_name.rb
CHANGED
@@ -45,19 +45,6 @@ class Maildir::UniqueName
|
|
45
45
|
Socket.gethostname
|
46
46
|
end
|
47
47
|
|
48
|
-
def secure_random(bytes=8)
|
49
|
-
# File.read("/dev/urandom", bytes).unpack("H*")[0]
|
50
|
-
raise "Not implemented"
|
51
|
-
end
|
52
|
-
|
53
|
-
def inode
|
54
|
-
raise "Not implemented"
|
55
|
-
end
|
56
|
-
|
57
|
-
def device_number
|
58
|
-
raise "Not implemented"
|
59
|
-
end
|
60
|
-
|
61
48
|
def microsecond
|
62
49
|
@now.usec.to_s
|
63
50
|
end
|
data/test/test_serializers.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
class TestSerializers < Test::Unit::TestCase
|
3
3
|
|
4
|
+
|
4
5
|
serializers = [
|
6
|
+
# Test the base serializer with a string
|
7
|
+
[Maildir::Serializer::Base, lambda {|data| data}],
|
8
|
+
# Test base serializer with IO object
|
9
|
+
[Maildir::Serializer::Base, lambda {|data| s = StringIO.new(data); s.rewind; s}],
|
5
10
|
[Maildir::Serializer::Mail, lambda {|data| Mail.new(data).to_s}],
|
6
11
|
[Maildir::Serializer::Marshal, lambda {|data| Marshal.dump(data)}],
|
7
12
|
[Maildir::Serializer::JSON, lambda {|data| JSON.dump(data)}],
|
@@ -9,15 +14,20 @@ class TestSerializers < Test::Unit::TestCase
|
|
9
14
|
]
|
10
15
|
|
11
16
|
serializers.each do |klass, dumper|
|
12
|
-
|
17
|
+
# NB: dumper.object_id makes test names unique
|
18
|
+
context "A message serialized with #{klass} (#{dumper.object_id})" do
|
13
19
|
setup do
|
14
20
|
FakeFS::FileSystem.clear
|
15
21
|
@data = case klass.new
|
16
22
|
when Maildir::Serializer::Mail
|
17
23
|
Mail.new
|
18
|
-
|
24
|
+
when Maildir::Serializer::Marshal, Maildir::Serializer::JSON, Maildir::Serializer::YAML
|
19
25
|
# Test a few common types
|
20
26
|
[1, nil, {"foo" => true}]
|
27
|
+
when Maildir::Serializer::Base
|
28
|
+
"Hello World!"
|
29
|
+
else
|
30
|
+
raise "Unknown class #{klass.inspect}"
|
21
31
|
end
|
22
32
|
|
23
33
|
# Set the message serializer
|
@@ -30,7 +40,10 @@ class TestSerializers < Test::Unit::TestCase
|
|
30
40
|
end
|
31
41
|
|
32
42
|
should "have serialized data on disk" do
|
33
|
-
|
43
|
+
expected_data = dumper.call(@data)
|
44
|
+
# Read the expected_data if @data is an IO object
|
45
|
+
expected_data = expected_data.read if expected_data.respond_to?(:read)
|
46
|
+
assert_equal expected_data, File.read(@message.path)
|
34
47
|
end
|
35
48
|
end
|
36
49
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maildir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Aaron Suggs
|
@@ -10,66 +16,88 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date: 2010-
|
19
|
+
date: 2010-12-19 00:00:00 -05:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
23
|
+
name: rake
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
18
34
|
type: :development
|
19
|
-
|
20
|
-
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: shoulda
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
21
41
|
requirements:
|
22
42
|
- - ">="
|
23
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
24
47
|
version: "0"
|
25
|
-
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
26
50
|
- !ruby/object:Gem::Dependency
|
27
51
|
name: mail
|
28
|
-
|
29
|
-
|
30
|
-
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
31
55
|
requirements:
|
32
56
|
- - ">="
|
33
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
34
61
|
version: "0"
|
35
|
-
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
36
64
|
- !ruby/object:Gem::Dependency
|
37
65
|
name: json
|
38
|
-
|
39
|
-
|
40
|
-
|
66
|
+
prerelease: false
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
41
69
|
requirements:
|
42
70
|
- - ">="
|
43
71
|
- !ruby/object:Gem::Version
|
72
|
+
hash: 3
|
73
|
+
segments:
|
74
|
+
- 0
|
44
75
|
version: "0"
|
45
|
-
|
76
|
+
type: :development
|
77
|
+
version_requirements: *id004
|
46
78
|
- !ruby/object:Gem::Dependency
|
47
79
|
name: ktheory-fakefs
|
48
|
-
|
49
|
-
|
50
|
-
|
80
|
+
prerelease: false
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
51
83
|
requirements:
|
52
84
|
- - ">="
|
53
85
|
- !ruby/object:Gem::Version
|
86
|
+
hash: 3
|
87
|
+
segments:
|
88
|
+
- 0
|
54
89
|
version: "0"
|
55
|
-
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id005
|
56
92
|
description: A ruby library for reading and writing arbitrary messages in DJB's maildir format
|
57
93
|
email: aaron@ktheory.com
|
58
94
|
executables: []
|
59
95
|
|
60
96
|
extensions: []
|
61
97
|
|
62
|
-
extra_rdoc_files:
|
63
|
-
|
64
|
-
- README.rdoc
|
98
|
+
extra_rdoc_files: []
|
99
|
+
|
65
100
|
files:
|
66
|
-
- .gitignore
|
67
|
-
- LICENSE
|
68
|
-
- README.rdoc
|
69
|
-
- Rakefile
|
70
|
-
- VERSION
|
71
|
-
- benchmarks/runner
|
72
|
-
- lib/maildir.rb
|
73
101
|
- lib/maildir/keywords.rb
|
74
102
|
- lib/maildir/message.rb
|
75
103
|
- lib/maildir/serializer/base.rb
|
@@ -79,7 +107,11 @@ files:
|
|
79
107
|
- lib/maildir/serializer/yaml.rb
|
80
108
|
- lib/maildir/subdirs.rb
|
81
109
|
- lib/maildir/unique_name.rb
|
82
|
-
- maildir.
|
110
|
+
- lib/maildir/version.rb
|
111
|
+
- lib/maildir.rb
|
112
|
+
- LICENSE
|
113
|
+
- README.rdoc
|
114
|
+
- Rakefile
|
83
115
|
- test/test_helper.rb
|
84
116
|
- test/test_keywords.rb
|
85
117
|
- test/test_maildir.rb
|
@@ -97,21 +129,29 @@ rdoc_options:
|
|
97
129
|
require_paths:
|
98
130
|
- lib
|
99
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
100
133
|
requirements:
|
101
134
|
- - ">="
|
102
135
|
- !ruby/object:Gem::Version
|
136
|
+
hash: 3
|
137
|
+
segments:
|
138
|
+
- 0
|
103
139
|
version: "0"
|
104
|
-
version:
|
105
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
106
142
|
requirements:
|
107
143
|
- - ">="
|
108
144
|
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
|
145
|
+
hash: 17
|
146
|
+
segments:
|
147
|
+
- 1
|
148
|
+
- 3
|
149
|
+
- 5
|
150
|
+
version: 1.3.5
|
111
151
|
requirements: []
|
112
152
|
|
113
153
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.3.
|
154
|
+
rubygems_version: 1.3.7
|
115
155
|
signing_key:
|
116
156
|
specification_version: 3
|
117
157
|
summary: Read & write messages in the maildir format
|
data/.gitignore
DELETED
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.6.0
|
data/benchmarks/runner
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
-
require 'maildir'
|
4
|
-
require 'benchmark'
|
5
|
-
|
6
|
-
maildir_path = ENV['MAILDIR'] || "./tmp"
|
7
|
-
maildir = Maildir.new(maildir_path)
|
8
|
-
|
9
|
-
n = 300
|
10
|
-
message = "Write #{n} messages:"
|
11
|
-
tms = Benchmark.bmbm(message.size) do |x|
|
12
|
-
x.report(message) { n.times { maildir.add("") } }
|
13
|
-
end
|
14
|
-
|
15
|
-
puts "#{n/tms.first.real} messages per second"
|
16
|
-
|
17
|
-
|
18
|
-
message = "List new:"
|
19
|
-
tms = Benchmark.bm(message.size) do |x|
|
20
|
-
x.report(message) { n.times { maildir.list_keys(:new)} }
|
21
|
-
end
|
22
|
-
|
23
|
-
# require 'ruby-prof'
|
24
|
-
# result = RubyProf.profile do
|
25
|
-
# n.times { maildir.list_keys(:new) }
|
26
|
-
# end
|
27
|
-
#
|
28
|
-
# # Print a graph profile to text
|
29
|
-
# printer = RubyProf::GraphPrinter.new(result)
|
30
|
-
# printer.print(STDOUT, 0)
|
data/maildir.gemspec
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{maildir}
|
8
|
-
s.version = "0.6.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Aaron Suggs", "Niklas E. Cathor"]
|
12
|
-
s.date = %q{2010-01-28}
|
13
|
-
s.description = %q{A ruby library for reading and writing arbitrary messages in DJB's maildir format}
|
14
|
-
s.email = %q{aaron@ktheory.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".gitignore",
|
21
|
-
"LICENSE",
|
22
|
-
"README.rdoc",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"benchmarks/runner",
|
26
|
-
"lib/maildir.rb",
|
27
|
-
"lib/maildir/keywords.rb",
|
28
|
-
"lib/maildir/message.rb",
|
29
|
-
"lib/maildir/serializer/base.rb",
|
30
|
-
"lib/maildir/serializer/json.rb",
|
31
|
-
"lib/maildir/serializer/mail.rb",
|
32
|
-
"lib/maildir/serializer/marshal.rb",
|
33
|
-
"lib/maildir/serializer/yaml.rb",
|
34
|
-
"lib/maildir/subdirs.rb",
|
35
|
-
"lib/maildir/unique_name.rb",
|
36
|
-
"maildir.gemspec",
|
37
|
-
"test/test_helper.rb",
|
38
|
-
"test/test_keywords.rb",
|
39
|
-
"test/test_maildir.rb",
|
40
|
-
"test/test_message.rb",
|
41
|
-
"test/test_serializers.rb",
|
42
|
-
"test/test_subdirs.rb",
|
43
|
-
"test/test_unique_name.rb"
|
44
|
-
]
|
45
|
-
s.homepage = %q{http://github.com/ktheory/maildir}
|
46
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
47
|
-
s.require_paths = ["lib"]
|
48
|
-
s.rubygems_version = %q{1.3.5}
|
49
|
-
s.summary = %q{Read & write messages in the maildir format}
|
50
|
-
s.test_files = [
|
51
|
-
"test/test_helper.rb",
|
52
|
-
"test/test_keywords.rb",
|
53
|
-
"test/test_maildir.rb",
|
54
|
-
"test/test_message.rb",
|
55
|
-
"test/test_serializers.rb",
|
56
|
-
"test/test_subdirs.rb",
|
57
|
-
"test/test_unique_name.rb"
|
58
|
-
]
|
59
|
-
|
60
|
-
if s.respond_to? :specification_version then
|
61
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
62
|
-
s.specification_version = 3
|
63
|
-
|
64
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
65
|
-
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
66
|
-
s.add_development_dependency(%q<mail>, [">= 0"])
|
67
|
-
s.add_development_dependency(%q<json>, [">= 0"])
|
68
|
-
s.add_development_dependency(%q<ktheory-fakefs>, [">= 0"])
|
69
|
-
else
|
70
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
71
|
-
s.add_dependency(%q<mail>, [">= 0"])
|
72
|
-
s.add_dependency(%q<json>, [">= 0"])
|
73
|
-
s.add_dependency(%q<ktheory-fakefs>, [">= 0"])
|
74
|
-
end
|
75
|
-
else
|
76
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
77
|
-
s.add_dependency(%q<mail>, [">= 0"])
|
78
|
-
s.add_dependency(%q<json>, [">= 0"])
|
79
|
-
s.add_dependency(%q<ktheory-fakefs>, [">= 0"])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|