forked from mhewedy/ews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_event.go
57 lines (48 loc) · 1.77 KB
/
create_event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ewsutil
import (
"github.com/mhewedy/ews"
"time"
)
func CreateHTMLEvent(
c ews.Client, to, optional []string, subject, body, location string, from time.Time, duration time.Duration,
) error {
return createEvent(c, to, optional, subject, body, location, "HTML", from, duration)
}
// CreateEvent helper method to send Message
func CreateEvent(
c ews.Client, to, optional []string, subject, body, location string, from time.Time, duration time.Duration,
) error {
return createEvent(c, to, optional, subject, body, location, "Text", from, duration)
}
func createEvent(
c ews.Client, to, optional []string, subject, body, location, bodyType string, from time.Time, duration time.Duration,
) error {
requiredAttendees := make([]ews.Attendee, len(to))
for i, tt := range to {
requiredAttendees[i] = ews.Attendee{Mailbox: ews.Mailbox{EmailAddress: tt}}
}
optionalAttendees := make([]ews.Attendee, len(optional))
for i, tt := range optional {
optionalAttendees[i] = ews.Attendee{Mailbox: ews.Mailbox{EmailAddress: tt}}
}
room := make([]ews.Attendee, 1)
room[0] = ews.Attendee{Mailbox: ews.Mailbox{EmailAddress: location}}
m := ews.CalendarItem{
Subject: subject,
Body: ews.Body{
BodyType: bodyType,
Body: []byte(body),
},
ReminderIsSet: true,
ReminderMinutesBeforeStart: 15,
Start: from,
End: from.Add(duration),
IsAllDayEvent: false,
LegacyFreeBusyStatus: ews.BusyTypeBusy,
Location: location,
RequiredAttendees: []ews.Attendees{{Attendee: requiredAttendees}},
OptionalAttendees: []ews.Attendees{{Attendee: optionalAttendees}},
Resources: []ews.Attendees{{Attendee: room}},
}
return ews.CreateCalendarItem(c, m)
}