From mboxrd@z Thu Jan 1 00:00:00 1970 From: marcus-sup@bar-coded.net (Marcus Williams) Date: Mon, 25 Feb 2008 20:50:09 +0000 Subject: [sup-talk] [PATCH] First draft of attachment processing for more gmail style searches Message-ID: <1203972458-sup-5906@tomsk> This patch adds the search terms "filename" and "filetype". This changes the index so requires a sup-sync --all to work properly, but should work on all new messages without it. You can now search for something like "from:phil* filetype:pdf" for all messages from a person called phil with a pdf attachment. You can also specify a file name for the attachment with "filename:(this is a filename with spaces.txt)". You can use wildcards in the filename ("filename:test*.pdf"). --- lib/sup/index.rb | 15 +++++++++++++++ lib/sup/message.rb | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index f812fc7..4205f2a 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -147,6 +147,7 @@ EOS 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 @@ -198,6 +199,7 @@ EOS :body => (entry[:body] || m.indexable_content), :snippet => snippet, # always override :label => m.labels.uniq.join(" "), # always override + :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(m.subj)), @@ -452,6 +454,19 @@ protected 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 subs = subs.gsub(/\b(before|on|in|during|after):(\((.+?)\)\B|(\S+)\b)/) do diff --git a/lib/sup/message.rb b/lib/sup/message.rb index 6a2a9c4..480f52c 100644 --- a/lib/sup/message.rb +++ b/lib/sup/message.rb @@ -37,7 +37,7 @@ class Message DEFAULT_SENDER = "(missing sender)" attr_reader :id, :date, :from, :subj, :refs, :replytos, :to, :source, - :cc, :bcc, :labels, :list_address, :recipient_email, :replyto, + :cc, :bcc, :labels, :attachments, :list_address, :recipient_email, :replyto, :source_info, :list_subscribe, :list_unsubscribe bool_reader :dirty, :source_marked_read, :snippet_contains_encrypted_content @@ -54,6 +54,7 @@ class Message @dirty = false @encrypted = false @chunks = nil + @attachments = [] ## we need to initialize this. see comments in parse_header as to ## why. @@ -405,6 +406,10 @@ private ## if there's a filename, we'll treat it as an attachment. if filename + # add this to the attachments list if its not a generated html + # attachment (should we allow images with generated names?). + # Lowercase the filename because searches are easier that way + @attachments.push filename.downcase unless filename =~ /^sup-attachment-/ [Chunk::Attachment.new(m.header.content_type, filename, m, sibling_types)] ## otherwise, it's body text -- 1.5.3.7