diff --git a/components.go b/components.go index 7c808b3..71d4e96 100644 --- a/components.go +++ b/components.go @@ -238,7 +238,11 @@ func (cb *ComponentBase) SetURL(s string, props ...PropertyParameter) { } func (cb *ComponentBase) SetOrganizer(s string, props ...PropertyParameter) { - cb.SetProperty(ComponentPropertyOrganizer, "mailto:"+s, props...) + if !strings.HasPrefix(s, "mailto:") { + s = "mailto:" + s + } + + cb.SetProperty(ComponentPropertyOrganizer, s, props...) } func (cb *ComponentBase) SetColor(s string, props ...PropertyParameter) { @@ -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) { diff --git a/components_test.go b/components_test.go index d42a83e..bb38585 100644 --- a/components_test.go +++ b/components_test.go @@ -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") + } +}