imsg-grep 0.1.3-darwin → 0.1.5-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/bin/imsg-grep +23 -5
- data/lib/imsg-grep/VERSION +1 -1
- data/lib/imsg-grep/images/img2png.dylib +0 -0
- data/lib/imsg-grep/messages.rb +23 -16
- metadata +2 -2
- data/bin/img2png +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57ddef6878c4ff5a7359f79d3482c5b0e9c391ed5170623bb06c7c4e5ddebb83
|
|
4
|
+
data.tar.gz: b2b548bf55ba13909a0e006b3dbfb27cdb633e575028e64bb358b525cdd35ae9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d6ea1f60dd4b4b132375c662156df78ab3de53e2def55d56763bba30a1c88bf7abec7246be24fe5cecab5c39b11bae098114dd28509d5ea4972aba5de27522b
|
|
7
|
+
data.tar.gz: 397b91312c94deb494289c14a038ddbb199707a6a65c4c652b5790697090816bcb17029eb3b76be037bf1c03ac30dc1fbf784162cb06e8b992a7688158f947f9
|
data/README.md
CHANGED
|
@@ -19,7 +19,9 @@ macOS, ruby 3.4+, SQLite.
|
|
|
19
19
|
|
|
20
20
|
Full Disk Access must be enabled for terminal.
|
|
21
21
|
|
|
22
|
-
iTerm or Ghostty (or other kitty) for image support.
|
|
22
|
+
iTerm or Ghostty (or other kitty) for image support.
|
|
23
|
+
|
|
24
|
+
swiftc for development. (run `rake build:lib`)
|
|
23
25
|
|
|
24
26
|
## Installing
|
|
25
27
|
|
data/bin/imsg-grep
CHANGED
|
@@ -371,6 +371,20 @@ begin
|
|
|
371
371
|
sorted_singles = keyed_singles.sort_by{|k,| filter_order.index(k) || Float::INFINITY }.map(&:last)
|
|
372
372
|
groups = sorted_singles + grouped # put it back together
|
|
373
373
|
|
|
374
|
+
begin
|
|
375
|
+
Messages.init_fs
|
|
376
|
+
rescue Errno::EPERM, Errno::EACCES => e
|
|
377
|
+
if $stdout.tty? && $stdin.tty?
|
|
378
|
+
$stderr.print "You must grant #{ENV['TERM_PROGRAM']} Full Disk Access so #{PROG} can access the chat database. Open System Settings pane? [y/N] "
|
|
379
|
+
$stdin.gets.to_s.strip.downcase == ?y and system 'open "x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"'
|
|
380
|
+
else
|
|
381
|
+
err! "full disk access required (#{e.message})"
|
|
382
|
+
end
|
|
383
|
+
exit 1
|
|
384
|
+
rescue => e
|
|
385
|
+
err! e.message
|
|
386
|
+
exit 1
|
|
387
|
+
end
|
|
374
388
|
Messages.init
|
|
375
389
|
|
|
376
390
|
@file_filters = []
|
|
@@ -568,7 +582,9 @@ begin
|
|
|
568
582
|
@link_images[link] = Concurrent::Promises.future_on(POOL, msg) do |msg|
|
|
569
583
|
ix = link[:image_idx] or next
|
|
570
584
|
file = msg.dig(:files, ix) or next
|
|
571
|
-
path =
|
|
585
|
+
path = file[:filename] or next
|
|
586
|
+
path = File.expand_path path
|
|
587
|
+
File.exist?(path) or next
|
|
572
588
|
img = Imaginator::Image.new(path).load or next
|
|
573
589
|
fit, fits = img.fit @link_preview_cols, @link_preview_min_rows
|
|
574
590
|
png = img.png_transform w:fit.w, h:fit.h, pad_w:fits[:cfit].pad_w
|
|
@@ -582,7 +598,9 @@ begin
|
|
|
582
598
|
msg[:images] = msg[:files].select{ it[:mime_type]&.start_with?('image/') }
|
|
583
599
|
preview?(:images) and msg[:images].each do |im|
|
|
584
600
|
@images[im] = Concurrent::Promises.future_on(POOL, im) do |im|
|
|
585
|
-
path =
|
|
601
|
+
path = im[:filename] or next
|
|
602
|
+
path = File.expand_path path
|
|
603
|
+
File.exist?(path) or next
|
|
586
604
|
img = Imaginator::Image.new(path).load or next
|
|
587
605
|
fit, = img.fit 25, @img_rows
|
|
588
606
|
png = img.png_transform w:fit.w, h:fit.h
|
|
@@ -684,7 +702,7 @@ begin
|
|
|
684
702
|
if img_rows != @link_preview_min_rows
|
|
685
703
|
img = Imaginator::Image.new(img).load if img.is_a? String # it's a path, original img released
|
|
686
704
|
fit1, fits = img.fit @link_preview_cols, img_rows
|
|
687
|
-
# if the
|
|
705
|
+
# if the promise-rendered image is different from what we need now that we know the text size, do it again
|
|
688
706
|
if fit1 != fit
|
|
689
707
|
fit = fit1
|
|
690
708
|
png = img.png_transform w:fit.w, h:fit.h, pad_w:fits[:cfit].pad_w
|
|
@@ -694,7 +712,7 @@ begin
|
|
|
694
712
|
print " "
|
|
695
713
|
Imaginator.print_image(data: png, c: @link_preview_cols)
|
|
696
714
|
puts
|
|
697
|
-
print "\e[#{fit.r}A" # go up by image rows
|
|
715
|
+
print "\e[#{fit.r}A" # go up by image rows to print padded buf next to it
|
|
698
716
|
end
|
|
699
717
|
|
|
700
718
|
print buf
|
|
@@ -702,7 +720,7 @@ begin
|
|
|
702
720
|
|
|
703
721
|
if @list_files
|
|
704
722
|
for file in files.reject{ it[:mime_type].nil? }
|
|
705
|
-
path, _, name = file[:filename].rpartition %r_(?<=/)_
|
|
723
|
+
path, _, name = file[:filename].to_s.rpartition %r_(?<=/)_
|
|
706
724
|
p, q, r = path.rpartition %r_/\KTemporaryItems(?=/)_
|
|
707
725
|
path = c.file_path(p) + c.file_path_bad(q) + c.file_path(r)
|
|
708
726
|
puts " " + path + c.file_name(name) + ?\n
|
data/lib/imsg-grep/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.5
|
|
Binary file
|
data/lib/imsg-grep/messages.rb
CHANGED
|
@@ -10,29 +10,36 @@ require_relative 'apple/attr_str'
|
|
|
10
10
|
module Messages
|
|
11
11
|
APPLE_EPOCH = 978307200
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
IMSG_DB = File.expand_path("~/Library/Messages/chat.db")
|
|
15
|
-
CACHE_DB = File.expand_path("~/.cache/imsg-grep/cache.db")
|
|
16
|
-
|
|
17
|
-
def self.reset_cache = FileUtils.rm_f(CACHE_DB)
|
|
13
|
+
def self.reset_cache = FileUtils.rm_f(@cache_db)
|
|
18
14
|
def self.db = @db
|
|
19
15
|
|
|
20
|
-
def self.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
def self.init_fs
|
|
17
|
+
return if @addy_db # already ran
|
|
18
|
+
@addy_db = Dir[File.expand_path("~/Library/Application Support/AddressBook/Sources/*/AddressBook-*.abcddb")][0]
|
|
19
|
+
@imsg_db = File.expand_path("~/Library/Messages/chat.db")
|
|
20
|
+
@cache_db = File.expand_path("~/.cache/imsg-grep/cache.db")
|
|
21
|
+
|
|
22
|
+
raise "Contacts database not found" unless @addy_db
|
|
23
|
+
|
|
24
|
+
FileUtils.mkdir_p File.dirname(@cache_db)
|
|
25
|
+
FileUtils.touch(@cache_db)
|
|
26
26
|
|
|
27
|
-
[
|
|
27
|
+
[@addy_db, @imsg_db, @cache_db].each do |db|
|
|
28
28
|
raise "Database not found: #{db}" unless File.exist?(db)
|
|
29
29
|
raise "Database not readable: #{db}" unless File.readable?(db)
|
|
30
30
|
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.init
|
|
34
|
+
################################################################################
|
|
35
|
+
### DB Setup ###################################################################
|
|
36
|
+
################################################################################
|
|
31
37
|
|
|
38
|
+
init_fs
|
|
32
39
|
@db = SQLite3::Database.new(":memory:")
|
|
33
|
-
@db.execute "ATTACH DATABASE '#{
|
|
34
|
-
@db.execute "ATTACH DATABASE '#{
|
|
35
|
-
@db.execute "ATTACH DATABASE '#{
|
|
40
|
+
@db.execute "ATTACH DATABASE '#{@addy_db}' AS _addy"
|
|
41
|
+
@db.execute "ATTACH DATABASE '#{@imsg_db}' AS _imsg"
|
|
42
|
+
@db.execute "ATTACH DATABASE '#{@cache_db}' AS _cache"
|
|
36
43
|
|
|
37
44
|
def @db.select_hashes(sql) = prepare(sql).execute.enum_for(:each_hash).map{ it.transform_keys(&:to_sym) }
|
|
38
45
|
def @db.ƒ(f, &) = define_function_with_flags(f.to_s, SQLite3::Constants::TextRep::UTF8 | SQLite3::Constants::TextRep::DETERMINISTIC, &)
|
|
@@ -182,7 +189,7 @@ module Messages
|
|
|
182
189
|
summary = rich_link&.dig "summary"
|
|
183
190
|
image = rich_link&.dig "imageMetadata", "URL"
|
|
184
191
|
image_idx = rich_link&.dig "image", "richLinkImageAttachmentSubstituteIndex"
|
|
185
|
-
ci_idx = rich_link&.dig
|
|
192
|
+
ci_idx = rich_link&.dig "contentImages", 0, "richLinkImageAttachmentSubstituteIndex"
|
|
186
193
|
image_idx = ci_idx if ci_idx
|
|
187
194
|
url = rich_url || orig_url || found_url
|
|
188
195
|
# i'm not sure the mapping richLinkImageAttachmentSubstituteIndex to
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imsg-grep
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: darwin
|
|
6
6
|
authors:
|
|
7
7
|
- Caio Chassot
|
|
@@ -117,7 +117,6 @@ extra_rdoc_files: []
|
|
|
117
117
|
files:
|
|
118
118
|
- LICENSE
|
|
119
119
|
- README.md
|
|
120
|
-
- bin/img2png
|
|
121
120
|
- bin/imsg-grep
|
|
122
121
|
- bin/msg-info
|
|
123
122
|
- bin/sql-shell
|
|
@@ -132,6 +131,7 @@ files:
|
|
|
132
131
|
- lib/imsg-grep/dev/print_query.rb
|
|
133
132
|
- lib/imsg-grep/dev/timer.rb
|
|
134
133
|
- lib/imsg-grep/images/imaginator.rb
|
|
134
|
+
- lib/imsg-grep/images/img2png.dylib
|
|
135
135
|
- lib/imsg-grep/images/img2png.rb
|
|
136
136
|
- lib/imsg-grep/messages.rb
|
|
137
137
|
- lib/imsg-grep/utils/date.rb
|
data/bin/img2png
DELETED
|
Binary file
|