This repository was archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlsync.rb
executable file
·102 lines (84 loc) · 3.07 KB
/
mlsync.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env ruby
# encoding: utf-8
# Copyright © 2016
# Contributed by Raphaël Bleuse <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require_relative 'connectors/extranet'
require_relative 'connectors/sympa'
require_relative 'credentials.rb' # configuration & credentials defined there
require_relative 'helpers/patches/hash'
$sympa_gresille = Sympa.new($gresille_url)
$sympa_gresille.login(login=$gresille_login, passwd=$gresille_passwd)
$extranet_ffcam = Extranet.new(url=$ffcam_url)
$extranet_ffcam.login(login=$ffcam_login, passwd=$ffcam_passwd)
def synchronize(listname)
#---------------------------------
# PICK NEW EMAIL ADDRESSES TO ADD
#---------------------------------
# retrieve subscription request & sign-off event
ffcam_request = $extranet_ffcam.review(listname)
gresille_signoff = $sympa_gresille.get_signoff(listname)
# drop subscription requests older than the log of sign-off span (we do
# here conservative adds: meaning we do not add unless we are sure the
# user really wants it)
ffcam_request.reject! do |row|
row[:date] < gresille_signoff[:valid_after]
end
# merge information on each email address
considered_emails = {}
ffcam_request.each do |row|
next unless row[:email]
content = {id: row[:id], email: row[:email], on: row[:date]}
considered_emails[row[:email]] =
considered_emails.fetch(row[:email], {}).merge(content)
end
gresille_signoff[:off].each do |row|
next unless row[:email]
content = {email: row[:email], off: row[:date]}
considered_emails[row[:email]] =
considered_emails.fetch(row[:email], {}).merge(content)
end
considered_emails = considered_emails.values
# drop email addresses that signed off
considered_emails.reject! do |row|
row.key? :off and (!row.key? :on or row[:on] < row[:off])
end
# remove already subscribed emails
gresille_members = $sympa_gresille.review(listname)
new_emails = considered_emails.map {|row| row[:email]}
new_emails -= gresille_members
#-----------------------------------
# PUSH NEW EMAIL ADDRESSES TO SYMPA
#-----------------------------------
# summarize actions header
puts '=' * 80
puts "\" #{listname}"
puts '=' * 80
# add new emails to sympa
if not new_emails.empty?
puts '" new users:'
new_emails.each do |email|
$sympa_gresille.add(listname=listname, email=email)
puts email
end
else
puts '" no new users'
end
end
mailing_lists = ['esmug-gucem', 'esmug-gucem-discussion']
mailing_lists.each do |listname|
synchronize(listname)
puts
end