pikuri-thunderbird 0.1.0 → 0.2.0
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 +19 -8
- data/design/architecture.md +827 -0
- data/lib/pikuri/thunderbird/calendar.rb +216 -70
- data/lib/pikuri/thunderbird/calendar_create.rb +16 -15
- data/lib/pikuri/thunderbird/calendar_read.rb +8 -3
- data/lib/pikuri/thunderbird/calendar_search.rb +16 -7
- data/lib/pikuri/thunderbird/compose_guard.rb +16 -11
- data/lib/pikuri/thunderbird/contact_search.rb +13 -3
- data/lib/pikuri/thunderbird/database_snapshot.rb +144 -78
- data/lib/pikuri/thunderbird/extension.rb +167 -55
- data/lib/pikuri/thunderbird/forwarded_mail.rb +191 -0
- data/lib/pikuri/thunderbird/gloda/attachment.rb +36 -0
- data/lib/pikuri/thunderbird/gloda/contacts.rb +53 -35
- data/lib/pikuri/thunderbird/gloda/mail.rb +75 -19
- data/lib/pikuri/thunderbird/gloda.rb +35 -15
- data/lib/pikuri/thunderbird/ical_line.rb +3 -3
- data/lib/pikuri/thunderbird/launcher.rb +10 -5
- data/lib/pikuri/thunderbird/mail_attachment_read.rb +282 -0
- data/lib/pikuri/thunderbird/mail_compose.rb +16 -16
- data/lib/pikuri/thunderbird/mail_read.rb +94 -15
- data/lib/pikuri/thunderbird/mail_search.rb +15 -6
- data/lib/pikuri/thunderbird/message_store.rb +203 -0
- data/lib/pikuri/thunderbird/profile.rb +64 -19
- data/lib/pikuri/thunderbird/recurrence.rb +207 -0
- data/lib/pikuri-thunderbird.rb +5 -5
- metadata +60 -13
- data/DESIGN.md +0 -460
|
@@ -12,21 +12,19 @@ module Pikuri
|
|
|
12
12
|
#
|
|
13
13
|
# contacts = Gloda::Contacts.new(gloda: gloda)
|
|
14
14
|
# contacts.resolve(query: 'jon', limit: 5) # name → ranked addresses
|
|
15
|
-
# contacts.
|
|
15
|
+
# contacts.domains_sent_to(['acme.com', 'paypa1.com']) # => ['acme.com']
|
|
16
16
|
#
|
|
17
17
|
# It owns no resources: it queries {Gloda}'s live snapshot through
|
|
18
18
|
# {Gloda#with_fresh_db} (so a rebuild under it is transparent), and there
|
|
19
19
|
# is nothing to close — the {Gloda} it holds is closed by its own owner.
|
|
20
20
|
#
|
|
21
|
-
# ==
|
|
21
|
+
# == Implementation details
|
|
22
22
|
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
# corresponded with?" — {#resolve} to fill a recipient, {#domains_seen}
|
|
29
|
-
# to flag a novel one.
|
|
23
|
+
# Both read the decoded +c3author+ / +c4recipients+ columns, where display
|
|
24
|
+
# name and address sit together, never Gloda's own graph tables: +contacts+
|
|
25
|
+
# is dead (frecency/popularity unpopulated, +name+ unreliable), and
|
|
26
|
+
# +identities+ holds every author, so a domain that only ever wrote to
|
|
27
|
+
# the user would count as known.
|
|
30
28
|
class Contacts
|
|
31
29
|
LOGGER = Pikuri.logger_for('Thunderbird::Gloda::Contacts')
|
|
32
30
|
|
|
@@ -97,36 +95,56 @@ module Pikuri
|
|
|
97
95
|
tally(rows, terms).first(limit)
|
|
98
96
|
end
|
|
99
97
|
|
|
100
|
-
# Which of +domains+ the user has
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
# so it answers "have I ever exchanged mail with this domain?" in both
|
|
104
|
-
# directions). Powers {ComposeGuard}'s recipient-novelty warn.
|
|
98
|
+
# Which of +domains+ the user has *sent* mail to: a recipient of a
|
|
99
|
+
# message in a Sent folder. Powers {ComposeGuard}'s recipient-novelty
|
|
100
|
+
# warn.
|
|
105
101
|
#
|
|
106
|
-
# contacts.
|
|
102
|
+
# contacts.domains_sent_to(['acme.com', 'paypa1.com']) # => ['acme.com']
|
|
103
|
+
#
|
|
104
|
+
# Received mail never counts, since an attacker earns that by writing
|
|
105
|
+
# first: a reply to a phishing mail has to warn. Sent mail archived out
|
|
106
|
+
# of the Sent folder doesn't count either, which only adds a warning.
|
|
107
107
|
#
|
|
108
108
|
# @param domains [Array<String>] lowercased bare domains.
|
|
109
|
-
# @return [Array<String
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
|
|
109
|
+
# @return [Array<String>, nil] the subset the user has sent mail to, or
|
|
110
|
+
# +nil+ when no Sent-folder mail is indexed at all (an account that
|
|
111
|
+
# keeps no Sent copies), where every recipient would look new.
|
|
112
|
+
# @raise [SQLite3::SQLException] if the schema differs from the probed
|
|
113
|
+
# shape — the caller degrades (it is unverified across Thunderbird
|
|
114
|
+
# versions).
|
|
115
|
+
def domains_sent_to(domains)
|
|
114
116
|
return [] if domains.empty?
|
|
115
117
|
|
|
116
118
|
@gloda.with_fresh_db do |db|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
SQL
|
|
124
|
-
end
|
|
119
|
+
next nil unless db.get_first_value(<<~SQL, [SENT_PRIORITY])
|
|
120
|
+
SELECT 1 FROM messages m JOIN folderLocations fl ON fl.id = m.folderID
|
|
121
|
+
WHERE fl.indexingPriority = ? AND m.deleted = 0 LIMIT 1
|
|
122
|
+
SQL
|
|
123
|
+
|
|
124
|
+
domains.select { |domain| sent_to?(db, domain) }
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
private
|
|
129
129
|
|
|
130
|
+
# @param db [SQLite3::Database]
|
|
131
|
+
# @param domain [String] a lowercased bare domain.
|
|
132
|
+
# @return [Boolean] whether a Sent-folder message has a recipient at
|
|
133
|
+
# exactly +domain+ (the SQL +instr+ only narrows; +@acme.com+ is also
|
|
134
|
+
# inside +@acme.com.evil.example+).
|
|
135
|
+
def sent_to?(db, domain)
|
|
136
|
+
cells = db.execute(<<~SQL, [SENT_PRIORITY, "@#{domain}"])
|
|
137
|
+
SELECT c.c4recipients FROM messages m
|
|
138
|
+
JOIN messagesText_content c ON c.docid = m.id
|
|
139
|
+
JOIN folderLocations fl ON fl.id = m.folderID
|
|
140
|
+
WHERE fl.indexingPriority = ? AND m.deleted = 0
|
|
141
|
+
AND instr(lower(c.c4recipients), ?) > 0
|
|
142
|
+
SQL
|
|
143
|
+
cells.any? do |(cell)|
|
|
144
|
+
cell.to_s.scan(EMAIL_RE).any? { |email| email.downcase.split('@', 2).last == domain }
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
130
148
|
# FTS5 expression matching any query term, restricted to the author /
|
|
131
149
|
# recipient columns (each term phrase-quoted so punctuation in the name
|
|
132
150
|
# is inert). A partial address like +vysny+ matches the tokenized
|
|
@@ -152,7 +170,7 @@ module Pikuri
|
|
|
152
170
|
rows.each do |author, recipients, priority|
|
|
153
171
|
sent = (priority == SENT_PRIORITY)
|
|
154
172
|
[author, recipients].each do |cell|
|
|
155
|
-
extract(cell, needles).each do |address, name|
|
|
173
|
+
extract(Gloda.strip_undefined(cell), needles).each do |address, name|
|
|
156
174
|
rec = agg[address]
|
|
157
175
|
rec[:count] += 1
|
|
158
176
|
rec[:sent] += 1 if sent
|
|
@@ -172,10 +190,10 @@ module Pikuri
|
|
|
172
190
|
# matched the *message* (recall, OR of terms), this keeps only the
|
|
173
191
|
# *entry* that matches every term (precision), while still scanning
|
|
174
192
|
# every email token in a kept entry (a cell can hold several matching
|
|
175
|
-
# recipients). Tolerates the real-data noise: missing brackets,
|
|
176
|
-
#
|
|
193
|
+
# recipients). Tolerates the real-data noise: missing brackets, quoted
|
|
194
|
+
# nicknames.
|
|
177
195
|
#
|
|
178
|
-
# @param cell [String, nil]
|
|
196
|
+
# @param cell [String, nil] with {Gloda.strip_undefined} applied.
|
|
179
197
|
# @param needles [Array<String>] lower-cased query terms.
|
|
180
198
|
# @return [Array<Array(String, String)>] +[address_downcased, name]+
|
|
181
199
|
# per email token found (name +""+ when none survives cleaning).
|
|
@@ -205,10 +223,10 @@ module Pikuri
|
|
|
205
223
|
end
|
|
206
224
|
|
|
207
225
|
# @param text [String, nil]
|
|
208
|
-
# @return [String] +text+ with brackets/quotes and
|
|
209
|
-
#
|
|
226
|
+
# @return [String] +text+ with brackets/quotes removed and whitespace
|
|
227
|
+
# collapsed.
|
|
210
228
|
def clean_name(text)
|
|
211
|
-
text.to_s.gsub(/[<>"]/, ' ').gsub(/\
|
|
229
|
+
text.to_s.gsub(/[<>"]/, ' ').gsub(/\s+/, ' ').strip
|
|
212
230
|
end
|
|
213
231
|
|
|
214
232
|
# Pick the most-seen non-empty display name and compute the final score.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
3
5
|
module Pikuri
|
|
4
6
|
module Thunderbird
|
|
5
7
|
class Gloda
|
|
@@ -21,6 +23,12 @@ module Pikuri
|
|
|
21
23
|
# everything). {#search} over-fetches and dedups by +headerMessageID+
|
|
22
24
|
# (falling back to a +gloda:<id>+ handle when absent) *before* the top-N
|
|
23
25
|
# cap, so duplicates can't eat result slots.
|
|
26
|
+
#
|
|
27
|
+
# A deduped hit keeps its best copy's rank but shows a copy whose body
|
|
28
|
+
# Gloda saw, when the over-fetch holds one. All Mail is often synced
|
|
29
|
+
# headers-only, and a headers-only copy outranks its downloaded twin on
|
|
30
|
+
# a subject match (bm25 favours the shorter document), so without this
|
|
31
|
+
# the hit would name All Mail and carry an empty snippet.
|
|
24
32
|
class Mail
|
|
25
33
|
# @return [Integer] over-fetch multiple before dedup+cap (so Gmail
|
|
26
34
|
# label duplicates don't shrink recall).
|
|
@@ -65,40 +73,84 @@ module Pikuri
|
|
|
65
73
|
dedup(rows).first(limit)
|
|
66
74
|
end
|
|
67
75
|
|
|
68
|
-
# Full decoded body + headers +
|
|
76
|
+
# Full decoded body + headers + attachments for one message.
|
|
77
|
+
#
|
|
78
|
+
# +folder_uris+ is every folder holding a copy, this row's own first —
|
|
79
|
+
# Gmail fans one message out over its labels, and any copy carries the
|
|
80
|
+
# same attachment bytes.
|
|
81
|
+
#
|
|
82
|
+
# +downloaded+ is whether Gloda saw the message's body. It parses the
|
|
83
|
+
# MIME only for a message in a local folder or one whose IMAP body is
|
|
84
|
+
# offline; any other it indexes from headers alone, leaving body and
|
|
85
|
+
# attachment names NULL — where a parsed message with no text or no
|
|
86
|
+
# attachments has an empty string (+IndexMsg.sys.mjs+, Thunderbird
|
|
87
|
+
# 159). So +attachments+ empty means "none" only when +downloaded+.
|
|
88
|
+
# Of a message's copies, one Gloda saw the body of is read first.
|
|
69
89
|
#
|
|
70
90
|
# @param message_id [String] the {#search} handle (an RFC +Message-ID+
|
|
71
91
|
# or a +gloda:<id>+ fallback).
|
|
72
92
|
# @return [Hash, nil] +{message_id:, date:, from:, to:, subject:,
|
|
73
|
-
# folder:,
|
|
93
|
+
# folder:, folder_uris: Array<String>, attachments: Array<Attachment>,
|
|
94
|
+
# body:, downloaded: Boolean}+, or +nil+ if not found.
|
|
95
|
+
# @raise [NoMatchingPatternError] on an +attachmentInfos+ entry of a
|
|
96
|
+
# shape Gloda never wrote.
|
|
74
97
|
def read(message_id:)
|
|
75
98
|
gloda_id = message_id.to_s[/\Agloda:(\d+)\z/, 1]
|
|
76
99
|
where, bind = gloda_id ? ['m.id = ?', gloda_id.to_i] : ['m.headerMessageID = ?', message_id]
|
|
77
|
-
row = @gloda.with_fresh_db do |db|
|
|
78
|
-
db.execute(<<~SQL, [bind]).first
|
|
100
|
+
row, attr_id, uris = @gloda.with_fresh_db do |db|
|
|
101
|
+
row = db.execute(<<~SQL, [bind]).first
|
|
79
102
|
SELECT m.id, m.headerMessageID, m.date,
|
|
80
|
-
c.c0body, c.c1subject, c.
|
|
81
|
-
fl.name
|
|
103
|
+
c.c0body, c.c1subject, c.c3author, c.c4recipients,
|
|
104
|
+
fl.name, fl.folderURI, m.jsonAttributes, c.c2attachmentNames IS NOT NULL
|
|
82
105
|
FROM messages m
|
|
83
106
|
JOIN messagesText_content c ON c.docid = m.id
|
|
84
107
|
LEFT JOIN folderLocations fl ON fl.id = m.folderID
|
|
85
108
|
WHERE #{where} AND m.deleted = 0
|
|
86
|
-
ORDER BY m.date DESC
|
|
109
|
+
ORDER BY c.c2attachmentNames IS NULL, m.date DESC
|
|
87
110
|
LIMIT 1
|
|
88
111
|
SQL
|
|
112
|
+
next unless row
|
|
113
|
+
|
|
114
|
+
# Attribute ids are assigned per profile at Gloda's creation, so
|
|
115
|
+
# look this one up by name rather than hardcoding the 51 seen live.
|
|
116
|
+
attr_id = db.get_first_value(
|
|
117
|
+
"SELECT id FROM attributeDefinitions WHERE extensionName = 'built-in' AND name = 'attachmentInfos'"
|
|
118
|
+
)
|
|
119
|
+
header_msgid = row[1]
|
|
120
|
+
uris = if header_msgid.to_s.empty?
|
|
121
|
+
[]
|
|
122
|
+
else
|
|
123
|
+
db.execute(<<~SQL, [header_msgid]).flatten
|
|
124
|
+
SELECT fl.folderURI FROM messages m JOIN folderLocations fl ON fl.id = m.folderID
|
|
125
|
+
WHERE m.headerMessageID = ? AND m.deleted = 0
|
|
126
|
+
SQL
|
|
127
|
+
end
|
|
128
|
+
[row, attr_id, uris]
|
|
89
129
|
end
|
|
90
130
|
return nil unless row
|
|
91
131
|
|
|
92
|
-
id, header_msgid, date_us, body, subj,
|
|
132
|
+
id, header_msgid, date_us, body, subj, author, recipients, folder, folder_uri, json, downloaded = row
|
|
93
133
|
{
|
|
94
134
|
message_id: header_msgid && !header_msgid.empty? ? header_msgid : "gloda:#{id}",
|
|
95
|
-
date: to_time(date_us), from: author,
|
|
96
|
-
|
|
135
|
+
date: to_time(date_us), from: Gloda.strip_undefined(author),
|
|
136
|
+
to: Gloda.strip_undefined(recipients), subject: subj,
|
|
137
|
+
folder: folder, folder_uris: [folder_uri, *uris].compact.uniq,
|
|
138
|
+
attachments: attachments(json, attr_id), body: body.to_s, downloaded: downloaded == 1
|
|
97
139
|
}
|
|
98
140
|
end
|
|
99
141
|
|
|
100
142
|
private
|
|
101
143
|
|
|
144
|
+
# @param json [String, nil] +messages.jsonAttributes+.
|
|
145
|
+
# @param attr_id [Integer, nil] the +attachmentInfos+ attribute id.
|
|
146
|
+
# @return [Array<Attachment>] in Gloda's order — the order the listing
|
|
147
|
+
# numbers them, so the reader resolves the same index.
|
|
148
|
+
def attachments(json, attr_id)
|
|
149
|
+
return [] if json.nil? || attr_id.nil?
|
|
150
|
+
|
|
151
|
+
(JSON.parse(json)[attr_id.to_s] || []).map { |entry| Attachment.from_gloda(entry) }
|
|
152
|
+
end
|
|
153
|
+
|
|
102
154
|
# @return [Array<Array>] raw result rows (see {#row_to_hit} for shape).
|
|
103
155
|
def fts_search(db, query:, from:, to:, subject:, after:, before:, folder:, fetch:)
|
|
104
156
|
clauses = ['fts MATCH ?', 'm.deleted = 0']
|
|
@@ -106,7 +158,7 @@ module Pikuri
|
|
|
106
158
|
append_filters(clauses, binds, from:, to:, subject:, after:, before:, folder:)
|
|
107
159
|
db.execute(<<~SQL, binds + [fetch])
|
|
108
160
|
SELECT m.headerMessageID, m.id, m.date, c.c1subject, c.c3author, c.c4recipients,
|
|
109
|
-
fl.name, snippet(fts, 0, '', '', ' … ', 12)
|
|
161
|
+
fl.name, snippet(fts, 0, '', '', ' … ', 12), c.c2attachmentNames IS NOT NULL
|
|
110
162
|
FROM fts
|
|
111
163
|
JOIN messages m ON m.id = fts.rowid
|
|
112
164
|
JOIN messagesText_content c ON c.docid = fts.rowid
|
|
@@ -124,7 +176,7 @@ module Pikuri
|
|
|
124
176
|
append_filters(clauses, binds, from:, to:, subject:, after:, before:, folder:)
|
|
125
177
|
db.execute(<<~SQL, binds + [fetch])
|
|
126
178
|
SELECT m.headerMessageID, m.id, m.date, c.c1subject, c.c3author, c.c4recipients,
|
|
127
|
-
fl.name, substr(c.c0body, 1, 180)
|
|
179
|
+
fl.name, substr(c.c0body, 1, 180), c.c2attachmentNames IS NOT NULL
|
|
128
180
|
FROM messages m
|
|
129
181
|
JOIN messagesText_content c ON c.docid = m.id
|
|
130
182
|
LEFT JOIN folderLocations fl ON fl.id = m.folderID
|
|
@@ -177,25 +229,29 @@ module Pikuri
|
|
|
177
229
|
end
|
|
178
230
|
|
|
179
231
|
# @param rows [Array<Array>] raw rows.
|
|
180
|
-
# @return [Array<Hash>] hit hashes, deduped by handle, order
|
|
232
|
+
# @return [Array<Hash>] hit hashes, deduped by handle, in the order
|
|
233
|
+
# each handle first appears; a hit is its first downloaded copy, or
|
|
234
|
+
# its first copy when none is.
|
|
181
235
|
def dedup(rows)
|
|
182
236
|
seen = {}
|
|
183
237
|
rows.each do |row|
|
|
238
|
+
downloaded = row.last == 1
|
|
184
239
|
hit = row_to_hit(row)
|
|
185
|
-
seen[hit[:message_id]]
|
|
240
|
+
kept = seen[hit[:message_id]]
|
|
241
|
+
seen[hit[:message_id]] = [hit, downloaded] if kept.nil? || (downloaded && !kept.last)
|
|
186
242
|
end
|
|
187
|
-
seen.values
|
|
243
|
+
seen.values.map(&:first)
|
|
188
244
|
end
|
|
189
245
|
|
|
190
246
|
# @param row [Array] +[headerMessageID, id, date_us, subject, author,
|
|
191
|
-
# recipients, folder, snippet]+
|
|
247
|
+
# recipients, folder, snippet, downloaded]+
|
|
192
248
|
# @return [Hash]
|
|
193
249
|
def row_to_hit(row)
|
|
194
|
-
header_msgid, id, date_us, subject, author, recipients, folder, snippet = row
|
|
250
|
+
header_msgid, id, date_us, subject, author, recipients, folder, snippet, = row
|
|
195
251
|
{
|
|
196
252
|
message_id: header_msgid && !header_msgid.empty? ? header_msgid : "gloda:#{id}",
|
|
197
|
-
date: to_time(date_us), from: author,
|
|
198
|
-
subject: subject, folder: folder, snippet: snippet.to_s.strip
|
|
253
|
+
date: to_time(date_us), from: Gloda.strip_undefined(author),
|
|
254
|
+
to: Gloda.strip_undefined(recipients), subject: subject, folder: folder, snippet: snippet.to_s.strip
|
|
199
255
|
}
|
|
200
256
|
end
|
|
201
257
|
|
|
@@ -31,13 +31,15 @@ module Pikuri
|
|
|
31
31
|
#
|
|
32
32
|
# == Freshness & consistency (one signal)
|
|
33
33
|
#
|
|
34
|
-
# Each {#with_fresh_db} first
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
#
|
|
34
|
+
# Each {#with_fresh_db} first asks whether the {DatabaseSnapshot} the
|
|
35
|
+
# copy+index were built from is still current; if not, a fresh one is
|
|
36
|
+
# taken and the FTS5 index rebuilt (~1 s). Between changes it's a header
|
|
37
|
+
# read and a no-op. The generation moves on any Gloda write, read/star/tag
|
|
38
|
+
# flips during triage included, so a rebuild can fire mid-conversation.
|
|
39
|
+
# Don't gate it on content (+max(id)+ / +count(*)+ / +sum(deleted)+):
|
|
40
|
+
# Gloda rewrites a moved message's +folderID+ in place and re-indexes a
|
|
41
|
+
# late-downloaded body in place, moving none of those, so the folder
|
|
42
|
+
# filter and the attachment read would go stale. See {DatabaseSnapshot}.
|
|
41
43
|
#
|
|
42
44
|
# Holds no external state beyond its own snapshot + connection, but {#close}
|
|
43
45
|
# is required for orderly teardown.
|
|
@@ -63,6 +65,24 @@ module Pikuri
|
|
|
63
65
|
class Gloda
|
|
64
66
|
LOGGER = Pikuri.logger_for('Thunderbird::Gloda')
|
|
65
67
|
|
|
68
|
+
# A literal +undefined+ right after an address, closing +>+ or bare.
|
|
69
|
+
UNDEFINED_AFTER_ADDRESS = /(>|@[^\s<>,;"']+) undefined\b/
|
|
70
|
+
|
|
71
|
+
# Removes the literal +undefined+ Gloda writes after every address in
|
|
72
|
+
# +c3author+ / +c4recipients+ but the owner's own as author:
|
|
73
|
+
#
|
|
74
|
+
# Gloda.strip_undefined('Mira <mira@lumo.example> undefined, bob@x.example undefined')
|
|
75
|
+
# # => "Mira <mira@lumo.example>, bob@x.example"
|
|
76
|
+
#
|
|
77
|
+
# The model would echo or interpret it, and it costs tokens per address.
|
|
78
|
+
# Only the word right after an address goes, so a person named
|
|
79
|
+
# "Undefined" survives. A +LIKE+ filter on the raw column needs no
|
|
80
|
+
# stripping: the suffix never stops a substring from matching.
|
|
81
|
+
#
|
|
82
|
+
# @param cell [String, nil] a +c3author+ or +c4recipients+ value.
|
|
83
|
+
# @return [String, nil] +cell+ without the suffix; +nil+ stays +nil+.
|
|
84
|
+
def self.strip_undefined(cell) = cell&.gsub(UNDEFINED_AFTER_ADDRESS, '\1')
|
|
85
|
+
|
|
66
86
|
# @param gloda_path [String] path to +global-messages-db.sqlite+.
|
|
67
87
|
# @param cache_dir [String] private 0700 dir for the snapshot copy. Must
|
|
68
88
|
# be this instance's alone — see the +== Sharing+ section.
|
|
@@ -71,7 +91,6 @@ module Pikuri
|
|
|
71
91
|
@source = gloda_path
|
|
72
92
|
@snapshot = DatabaseSnapshot.new(source: gloda_path, dir: cache_dir)
|
|
73
93
|
@db = nil
|
|
74
|
-
@indexed_generation = nil
|
|
75
94
|
@lock = Mutex.new
|
|
76
95
|
end
|
|
77
96
|
|
|
@@ -119,18 +138,19 @@ module Pikuri
|
|
|
119
138
|
end
|
|
120
139
|
|
|
121
140
|
# (Re)take the snapshot + rebuild the FTS5 index iff the live Gloda
|
|
122
|
-
# generation differs from what the current index was built from.
|
|
123
|
-
#
|
|
141
|
+
# generation differs from what the current index was built from. While
|
|
142
|
+
# Thunderbird is busy writing, the older copy and its index keep serving.
|
|
143
|
+
# Callers hold the lock.
|
|
124
144
|
#
|
|
125
145
|
# @return [void]
|
|
146
|
+
# @raise [DatabaseSnapshot::TornError] Thunderbird is busy and no copy
|
|
147
|
+
# exists yet.
|
|
126
148
|
def ensure_fresh
|
|
127
|
-
|
|
128
|
-
return
|
|
149
|
+
return if @db && @snapshot.current?
|
|
150
|
+
return unless @snapshot.refresh || @db.nil?
|
|
129
151
|
|
|
130
|
-
close!
|
|
131
|
-
@snapshot.refresh
|
|
152
|
+
close!
|
|
132
153
|
open_and_index
|
|
133
|
-
@indexed_generation = @snapshot.generation
|
|
134
154
|
end
|
|
135
155
|
|
|
136
156
|
# Open the fresh snapshot copy read-write and build an external-content
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Pikuri
|
|
4
4
|
module Thunderbird
|
|
5
|
-
# Parses the little iCalendar that Thunderbird leaves opaque —
|
|
6
|
-
#
|
|
7
|
-
#
|
|
5
|
+
# Parses the little iCalendar that Thunderbird leaves opaque — the raw
|
|
6
|
+
# content lines of +cal_attendees+ and +cal_recurrence+ (everything else
|
|
7
|
+
# is already in normalized columns). The
|
|
8
8
|
# inbound counterpart to {IcsEvent}'s outbound line *building*. Two entry
|
|
9
9
|
# points:
|
|
10
10
|
#
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Pikuri
|
|
4
4
|
module Thunderbird
|
|
5
5
|
# Detached launch of the user's Thunderbird — the shared mechanism behind
|
|
6
|
-
# both
|
|
6
|
+
# both outbound tools. Given an argument Thunderbird understands on its
|
|
7
7
|
# command line (a +mailto:+ URI for {MailCompose}, an +.ics+ path for
|
|
8
8
|
# {CalendarCreate}), it opens it in the running instance:
|
|
9
9
|
#
|
|
@@ -26,7 +26,7 @@ module Pikuri
|
|
|
26
26
|
# tool turns it into an +"Error: …"+ observation.
|
|
27
27
|
class Error < StandardError; end
|
|
28
28
|
|
|
29
|
-
# @param thunderbird_bin [String] the
|
|
29
|
+
# @param thunderbird_bin [String] test seam — the executable, a PATH name
|
|
30
30
|
# (default +"thunderbird"+) or an absolute path.
|
|
31
31
|
# @param spawn [#call, nil] test seam — a callable given the argument that
|
|
32
32
|
# returns a {Pikuri::Subprocess} result (responds to +#status+ /
|
|
@@ -44,8 +44,8 @@ module Pikuri
|
|
|
44
44
|
# @raise [Error] if the binary is missing or the spawn fails.
|
|
45
45
|
def launch(arg)
|
|
46
46
|
unless resolvable?(@thunderbird_bin)
|
|
47
|
-
raise Error, "Thunderbird executable #{@thunderbird_bin.inspect} not found — " \
|
|
48
|
-
'
|
|
47
|
+
raise Error, "Thunderbird executable #{@thunderbird_bin.inspect} not found on PATH — " \
|
|
48
|
+
'is Thunderbird installed?'
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
result = @spawn.call(arg)
|
|
@@ -56,10 +56,15 @@ module Pikuri
|
|
|
56
56
|
|
|
57
57
|
private
|
|
58
58
|
|
|
59
|
+
# De-bundlerized ({Pikuri::BundlerEnv}): a Thunderbird not yet running
|
|
60
|
+
# starts here as the user's own instance, outlives pikuri, and passes its
|
|
61
|
+
# environment to everything it launches.
|
|
62
|
+
#
|
|
59
63
|
# @param arg [String] the argument to open.
|
|
60
64
|
# @return [Object] the {Pikuri::Subprocess} wait result.
|
|
61
65
|
def detached_spawn(arg)
|
|
62
|
-
Pikuri::Subprocess.spawn('setsid', '--fork', @thunderbird_bin, arg,
|
|
66
|
+
Pikuri::Subprocess.spawn('setsid', '--fork', @thunderbird_bin, arg,
|
|
67
|
+
chdir: Dir.home, env: Pikuri::BundlerEnv.clean_delta).wait
|
|
63
68
|
end
|
|
64
69
|
|
|
65
70
|
# @param bin [String] a PATH name or absolute path.
|