Skip to content

Commit

Permalink
Merge pull request #88 from meain/org-mailto
Browse files Browse the repository at this point in the history
Prefix mailto: for email in organizer property
  • Loading branch information
arran4 authored Mar 4, 2024
2 parents 0fcebed + 93ca35f commit 84a339a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (cb *ComponentBase) SetURL(s string, props ...PropertyParameter) {
}

func (cb *ComponentBase) SetOrganizer(s string, props ...PropertyParameter) {
if !strings.HasPrefix(s, "mailto:") {
s = "mailto:" + s
}

cb.SetProperty(ComponentPropertyOrganizer, s, props...)
}

Expand All @@ -258,7 +262,11 @@ func (cb *ComponentBase) setResources(r string, props ...PropertyParameter) {
}

func (cb *ComponentBase) AddAttendee(s string, props ...PropertyParameter) {
cb.AddProperty(ComponentPropertyAttendee, "mailto:"+s, props...)
if !strings.HasPrefix(s, "mailto:") {
s = "mailto:" + s
}

cb.AddProperty(ComponentPropertyAttendee, s, props...)
}

func (cb *ComponentBase) AddExdate(s string, props ...PropertyParameter) {
Expand Down
24 changes: 24 additions & 0 deletions components_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,27 @@ func TestGetLastModifiedAt(t *testing.T) {
t.Errorf("got last modified = %q, want %q", got, lastModified)
}
}

func TestSetMailtoPrefix(t *testing.T) {
e := NewEvent("test-set-organizer")

e.SetOrganizer("org1@provider.com")
if !strings.Contains(e.Serialize(), "ORGANIZER:mailto:org1@provider.com") {
t.Errorf("expected single mailto: prefix for email org1")
}

e.SetOrganizer("mailto:org2@provider.com")
if !strings.Contains(e.Serialize(), "ORGANIZER:mailto:org2@provider.com") {
t.Errorf("expected single mailto: prefix for email org2")
}

e.AddAttendee("att1@provider.com")
if !strings.Contains(e.Serialize(), "ATTENDEE:mailto:att1@provider.com") {
t.Errorf("expected single mailto: prefix for email att1")
}

e.AddAttendee("mailto:att2@provider.com")
if !strings.Contains(e.Serialize(), "ATTENDEE:mailto:att2@provider.com") {
t.Errorf("expected single mailto: prefix for email att2")
}
}

0 comments on commit 84a339a

Please sign in to comment.