From: marcus-sup@bar-coded.net (Marcus Williams)
Subject: [sup-talk] [PATCH] First draft of attachment processing for more gmail style searches
Date: Mon, 25 Feb 2008 20:50:09 +0000 [thread overview]
Message-ID: <1203972458-sup-5906@tomsk> (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
next reply other threads:[~2008-02-25 20:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-25 20:50 Marcus Williams [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1203972458-sup-5906@tomsk \
--to=marcus-sup@bar-coded.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox