nilclass-maildir 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -1,13 +1,12 @@
1
1
  # implements IMAP Keywords as used by the Courier Mail Server
2
2
  # see http://www.courier-mta.org/imap/README.imapkeywords.html for details
3
3
 
4
- require 'ftools'
5
4
  require 'maildir'
6
5
  module Maildir::Keywords
7
6
  def self.included(base)
8
7
  Maildir::Message.send(:include, MessageExtension)
9
8
  end
10
-
9
+
11
10
  def keyword_dir
12
11
  @keyword_dir ||= File.join(path, 'courierimapkeywords')
13
12
  Dir.mkdir(@keyword_dir) unless File.directory?(@keyword_dir)
@@ -45,14 +44,14 @@ module Maildir::Keywords
45
44
  else
46
45
  n = t + 1
47
46
  key = file
48
- File.move(File.join(keyword_dir, file), File.join(keyword_dir, ".#{n}.#{key}"))
47
+ FileUtils.mv(File.join(keyword_dir, file), File.join(keyword_dir, ".#{n}.#{key}"))
49
48
  end
50
49
  if msg = messages[key]
51
50
  (keyword_files[key] ||= []) << [n, key]
52
51
  else # message doesn't exist
53
52
  fname = File.join(keyword_dir, file)
54
53
  if File.stat(fname).ctime < (Time.now - (15 * 60))
55
- File.unlink(fname)
54
+ FileUtils.rm(fname)
56
55
  end
57
56
  end
58
57
  next(keyword_files)
@@ -60,7 +59,7 @@ module Maildir::Keywords
60
59
  # process keyword files
61
60
  keyword_files.each_pair do |key, files|
62
61
  files.sort! { |a, b| a[0] <=> b[0] }
63
- files[0..-2].each { |f| File.unlink(File.join(keyword_dir, ".#{f.join('.')}")) } if files.last[0] < t
62
+ files[0..-2].each { |f| FileUtils.rm(File.join(keyword_dir, ".#{f.join('.')}")) } if files.last[0] < t
64
63
  msg = messages[key]
65
64
  file = (File.exist?(File.join(keyword_dir, files.last[1])) ? files.last[1] : ".#{files.last.join('.')}")
66
65
  current_keywords = File.read(File.join(keyword_dir, file)).split(/\s+/)
@@ -80,7 +79,7 @@ module Maildir::Keywords
80
79
  @keywords[key] = msg.keywords
81
80
  end
82
81
  }
83
- File.move(tmp_file, list_file)
82
+ FileUtils.mv(tmp_file, list_file)
84
83
  end
85
84
 
86
85
  def keywords(key)
@@ -98,7 +97,7 @@ module Maildir::Keywords
98
97
  def keywords=(list)
99
98
  tmp_fname = File.join(@maildir.path, 'tmp', unique_name)
100
99
  File.open(tmp_fname, 'w') { |f| f.write(list.join("\n")) }
101
- File.move(tmp_fname, File.join(@maildir.keyword_dir, unique_name))
100
+ FileUtils.mv(tmp_fname, File.join(@maildir.keyword_dir, unique_name))
102
101
  end
103
102
 
104
103
  # sets @keywords to the given list
@@ -1,16 +1,28 @@
1
1
  # implements subdirs as used by the Courier Mail Server (courier-mta.org)
2
2
  require 'maildir'
3
3
  module Maildir::Subdirs
4
+ class MaildirNotFound < Exception
5
+ end
4
6
  ROOT_NAME = 'INBOX'
5
7
  DELIM = '.'
6
8
 
7
9
  def self.included(base)
8
- base.instance_eval do
10
+ base.instance_eval do
9
11
  alias_method :inspect_without_subdirs, :inspect
10
12
  alias_method :inspect, :inspect_with_subdirs
11
13
  end
12
14
  end
13
15
 
16
+ def subdir_by_path(sd_path)
17
+ if(File.directory?(p = File.join(path, ".#{sd_path}")))
18
+ Maildir.new(p, false)
19
+ elsif(File.directory?(p = File.join(path, ".INBOX.#{sd_path}")))
20
+ Maildir.new(p, false)
21
+ else
22
+ raise MaildirNotFound
23
+ end
24
+ end
25
+
14
26
  def name
15
27
  root? ? ROOT_NAME : subdir_parts(path).last
16
28
  end
@@ -39,7 +51,7 @@ module Maildir::Subdirs
39
51
  @subdirs ||= root.subdirs(false).select { |md| subdir_parts(File.basename(md.path))[0..-2] == my_parts }
40
52
  end
41
53
  end
42
-
54
+
43
55
  # Friendly inspect method
44
56
  def inspect_with_subdirs
45
57
  "#<#{self.class} path=#{@path} mailbox_path=#{mailbox_path}>"
data/test/test_subdirs.rb CHANGED
@@ -30,6 +30,18 @@ class TestSubdirs < Test::Unit::TestCase
30
30
  @maildir.create_subdir("test")
31
31
  assert @maildir.subdirs.map(&:name).include?("test")
32
32
  end
33
+
34
+ should "find the subdir by path" do
35
+ assert_nothing_raised do
36
+ @maildir.subdir_by_path('a.x')
37
+ end
38
+ end
39
+
40
+ should "raise MaildirNotFound" do
41
+ assert_raise Maildir::Subdirs::MaildirNotFound do
42
+ @maildir.subdir_by_path('a.b.c')
43
+ end
44
+ end
33
45
  end
34
46
 
35
47
  context "A subdir" do
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Suggs