diff options
author | mms <git@sapka.me> | 2024-11-07 14:57:41 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-07 14:57:41 +0100 |
commit | acc8415d7109e8fb45bbfcd8cf545ebcf5b5d16a (patch) | |
tree | 1c8b1ec2efbd7602fa972aa7dbd6e8baa63ef515 |
init spike
-rw-r--r-- | LICENSE | 9 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | lib/.ruby-version | 1 | ||||
-rw-r--r-- | lib/some.rb | 34 | ||||
l--------- | lib/some/.#messages.rb | 1 | ||||
-rw-r--r-- | lib/some/database.rb | 15 | ||||
-rw-r--r-- | lib/some/helpers.rb | 13 | ||||
-rw-r--r-- | lib/some/message.rb | 23 | ||||
-rw-r--r-- | lib/some/messages.rb | 39 |
9 files changed, 138 insertions, 0 deletions
@@ -0,0 +1,9 @@ +Copyright (c) 2024 mms + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed201df --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# some + +An inititial tagger for Notmucn
\ No newline at end of file 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 |