Class: VPOPMail::Folder

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#curpathObject (readonly)

Returns the value of attribute curpath.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def curpath
  @curpath
end

#imapdbObject (readonly)

Returns the value of attribute imapdb.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def imapdb
  @imapdb
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def name
  @name
end

#newpathObject (readonly)

Returns the value of attribute newpath.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def newpath
  @newpath
end

#pathObject (readonly)

Returns the value of attribute path.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def path
  @path
end

#tmppathObject (readonly)

Returns the value of attribute tmppath.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def tmppath
  @tmppath
end

#userObject (readonly)

Returns the value of attribute user.



27
28
29
# File 'lib/vpopmail/folder.rb', line 27

def user
  @user
end

Class Method Details

.loggerObject



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

#domainObject


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

#eachObject


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 = Message.new(self, entry)
		yield(message)
	}
	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

Raises:

  • (ArgumentError)


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 {|message|
		logger.info "Processing message #{message.id}" if !@@logger.nil?
		message.learnAs(p_kind)
		message.copyTo(p_archiveFolder) if !p_archiveFolder.nil?
		message.markAs(p_kind)
		message.moveTo(p_properFolder)  if !p_properFolder.nil?
	}
	self
end

#loggerObject



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

#sizeObject


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_sObject


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_xmlObject


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