A webmail client. Forked from https://git.sr.ht/~migadu/alps
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.
 
 
 
 

47 lines
999 B

  1. package alpscarddav
  2. import (
  3. "fmt"
  4. "net/http"
  5. "net/url"
  6. "git.sr.ht/~emersion/alps"
  7. "github.com/emersion/go-webdav/carddav"
  8. )
  9. var errNoAddressBook = fmt.Errorf("carddav: no address book found")
  10. type authRoundTripper struct {
  11. upstream http.RoundTripper
  12. session *alps.Session
  13. }
  14. func (rt *authRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
  15. rt.session.SetHTTPBasicAuth(req)
  16. return rt.upstream.RoundTrip(req)
  17. }
  18. func newClient(u *url.URL, session *alps.Session) (*carddav.Client, error) {
  19. rt := authRoundTripper{
  20. upstream: http.DefaultTransport,
  21. session: session,
  22. }
  23. return carddav.NewClient(&http.Client{Transport: &rt}, u.String())
  24. }
  25. type AddressObject struct {
  26. *carddav.AddressObject
  27. }
  28. func newAddressObjectList(aos []carddav.AddressObject) []AddressObject {
  29. l := make([]AddressObject, len(aos))
  30. for i := range aos {
  31. l[i] = AddressObject{&aos[i]}
  32. }
  33. return l
  34. }
  35. func (ao AddressObject) URL() string {
  36. return "/contacts/" + url.PathEscape(ao.Path)
  37. }