aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-11-07 14:57:41 +0100
committermms <git@sapka.me>2024-11-07 14:57:41 +0100
commitacc8415d7109e8fb45bbfcd8cf545ebcf5b5d16a (patch)
tree1c8b1ec2efbd7602fa972aa7dbd6e8baa63ef515 /lib
init spike
Diffstat (limited to 'lib')
-rw-r--r--lib/.ruby-version1
-rw-r--r--lib/some.rb34
l---------lib/some/.#messages.rb1
-rw-r--r--lib/some/database.rb15
-rw-r--r--lib/some/helpers.rb13
-rw-r--r--lib/some/message.rb23
-rw-r--r--lib/some/messages.rb39
7 files changed, 126 insertions, 0 deletions
diff --git a/lib/.ruby-version b/lib/.ruby-version
new file mode 100644
index 0000000..bec3a35
--- /dev/null
+++ b/lib/.ruby-version
@@ -0,0 +1 @@
+system
diff --git a/lib/some.rb b/lib/some.rb
new file mode 100644
index 0000000..7e1dbdb
--- /dev/null
+++ b/lib/some.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+require 'notmuch'
+require 'pry'
+
+require_relative 'some/database'
+require_relative 'some/message'
+require_relative 'some/messages'
+require_relative 'some/helpers'
+
+module Some
+ class Some
+ def initialize
+ @db = Database.new(path: '/home/mms/mail')
+ end
+
+ def with_filter(filter_string)
+ db.query(filter_string).search_messages.each do |msg|
+ yield Message.new(msg: msg)
+ end
+ rescue StandardError => e
+ p e
+ end
+
+ private
+
+ attr_reader :db
+ end
+end
+
+p Some::Messages.new
+ .filter(from: 'janek', tags: [1, 2])
+ .or.filter(subject: 'a')
+ .query_string
diff --git a/lib/some/.#messages.rb b/lib/some/.#messages.rb
new file mode 120000
index 0000000..b1e8e06
--- /dev/null
+++ b/lib/some/.#messages.rb
@@ -0,0 +1 @@
+mms@voyager.local.90786:1730615032 \ No newline at end of file
diff --git a/lib/some/database.rb b/lib/some/database.rb
new file mode 100644
index 0000000..5595a41
--- /dev/null
+++ b/lib/some/database.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+module Some
+ class Database
+ attr_reader :db
+
+ def initialize(path:)
+ @db = ::Notmuch::Database.new(path)
+ end
+
+ def query(query)
+ db.query(query)
+ end
+ end
+end
diff --git a/lib/some/helpers.rb b/lib/some/helpers.rb
new file mode 100644
index 0000000..5842f73
--- /dev/null
+++ b/lib/some/helpers.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+module Some
+ module Helpers
+ def header_name_from_dsl(method_name)
+ method_name
+ .to_s
+ .split('_')
+ .map(&:capitalize)
+ .join('-')
+ end
+ end
+end
diff --git a/lib/some/message.rb b/lib/some/message.rb
new file mode 100644
index 0000000..47e397e
--- /dev/null
+++ b/lib/some/message.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Some
+ class Message
+ attr_reader :message
+
+ def initialize(msg:)
+ @message = msg
+ end
+
+ def method_missing(method_name, *_args)
+ handle_get(Helpers.header_name_from_dsl(method_name))
+ end
+
+ def handle_get(header_name)
+ message.header(header_name) if message.header(header_name)
+ end
+
+ def tags
+ @message.tags
+ end
+ end
+end
diff --git a/lib/some/messages.rb b/lib/some/messages.rb
new file mode 100644
index 0000000..2f89d2b
--- /dev/null
+++ b/lib/some/messages.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+module Some
+ class Messages
+ AND_CONJUCTION = :and
+ OR_CONJUCTION = :or
+ DEFAULT_CONJUCTION = AND_CONJUCTION
+
+ attr_reader :query, :current_conjuction
+
+ def initialize
+ @query = []
+ @current_conjuction = AND_CONJUCTION
+ end
+
+ def or
+ @current_conjuction = OR_CONJUCTION
+ self
+ end
+
+ def filter(params)
+ query << params.map do |key, value|
+ unless value.is_a? Array
+ [current_conjuction, key, value.to_sym]
+ else
+
+ [current_conjuction,
+ value.map { |subarg| [OR_CONJUCTION, key, subarg] }]
+ end
+ end
+
+ self
+ end
+
+ def query_string
+
+ end
+ end
+end