aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xapp/helpers/link_to_helper.rb3
-rw-r--r--app/views/general/search.html.erb27
-rw-r--r--lib/mail_handler/backends/mail_extensions.rb20
-rw-r--r--spec/fixtures/files/unrecognized-encoding-mail.email36
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb5
5 files changed, 71 insertions, 20 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 238a36ce4..5533402c5 100755
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -218,9 +218,6 @@ module LinkToHelper
return url
end
- def search_link(query, variety_postfix = nil, sort_postfix = nil, advanced = nil)
- link_to h(query), search_url(query)
- end
def search_path(query, options = {})
search_url(query, options.merge(:only_path => true))
diff --git a/app/views/general/search.html.erb b/app/views/general/search.html.erb
index 6234687f2..d526a93c0 100644
--- a/app/views/general/search.html.erb
+++ b/app/views/general/search.html.erb
@@ -35,15 +35,23 @@
<% end %>
</div>
<% else %>
- <%= form_tag(request.url, {:method => "get", :id => "search_form"}) do %>
+
+
+ <%= form_tag(search_redirect_path, {:method => "get", :id => "search_form"}) do %>
<p>
<%= text_field_tag 'query', params[:query], { :size => 40, :title => "type your search term here" } %>
+
+ <%= submit_tag _("Search") %>
+ <%= link_to(_("Advanced search"), advanced_search_path) %>
+ </p>
+ <% end %>
+ <%= form_tag(request.url, {:method => "get", :id => "filter_form"}) do %>
+ <p>
<%= hidden_field_tag 'sortby', @inputted_sortby %>
<% if @bodies %>
<%= hidden_field_tag 'bodies', 1 %>
<% end %>
- <%= submit_tag _("Search") %>
- <%= link_to(_("Advanced search"), advanced_search_path) %>
+
</p>
<div id="common-subfilters">
@@ -63,18 +71,6 @@
<%= "|" unless variety == labels.last[0]%>
<% end %>
</div>
-
- <% if false %>
- <%-# Commented out for now as tags are of limited use when users can't see them. This will change in the future! -%>
- <% if @variety_postfix != "users" %>
- <div>
- <%= label_tag(:query, _("Tags (separated by a space):")) %><%= text_field_tag(:tags, params[:tags], { :size => 20 }) %>
- <% for tag in InfoRequest.get_tags %>
- <%= tag.name_and_value %>
- <% end %>
- </div>
- <% end %>
- <% end %>
</div>
<% if @variety_postfix == "requests" %>
@@ -139,7 +135,6 @@
<% end %>
<div style="clear:both;"></div>
-
<% if @total_hits == 0 %>
<h2><%=@title %></h2>
<% end %>
diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb
index 322c49bb5..a5b6bc97e 100644
--- a/lib/mail_handler/backends/mail_extensions.rb
+++ b/lib/mail_handler/backends/mail_extensions.rb
@@ -78,7 +78,10 @@ module Mail
# invalid character at the end of the string, even
# with UTF-8//IGNORE:
# http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
- str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str + " ")[0...-4]
+ begin
+ str = Iconv.conv('UTF-8//IGNORE', fix_encoding(encoding), str + " ")[0...-4]
+ rescue Iconv::InvalidEncoding
+ end
end
str
end
@@ -114,6 +117,21 @@ module Mail
end
class Ruby19
+ def Ruby19.b_value_decode(str)
+ match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m)
+ if match
+ encoding = match[1]
+ str = Ruby19.decode_base64(match[2])
+ # Rescue an ArgumentError arising from an unknown encoding.
+ begin
+ str.force_encoding(fix_encoding(encoding))
+ rescue ArgumentError
+ end
+ end
+ decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
+ decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
+ end
+
def Ruby19.q_value_decode(str)
match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m)
if match
diff --git a/spec/fixtures/files/unrecognized-encoding-mail.email b/spec/fixtures/files/unrecognized-encoding-mail.email
new file mode 100644
index 000000000..266a90fbc
--- /dev/null
+++ b/spec/fixtures/files/unrecognized-encoding-mail.email
@@ -0,0 +1,36 @@
+From xxx@example.com Fri Jun 21 07:50:52 2013
+Return-path: <xxx@example.com>
+Envelope-to: xxx@example.com
+Delivery-date: Fri, 21 Jun 2013 07:50:52 +0100
+Message-ID: <185C0D48380D7AE612DD38A527D5EAF2@tmvbalem>
+From: "cttlqvx" <xxx@example.com>
+To: <xxx@example.com>
+Subject: =?hz-gb-2312?B?fntPck9ISXpWQn59c3J5dW95d3MoQUQpICAgIA==?=
+Date: Fri, 21 Jun 2013 14:48:20 +0800
+MIME-Version: 1.0
+Content-Type: multipart/related;
+ type="multipart/alternative";
+ boundary="----=_NextPart_000_02ED_01A0462A.178683F0"
+X-Priority: 1
+X-MSMail-Priority: High
+X-Mailer: Microsoft Outlook Express 6.00.2900.5512
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
+
+This is a multi-part message in MIME format.
+
+------=_NextPart_000_02ED_01A0462A.178683F0
+Content-Type: multipart/alternative;
+ boundary="----=_NextPart_001_09EC_01A0462A.178683F0"
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/plain;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+
+------=_NextPart_001_09EC_01A0462A.178683F0
+Content-Type: text/html;
+ charset="hz-gb-2312"
+Content-Transfer-Encoding: base64
+
+------=_NextPart_001_09EC_01A0462A.178683F0--
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index d6e7ba5d2..241ce06c1 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -60,6 +60,11 @@ describe 'when creating a mail object from raw data' do
body.should match(/ \xe2\x80\x93 /)
end
+ it 'should not error on a subject line with an encoding encoding not recognized by iconv' do
+ mail = get_fixture_mail('unrecognized-encoding-mail.email')
+ lambda{ mail.subject }.should_not raise_error
+ end
+
end
describe 'when asked for the from name' do