rainloop-nextcloud icon indicating copy to clipboard operation
rainloop-nextcloud copied to clipboard

Nextcloud Calendar Integration - Allow access to .ics files

Open Bolli84 opened this issue 5 years ago • 2 comments

Hello,

we always had issues with caldav and the nextcloud mail client.

To enable copy and inserting of the calendar into the nextcloud-calendar, we added a little script to make it possible. The functions open a new window to select all shared calendars and make is possible to add the new entry.

Copy into rainloog.js:

`var windowHtml = '

Add to Calendar


';

/Kalenderliste holen. Wird Oben im HTML benutzt./ function getCalXML(username, password) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "PROPFIND", 'https://'+OC.getHostName()+'/remote.php/dav/calendars/'+username, false ); // false for synchronous request xmlHttp.setRequestHeader("Authorization", "Bearer "+btoa(username+":"+password)); xmlHttp.send( null ); return xmlHttp.responseText; } function getUserName(){ return document.head.getAttribute("data-user"); } /Funktion, wenn Add-Knopf gedrückt wird./ function addFunc(fileName, fileLink) { let username = getUserName(); createNewWindow(fileLink, username); } /* Parsed die Kalendernamen aus dem XML. Gibt eine Liste mit den Kalendernamen zurück. Wird Oben im HTML benutzt. / function getCalendars(xmlString){ let cals = []; let b = xmlString.split("cal:calendar/"); for(let i=0; i<b.length; i++){ if(b[i].lastIndexOf("404")<b[i].lastIndexOf("remote.php")){ let tmp = b[i].substring(b[i].lastIndexOf("remote.php")).split("/<")[0].split("/"); cals.push(tmp[tmp.length-1]); } } return cals; } / Baut das Fenster */ function createNewWindow(dlLink, username){ var Chooser = window.open("about:blank", "Zweitfenster", "width=300,height=400,left=100,top=200"); let newHtml = windowHtml.replace("username", username); newHtml = newHtml.replace("filelink", dlLink); newHtml = newHtml.replace("host", OC.getHostName()); Chooser.document.write(newHtml); Chooser.focus(); } /Holt sich die Dateinamen und Links aller Anhänge/ function getFileInfo(){ var rainloopFrame = document.getElementById("rliframe"); var items = rainloopFrame.contentDocument.getElementsByClassName("attachmentItem"); var names = []; var links = []; for(let i=0; i<items.length; i++){ if (items[i].title.endsWith(".ics")){ names.push(items[i].title); links.push(items[i].getElementsByTagName("a")[0].href); } } return [names, links]; } function getNamesString(names){ var full=""; for(let i=0; i<names.length; i++){ full += names[i]; } return full; } /Funktion für GET-Anfragen/ function httpGet(theUrl) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", theUrl, false ); // false for synchronous request xmlHttp.send( null ); return xmlHttp.responseText; } /Parsen der ICS-Datei/ function getTitle(textToParse){ let lines = textToParse.split("\n") let eventCode = false; for(let i = 0; i < lines.length; i++){ if(lines[i].indexOf("BEGIN:VEVENT")>-1){ eventCode=true; } if(eventCode){ if(lines[i].indexOf("SUMMARY")>-1){ return lines[i].replace("SUMMARY", "").replace(":", "").replace(";", "") } } } } function getStart(textToParse){ let lines = textToParse.split("\n") let eventCode = false; for(let i = 0; i < lines.length; i++){ if(lines[i].indexOf("BEGIN:VEVENT")>-1){ eventCode=true; } if(eventCode){ if(lines[i].indexOf("DTSTART")>-1){ return lines[i].replace("DTSTART", "").replace(":", "").replace(";", "") } } } } function getEnd(textToParse){ let lines = textToParse.split("\n") let eventCode = false; for(let i = 0; i < lines.length; i++){ if(lines[i].indexOf("BEGIN:VEVENT")>-1){ eventCode=true; } if(eventCode){ if(lines[i].indexOf("DTEND")>-1){ return lines[i].replace("DTEND", "").replace(":", "").replace(";", "") } } } } function timeString(line){ try{ let numbers = ""; for(let i=line.length-1; i>=0; i--){ if(!isNaN(line[i]) && line[i]!="\n" && line[i] !="\r"){ numbers += line[i]; } if(numbers.length>=14){ break; } } let sec = numbers[1]+numbers[0]; let min = numbers[3]+numbers[2]; let hour = numbers[5]+numbers[4]; let day = numbers[7]+numbers[6]; let month = numbers[9]+numbers[8]; let year = numbers[13]+numbers[12]+numbers[11]+numbers[10]; return day+"."+month+"."+year+" at: "+hour+":"+min+" ("+sec+")"; } catch(e){ return line; } } /HTML der Vorschautabelle/ var tableStyle = '' var tableHtml = '<table class="caltable", style="width: 50%">\

\ Title__title__\ \ \ Start__stime__\ \ \ End__etime__\ \ \ ' /*Funktion fügt Buttons zu Anhängen hinzu, die das Dateiformat .ICS haben.*/ function addButtons() { try{ var infos = getFileInfo(); var names = infos[0]; var links = infos[1]; var rainloopFrame = document.getElementById("rliframe"); var mailtops = rainloopFrame.contentDocument.querySelectorAll('[data-x-div-type=html]'); for (let n=0; n")==-1){ var newHtml = ""; for(let i=0; i let responseText = httpGet(dlLink); let parsedTitle = getTitle(responseText); let parsedStartTime = getStart(responseText); let parsedEndTime = getEnd(responseText); let tmp = tableHtml.replace("__title__", parsedTitle); tmp = tmp.replace("__stime__", timeString(parsedStartTime)); tmp = tmp.replace("__etime__", timeString(parsedEndTime)); tmp = tmp.replace("__name__", name); tmp = tmp.replace("__link__", dlLink); newHtml += tmp; } mailtop.innerHTML = tableStyle + newHtml + "<div id=\"endCalenderTable\"></div>" + mailtop.innerHTML; } } } catch(e){}

} setInterval(addButtons, 1000);`

Bolli84 avatar May 06 '20 18:05 Bolli84

Hi there, Is this linked with Rainloop of the Mail app for Nextcloud?

pierre-alain-b avatar May 15 '20 09:05 pierre-alain-b

@pierre-alain-b : sorry, I did not get the question. It has nothing to do with the internal nextcloud mail-app.

It simply allows the received *.ics files within rainloop to be integrated into the nextcloud calendars. Nothing more.

We are currently working on more solutions for reoccuring invites and nicer looks.

We just fork the rainlook.js file from your repository and added some functions.

Bolli84 avatar May 17 '20 11:05 Bolli84

I suggest that you look at the work here on Snappymail: https://github.com/the-djmaze/snappymail/issues/96

pierre-alain-b avatar Oct 14 '22 04:10 pierre-alain-b