diff --git a/src/calanonsync/calanonsync.go b/src/calanonsync/calanonsync.go index a15cc09..5ac5bf4 100644 --- a/src/calanonsync/calanonsync.go +++ b/src/calanonsync/calanonsync.go @@ -95,11 +95,7 @@ func runSynchronization(cmd *cobra.Command, args []string) { // Find items we don't know so far and create them. for uid, ewsItem := range relevantEWSItems { if _, ok := calDavItemMap[uid]; !ok { - title := s.Anonymize.Title - if title == "" { - // No anonymization? Fine. - title = ewsItem.Subject - } + title := s.Anonymize.Title.Apply(ewsItem.Subject) ical := CreateICal(ewsItem.Hash(), title, ewsItem.Start, ewsItem.End, ewsItem.IsAllDayEvent) calDavItem := CalDAVItem{HRef: uid + ".ics", ICal: ical} diff --git a/src/calanonsync/settings.go b/src/calanonsync/settings.go index aa8ff8f..ce371f8 100644 --- a/src/calanonsync/settings.go +++ b/src/calanonsync/settings.go @@ -22,11 +22,16 @@ type ServerSettings struct { Password string } +type StringAnonSettings struct { + ReplaceWith string + Whitelist []string +} + type Settings struct { EWS ServerSettings CalDAV ServerSettings Anonymize struct { - Title string + Title *StringAnonSettings } } @@ -218,3 +223,11 @@ func runSettingsDecryption(cmd *cobra.Command, args []string) { log.Println("Settings decrypted") } + +func (settings *StringAnonSettings) Apply(s string) string { + if settings == nil || settings.ReplaceWith == "" { + return s + } + + return settings.ReplaceWith +} diff --git a/src/calanonsync/settings_test.go b/src/calanonsync/settings_test.go new file mode 100644 index 0000000..59547e9 --- /dev/null +++ b/src/calanonsync/settings_test.go @@ -0,0 +1,23 @@ +package main + +import "testing" + +func TestStringAnonSettings_Apply(t *testing.T) { + t.Run("Not replaced when nil", func(t *testing.T) { + title := "Test" + var anonTitle *StringAnonSettings = nil + + if anonTitle.Apply(title) != title { + t.Fatal("The title should be unchanged.") + } + }) + + t.Run("Not replaced when empty", func(t *testing.T) { + title := "Test" + var anonTitle *StringAnonSettings = &StringAnonSettings{ReplaceWith: ""} + + if anonTitle.Apply(title) != title { + t.Fatal("The title should be unchanged.") + } + }) +}