aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb3
-rw-r--r--app/models/incoming_message.rb13
2 files changed, 12 insertions, 4 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 82cf76cc8..65ab168e9 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -4,13 +4,14 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: request_controller.rb,v 1.7 2007-10-30 14:03:27 francis Exp $
+# $Id: request_controller.rb,v 1.8 2007-10-30 14:13:46 francis Exp $
class RequestController < ApplicationController
def show
@info_request = InfoRequest.find(params[:id])
@correspondences = @info_request.outgoing_messages + @info_request.incoming_messages
+ @correspondences.sort! { |a,b| a.sent_at <=> b.sent_at }
end
def list
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index fe70fb783..56668582a 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -1,11 +1,11 @@
# models/incoming_message.rb:
-# A message from really anybody to be logged with a request. e.g.
-# A response from the public body.
+# An (email) message from really anybody to be logged with a request. e.g. A
+# response from the public body.
#
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: incoming_message.rb,v 1.2 2007-10-30 14:03:28 francis Exp $
+# $Id: incoming_message.rb,v 1.3 2007-10-30 14:13:46 francis Exp $
class IncomingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -13,15 +13,22 @@ class IncomingMessage < ActiveRecord::Base
validates_presence_of :raw_data
+ # We store the raw email in the database, and parse it into
+ # a structured TMail every time we get it out again.
def after_initialize
@mail = TMail::Mail.parse(self.raw_data)
@mail.base64_decode
end
+
+ # Return the structured TMail::Mail object
+ # Documentation at http://i.loveruby.net/en/projects/tmail/doc/
def mail
@mail
end
+ # Return date mail was sent
def sent_at
+ # Use date it arrived (created_at) if mail itself doesn't have Date: header
self.mail.date || self.created_at
end
end