maildir 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -1
- data/lib/maildir.rb +16 -3
- data/lib/maildir/message.rb +1 -1
- data/lib/maildir/serializer/base.rb +3 -1
- data/lib/maildir/unique_name.rb +1 -1
- data/lib/maildir/version.rb +1 -1
- data/test/test_maildir.rb +45 -6
- data/test/test_message.rb +4 -0
- data/test/test_unique_name.rb +10 -0
- metadata +38 -13
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ 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
|
-
"Two words: no locks." -- Daniel J.
|
9
|
+
"Two words: no locks." -- Daniel J. Bernstein
|
10
10
|
|
11
11
|
The maildir format allows multiple processes to read and write arbitrary messages without file locks.
|
12
12
|
|
@@ -14,6 +14,9 @@ New messages are initially written to a "tmp" directory with an automatically-ge
|
|
14
14
|
|
15
15
|
While the maildir format was created for email, it works well for arbitrary data. This library can read & write email messages or arbitrary data. See Pluggable serializers for more.
|
16
16
|
|
17
|
+
{<img src="https://secure.travis-ci.org/ktheory/maildir.png" />}[http://travis-ci.org/ktheory/maildir]
|
18
|
+
|
19
|
+
|
17
20
|
== Install
|
18
21
|
|
19
22
|
gem install maildir
|
@@ -50,6 +53,12 @@ Add some flags to the message to indicate state. See "What can I put in info" at
|
|
50
53
|
message.remove_flag("F") # unflag the message
|
51
54
|
message.add_flag("T") # Mark the message as "trashed"
|
52
55
|
|
56
|
+
List :cur messages based on flags.
|
57
|
+
|
58
|
+
maildir.list(:cur, :flags => 'F') # => lists all messages with flag 'F
|
59
|
+
maildir.list(:cur, :flags => 'FS') # => lists all messages with flag 'F' and 'S'; Flags must be specified in acending ASCII order ('FS' and not 'SF')
|
60
|
+
maildir.list(:cur, :flags => '') # => lists all messages without any flags
|
61
|
+
|
53
62
|
Get a key to uniquely identify the message
|
54
63
|
|
55
64
|
key = message.key
|
data/lib/maildir.rb
CHANGED
@@ -76,6 +76,14 @@ class Maildir
|
|
76
76
|
end
|
77
77
|
|
78
78
|
# Returns an arry of messages from :new or :cur directory, sorted by key.
|
79
|
+
# If options[:flags] is specified and directory is :cur, returns messages with flags specified
|
80
|
+
#
|
81
|
+
# E.g.
|
82
|
+
# maildir.list(:cur, :flags => 'F') # => lists all messages with flag 'F'
|
83
|
+
# maildir.list(:cur, :flags => 'FS') # => lists all messages with flag 'F' and 'S'; Flags must be specified in acending ASCII order ('FS' and not 'SF')
|
84
|
+
# maildir.list(:cur, :flags => '') # => lists all messages without any flags
|
85
|
+
# This option does not work for :new directory
|
86
|
+
#
|
79
87
|
# If options[:limit] is specified, returns only so many keys.
|
80
88
|
#
|
81
89
|
# E.g.
|
@@ -86,7 +94,10 @@ class Maildir
|
|
86
94
|
raise ArgumentError, "dir must be :new, :cur, or :tmp"
|
87
95
|
end
|
88
96
|
|
89
|
-
|
97
|
+
# Set flags to filter messages
|
98
|
+
# Silently ignored if dir is :new
|
99
|
+
flags = (dir.to_sym == :cur) ? options[:flags] : nil
|
100
|
+
keys = get_dir_listing(dir, :flags => flags)
|
90
101
|
|
91
102
|
# Sort the keys (chronological order)
|
92
103
|
# TODO: make sorting configurable
|
@@ -127,8 +138,10 @@ class Maildir
|
|
127
138
|
|
128
139
|
protected
|
129
140
|
# Returns an array of keys in dir
|
130
|
-
def get_dir_listing(dir)
|
131
|
-
|
141
|
+
def get_dir_listing(dir, options={})
|
142
|
+
filter = "*"
|
143
|
+
filter = "#{filter}:2,#{options[:flags]}" if options[:flags]
|
144
|
+
search_path = File.join(self.path, dir.to_s, filter)
|
132
145
|
keys = Dir.glob(search_path)
|
133
146
|
# Remove the maildir's path from the keys
|
134
147
|
keys.each do |key|
|
data/lib/maildir/message.rb
CHANGED
data/lib/maildir/unique_name.rb
CHANGED
@@ -37,7 +37,7 @@ class Maildir::UniqueName
|
|
37
37
|
# The middle part contains the microsecond, the process id, and a
|
38
38
|
# per-process incrementing counter
|
39
39
|
def middle
|
40
|
-
"M#{microsecond}P#{process_id}Q#{delivery_count}"
|
40
|
+
"M#{'%06d' % microsecond}P#{process_id}Q#{delivery_count}"
|
41
41
|
end
|
42
42
|
|
43
43
|
# The right part is the hostname
|
data/lib/maildir/version.rb
CHANGED
data/test/test_maildir.rb
CHANGED
@@ -53,12 +53,51 @@ class TestMaildir < Test::Unit::TestCase
|
|
53
53
|
messages = temp_maildir.list(:new)
|
54
54
|
assert_equal messages, [@message]
|
55
55
|
end
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
56
|
+
|
57
|
+
context "cur message" do
|
58
|
+
should "list a cur message" do
|
59
|
+
@message = temp_maildir.add("")
|
60
|
+
@message.process
|
61
|
+
messages = temp_maildir.list(:cur)
|
62
|
+
assert_equal messages, [@message]
|
63
|
+
end
|
64
|
+
|
65
|
+
should "list and filter cur messages based on flags" do
|
66
|
+
@message = temp_maildir.add("")
|
67
|
+
@message.process
|
68
|
+
|
69
|
+
@flagged_message = temp_maildir.add("")
|
70
|
+
@flagged_message.process
|
71
|
+
@flagged_message.add_flag('F')
|
72
|
+
|
73
|
+
messages = temp_maildir.list(:cur, :flags => 'F')
|
74
|
+
assert_equal messages, [@flagged_message]
|
75
|
+
end
|
76
|
+
|
77
|
+
should "list and filter cur messages based on multiple flags" do
|
78
|
+
@message = temp_maildir.add("")
|
79
|
+
@message.process
|
80
|
+
|
81
|
+
@flagged_message = temp_maildir.add("")
|
82
|
+
@flagged_message.process
|
83
|
+
@flagged_message.add_flag('F')
|
84
|
+
@flagged_message.add_flag('S')
|
85
|
+
|
86
|
+
messages = temp_maildir.list(:cur, :flags => 'FS')
|
87
|
+
assert_equal messages, [@flagged_message]
|
88
|
+
end
|
89
|
+
|
90
|
+
should "list and filter cur messages without any flags" do
|
91
|
+
@message = temp_maildir.add("")
|
92
|
+
@message.process
|
93
|
+
|
94
|
+
@flagged_message = temp_maildir.add("")
|
95
|
+
@flagged_message.process
|
96
|
+
@flagged_message.add_flag('F')
|
97
|
+
|
98
|
+
messages = temp_maildir.list(:cur, :flags => '')
|
99
|
+
assert_equal messages, [@message]
|
100
|
+
end
|
62
101
|
end
|
63
102
|
end
|
64
103
|
|
data/test/test_message.rb
CHANGED
data/test/test_unique_name.rb
CHANGED
@@ -30,6 +30,16 @@ class TestUniqueName < Test::Unit::TestCase
|
|
30
30
|
@new_name.send(:instance_variable_set, :@now, @now)
|
31
31
|
assert_not_equal @name, @new_name.to_s
|
32
32
|
end
|
33
|
+
|
34
|
+
should "be chronological" do
|
35
|
+
@name1 = Maildir::UniqueName.new
|
36
|
+
@name1.send(:instance_variable_set, :@now, Time.at(0.000009))
|
37
|
+
|
38
|
+
@name2 = Maildir::UniqueName.new
|
39
|
+
@name2.send(:instance_variable_set, :@now, Time.at(0.100000))
|
40
|
+
|
41
|
+
assert_operator @name2.to_s, :>, @name1.to_s
|
42
|
+
end
|
33
43
|
|
34
44
|
end
|
35
45
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maildir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: shoulda
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: mail
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: json
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: fakefs
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,7 +85,12 @@ dependencies:
|
|
65
85
|
version: 0.3.2
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.3.2
|
69
94
|
description: A ruby library for reading and writing arbitrary messages in DJB's maildir
|
70
95
|
format
|
71
96
|
email: aaron@ktheory.com
|
@@ -111,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
136
|
version: 1.3.5
|
112
137
|
requirements: []
|
113
138
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.8.
|
139
|
+
rubygems_version: 1.8.23
|
115
140
|
signing_key:
|
116
141
|
specification_version: 3
|
117
142
|
summary: Read & write messages in the maildir format
|