* [sup-talk] [PATCH] Gmail style attachment processing
@ 2008-04-29 20:45 Marcus Williams
2008-04-29 21:02 ` John Bent
2008-05-25 4:10 ` William Morgan
0 siblings, 2 replies; 4+ messages in thread
From: Marcus Williams @ 2008-04-29 20:45 UTC (permalink / raw)
This patch adds:
* the search terms "filename" and "filetype"
* hidden/reserved attachment label to track attachments
* new flag on thread index mode to denote an attachment '@'
* a "has:attachment" search query.
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"). You can search for all messages from someone
with attachments using "from:someone has:attachment"
It will require sup-sync -all to work against all sources, but attempts
to be backwards compatable with non-synced sources.
---
lib/sup/index.rb | 17 ++++++++++++++++-
lib/sup/label.rb | 6 +++---
lib/sup/message.rb | 8 +++++++-
lib/sup/modes/thread-index-mode.rb | 3 ++-
4 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
index f1ede55..12385d3 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
@@ -223,6 +224,7 @@ EOS
: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))),
@@ -465,7 +467,7 @@ protected
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"
@@ -481,6 +483,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/label.rb b/lib/sup/label.rb
index 4afc0f9..716ef98 100644
--- a/lib/sup/label.rb
+++ b/lib/sup/label.rb
@@ -5,13 +5,13 @@ class LabelManager
## labels that have special semantics. user will be unable to
## add/remove these via normal label mechanisms.
- RESERVED_LABELS = [ :starred, :spam, :draft, :unread, :killed, :sent, :deleted, :inbox ]
+ RESERVED_LABELS = [ :starred, :spam, :draft, :unread, :killed, :sent, :deleted, :inbox, :attachment ]
## labels which it nonetheless makes sense to search for by
- LISTABLE_RESERVED_LABELS = [ :starred, :spam, :draft, :sent, :killed, :deleted, :inbox ]
+ LISTABLE_RESERVED_LABELS = [ :starred, :spam, :draft, :sent, :killed, :deleted, :inbox, :attachment ]
## labels that will typically be hidden from the user
- HIDDEN_RESERVED_LABELS = [ :starred, :unread ]
+ HIDDEN_RESERVED_LABELS = [ :starred, :unread, :attachment ]
def initialize fn
@fn = fn
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
index 249b6c6..5fc91de 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,11 @@ 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-/
+ add_label :attachment unless filename =~ /^sup-attachment-/
[Chunk::Attachment.new(m.header.content_type, filename, m, sibling_types)]
## otherwise, it's body text
diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb
index 7a0b815..598c1ea 100644
--- a/lib/sup/modes/thread-index-mode.rb
+++ b/lib/sup/modes/thread-index-mode.rb
@@ -713,7 +713,8 @@ protected
from +
[
[subj_color, size_widget_text],
- [:to_me_color, dp ? " >" : (p ? ' +' : " ")],
+ [:to_me_color, t.labels.member?(:attachment) ? "@" : " "],
+ [:to_me_color, dp ? ">" : (p ? '+' : " ")],
[subj_color, t.subj + (t.subj.empty? ? "" : " ")],
] +
(t.labels - @hidden_labels).map { |label| [:label_color, "+#{label} "] } +
--
1.5.4.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [sup-talk] [PATCH] Gmail style attachment processing
2008-04-29 20:45 [sup-talk] [PATCH] Gmail style attachment processing Marcus Williams
@ 2008-04-29 21:02 ` John Bent
2008-04-29 21:12 ` Marcus Williams
2008-05-25 4:10 ` William Morgan
1 sibling, 1 reply; 4+ messages in thread
From: John Bent @ 2008-04-29 21:02 UTC (permalink / raw)
Excerpts from Marcus Williams's message of Tue Apr 29 14:45:39 -0600 2008:
> This patch adds:
>
> * the search terms "filename" and "filetype"
> * hidden/reserved attachment label to track attachments
> * new flag on thread index mode to denote an attachment '@'
> * a "has:attachment" search query.
This is excellent. Thanks very much! I don't like doing the patches
myself but I'm looking forward to this getting into next.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [sup-talk] [PATCH] Gmail style attachment processing
2008-04-29 21:02 ` John Bent
@ 2008-04-29 21:12 ` Marcus Williams
0 siblings, 0 replies; 4+ messages in thread
From: Marcus Williams @ 2008-04-29 21:12 UTC (permalink / raw)
On 29.4.2008, John Bent wrote:
> This is excellent. Thanks very much! I don't like doing the patches
> myself but I'm looking forward to this getting into next.
:) I couldnt live without it in gmail so I had to have it in sup! I'd
like to have added the regexanalyser suggested by William so that I
could have a list of attachments on the message object just by
querying the index but this affected searching usability a bit (I get
a lot of attachments with spaces in and using the regexanalyser meant
that you couldnt search for single words from that attachment without
wildcards which didnt seem right). I may work on that a bit and add to
this patch but for now it works really well for my usage.
Marcus
^ permalink raw reply [flat|nested] 4+ messages in thread
* [sup-talk] [PATCH] Gmail style attachment processing
2008-04-29 20:45 [sup-talk] [PATCH] Gmail style attachment processing Marcus Williams
2008-04-29 21:02 ` John Bent
@ 2008-05-25 4:10 ` William Morgan
1 sibling, 0 replies; 4+ messages in thread
From: William Morgan @ 2008-05-25 4:10 UTC (permalink / raw)
Very nice. Published as 'attachments' and merged into next. Thanks!
--
William <wmorgan-sup at masanjin.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-25 4:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-29 20:45 [sup-talk] [PATCH] Gmail style attachment processing Marcus Williams
2008-04-29 21:02 ` John Bent
2008-04-29 21:12 ` Marcus Williams
2008-05-25 4:10 ` William Morgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox