Class: Heathrow::Notmuch
- Inherits:
-
Object
- Object
- Heathrow::Notmuch
- Defined in:
- lib/heathrow/notmuch.rb
Constant Summary collapse
- NOTMUCH_BIN =
'/usr/bin/notmuch'
Class Method Summary collapse
- .available? ⇒ Boolean
-
.count(query) ⇒ Object
Count results for a query.
-
.search(query, limit: 50) ⇒ Object
Search for messages, returns structured results.
-
.search_files(query) ⇒ Object
Search for messages matching query, returns array of file paths.
-
.thread(message_id) ⇒ Object
Get thread containing a message.
Class Method Details
.available? ⇒ Boolean
8 9 10 |
# File 'lib/heathrow/notmuch.rb', line 8 def self.available? File.executable?(NOTMUCH_BIN) end |
.count(query) ⇒ Object
Count results for a query
39 40 41 42 43 |
# File 'lib/heathrow/notmuch.rb', line 39 def self.count(query) return 0 unless available? cmd = "#{NOTMUCH_BIN} count #{Shellwords.escape(query)}" `#{cmd} 2>/dev/null`.strip.to_i end |
.search(query, limit: 50) ⇒ Object
Search for messages, returns structured results
21 22 23 24 25 26 27 28 |
# File 'lib/heathrow/notmuch.rb', line 21 def self.search(query, limit: 50) return [] unless available? cmd = "#{NOTMUCH_BIN} search --format=json --limit=#{limit} #{Shellwords.escape(query)}" output = `#{cmd} 2>/dev/null` JSON.parse(output) rescue JSON::ParserError [] end |
.search_files(query) ⇒ Object
Search for messages matching query, returns array of file paths
13 14 15 16 17 18 |
# File 'lib/heathrow/notmuch.rb', line 13 def self.search_files(query) return [] unless available? cmd = "#{NOTMUCH_BIN} search --output=files #{Shellwords.escape(query)}" output = `#{cmd} 2>/dev/null` output.split("\n").reject(&:empty?) end |
.thread(message_id) ⇒ Object
Get thread containing a message
31 32 33 34 35 36 |
# File 'lib/heathrow/notmuch.rb', line 31 def self.thread() return [] unless available? cmd = "#{NOTMUCH_BIN} search --output=files --format=text #{Shellwords.escape("thread:{id:#{}}")}" output = `#{cmd} 2>/dev/null` output.split("\n").reject(&:empty?) end |