chotto 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chotto/config.rb +5 -0
- data/lib/chotto/database.rb +19 -0
- data/lib/chotto/helpers.rb +13 -0
- data/lib/chotto/message.rb +43 -0
- data/lib/chotto/message_thread.rb +22 -0
- data/lib/chotto/messages.rb +98 -0
- data/lib/chotto/ruleset.rb +13 -0
- data/lib/chotto/token.rb +12 -0
- data/lib/chotto/token_group.rb +30 -0
- metadata +31 -8
- /data/{bin → exe}/chotto +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 372dec253b24d3abd183e75e361210b2ec2c601a70466816789361b0e3070ab6
|
4
|
+
data.tar.gz: ee395a74ab114ec52d3a4e019f1e35e42fa972aeb7a17f3cd59cb6e797f2688a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f00b7a2a92cbb8ae9c1785cf0c11a447a269f1dba097fdf161cb4beb1976252a5aef4a7e4cadce95e68e22b6cf65a1dece24069624966c7a3d69d30456237fb6
|
7
|
+
data.tar.gz: fe0350716b91cf3e3fb9a75413f91861120d56db2983c105e7233e0d7ab72525c650fa506b2b253f21ed9954c93d420ba44546bda63c85bf327c3c91ab59ba04
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
class Database
|
5
|
+
attr_reader :db
|
6
|
+
|
7
|
+
def initialize(path:, db_class:)
|
8
|
+
@db = db_class.new(path, mode: Notmuch::MODE_READ_WRITE)
|
9
|
+
end
|
10
|
+
|
11
|
+
def search_messages(query)
|
12
|
+
db.query(query).search_messages
|
13
|
+
end
|
14
|
+
|
15
|
+
def close
|
16
|
+
db.close
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
class Message
|
5
|
+
attr_reader :message, :messages, :db
|
6
|
+
|
7
|
+
# attr_accessor :tags
|
8
|
+
|
9
|
+
def initialize(msg:, db:)
|
10
|
+
@message = msg
|
11
|
+
@db = db
|
12
|
+
# @tags = MessageTags.new(message: message)
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method_name, *_args)
|
16
|
+
handle_get_header(Chotto::Helpers.header_name_from_dsl(method_name))
|
17
|
+
end
|
18
|
+
|
19
|
+
def tags
|
20
|
+
@tags ||= message.tags
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_writer :tags
|
24
|
+
|
25
|
+
def save!
|
26
|
+
message.remove_all_tags
|
27
|
+
tags.each do |tag|
|
28
|
+
message.add_tag(tag.to_s)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def thread
|
33
|
+
thread_id = message.thread_id
|
34
|
+
MessageThread.new(thread_id: thread_id, db: db)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def handle_get_header(header_name)
|
40
|
+
message.header(header_name)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
class MessageThread
|
5
|
+
attr_reader :thread_id, :db
|
6
|
+
|
7
|
+
def initialize(thread_id:, db:)
|
8
|
+
@thread_id = thread_id
|
9
|
+
@db = db
|
10
|
+
end
|
11
|
+
|
12
|
+
def each
|
13
|
+
db.search_messages("thread:#{thread_id}").each do |msg|
|
14
|
+
yield(
|
15
|
+
Message.new(
|
16
|
+
msg: msg,
|
17
|
+
db: db
|
18
|
+
))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
AND_CONJUCTION = :and
|
5
|
+
OR_CONJUCTION = :or
|
6
|
+
DEFAULT_CONJUCTION = AND_CONJUCTION
|
7
|
+
OLDEST_FIRST_ORDER = 'oldest_first'
|
8
|
+
NEWEST_FIRST_ORDER = 'newest_first'
|
9
|
+
DEFAULT_ORDER = OLDEST_FIRST_ORDER
|
10
|
+
|
11
|
+
class Messages
|
12
|
+
attr_accessor :query, :current_conjuction, :token_count, :order, :only_new
|
13
|
+
attr_reader :db
|
14
|
+
|
15
|
+
include Enumerable
|
16
|
+
|
17
|
+
def initialize(db:, only_new:)
|
18
|
+
@db = db
|
19
|
+
@current_conjuction = AND_CONJUCTION
|
20
|
+
@token_count = 0
|
21
|
+
@order = DEFAULT_ORDER
|
22
|
+
@only_new = only_new
|
23
|
+
clear_filter!
|
24
|
+
end
|
25
|
+
|
26
|
+
def or
|
27
|
+
@current_conjuction = OR_CONJUCTION
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def and
|
32
|
+
@current_conjuction = AND_CONJUCTION
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def filter(params)
|
37
|
+
case params
|
38
|
+
when String
|
39
|
+
add_filter_from_string(params)
|
40
|
+
when Hash
|
41
|
+
add_filter_from_hash(params)
|
42
|
+
end
|
43
|
+
|
44
|
+
self
|
45
|
+
end
|
46
|
+
|
47
|
+
def clear_filter!
|
48
|
+
@query = []
|
49
|
+
end
|
50
|
+
|
51
|
+
def newest_first
|
52
|
+
@order = NEWEST_FIRST_ORDER
|
53
|
+
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def oldest_first
|
58
|
+
@order = OLDEST_FIRST_ORDER
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def each
|
64
|
+
db.search_messages(query_string).each do |msg|
|
65
|
+
yield(
|
66
|
+
Message.new(
|
67
|
+
msg: msg,
|
68
|
+
db: db
|
69
|
+
))
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_filter_from_string(string)
|
74
|
+
@query << Token.new(current_conjuction, :direct, string, self)
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_filter_from_hash(hash)
|
78
|
+
group = TokenGroup.new(current_conjuction, [], self)
|
79
|
+
hash.each do |key, value|
|
80
|
+
group.push_token(key, value)
|
81
|
+
end
|
82
|
+
@query << group
|
83
|
+
end
|
84
|
+
|
85
|
+
def query_string
|
86
|
+
string_from_filters = query.map(&:to_query).join(' ')
|
87
|
+
if only_new
|
88
|
+
"tag:new AND (#{string_from_filters})"
|
89
|
+
else
|
90
|
+
string_from_filters
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def next_token_id
|
95
|
+
@token_count += 1
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/chotto/token.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
Token = Struct.new(:conjuction, :field, :value, :messages) do
|
5
|
+
def to_query
|
6
|
+
conjuction_to_use = messages.next_token_id > 1 ? conjuction : ''
|
7
|
+
return "#{conjuction_to_use} (#{value})" if field == :direct
|
8
|
+
|
9
|
+
"#{conjuction_to_use} (#{field}:#{value})"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Chotto
|
4
|
+
TokenGroup = Struct.new(:conjuction, :tokens, :messages) do
|
5
|
+
def initialize(*)
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_query
|
10
|
+
tokens.flat_map(&:to_query).join(' ').to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def push_token(field, value)
|
14
|
+
if value.is_a? String
|
15
|
+
tokens.push(Token.new(conjuction, field, value, messages))
|
16
|
+
elsif value.is_a? Array
|
17
|
+
group = TokenGroup.new(OR_CONJUCTION, [], messages)
|
18
|
+
value.each do |val|
|
19
|
+
group.push_token(field, val)
|
20
|
+
end
|
21
|
+
tokens.push group
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def next_token_id
|
27
|
+
@token_count += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chotto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mms
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2024-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description: Initial tagging script for Notmuch
|
14
28
|
email: chotto@sapka.me
|
15
29
|
executables:
|
16
30
|
- chotto
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
20
|
-
-
|
34
|
+
- exe/chotto
|
21
35
|
- lib/chotto.rb
|
36
|
+
- lib/chotto/config.rb
|
37
|
+
- lib/chotto/database.rb
|
38
|
+
- lib/chotto/helpers.rb
|
39
|
+
- lib/chotto/message.rb
|
40
|
+
- lib/chotto/message_thread.rb
|
41
|
+
- lib/chotto/messages.rb
|
42
|
+
- lib/chotto/ruleset.rb
|
43
|
+
- lib/chotto/token.rb
|
44
|
+
- lib/chotto/token_group.rb
|
22
45
|
homepage: https://crys.site/projects/chotto
|
23
46
|
licenses:
|
24
47
|
- BSD-3-Clause
|
@@ -39,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
62
|
- !ruby/object:Gem::Version
|
40
63
|
version: '0'
|
41
64
|
requirements: []
|
42
|
-
rubygems_version: 3.5.
|
65
|
+
rubygems_version: 3.5.23
|
43
66
|
signing_key:
|
44
67
|
specification_version: 4
|
45
|
-
summary:
|
68
|
+
summary: chotto-0.1.1
|
46
69
|
test_files: []
|
/data/{bin → exe}/chotto
RENAMED
File without changes
|