posto-client 0.6.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 +7 -0
- data/CHANGELOG.md +18 -0
- data/LICENSE +21 -0
- data/README.md +219 -0
- data/lib/posto/client/version.rb +10 -0
- data/lib/posto/client.rb +10 -0
- data/lib/posto/models/model.rb +18 -0
- data/lib/posto/models.rb +162 -0
- metadata +88 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3a6b039358546149931dea04db4fabc9c3605435615ec35b8ceff819ad849a21
|
|
4
|
+
data.tar.gz: 406872f21ca57a4a8260c1a3394d9c9ccaec8fa143a1f8371ff0df96b10eaf29
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1354c88fc55afab6f616490a80d85ed0a1c14e56ec46a5d04c14e19cec43bfee183807a1b73addb91486805b086722db614743e4fabb5634bb5e25359e1a2881
|
|
7
|
+
data.tar.gz: 87332db134d25dcb471a3053f5b8f1b3645bce74639b877049af5130466c4e0a058347b7a9dff1fc9c9954393670713f1c2c1436e973639a4a74ec60e18a3c68
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
The minor version tracks the Posto schema migration the models expect.
|
|
4
|
+
|
|
5
|
+
## 0.6.0
|
|
6
|
+
|
|
7
|
+
First published release, for Posto schema migration 0006.
|
|
8
|
+
|
|
9
|
+
- Plain `Sequel::Model` classes under `Posto::Models`, on an abstract
|
|
10
|
+
`Posto::Models::Model` with its own database.
|
|
11
|
+
- `external_id` on `List`, `Alias` and `ListRecipient` (snapshotted on
|
|
12
|
+
`SubscriptionEvent`) for applications that manage Posto rows.
|
|
13
|
+
- List and alias recipients are unique ignoring case (stored as typed);
|
|
14
|
+
a second spelling raises `Sequel::UniqueConstraintViolation`.
|
|
15
|
+
- `List#replies_to` (required) and `List#from_rewrite`;
|
|
16
|
+
`ListPosting#author_dmarc`.
|
|
17
|
+
- Requiring `posto/models` raises `Posto::Models::SchemaMismatch` when the
|
|
18
|
+
database predates migration 0006.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Austin Bales
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# posto-client
|
|
2
|
+
|
|
3
|
+
Ruby models for applications connecting directly to a Posto
|
|
4
|
+
mail server's PostgreSQL database: mailing lists, subscriptions, aliases,
|
|
5
|
+
mailboxes, moderation, and delivery records. Posto's canonical schema
|
|
6
|
+
(`src/priv/schema.sql` in the Posto repository) is authoritative. This library
|
|
7
|
+
does not initialize or migrate it, start Posto, or call its HTTP API.
|
|
8
|
+
|
|
9
|
+
The minor version tracks the Posto schema migration it expects (0.6.x expects
|
|
10
|
+
migration 0006). Requiring `posto/models` raises `Posto::Models::SchemaMismatch`
|
|
11
|
+
against an older database; Posto applies its own migrations when it restarts.
|
|
12
|
+
|
|
13
|
+
## Install and connect
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
# Gemfile
|
|
17
|
+
gem "posto-client", "~> 0.6"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
require "posto/client"
|
|
22
|
+
|
|
23
|
+
# Supply this through your application's environment; never commit credentials.
|
|
24
|
+
POSTO_DB = Sequel.connect(ENV.fetch("POSTO_DATABASE_URL"))
|
|
25
|
+
Posto::Models::Model.db = POSTO_DB
|
|
26
|
+
require "posto/models"
|
|
27
|
+
|
|
28
|
+
Posto::Models::List.order(:name).all
|
|
29
|
+
Posto::Models::ListRecipient.active.where(recipient: "reader@example.net").all
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The models are ordinary named `Sequel::Model` classes under `Posto::Models`,
|
|
33
|
+
inheriting from the abstract `Posto::Models::Model`. Assign its database before
|
|
34
|
+
requiring `posto/models`: like any Sequel model, each class reads its table's
|
|
35
|
+
columns when it is defined. Assigning `Posto::Models::Model.db` does not change
|
|
36
|
+
`Sequel::Model.db` or other models in the application. If you skip it, Sequel's
|
|
37
|
+
usual default (the first database connected) applies. Requiring the models
|
|
38
|
+
enables Sequel's `pg_array` extension on that connection. One process binds to
|
|
39
|
+
one Posto database.
|
|
40
|
+
|
|
41
|
+
The caller owns the connection and its pool, SSL settings, credentials, search
|
|
42
|
+
path, and lifetime (`POSTO_DB.disconnect`). Load the models after schema upgrades.
|
|
43
|
+
Ruby 3.1+, Sequel 5.87+, and the `pg` gem are required.
|
|
44
|
+
|
|
45
|
+
For a connection over the Internet, require `sslmode=verify-full` and a trusted
|
|
46
|
+
`sslrootcert` CA bundle in the connection options/URL; never disable certificate
|
|
47
|
+
or hostname verification. Full-access credentials are for trusted server-side
|
|
48
|
+
applications, never browsers.
|
|
49
|
+
|
|
50
|
+
## Using Posto from another application
|
|
51
|
+
|
|
52
|
+
Plugins applied to `Sequel::Model` itself (for example `Sequel::Model.plugin
|
|
53
|
+
:dirty`) are inherited by these models too, as are global settings such as
|
|
54
|
+
`Sequel.application_timezone`. Plugins applied to your own model classes are not.
|
|
55
|
+
Tools that walk `Sequel::Model.subclasses` (schema dumpers, RBI generators) will
|
|
56
|
+
also find `Posto::Models` classes; point them at `Posto::Models::Model.db` or skip
|
|
57
|
+
them.
|
|
58
|
+
|
|
59
|
+
Your application's database and Posto's are separate, so a write to both is never
|
|
60
|
+
one transaction. Write to Posto after your own transaction commits (Sequel's
|
|
61
|
+
`db.after_commit`), and run a periodic reconciliation that makes Posto match your
|
|
62
|
+
records, so a crash between the two writes heals itself.
|
|
63
|
+
|
|
64
|
+
`List`, `Alias` and `ListRecipient` have an optional, opaque `external_id`
|
|
65
|
+
(1-255 bytes) for exactly this. Use a namespaced value such as
|
|
66
|
+
`"myapp:member:42"`:
|
|
67
|
+
|
|
68
|
+
- It marks the rows your application manages. A reconciliation should only
|
|
69
|
+
unsubscribe or remove rows carrying its own prefix, never rows added by SQL,
|
|
70
|
+
the HTTP API, or another application.
|
|
71
|
+
- It is unique per table for lists and aliases, and per list for subscriptions,
|
|
72
|
+
so a retried create finds the existing row instead of adding a duplicate.
|
|
73
|
+
- A subscription's `external_id` is stable when the member's address changes:
|
|
74
|
+
update `recipient` instead of unsubscribing and resubscribing.
|
|
75
|
+
- `SubscriptionEvent#external_id` snapshots it, so unsubscribes made through
|
|
76
|
+
Posto's links map back to your member without matching email addresses.
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
member_key = "myapp:member:#{member.id}"
|
|
80
|
+
subscription = Posto::Models::ListRecipient.first(list_id: list.id, external_id: member_key) ||
|
|
81
|
+
Posto::Models::ListRecipient.create(list_id: list.id, external_id: member_key,
|
|
82
|
+
recipient: member.email)
|
|
83
|
+
subscription.update(recipient: member.email) if subscription.recipient != member.email
|
|
84
|
+
|
|
85
|
+
Posto::Models::SubscriptionEvent.where(Sequel.like(:external_id, "myapp:member:%"))
|
|
86
|
+
.where { id > last_seen_event_id }.order(:id).each do |event|
|
|
87
|
+
# event.subscribed == false: the member unsubscribed through Posto.
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Posto does not send webhooks yet; poll `subscription_events` by `id`.
|
|
92
|
+
|
|
93
|
+
## Manage recipient configuration
|
|
94
|
+
|
|
95
|
+
Lists and aliases are distinct models. `ListRecipient` is the subscription model;
|
|
96
|
+
there is no separate membership or subscription-settings record.
|
|
97
|
+
|
|
98
|
+
Posto seeds `Configuration[1].list_id_domain` once from `server.origin`.
|
|
99
|
+
For SQL/Ruby provisioning before the first startup, create that row yourself:
|
|
100
|
+
`Posto::Models::Configuration.create(list_id_domain: "mail.example.org")`.
|
|
101
|
+
New lists get `<id>.list-id.<domain>` automatically; existing identifiers never
|
|
102
|
+
change when a list is renamed or the configuration is edited. Explicit identifiers
|
|
103
|
+
remain supported for imports.
|
|
104
|
+
|
|
105
|
+
An omitted `List#unsubscribe_url` is copied from
|
|
106
|
+
`Configuration[1].unsubscribe_base_url`, initially
|
|
107
|
+
`https://mail.giraffe.camp/unsubscribe`. This prefix targets Posto's built-in
|
|
108
|
+
`/unsubscribe/<token>` routes. Set a different public HTTPS prefix through
|
|
109
|
+
`Posto::Models::Configuration[1].update(unsubscribe_base_url: "...")` before creating
|
|
110
|
+
lists on another deployment, or supply an explicit `unsubscribe_url` per list.
|
|
111
|
+
Changing the default does not rewrite existing lists or queued messages.
|
|
112
|
+
The default does not enable Posto's HTTP listener or configure an HTTPS proxy.
|
|
113
|
+
|
|
114
|
+
Creating a list or an alias with `address:` also creates its canonical
|
|
115
|
+
`Address` row in PostgreSQL. Add further addresses with `Address.create`.
|
|
116
|
+
Changing the canonical address adds the new row and keeps the old one routing.
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
list = Posto::Models::List.create(
|
|
120
|
+
name: "Gardening",
|
|
121
|
+
posting_policy: "members",
|
|
122
|
+
replies_to: "list", # or "sender"; non-members' posts always reply to the sender
|
|
123
|
+
posting_address: "garden@lists.example.org"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
subscription = Posto::Models::ListRecipient.create(
|
|
127
|
+
list_id: list.id, recipient: "reader@example.net"
|
|
128
|
+
)
|
|
129
|
+
subscription.update(subscribed: false) # Unsubscribe; retain historical references.
|
|
130
|
+
subscription.update(subscribed: true) # PostgreSQL rotates the capability.
|
|
131
|
+
token = subscription.unsubscribe_token # Already refreshed from UPDATE RETURNING.
|
|
132
|
+
events = subscription.events_dataset.order(:id).all
|
|
133
|
+
|
|
134
|
+
mailbox = Posto::Models::Mailbox.create(name: "archive")
|
|
135
|
+
Posto::Models::Address.create(address: "archive@example.org", mailbox_id: mailbox.id)
|
|
136
|
+
redirect = Posto::Models::Alias.create(name: "editors", address: "editors@example.org")
|
|
137
|
+
Posto::Models::AliasRecipient.create(alias_id: redirect.id, recipient: "archive@example.org")
|
|
138
|
+
redirect.recipients # AliasRecipient instances; recipients may also be external.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Defaults, validation, token rotation, timestamps, and subscription events are
|
|
142
|
+
owned by PostgreSQL constraints/triggers, not duplicated in callbacks. Invalid
|
|
143
|
+
writes raise Sequel database exceptions. An address must be lowercase and point
|
|
144
|
+
to exactly one mailbox, alias, or list. `Address` has a natural `address` primary
|
|
145
|
+
key; `AliasRecipient` has the composite key `[alias_id, recipient]`. Other models
|
|
146
|
+
use `id`. Do not supply generated identity IDs when creating rows.
|
|
147
|
+
|
|
148
|
+
Recipients are unique per list (and per alias) ignoring case, but stored and
|
|
149
|
+
delivered exactly as given: adding `Reader@example.net` next to
|
|
150
|
+
`reader@example.net` raises `Sequel::UniqueConstraintViolation`. Posto does not
|
|
151
|
+
strip plus tags or apply provider-specific rules; match people in your own
|
|
152
|
+
application (or by `external_id`) instead.
|
|
153
|
+
|
|
154
|
+
Unsubscribe by setting `subscribed: false`, not deleting a membership. Tokens are
|
|
155
|
+
capabilities: do not log or expose `ListRecipient#values` indiscriminately.
|
|
156
|
+
An update refreshes that instance's database-generated token/timestamp; previously
|
|
157
|
+
loaded instances and associations still need the usual Sequel `refresh`/reload.
|
|
158
|
+
|
|
159
|
+
## Read mail, inspect delivery, and moderate
|
|
160
|
+
|
|
161
|
+
```ruby
|
|
162
|
+
# The view includes prepared MIME plus this subscription's personal headers.
|
|
163
|
+
mailbox.messages_dataset.order(:delivered_at, :id).each do |message|
|
|
164
|
+
bytes = message.raw # Binary String (bytea), not decoded or transcoded MIME.
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
posting = Posto::Models::ListPosting.held.order(:id).first
|
|
168
|
+
posting&.update(status: "approved", decision_reason: "Approved by moderator")
|
|
169
|
+
# Posto's queue worker performs distribution; this library does not send mail.
|
|
170
|
+
|
|
171
|
+
Posto::Models::OutboundDelivery.where(status: "failed").all
|
|
172
|
+
Posto::Models::Message.first&.envelope_recipients # Sequel::Postgres::PGArray
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
| Model | Table/view | Intended client writes |
|
|
176
|
+
|---|---|---|
|
|
177
|
+
| `Configuration` | `configuration` (singleton `id = 1`) | Yes |
|
|
178
|
+
| `Mailbox` | `mailboxes` | Yes |
|
|
179
|
+
| `Alias` | `aliases` | Yes |
|
|
180
|
+
| `List` | `lists` | Yes |
|
|
181
|
+
| `Address` | `addresses` | Yes |
|
|
182
|
+
| `AliasRecipient` | `alias_recipients` | Yes |
|
|
183
|
+
| `ListRecipient` | `list_recipients` | Yes |
|
|
184
|
+
| `ListPosting` | `list_postings` | Yes (moderation) |
|
|
185
|
+
| `SubscriptionEvent` | `subscription_events` | Read-only history |
|
|
186
|
+
| `Message` | `messages` | Read-only immutable input |
|
|
187
|
+
| `Distribution` | `distributions` | Read-only prepared output |
|
|
188
|
+
| `MailboxEntry` | `mailbox_entries` | Read-only deposited content |
|
|
189
|
+
| `OutboundDelivery` | `outbound_deliveries` | Read-only worker-owned queue |
|
|
190
|
+
| `MailboxMessage` | `mailbox_messages` view | Read-only personalized content |
|
|
191
|
+
|
|
192
|
+
Foreign-key associations navigate both directions (including nullable direct
|
|
193
|
+
delivery/subscription references) and are standard Sequel associations, with
|
|
194
|
+
`*_dataset` methods and `add_*`/`remove_*` helpers. Events intentionally have no
|
|
195
|
+
foreign keys and remain readable after the subscription/list is deleted.
|
|
196
|
+
|
|
197
|
+
The models do not block writes: rows marked read-only above belong to Posto's
|
|
198
|
+
server, and **database grants are the write boundary.** Give client roles only
|
|
199
|
+
the tables, operations, and columns they need. Never modify immutable
|
|
200
|
+
messages, delivery leases, or deposited content through a client app. Reads of
|
|
201
|
+
`Message#raw` are original input; use `MailboxMessage#raw` for delivered bytes.
|
|
202
|
+
|
|
203
|
+
## Tests
|
|
204
|
+
|
|
205
|
+
Use a dedicated, empty local test database, never a deployed database. Load the
|
|
206
|
+
canonical schema first:
|
|
207
|
+
|
|
208
|
+
```sh
|
|
209
|
+
psql "$POSTO_TEST_DATABASE_URL" -X -v ON_ERROR_STOP=1 -f src/priv/schema.sql
|
|
210
|
+
cd clients/ruby
|
|
211
|
+
bundle install
|
|
212
|
+
bundle exec ruby -Ilib test/models_test.rb
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`POSTO_TEST_DATABASE_URL` must be explicitly supplied through the environment;
|
|
216
|
+
there is no fallback to `DATABASE_URL`. The suite refuses nonempty application
|
|
217
|
+
tables and rolls every test back, leaving the schema intact. It exercises the
|
|
218
|
+
real PostgreSQL constraints/triggers, not a mock database. It creates no databases
|
|
219
|
+
and applies no schema changes itself.
|
data/lib/posto/client.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Entry point for the posto-client gem. Assign the models' database, then load
|
|
4
|
+
# them:
|
|
5
|
+
#
|
|
6
|
+
# require "posto/client"
|
|
7
|
+
# Posto::Models::Model.db = Sequel.connect(ENV.fetch("POSTO_DATABASE_URL"))
|
|
8
|
+
# require "posto/models"
|
|
9
|
+
require_relative "client/version"
|
|
10
|
+
require_relative "models/model"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "sequel"
|
|
4
|
+
|
|
5
|
+
module Posto
|
|
6
|
+
module Models
|
|
7
|
+
# Abstract base for Posto's models, so they can use a database other than
|
|
8
|
+
# Sequel::Model.db. Assign it before requiring "posto/models":
|
|
9
|
+
#
|
|
10
|
+
# require "posto/models/model"
|
|
11
|
+
# Posto::Models::Model.db = DB
|
|
12
|
+
# require "posto/models"
|
|
13
|
+
Model = Class.new(Sequel::Model)
|
|
14
|
+
Model.def_Model(self)
|
|
15
|
+
# Resolve association `class:` names such as :ListRecipient in this namespace.
|
|
16
|
+
Model.default_association_options = { class_namespace: name }
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/posto/models.rb
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "client/version"
|
|
4
|
+
require_relative "models/model"
|
|
5
|
+
|
|
6
|
+
module Posto
|
|
7
|
+
module Models
|
|
8
|
+
# The database predates the schema these models expect.
|
|
9
|
+
class SchemaMismatch < StandardError; end
|
|
10
|
+
|
|
11
|
+
# Tables (and the view) the models map, with the columns added by the
|
|
12
|
+
# newest migrations. Sequel would otherwise define models silently against
|
|
13
|
+
# a stale schema when an application sets require_valid_table = false.
|
|
14
|
+
REQUIRED_COLUMNS = {
|
|
15
|
+
configuration: %i[list_id_domain unsubscribe_base_url],
|
|
16
|
+
mailboxes: [], addresses: [],
|
|
17
|
+
aliases: %i[address external_id],
|
|
18
|
+
alias_recipients: [],
|
|
19
|
+
lists: %i[replies_to from_rewrite external_id],
|
|
20
|
+
list_recipients: %i[external_id],
|
|
21
|
+
subscription_events: %i[external_id],
|
|
22
|
+
messages: [],
|
|
23
|
+
list_postings: %i[author_dmarc],
|
|
24
|
+
distributions: [], mailbox_entries: [], outbound_deliveries: [],
|
|
25
|
+
mailbox_messages: []
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
# Raise SchemaMismatch unless `db` has every table and column the models
|
|
29
|
+
# need (Posto applies its own migrations at startup; restart it first).
|
|
30
|
+
def self.check_schema!(db = Model.db)
|
|
31
|
+
missing = REQUIRED_COLUMNS.flat_map do |table, columns|
|
|
32
|
+
present = begin
|
|
33
|
+
db.schema(table, reload: true).map(&:first)
|
|
34
|
+
rescue Sequel::Error
|
|
35
|
+
next ["#{table} (table)"]
|
|
36
|
+
end
|
|
37
|
+
(columns - present).map { |column| "#{table}.#{column}" }
|
|
38
|
+
end
|
|
39
|
+
return if missing.empty?
|
|
40
|
+
|
|
41
|
+
raise SchemaMismatch,
|
|
42
|
+
"Posto database is older than migration #{Posto::Client::SCHEMA_MIGRATION} " \
|
|
43
|
+
"(posto-client #{Posto::Client::VERSION}); missing #{missing.join(", ")}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
Posto::Models.check_schema!
|
|
49
|
+
|
|
50
|
+
# Message#envelope_recipients is a text[] column.
|
|
51
|
+
Posto::Models::Model.db.extension :pg_array
|
|
52
|
+
|
|
53
|
+
module Posto
|
|
54
|
+
# Sequel models for Posto's canonical PostgreSQL schema. Constraints and
|
|
55
|
+
# triggers own defaults, validation, token rotation, canonical address rows,
|
|
56
|
+
# and subscription events; these classes do not duplicate them.
|
|
57
|
+
module Models
|
|
58
|
+
class Configuration < Model(:configuration)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
class Mailbox < Model(:mailboxes)
|
|
62
|
+
one_to_many :addresses
|
|
63
|
+
one_to_many :entries, class: :MailboxEntry
|
|
64
|
+
one_to_many :messages, class: :MailboxMessage
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
class Alias < Model(:aliases)
|
|
68
|
+
many_to_one :canonical_address, class: :Address, key: :address
|
|
69
|
+
one_to_many :addresses
|
|
70
|
+
one_to_many :recipients, class: :AliasRecipient
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class List < Model(:lists)
|
|
74
|
+
many_to_one :canonical_address, class: :Address, key: :posting_address
|
|
75
|
+
one_to_many :addresses
|
|
76
|
+
one_to_many :recipients, class: :ListRecipient
|
|
77
|
+
one_to_many :postings, class: :ListPosting
|
|
78
|
+
one_to_many :subscription_events
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class Address < Model(:addresses)
|
|
82
|
+
unrestrict_primary_key
|
|
83
|
+
plugin :update_primary_key
|
|
84
|
+
|
|
85
|
+
many_to_one :mailbox
|
|
86
|
+
many_to_one :alias
|
|
87
|
+
many_to_one :list
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class AliasRecipient < Model(:alias_recipients)
|
|
91
|
+
unrestrict_primary_key
|
|
92
|
+
plugin :update_primary_key
|
|
93
|
+
|
|
94
|
+
many_to_one :alias
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# The subscription model. BEFORE UPDATE triggers rotate the token and set
|
|
98
|
+
# updated_at; update_refresh reads them back with RETURNING.
|
|
99
|
+
class ListRecipient < Model(:list_recipients)
|
|
100
|
+
plugin :update_refresh
|
|
101
|
+
|
|
102
|
+
many_to_one :list
|
|
103
|
+
one_to_many :mailbox_entries, key: :subscription_id
|
|
104
|
+
one_to_many :outbound_deliveries, key: :subscription_id
|
|
105
|
+
one_to_many :events, class: :SubscriptionEvent, key: :subscription_id
|
|
106
|
+
|
|
107
|
+
dataset_module do
|
|
108
|
+
where :active, subscribed: true
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# History without foreign keys: it outlives deleted subscriptions and lists.
|
|
113
|
+
class SubscriptionEvent < Model(:subscription_events)
|
|
114
|
+
many_to_one :subscription, class: :ListRecipient
|
|
115
|
+
many_to_one :list
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class Message < Model(:messages)
|
|
119
|
+
one_to_many :postings, class: :ListPosting
|
|
120
|
+
one_to_many :distributions
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class ListPosting < Model(:list_postings)
|
|
124
|
+
many_to_one :list
|
|
125
|
+
many_to_one :message
|
|
126
|
+
one_to_one :distribution
|
|
127
|
+
|
|
128
|
+
dataset_module do
|
|
129
|
+
where :held, status: "held"
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class Distribution < Model(:distributions)
|
|
134
|
+
many_to_one :message
|
|
135
|
+
many_to_one :list_posting
|
|
136
|
+
one_to_many :mailbox_entries
|
|
137
|
+
one_to_many :outbound_deliveries
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
class MailboxEntry < Model(:mailbox_entries)
|
|
141
|
+
many_to_one :mailbox
|
|
142
|
+
many_to_one :distribution
|
|
143
|
+
many_to_one :subscription, class: :ListRecipient
|
|
144
|
+
one_to_one :mailbox_message, key: :id
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
class OutboundDelivery < Model(:outbound_deliveries)
|
|
148
|
+
many_to_one :distribution
|
|
149
|
+
many_to_one :subscription, class: :ListRecipient
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Personalized stored bytes: a view over mailbox_entries.
|
|
153
|
+
class MailboxMessage < Model(:mailbox_messages)
|
|
154
|
+
set_primary_key :id
|
|
155
|
+
|
|
156
|
+
many_to_one :mailbox
|
|
157
|
+
many_to_one :distribution
|
|
158
|
+
many_to_one :subscription, class: :ListRecipient
|
|
159
|
+
many_to_one :mailbox_entry, key: :id
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: posto-client
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.6.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Austin Bales
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: sequel
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '5.87'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '6'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '5.87'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '6'
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: pg
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '1.5'
|
|
39
|
+
- - "<"
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '2'
|
|
42
|
+
type: :runtime
|
|
43
|
+
prerelease: false
|
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '1.5'
|
|
49
|
+
- - "<"
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '2'
|
|
52
|
+
description: |
|
|
53
|
+
Plain Sequel models for Posto's mailing lists, subscriptions, aliases,
|
|
54
|
+
mailboxes, moderation and delivery records. PostgreSQL constraints and
|
|
55
|
+
triggers remain the source of truth; the models add no callbacks.
|
|
56
|
+
executables: []
|
|
57
|
+
extensions: []
|
|
58
|
+
extra_rdoc_files: []
|
|
59
|
+
files:
|
|
60
|
+
- CHANGELOG.md
|
|
61
|
+
- LICENSE
|
|
62
|
+
- README.md
|
|
63
|
+
- lib/posto/client.rb
|
|
64
|
+
- lib/posto/client/version.rb
|
|
65
|
+
- lib/posto/models.rb
|
|
66
|
+
- lib/posto/models/model.rb
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
rubygems_mfa_required: 'true'
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '3.1'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubygems_version: 3.6.2
|
|
86
|
+
specification_version: 4
|
|
87
|
+
summary: Sequel models for direct access to a Posto mail server's PostgreSQL database
|
|
88
|
+
test_files: []
|