104 lines
2.7 KiB
Scheme
104 lines
2.7 KiB
Scheme
;;
|
|
;; mailman2.scm
|
|
;;
|
|
;; Mailman management interface - Mailman version 2.x 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 mailman2))
|
|
|
|
(module
|
|
mailman2
|
|
(
|
|
list-mailman2-lists
|
|
list-mailman2-list-members
|
|
|
|
add-email-to-mailman2-list
|
|
remove-email-from-mailman2-list
|
|
)
|
|
|
|
(import scheme
|
|
(chicken base)
|
|
(chicken pathname)
|
|
(chicken string)
|
|
(chicken sort)
|
|
(chicken format)
|
|
srfi-1
|
|
util-bst-lset
|
|
util-io
|
|
mailman-common
|
|
configuration)
|
|
|
|
;; Returns full path to given mailman binary
|
|
(define (mailman-bin bin)
|
|
(make-pathname (*mailman2-bin*) bin))
|
|
|
|
;; Mailman-specific process output lines capture
|
|
(define (get-mailman-output-lines bin . args)
|
|
(apply
|
|
get-process-output-lines
|
|
(mailman-bin bin)
|
|
args))
|
|
|
|
;; Sends all lines to the process
|
|
(define (mailman-send/recv bin args . lines)
|
|
(apply
|
|
process-send/recv
|
|
(mailman-bin bin)
|
|
args
|
|
lines))
|
|
|
|
;; Returns the list of available lists
|
|
(define (list-mailman2-lists)
|
|
(get-mailman-output-lines "list_lists" "-b"))
|
|
|
|
;; Returns the list of members of given list
|
|
(define (list-mailman2-list-members lst)
|
|
(sort
|
|
(get-mailman-output-lines "list_members" lst)
|
|
string-ci<?))
|
|
|
|
;; Adds given email to given listname
|
|
(define (add-email-to-mailman2-list listname email)
|
|
(print "Add " email " to " listname ".")
|
|
(let ((result
|
|
(mailman-send/recv
|
|
"add_members"
|
|
(list "-r" "-" listname)
|
|
email)))
|
|
(let loop ((lines result))
|
|
(when (not (null? lines))
|
|
(print " | " (car lines))
|
|
(loop (cdr lines))))))
|
|
|
|
;; Removes given email from given listname
|
|
(define (remove-email-from-mailman2-list listname email)
|
|
(print "Remove " email " from " listname ".")
|
|
(let ((result
|
|
(get-mailman-output-lines
|
|
"remove_members" listname
|
|
(sprintf "~A" email))))
|
|
(let loop ((lines result))
|
|
(when (not (null? lines))
|
|
(print " | " (car lines))
|
|
(loop (cdr lines))))))
|
|
|
|
)
|