mysociety / alaveteli

Provide a Freedom of Information request system for your jurisdiction
https://alaveteli.org
Other
389 stars 195 forks source link

Extract quoted section removal to library and make quoted section markers translatable #2662

Open garethrees opened 9 years ago

garethrees commented 9 years ago

@petterreinholdtsen submitted https://github.com/mysociety/alaveteli/pull/2654 to add a quoted section marker in their language.

I don't see the benefit in continually adding additional strings to this method, as many of them will be irrelevant for a given install.

The particular markers are theme-specific, so we should supply an interface for them to be customised from a theme. This would have the benefit of reducing the performance cost of processing messages.

A nice interface to add markers would be something along the lines of:

Alaveteli::QuotedSectionRemoval.end_of_message_strings << '''----*\s*Opprinnelig melding\s*----*'''

Usage of the library in alaveteli core should look something like:

class IncomingMessage
  def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION")
   MessageFilter::RemoveQuotedSection.new(text, replacement).apply
  end
end

There also looks like some special handling for other UK-specific stuff.

It would be awesome if you could build up a filter chain for sanitising your messages:

# config/initializers/my_theme_message_filtering.rb

IncomingMessage.filter_chain = [ RemoveLotusQuotes,
                                 RemoveQuotedSection,
                                 RemoveBBCFurtherCommsConsent,
                                 HideEmailAddresses ]
garethrees commented 9 years ago

This is a similar problem to #2551.

garethrees commented 9 years ago
petterreinholdtsen commented 8 years ago

I revisited #2654 today, to see what I could to do make the message view nicer on Mimes brønn, but reading through this issue again leave me mystified about how to solve it. Is there some documentation somewhere explaining how to customize the original_message setting?

garethrees commented 8 years ago

Hi Petter,

You can override the full method in your theme.

# THEME_ROOT/lib/model_patches.rb

# -*- encoding : utf-8 -*-
Rails.configuration.to_prepare do
  InfoRequest.class_eval do
    def self.remove_quoted_sections(text, replacement = "FOLDED_QUOTED_SECTION")
      # method body omitted for demonstration
    end
  end
end

I tend to copy the full method from the commit you're deployed at, then you can make the change in 99aeb8ff1ed96bf437183e5513b6ac8db7927f77 against the overridden version in the theme.

Here's an example we've overridden in WDTK:

garethrees commented 6 years ago

Or try https://github.com/mysociety/alaveteli/issues/1722