Java-basierte Mailinglisten-Anwendung, die auf IMAP+SMTP aufsetzt, und damit (fast) jede Mailbox in eine Mailingliste verwandeln kann.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
10 KiB

function addMod(userEmail,listEmail){
$.post('/api/list/add_mod',{list:listEmail,email:userEmail},reload,'json');
}
function addPermission(userEmail,permission){
if (confirm("Wirklich Berechtigung an "+userEmail+" geben?")){
$.post('/api/user/addpermission',{email:userEmail,permissions:permission},reload,'json');
}
}
function disableList(listEmail){
$.post('/api/list/disable',{list:listEmail},showListResult,'json');
}
function dropList(listEmail){
$.post('/api/list/drop',{list:listEmail},showListResult,'json');
}
function dropMail(mailId){
$.post('/api/mail/drop',{message_id:mailId},showListResult,'json');
}
function dropMember(userEmail,listEmail){
$.post('/api/list/drop_member',{list:listEmail,email:userEmail},reload,'json');
}
function dropMod(userEmail,listEmail){
$.post('/api/list/drop_mod',{list:listEmail,email:userEmail},reload,'json');
}
function dropPermission(userEmail,permission){
if (confirm("Wirklich Berechtigung von "+userEmail+" wegnehmen?")){
$.post('/api/user/droppermission',{email:userEmail,permissions:permission},reload,'json');
}
}
function enableList(listEmail){
$.post('/api/list/enable',{list:listEmail},showListResult,'json');
}
function hideList(listEmail){
$.post('/api/list/hide',{list:listEmail},showListResult,'json');
}
function loadArchive(listEmail,month){
$.get('/api/list/archive?month='+month+'&list='+listEmail,showListArchive,'json');
}
function loadArchiveSummary(listEmail){
$.get('/api/list/archive?list='+listEmail,showListArchiveSummary,'json');
}
function loadListDetail(listEmail){
$.post('/api/list/detail',{list:listEmail},showListDetail,'json');
}
function loadListOfModeratedLists(){
$.getJSON('/api/list/moderated', showListOfModeratedLists);
}
function loadListOfSubscribableLists(){
$.getJSON('/api/list/subscribable', showListList);
}
function loadMembers(listEmail){
$.post('/api/list/members',{list:listEmail},showMembers,'json');
}
function loadUserList(){
$.getJSON('/api/user/list', showUserList);
}
function reload(){
window.location.reload(true);
}
function showList(listEmail){
$.post('/api/list/show',{list:listEmail},showListResult,'json');
}
function showListArchive(data){
console.log(data);
let moderator = data.archive.moderator;
console.log('moderator: ',moderator);
let posts = data.archive.posts;
for (let time in posts){
let post = posts[time];
let row = $('<tr/>');
var url = 'post?id='+post.id;
$('<td/>').html('<a href="'+url+'">'+post.date+'</a>').appendTo(row);
$('<td/>').html('<a href="'+url+'">'+post.from_name+'</a>').appendTo(row);
$('<td/>').html('<a href="'+url+'">'+post.subject+'</a>').appendTo(row);
if (moderator){
$('<button/>',{onclick:"dropMail('"+post.id+"');"}).text('Löschen').appendTo($('<td/>')).appendTo(row);
}
3 years ago
row.appendTo($('#archive table'));
}
}
function showListArchiveSummary(data){
console.log(data);
let summary = data.archive.summary;
for (let month in summary){
let url = 'archive?month='+month+'&list='+data.archive.list;
let row = $('<tr/>');
$('<td/>').html('<a href="'+url+'">'+month+'</a>').appendTo(row);
$('<td/>').html('<a href="'+url+'">'+summary[month]+'</a>').appendTo(row);
3 years ago
row.appendTo($('#archive table'));
}
}
function showListDetail(data){
var options = ['forward_from','forward_attached','hide_receivers','reply_to_list','open_for_guests','open_for_subscribers','archive','edit_mods','delete_messages'];
options.forEach(function(option,index,array){
console.log(option,'→',data[option]);
if (data[option]) $('input[name="'+option+'"]').prop('checked',true);
});
if (data['delete_messages']) $('input[name="hold_time"]').val(data['delete_messages']);
}
function showListOfModeratedLists(data){
for (let i in data.lists){
let list = data.lists[i];
let row = $('<tr/>');
let addr = list.email.prefix+'@'+list.email.domain;
let inspect = 'inspect?list='+addr;
let td = $('<td/>');
$('<a/>',{href:inspect}).text(list.name).appendTo(td);
td.appendTo(row);
td = $('<td/>');
$('<a/>',{href:inspect}).text(addr).appendTo(td)
td.appendTo(row);
let states = [];
for (let state in list.state){
if (list.state[state] > 0) states.push(state);
}
$('<td/>').text(states.toString()).appendTo(row);
if (list.last_error){
$('<td/>').html('<span class="error">'+list.last_error+'</span>').appendTo(row);
} else $('<td/>').text('-').appendTo(row);
let select = $('<select/>',{name:addr}).change(function () {
let selected = $(this).children("option:selected");
let action = selected.val();
let verb = selected.text();
let list = $(this).attr('name');
if (confirm("Dies wird '"+list+"' "+verb+". Sind Sie sicher?")) self[action+'List'](list);
});
$('<option/>').text('Aktionen').appendTo(select);
Object.entries({
'enable':'aktivieren',
'disable':'deaktivieren',
'drop':'löschen',
'hide':'verstecken',
'show':'veröffentlichen',
'test':'testen'
}).forEach(([k,v],i) => {
$('<option/>',{value:k}).text(v).appendTo(select)
});
select.appendTo($('<td/>')).appendTo(row);
$('<td/>').text(list.imap_host).appendTo(row);
$('<td/>').text(list.imap_port).appendTo(row);
$('<td/>').text(list.inbox).appendTo(row);
$('<td/>').text(list.smtp_host).appendTo(row);
$('<td/>').text(list.smtp_port).appendTo(row);
row.appendTo('#listlist');
}
if (data.user.permissions.includes('create lists')){
$('a[href=add_list]').show();
} else {
$('a[href=add_list]').hide();
}
}
function showListList(data){
for (let i in data.lists){
let list = data.lists[i];
let row = $('<tr/>');
let email = list.email.prefix + '@' + list.email.domain;
$('<td/>').html('<a href="archive?list='+email+'">'+list.name+'</a>').appendTo(row);
$('<td/>').text(email).appendTo(row);
let states = [];
for (let state in list.state){
if (list.state[state] > 0) states.push(state);
}
$('<td/>').text(states.toString()).appendTo(row);
let td = $('<td/>',{class:'actions'});
$('<button/>',{onclick:"subscribeTo('"+email+"');"}).text('abonnieren').appendTo(td);
$('<button/>',{onclick:"unsubscribeFrom('"+email+"');"}).text('abbestellen').appendTo(td);
td.appendTo(row);
row.appendTo('#listlist');
}
}
function showListResult(result){
if ('error' in result){
alert(result.error);
return;
}
if ('success' in result){
alert(result.success);
reload();
return;
}
alert("Api call did not return result");
}
function showMembers(data){
var list_mail = data.list.email.prefix+'@'+data.list.email.domain;
console.log("data",data);
var owner = false;
for (let member of data.members){
if (member.email == data.user.email && member.state.includes("Besitzer")) owner = member.email;
}
for (let i in data.members){
let member = data.members[i];
let row = $('<tr/>');
$('<td/>').text(member.name).appendTo(row);
$('<td/>').text(member.email).appendTo(row);
$('<td/>').text(member.state).appendTo(row);
let col = $('<td/>');
if (member.state.includes("Moderator")) {
if (member.email != owner){
$('<button/>',{onclick:'dropMod("'+member.email+'","'+list_mail+'")'}).text("- Moderator").appendTo(col);
if (data.user.email == owner) $('<button/>',{onclick:'transfer("'+member.email+'","'+list_mail+'")'}).text("Eigentum übertragen").appendTo(col);
}
} else {
$('<button/>',{onclick:'addMod("'+member.email+'","'+list_mail+'")'}).text("+ Moderator").appendTo(col);
}
if (!member.state.includes("owner")) {
$('<button/>',{onclick:'dropMember("'+member.email+'","'+list_mail+'")'}).text("entfernen").appendTo(col);
}
col.appendTo(row);
row.appendTo('#memberlist');
}
}
function showUserList(data){
let isAdmin = data.user.permissions.includes('admin');
for (let i in data.users){
let user = data.users[i];
let row = $('<tr/>');
$('<td/>').text(user.name).appendTo(row);
$('<td/>').text(user.email).appendTo(row);
$('<td/>').text(user.password).appendTo(row);
$('<td/>').text(user.permissions).appendTo(row);
let permissions = $('<span/>');
if (isAdmin){
if (user.permissions.includes('admin')){
$('<button/>').text("- Admin").click(() => dropPermission(user.email,1)).appendTo(permissions);
} else {
$('<button/>').text("+ Admin").click(() => addPermission(user.email,1)).appendTo(permissions);
}
if (user.permissions.includes('create lists')){
$('<button/>').text("- Listen anlegen").click(() => dropPermission(user.email,2)).appendTo(permissions);
} else {
$('<button/>').text("+ Listen anlegen").click(() => addPermission(user.email,2)).appendTo(permissions);
}
}
permissions.appendTo(row);
row.appendTo('#userlist');
}
if (isAdmin){
$('a[href=register]').show();
} else {
$('a[href=register]').hide();
}
}
function start(){
console.log("application started");
}
function subscribeTo(listEmail){
window.location.href='subscribe?list='+listEmail;
}
function testList(listEmail){
$.post('/api/list/test',{list:listEmail},showListResult,'json');
}
function transfer(newOwner,listEmail){
if (confirm(listEmail+" wirklich an "+newOwner+" übereignen?")){
$.post('/api/list/transfer',{email:newOwner,list:listEmail},reload,'json');
}
}
function unsubscribeFrom(listEmail){
window.location.href='unsubscribe?list='+listEmail;
}
$(start); // document.on ready