Hello all
Where I work some people use Blackberries, and they don''t add an
In-Reply-To header to email, so I do quite a bit of manual re-threading
using the ''#'' key. I''d like to not have to do it so
much, but I don''t
want to just thread all mail by subject, as the blackberry messages are
not /so/ frequent. So I''ve put the below in my before-add-message.rb
hook that others might find useful.
The code:
* only runs if the message is from a blackberry and the subject
indicates it is a reply.
* looks for the most recent message that matches the subject, and adds a
ref to that message, so they should then be in the same thead.
Any feedback or improvements appreciated.
Hamish
subj = message.subj.downcase
# if from a blackberry and is a reply, then try to find a matching thread
if message.id.downcase.include?(''blackberry'') &&
Message.subj_is_reply?(subj)
thread_subj = Message.normalize_subj subj
query = Index.parse_query "subject:\"#{thread_subj}\""
# the query returns newest match first
first_id = Index.each_id(query) { |id| break id }
message.add_ref(first_id) unless first_id.nil?
end