61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// simple test XML
|
|
const xml string = `
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<d:propfind xmlns:d="DAV:">
|
|
<d:prop>
|
|
<d:displayname/>
|
|
<d:resourcetype/>
|
|
</d:prop>
|
|
</d:propfind>
|
|
`
|
|
|
|
var client *http.Client
|
|
|
|
func init_dav_client() {
|
|
client = &http.Client{}
|
|
}
|
|
|
|
type SimpleCalDavData struct {
|
|
DisplayName string
|
|
Calandars []string
|
|
}
|
|
|
|
// this makes stalwart assumptions
|
|
func get_caldav_data(username string, password string) SimpleCalDavData {
|
|
req, _ := http.NewRequest(
|
|
"PROPFIND",
|
|
serverConfig.URL+"/dav/cal/"+convert_username_into_url(username),
|
|
strings.NewReader(xml),
|
|
)
|
|
|
|
req.SetBasicAuth(username, password)
|
|
req.Header.Set("Depth", "1")
|
|
req.Header.Set("Content-Type", "application/xml")
|
|
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
fmt.Print(err.Error())
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
_, err = io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return SimpleCalDavData{
|
|
DisplayName: "N/A",
|
|
Calandars: []string{},
|
|
}
|
|
}
|