Commit f606cbe76f7b5a1ce885fa619d780951c77e1549

  • avatar
  • Rich Lane <rlane @cl…b.cc.cmu.edu> (Committer)
  • Mon Mar 15 06:00:12 CET 2010
  • avatar
  • Michael Stapelberg (Author)
  • Tue Mar 09 23:56:02 CET 2010
Use multiple body arrays when calling before-edit for each reply type

This allows for before-edit hooks which modify the body of the message
based on the different headers (previously, they could only modify
headers).

As an example, I use it to sign mail in english if one of the recipients
(not *the* recipient, but one of them) is speaking english.
  
4242
4343 def initialize message, type_arg=nil
4444 @m = message
45 @edited = false
4546
4647 ## it's important to put this early because it forces a read of
4748 ## the full headers (most importantly the list-post header, if
151151 :recipient
152152 end)
153153
154 @bodies = {}
154155 @headers.each do |k, v|
155 HookManager.run "before-edit", :header => v, :body => body
156 @bodies[k] = body
157 HookManager.run "before-edit", :header => v, :body => @bodies[k]
156158 end
157159
158 super :header => @headers[@type_selector.val], :body => body, :twiddles => false
160 super :header => @headers[@type_selector.val], :body => @bodies[@type_selector.val], :twiddles => false
159161 add_selector @type_selector
160162 end
161163
167167 super
168168 if @headers[@type_selector.val] != self.header
169169 self.header = @headers[@type_selector.val]
170 self.body = @bodies[@type_selector.val] unless @edited
170171 update
171172 end
172173 end
176176 super
177177 if @headers[@type_selector.val] != self.header
178178 self.header = @headers[@type_selector.val]
179 self.body = @bodies[@type_selector.val] unless @edited
179180 update
180181 end
181182 end
193193 end
194194
195195 def handle_new_text new_header, new_body
196 if new_body != @bodies[@type_selector.val]
197 @bodies[@type_selector.val] = new_body
198 @edited = true
199 end
196200 old_header = @headers[@type_selector.val]
197201 if new_header.size != old_header.size || old_header.any? { |k, v| new_header[k] != v }
198202 @type_selector.set_to :user