Skip to content

Commit

Permalink
* mail -> message.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/groonga/examples@850 2d713de4-4fbb-4d10-8406-bb89ef438322
  • Loading branch information
kou committed Nov 30, 2009
1 parent 00754fc commit 8757672
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
24 changes: 15 additions & 9 deletions message-archiver/archiver.rb
Expand Up @@ -12,26 +12,32 @@
class Archiver
def initialize
@context = Groonga::Context.default
@mails = @context["mails"]
@messages = @context["messages"]
@people = @context["people"]
@names = @context["names"]
end

def feed(data)
mail = Mail.read(data)
_mail = @mails.add
_mail["subject"] = NKF.nkf("-w", mail.subject.value)
_mail["date"] = Time.parse(mail.date.value)
def feed(path)
data = File.read(path)
mail = Mail.new(data)
message = @messages.add
message["subject"] = to_utf8(mail.subject.value)
message["date"] = Time.parse(mail.date.value)
from = mail.from.send(:tree).addresses[0]
from_person = @people[from.address] || @people.add(from.address)
from_name = from.display_name
if from_name
from_name = NKF.nkf("-w", from_name)
from_name = to_utf8(from_name)
from_name = @names.add(:value => from_name)
end
from_person.append("names", from_name) if from_name
_mail["from"] = from_person
_mail["body"] = NKF.nkf("-w", mail.body.raw_source)
message["from"] = from_person
message["body"] = to_utf8(mail.body.raw_source)
end

private
def to_utf8(string)
NKF.nkf("-w", string)
end
end

Expand Down
6 changes: 3 additions & 3 deletions message-archiver/models.rb
Expand Up @@ -49,7 +49,7 @@ def ensure_schema
table.short_text("value")
end

schema.create_table("mails") do |table|
schema.create_table("messages") do |table|
table.short_text("subject")
table.time("date")
table.time("received_date")
Expand All @@ -73,8 +73,8 @@ def ensure_schema
:key_normalize => true,
:sub_records => true,
:default_tokenizer => "TokenBigram") do |table|
table.index("mails.subject")
table.index("mails.body")
table.index("messages.subject")
table.index("messages.body")
table.index("headers.value")
table.index("names.value")
table.index("attachments.name")
Expand Down
2 changes: 1 addition & 1 deletion message-archiver/public/style.css
Expand Up @@ -174,7 +174,7 @@ span.keyword
font-weight: bold;
}

ol.mails li
ol.messages li
{
margin-top: 5px;
margin-bottom: 5px;
Expand Down
10 changes: 5 additions & 5 deletions message-archiver/searcher.rb
Expand Up @@ -11,22 +11,22 @@ class Searcher < Sinatra::Base
set :static, true

before do
@mails = Groonga::Context.default["mails"]
@messages = Groonga::Context.default["messages"]
end

get "/" do
@mails = @mails.sort([["date", :descending]])
@messages = @messages.sort([["date", :descending]])
haml :index
end

get "/:id" do |id|
@mail = Groonga::Record.new(@mails, Integer(id))
@message = Groonga::Record.new(@messages, Integer(id))
haml :show
end

get "/search/" do
@query = params[:query]
@mails = @mails.select do |record|
@messages = @messages.select do |record|
record["body"].match(@query)
end
haml :search
Expand All @@ -37,7 +37,7 @@ def highlight(body)
query = params[:query]
return html_escape(body) if query.nil?

expression_builder = Groonga::RecordExpressionBuilder.new(@mails, nil)
expression_builder = Groonga::RecordExpressionBuilder.new(@messages, nil)
expression_builder.query = query
expression_builder.default_column = "body"
expression = expression_builder.build
Expand Down
6 changes: 3 additions & 3 deletions message-archiver/views/index.haml
@@ -1,6 +1,6 @@
%h2 メール一覧

%ol.mails
- @mails.each do |mail|
%ol.messages
- @messages.each do |message|
%li
%a{"href" => "/#{mail.id}"}&= mail["subject"]
%a{"href" => "/#{message.id}"}&= message["subject"]
8 changes: 4 additions & 4 deletions message-archiver/views/search.haml
@@ -1,8 +1,8 @@
%h2 検索結果

.result
- @mails.each do |mail|
.mail
- @messages.each do |message|
.message
%h3
%a{"href" => "/#{mail.id}?query=#{@query}"}&= mail["subject"]
%p.snippet= snippet(mail)
%a{"href" => "/#{message.id}?query=#{@query}"}&= message["subject"]
%p.snippet= snippet(message)
10 changes: 5 additions & 5 deletions message-archiver/views/show.haml
@@ -1,14 +1,14 @@
%h2&= @mail["subject"]
%h2&= @message["subject"]

%dl.headers
%dt 送信者
%dd &nbsp;#{html_escape(@mail[".from.names.value"])}
%dd &nbsp;#{html_escape(@message[".from.names.value"])}
%dt 受信者
%dd
&nbsp;
- @mail["to"].each do |to|
- @message["to"].each do |to|
= to
%dt 送信日
%dd&= @mail["date"]
%dd&= @message["date"]

%pre.body= highlight(@mail["body"])
%pre.body= highlight(@message["body"])

0 comments on commit 8757672

Please sign in to comment.