-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- CardDav submission type (create vCard contacts on form submission) - [BREAKING] restructure config to support multiple form types - lots of refactorings...
- Loading branch information
Showing
9 changed files
with
328 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2024 Denys Konovalov <[email protected]> | ||
|
||
package carddav | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
forms_service "github.com/denyskon/postalion/form" | ||
"github.com/emersion/go-vcard" | ||
"github.com/emersion/go-webdav" | ||
"github.com/emersion/go-webdav/carddav" | ||
) | ||
|
||
func HandleForm(form *forms_service.Form, req *http.Request) error { | ||
config := form.CardDavConfig | ||
|
||
c, err := carddav.NewClient( | ||
webdav.HTTPClientWithBasicAuth(nil, config.Username, config.Password), | ||
config.DavEndpoint, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
card := vcard.Card{ | ||
"VERSION": []*vcard.Field{{Value: "3.0"}}, | ||
} | ||
|
||
for name, field := range config.Fields { | ||
card.SetValue(name, field.GetFormattedString(req)) | ||
} | ||
|
||
path := config.ContactPath.GetFormattedString(req) | ||
ctx := context.Background() | ||
if _, err = c.PutAddressObject(ctx, path, card); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,30 +8,58 @@ mailAccounts: | |
encryption: starttls | ||
forms: | ||
test-form: | ||
account: test-account | ||
from: "Postalion <[email protected]>" | ||
to: "Contact <[email protected]>" | ||
type: mail | ||
honeypot: honeypot | ||
replyTo: | ||
format: "%s <%s>" | ||
fields: | ||
- name | ||
subjectField: subject | ||
template: default | ||
redirect: https://example.com/pages/contact-redirect | ||
fields: | ||
- name: name | ||
label: Name | ||
type: string | ||
- name: email | ||
label: Email | ||
type: string | ||
- name: subject | ||
label: Subject | ||
type: string | ||
- name: file | ||
label: File | ||
type: file | ||
mailConfig: | ||
account: test-account | ||
from: "Postalion <[email protected]>" | ||
to: "Contact <[email protected]>" | ||
replyTo: | ||
format: "%s <%s>" | ||
fields: | ||
- name | ||
subjectField: subject | ||
template: default | ||
fields: | ||
- name: name | ||
label: Name | ||
type: string | ||
- name: email | ||
label: Email | ||
type: string | ||
- name: subject | ||
label: Subject | ||
type: string | ||
- name: file | ||
label: File | ||
type: file | ||
carddav-test: | ||
type: carddav | ||
cardDavConfig: | ||
davEndpoint: https://mail.example.com | ||
contactPath: | ||
format: "/SOGo/dav/[email protected]/Contacts/private/%s-%s.vcf" | ||
fields: | ||
- familyname | ||
- givenname | ||
username: [email protected] | ||
password: p@ssword | ||
fields: | ||
"N": | ||
format: "%s;%s" | ||
fields: | ||
- familyname | ||
- givenname | ||
"EMAIL": | ||
format: "%s" | ||
fields: | ||
"NOTE": | ||
format: "Submitted on %s" | ||
fields: | ||
- date | ||
redirect: https://example.com/pages/carddav-redirect | ||
port: 8080 | ||
templateDir: /app/data/templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.