Class: VPOPMail::Folder
- Inherits:
-
Object
- Object
- VPOPMail::Folder
- Defined in:
- lib/vpopmail/folder.rb
Overview
class: Folder {{{ ++ The Folder class represents a Maildir folder
Constant Summary collapse
- @@logger =
class attribute: logger {{{
nil
Instance Attribute Summary collapse
-
#curpath ⇒ Object
readonly
Returns the value of attribute curpath.
-
#imapdb ⇒ Object
readonly
Returns the value of attribute imapdb.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#newpath ⇒ Object
readonly
Returns the value of attribute newpath.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#tmppath ⇒ Object
readonly
Returns the value of attribute tmppath.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#domain ⇒ Object
———————————————————————————- method: domain {{{ ++ Gives the Domain of the User that owns the Folder.
-
#each ⇒ Object
———————————————————————————- method: each {{{ ++ Apply the block to all Message objects stored in the Folder Returns self.
-
#initialize(p_user, p_name = nil) ⇒ Folder
constructor
———————————————————————————- method: initialize {{{ ++ Creates a new Folder object after
p_name
and owned by the Userp_user
Ifp_name
is not given opens the Inbox. -
#learnAs(p_kind = "spam", p_properFolder = nil, p_archiveFolder = nil) ⇒ Object
———————————————————————————- method: learnAs {{{ ++ Learns all Message objects as
p_kind
. Moves them to thep_properFolder
Folder if present. And makes a copy of each Message to thep_archiveFolder
if present. This allows to re-train the spam analyzer with a bunch of ham and spam messages later on. - #logger ⇒ Object
- #logger=(p_object) ⇒ Object
-
#size ⇒ Object
———————————————————————————- method: size {{{ ++ Gives the number of Message objects stored in the Folder.
-
#to_s ⇒ Object
———————————————————————————- method: to_s {{{ ++ Returns the String representation of the Domain object.
-
#to_xml ⇒ Object
———————————————————————————- method: to_xml {{{ ++ Returns the REXML::Document that represents the Folder object.
Constructor Details
#initialize(p_user, p_name = nil) ⇒ Folder
method: initialize {{{ ++ Creates a new Folder object after p_name
and owned by the User p_user
If p_name
is not given opens the Inbox.
Initializes the IMAPDB Database for the given Folder and set the working directory to the cur Maildir folder.
Raises a SystemCallError if the Maildir folder does not exist
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/vpopmail/folder.rb', line 48 def initialize(p_user, p_name = nil) @user = p_user @name = p_name @name = "INBOX" if @name.nil? or @name.empty? @path = p_user.path + File::SEPARATOR + "Maildir" @path = @path + File::SEPARATOR + '.' + @name if @name !~ /inbox/i @path = @path @curpath = @path + File::SEPARATOR + "cur" @newpath = @path + File::SEPARATOR + "new" @tmppath = @path + File::SEPARATOR + "tmp" @dir = Dir.new(@curpath) # This will raise a if the path does not exist @imapdb = IMAPDB.new(self) end |
Instance Attribute Details
#curpath ⇒ Object (readonly)
Returns the value of attribute curpath.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def curpath @curpath end |
#imapdb ⇒ Object (readonly)
Returns the value of attribute imapdb.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def imapdb @imapdb end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def name @name end |
#newpath ⇒ Object (readonly)
Returns the value of attribute newpath.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def newpath @newpath end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def path @path end |
#tmppath ⇒ Object (readonly)
Returns the value of attribute tmppath.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def tmppath @tmppath end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
27 28 29 |
# File 'lib/vpopmail/folder.rb', line 27 def user @user end |
Class Method Details
.logger ⇒ Object
32 |
# File 'lib/vpopmail/folder.rb', line 32 def self.logger ; @@logger ; end |
.logger=(p_object) ⇒ Object
33 |
# File 'lib/vpopmail/folder.rb', line 33 def self.logger=(p_object) ; @@logger = p_object ; end |
Instance Method Details
#domain ⇒ Object
method: domain {{{ ++ Gives the Domain of the User that owns the Folder
66 67 68 |
# File 'lib/vpopmail/folder.rb', line 66 def domain return @user.domain end |
#each ⇒ Object
method: each {{{ ++ Apply the block to all Message objects stored in the Folder Returns self
83 84 85 86 87 88 89 90 91 |
# File 'lib/vpopmail/folder.rb', line 83 def each #p_block @dir.each { |entry| next if entry == "." next if entry == ".." = Message.new(self, entry) yield() } self end |
#learnAs(p_kind = "spam", p_properFolder = nil, p_archiveFolder = nil) ⇒ Object
method: learnAs {{{ ++ Learns all Message objects as p_kind
. Moves them to the p_properFolder
Folder if present. And makes a copy of each Message to the p_archiveFolder
if present. This allows to re-train the spam analyzer with a bunch of ham and spam messages later on.
Returns self
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vpopmail/folder.rb', line 102 def learnAs(p_kind = "spam", p_properFolder = nil, p_archiveFolder = nil) raise ArgumentError unless p_kind == "spam" or p_kind == "ham" self.each {|| logger.info "Processing message #{.id}" if !@@logger.nil? .learnAs(p_kind) .copyTo(p_archiveFolder) if !p_archiveFolder.nil? .markAs(p_kind) .moveTo(p_properFolder) if !p_properFolder.nil? } self end |
#logger ⇒ Object
34 |
# File 'lib/vpopmail/folder.rb', line 34 def logger ; @@logger ; end |
#logger=(p_object) ⇒ Object
35 |
# File 'lib/vpopmail/folder.rb', line 35 def logger=(p_object) ; @@logger = p_object ; end |
#size ⇒ Object
method: size {{{ ++ Gives the number of Message objects stored in the Folder
74 75 76 |
# File 'lib/vpopmail/folder.rb', line 74 def size return @dir.entries.size - 2 # . and .. should not be counted end |
#to_s ⇒ Object
method: to_s {{{ ++ Returns the String representation of the Domain object
126 127 128 |
# File 'lib/vpopmail/folder.rb', line 126 def to_s return "Folder #{@name}, path=\"#{@path}\"" end |
#to_xml ⇒ Object
method: to_xml {{{ ++ Returns the REXML::Document that represents the Folder object
118 119 120 |
# File 'lib/vpopmail/folder.rb', line 118 def to_xml return REXML::Document.new("<Folder name=\"#{@name}\" path=\"#{@path}\" />") end |