72 lines
2.2 KiB
Scheme
72 lines
2.2 KiB
Scheme
;;
|
|
;; mailman3-sql.scm
|
|
;;
|
|
;; Mailman management interface - Mailman version 3.x - direct SQLite3
|
|
;; DB support
|
|
;;
|
|
;; ISC License
|
|
;;
|
|
;; Copyright 2023 Brmlab, z.s.
|
|
;; Dominik Pantůček <dominik.pantucek@trustica.cz>
|
|
;;
|
|
;; Permission to use, copy, modify, and/or distribute this software
|
|
;; for any purpose with or without fee is hereby granted, provided
|
|
;; that the above copyright notice and this permission notice appear
|
|
;; in all copies.
|
|
;;
|
|
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
;;
|
|
|
|
(declare (unit mailman3-sql)
|
|
(uses sqlite3))
|
|
|
|
(module
|
|
mailman3-sql
|
|
(
|
|
list-mailman3-sql-lists
|
|
list-mailman3-sql-list-members
|
|
)
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken format)
|
|
sqlite3
|
|
configuration)
|
|
|
|
;; Thread-local parameter to re-use SQLite3 DB handle for subsequent queries
|
|
(define *cached-mailman3-db* (make-parameter #f))
|
|
|
|
;; Returns (possibly cached) SQLite3 DB handle
|
|
(define (mailman3-db)
|
|
(when (not (*cached-mailman3-db*))
|
|
(*cached-mailman3-db* (open-database (*mailman3-sql-path*))))
|
|
(*cached-mailman3-db*))
|
|
|
|
;; Returns the list of mailman3 mailinglists by querying te
|
|
;; underlying SQLite3 DB directly
|
|
(define (list-mailman3-sql-lists)
|
|
(let-values (((stmt _)
|
|
(prepare (mailman3-db)
|
|
"SELECT list_name FROM mailinglist")))
|
|
(map-row identity stmt)))
|
|
|
|
;; Returns a list of email addresses subscribed to given mailinglist
|
|
(define (list-mailman3-sql-list-members lst)
|
|
(let-values (((stmt _)
|
|
(prepare (mailman3-db)
|
|
"SELECT DISTINCT address.email
|
|
FROM member
|
|
LEFT JOIN address
|
|
ON member.address_id=address.id
|
|
WHERE list_id=? AND role=1")))
|
|
(map-row identity
|
|
stmt
|
|
(format "~A.brmlab.cz" lst))))
|
|
|
|
)
|