Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] First draft of attachment processing for more gmail style searches
@ 2008-02-25 20:50 Marcus Williams
  2008-02-28 17:40 ` William Morgan
  0 siblings, 1 reply; 9+ messages in thread
From: Marcus Williams @ 2008-02-25 20:50 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-04-02 21:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-25 20:50 [sup-talk] [PATCH] First draft of attachment processing for more gmail style searches Marcus Williams
2008-02-28 17:40 ` William Morgan
2008-02-28 21:15   ` Marcus Williams
2008-03-02 18:08     ` William Morgan
2008-03-05 10:01       ` Marcus Williams
2008-03-08 22:02         ` William Morgan
2008-03-23 21:13           ` Marcus Williams
2008-04-02 20:51             ` William Morgan
2008-04-02 21:16               ` vasudeva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox