Skip to content

Commit

Permalink
added more methods regarding recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
jashmenn committed Aug 7, 2011
1 parent 9dcc2eb commit 50cdf5b
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 33 deletions.
1 change: 1 addition & 0 deletions lib/pst.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module Pst; end
end
end

require "pst/extensions"
require "pst/version"
require "pst/base"
28 changes: 27 additions & 1 deletion lib/pst/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class Java::ComPff::PSTMessage

alias_method :subject, :getSubject
alias_method :display_to, :getDisplayTo
alias_method :num_recipients, :getNumberOfRecipients
alias_method :num_attachments, :getNumberOfAttachments

def human_id
"%s:%s:%s:%s" % [ folder.human_id, self.getClientSubmitTime.to_s, self.getInternetMessageId, self.subject ]
Expand All @@ -106,15 +108,39 @@ def pretty_string
self.getClientSubmitTime,
self.hasAttachments]
end

def recipients
Enumerator.new do |yielder|
i = 0
while i < self.getNumberOfRecipients
recipient = self.getRecipient(i)
yielder.yield recipient
i = i + 1
end
end
end
end

class Java::ComPff::PSTRecipient
alias_method :name, :getDisplayName
alias_method :email, :getEmailAddress
alias_method :smtp, :getSmtpAddress

def pretty_string
"%s <%s>" % [self.getDisplayName, self.getEmailAddress]
"%s <%s>" % [name, email]
end

def human_id
pretty_string
end

def hash_string
Digest::SHA1.hexdigest(human_id)
end
end

class Java::ComPff::PSTAttachment
# todo hash
def pretty_string
"[%s] %s <%s, %d>" % [self.getContentId, self.getFilename, self.getMimeTag, self.getSize]
end
Expand Down
106 changes: 74 additions & 32 deletions spec/pst_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,68 @@

Pff = Java::ComPff

describe "Pst::File" do
describe "PST" do

before(:all) do
@filename = testdatadir + "/albert_meyers_000.pst"
#@pstfile = Pst::File.new(@filename)
@pstfile = Pff::PSTFile.new(@filename)
end
it "should have a name" do
@pstfile.name.should eql("albert_meyers_000")
end

it "should have a filename" do
@pstfile.filename.should eql(@filename)
@folders = @pstfile.root.sub_folders.inject({}){|acc,f|
acc[f.name] = f
acc
}

end

it "should have a root" do
@pstfile.root.should_not be_nil
end
context "PSTFile" do

it "should have a name" do
@pstfile.name.should eql("albert_meyers_000")
end

it "should have a filename" do
@pstfile.filename.should eql(@filename)
end

it "should have a root" do
@pstfile.root.should_not be_nil
end

it "should tell root about itself" do
@pstfile.root.file.should eql(@pstfile)
@pstfile.root.file.name.should eql(@pstfile.name)
it "should tell root about itself" do
@pstfile.root.file.should eql(@pstfile)
@pstfile.root.file.name.should eql(@pstfile.name)
end
end

context "with sub folders" do
context "PSTFolder" do

before(:all) do
@folder_names = @pstfile.root.sub_folders.inject({}){|acc,f|
acc[f.name] = f
acc
}

end

it "should have sub folders" do
@folder_names.should have_key("ExMerge - Meyers, Albert")
@folder_names.should have_key("meyers-a")
@folders.should have_key("ExMerge - Meyers, Albert")
@folders.should have_key("meyers-a")
end

it "should have content counts" do
@folder_names["Deleted Items"].getContentCount.should eql(1130)
@folder_names["Inbox"].getContentCount.should eql(22)
@folders["Deleted Items"].getContentCount.should eql(1130)
@folders["Inbox"].getContentCount.should eql(22)
end

it "should have a path" do
@folder_names["Inbox"].path.should eql("/Top of Personal Folders/Inbox")
@folders["Inbox"].path.should eql("/Top of Personal Folders/Inbox")
end

it "should have a hash string" do
@folder_names["Inbox"].human_id.should eql("no-collection:/Users/nmurray/projects/enron/software/pst.rb/spec/../test/data/albert_meyers_000.pst:/Top of Personal Folders/Inbox")
@folder_names["Inbox"].hash_string.should eql("767d47f8134cd5c14786efd0274586b1065278e7")
@folders["Inbox"].human_id.should eql("no-collection:/Users/nmurray/projects/enron/software/pst.rb/spec/../test/data/albert_meyers_000.pst:/Top of Personal Folders/Inbox")
@folders["Inbox"].hash_string.should eql("767d47f8134cd5c14786efd0274586b1065278e7")
end

end

context "with emails" do
context "PSTMessage" do
before(:all) do
@folders = @pstfile.root.sub_folders.inject({}){|acc,f|
acc[f.name] = f
acc
}
@folder = @folders["Deleted Items"]
@email = @folder.children.first
end
Expand All @@ -79,8 +81,48 @@
it "should have an id" do
@email.human_id.should eql("no-collection:/Users/nmurray/projects/enron/software/pst.rb/spec/../test/data/albert_meyers_000.pst:/Top of Personal Folders/Deleted Items:Fri Apr 06 01:02:00 PDT 2001:<ML1KCRAP2G52RFDSYPSFSAQ0J30PDFMMB@zlsvr22>:Re: deal 539246.1 REliant HLP dms 7634/7636")
@email.hash_string.should eql("c512b175785b28532146be7cdb165a5bbee4d130")
pp @email.pretty_string
# pp @email.pretty_string
end

it "should have the number of recipients" do
@email.getNumberOfRecipients.should eql(1)
end

it "should iterate over recipients" do
@email.recipients.count.should eql(1)
#@email.recipients.each do |r|
# pp r
#end
end

end

describe "PSTRecipient" do
before(:all) do
@folder = @folders["Deleted Items"]
@email = @folder.children.take(5).last

@recipients = @email.recipients.inject({}){|acc,r|
acc[r.name] = r
acc
}
end

it "should have a name" do
@recipients.should have_key("Volume Management")
@recipients.should have_key("Williams III")
@recipients.should have_key("Bill")
end

it "should have an email field" do
@recipients["Williams III"].email.should eql("Williams III")
@recipients["Bill"].email.should eql("/O=ENRON/OU=NA/CN=RECIPIENTS/CN=Bwillia5")
end

it "should have a hash string" do
@recipients["Bill"].hash_string.should eql("f161dd2a45952784c440bd5879684ae89b8b0523")
end

end

end

0 comments on commit 50cdf5b

Please sign in to comment.