lib/sup/index.rb in sup-0.5 vs lib/sup/index.rb in sup-0.6

- old
+ new

@@ -145,10 +145,11 @@ field_infos.add_field :source_id field_infos.add_field :source_info field_infos.add_field :date, :index => :untokenized field_infos.add_field :body field_infos.add_field :label + field_infos.add_field :attachments field_infos.add_field :subject field_infos.add_field :from field_infos.add_field :to field_infos.add_field :refs field_infos.add_field :snippet, :index => :no, :term_vector => :no @@ -221,10 +222,11 @@ :source_info => m.source_info, :date => (entry[:date] || m.date.to_indexable_s), :body => (entry[:body] || m.indexable_content), :snippet => snippet, # always override :label => labels.uniq.join(" "), + :attachments => (entry[:attachments] || m.attachments.uniq.join(" ")), :from => (entry[:from] || (m.from ? m.from.indexable_content : "")), :to => (entry[:to] || (m.to + m.cc + m.bcc).map { |x| x.indexable_content }.join(" ")), :subject => (entry[:subject] || wrap_subj(Message.normalize_subj(m.subj))), :refs => (entry[:refs] || (m.refs + m.replytos).uniq.join(" ")), } @@ -463,11 +465,11 @@ ## search spam messages, then not adding it won't have any effect. extraopts[:load_spam] = true if subs =~ /\blabel:spam\b/ extraopts[:load_deleted] = true if subs =~ /\blabel:deleted\b/ ## gmail style "is" operator - subs = subs.gsub(/\b(is):(\S+)\b/) do + subs = subs.gsub(/\b(is|has):(\S+)\b/) do field, label = $1, $2 case label when "read" "-label:unread" when "spam" @@ -476,9 +478,22 @@ when "deleted" extraopts[:load_deleted] = true "label:deleted" else "label:#{$2}" + end + end + + ## gmail style attachments "filename" and "filetype" searches + subs = subs.gsub(/\b(filename|filetype):(\((.+?)\)\B|(\S+)\b)/) do + field, name = $1, ($3 || $4) + case field + when "filename" + Redwood::log "filename - translated #{field}:#{name} to attachments:(#{name.downcase})" + "attachments:(#{name.downcase})" + when "filetype" + Redwood::log "filetype - translated #{field}:#{name} to attachments:(*.#{name.downcase})" + "attachments:(*.#{name.downcase})" end end if $have_chronic chronic_failure = false