aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrancis <francis>2008-06-12 14:30:08 +0000
committerfrancis <francis>2008-06-12 14:30:08 +0000
commit5e2eadde3a053250e69eae78171f2711a525a184 (patch)
treeea8fa29e868efbf97301f75bd9c078d6b579522d
parent290728b02b9398e6c922ace36154443dd960b388 (diff)
Fix bug with display of emails that are just attachments.
-rw-r--r--app/models/incoming_message.rb47
-rw-r--r--todo.txt5
2 files changed, 31 insertions, 21 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 77ed14edf..0fe12b96a 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -18,7 +18,7 @@
# 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.110 2008-06-09 14:21:49 francis Exp $
+# $Id: incoming_message.rb,v 1.111 2008-06-12 14:30:08 francis Exp $
# TODO
# Move some of the (e.g. quoting) functions here into rblib, as they feel
@@ -398,17 +398,22 @@ text = IncomingMessage.mask_string_multicharset(text, 'request-144-a724c835@what
# Returns body text from main text part of email, converted to UTF-8
def get_main_body_text_internal
main_part = get_main_body_text_part
- text = main_part.body
- text_charset = main_part.charset
- if main_part.content_type == 'text/html'
- # XXX could use better HTML to text conversion than this!
- # (it only matters for emails without a text part, so not a massive deal
- # e.g. http://www.whatdotheyknow.com/request/35/response/177 )
- text.gsub!(/<br[^>]+>/, "\n")
- text.gsub!(/<p[^>]+>/, "\n\n")
- text.gsub!(/<div[^>]+>/, "\n\n")
- text.gsub!(/<\/?[^>]*>/, "")
- text = HTMLEntities.decode_entities(text)
+ if main_part.nil?
+ text = "[ Email has no body, please see attachments ]"
+ text_charset = "utf-8"
+ else
+ text = main_part.body
+ text_charset = main_part.charset
+ if main_part.content_type == 'text/html'
+ # XXX could use better HTML to text conversion than this!
+ # (it only matters for emails without a text part, so not a massive deal
+ # e.g. http://www.whatdotheyknow.com/request/35/response/177 )
+ text.gsub!(/<br[^>]+>/, "\n")
+ text.gsub!(/<p[^>]+>/, "\n\n")
+ text.gsub!(/<div[^>]+>/, "\n\n")
+ text.gsub!(/<\/?[^>]*>/, "")
+ text = HTMLEntities.decode_entities(text)
+ end
end
# Charset conversion, turn everything into UTF-8
@@ -456,7 +461,7 @@ text = IncomingMessage.mask_string_multicharset(text, 'request-144-a724c835@what
return text
end
- # Returns part which contains main body text
+ # Returns part which contains main body text, or nil if there isn't one
def get_main_body_text_part
leaves = get_attachment_leaves
@@ -474,9 +479,19 @@ text = IncomingMessage.mask_string_multicharset(text, 'request-144-a724c835@what
end
end
- # ... or if none, just first part (covers cases of one part, not
- # labelled as text - not sure what the better way to handle this is)
- return leaves[0]
+ # ... or if none, consider first part
+ p = leaves[0]
+ # if it is a known type then don't use it, return no body (nil)
+ if mimetype_to_extension(p.content_type)
+ # this is guess of case where there are only attachments, no body text
+ # e.g. http://www.whatdotheyknow.com/request/cost_benefit_analysis_for_real_n
+ return nil
+ end
+ # otherwise return it assuming it is text (sometimes you get things
+ # like binary/octet-stream, or the like, which are really text - XXX if
+ # you find an example, put URL here - perhaps we should be always returning
+ # nil in this case)
+ return p
end
# Returns attachments that are uuencoded in main body part
def get_main_body_text_uudecode_attachments
diff --git a/todo.txt b/todo.txt
index a262f9d85..9ca4b7978 100644
--- a/todo.txt
+++ b/todo.txt
@@ -63,11 +63,6 @@ Show list of popular tracks somewhere (finds most popular requests in a way)
user/show.rhtml sidebar vs. generic sidebar? (ask Tommy)
Needs tagline that v. quickly explains what site is on each page
-This one is a word doc by itself:
-http://www.whatdotheyknow.com/request/cost_benefit_analysis_for_real_n
-
-rename delete_old_sessions
-
Later
=====