Show
Ignore:
Timestamp:
04/07/08 16:46:43 (6 years ago)
Author:
ihag
Message:

lang/ruby/mdmaildir/mdmerge.rb:

  • add -f COMMAND_FILE option for make cmdfile mode.
  • add -c -f COMMAND_FILE option for commit from cmdfile mode.
  • Introduced CMDProcessor class for abstracting the behavior of command.

lang/ruby/mdmaildir/mdd.rb: add comments.
lang/ruby/mdmaildir/README: fix typo.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/mdmaildir/mdd.rb

    r5682 r9074  
    11#!/usr/local/bin/ruby 
    22# $Id$ 
    3 require 'gdbm' 
    4 require 'digest/sha1' 
    5 require 'pp' 
    63 
     4# 
     5# = Manipulates message-digest file for whole of messages in the Maildir. 
     6# 
     7# Authors::  $Author: genta $ 
     8# Revision:: $Revision: 77 $ 
     9# 
     10class MDDigest 
     11  require 'gdbm' 
     12  require 'digest/sha1' 
     13  require 'pp' 
    714 
    8 # Maildir digest file class 
    9 class MDDigest 
    1015  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 
    1123  def initialize(maildir) 
    1224    @basedir = maildir.dup 
     
    1628 
    1729  def open;  @db = GDBM.open(@path); end 
    18   def close; @db.reorganize.close;   end 
    19   def clear; @db.clear;              end 
     30  private :open 
    2031 
     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 
    2147  def add(path) 
    2248    apath = abspath(path) 
     
    3359  end 
    3460 
     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. 
    3569  def has_file?(key, file) 
    3670    return false if @db[key].nil? 
     
    4175  end 
    4276 
     77  # Wrapper of GDBM#each. It is for traversal all of messages in Maildir 
     78  # by using a message-digest file. 
    4379  def each(&block) 
    4480    @db.each(&block) 
     
    4682 
    4783 
     84  private 
     85 
     86  # Caliculates a Message digest for specified message. 
     87  # 
     88  # _file_::  Path for a message. 
     89  # returns:: Instance of Digest::SHA1. 
    4890  def hash(file) 
    4991    md = Digest::SHA1.new 
     
    5799  end 
    58100 
    59   def abspath(file) 
    60     File.expand_path(file, @basedir) 
    61   end 
    62  
     101  # _key_:: 
     102  # _dest_:: 
    63103  def merge(key, dest) 
    64104    dfolder = folder(abspath(dest)) 
     
    77117  end 
    78118 
     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. 
    79123  def folder(path) 
    80124    f, = path.split('/') 
     
    82126    return f 
    83127  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 
    84137end