Changeset 9074 for lang/ruby/mdmaildir/mdd.rb
- Timestamp:
- 04/07/08 16:46:43 (5 years ago)
- Files:
-
- 1 modified
-
lang/ruby/mdmaildir/mdd.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/ruby/mdmaildir/mdd.rb
r5682 r9074 1 1 #!/usr/local/bin/ruby 2 2 # $Id$ 3 require 'gdbm'4 require 'digest/sha1'5 require 'pp'6 3 4 # 5 # = Manipulates message-digest file for whole of messages in the Maildir. 6 # 7 # Authors:: $Author: genta $ 8 # Revision:: $Revision: 77 $ 9 # 10 class MDDigest 11 require 'gdbm' 12 require 'digest/sha1' 13 require 'pp' 7 14 8 # Maildir digest file class9 class MDDigest10 15 attr_reader :path, :basedir, :db 16 17 # Create MDDigest instance. MDDigest opens a message-digest file in 18 # the specified Maildir. The message-digest file is stored into the 19 # top-level directory as filename like "_maildir_/mddigest". 20 # 21 # _maildir_:: Path of Maildir. 22 # returns:: An instance of MDDigest class 11 23 def initialize(maildir) 12 24 @basedir = maildir.dup … … 16 28 17 29 def open; @db = GDBM.open(@path); end 18 def close; @db.reorganize.close; end 19 def clear; @db.clear; end 30 private :open 20 31 32 # Close the backend DBM. Call this method at the end of your program. 33 def close; 34 @db.reorganize.close 35 end 36 37 # Truncate message-digest file. 38 def clear 39 @db.clear 40 end 41 42 # Caliculates a message-digest for specified message, and records it 43 # into message-digest file. 44 # 45 # _path_:: Relative path of a message from Maildir directory. 46 # returns:: void 21 47 def add(path) 22 48 apath = abspath(path) … … 33 59 end 34 60 61 # Check specified key and file are already records in message-digest 62 # file, or not. 63 # 64 # _key_:: Key of file-hash. It typically message-digest + size of 65 # message. 66 # _file_:: Relative path of a message from Maildir directory. 67 # returns:: *true* if it already exists. 68 # *false* for not exists. 35 69 def has_file?(key, file) 36 70 return false if @db[key].nil? … … 41 75 end 42 76 77 # Wrapper of GDBM#each. It is for traversal all of messages in Maildir 78 # by using a message-digest file. 43 79 def each(&block) 44 80 @db.each(&block) … … 46 82 47 83 84 private 85 86 # Caliculates a Message digest for specified message. 87 # 88 # _file_:: Path for a message. 89 # returns:: Instance of Digest::SHA1. 48 90 def hash(file) 49 91 md = Digest::SHA1.new … … 57 99 end 58 100 59 def abspath(file) 60 File.expand_path(file, @basedir) 61 end 62 101 # _key_:: 102 # _dest_:: 63 103 def merge(key, dest) 64 104 dfolder = folder(abspath(dest)) … … 77 117 end 78 118 119 # Determines a folder name for a specified message. 120 # 121 # _path_:: Relative path of a message from Maildir directory 122 # returns:: A folder name in Maildir for a message that directed by path. 79 123 def folder(path) 80 124 f, = path.split('/') … … 82 126 return f 83 127 end 128 129 # Convert relative path to the absolute path. The root of absolute path is 130 # Maildir directory. 131 # 132 # _file_:: Relative path from Maildir directory. 133 # returns:: Absolute path that converted from _file_. 134 def abspath(file) 135 File.expand_path(file, @basedir) 136 end 84 137 end
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)