forked from andlabs/ews
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#7 Allow to receive ItemId and support calendar refresh #8
Open
johnwiichang
wants to merge
6
commits into
mhewedy:master
Choose a base branch
from
johnwiichang:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c0df4a6
downgrade when ntlm is selected
johnwiichang 959212b
support update&delete
johnwiichang 7a6d1d2
add test
johnwiichang 30bfbb0
recover file
johnwiichang 5c77a44
Add support of oauth request for Microsoft 365
599d9a1
add support for customised transport
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ews | ||
|
||
import ( | ||
"encoding/xml" | ||
"errors" | ||
) | ||
|
||
type DeleteStrategy struct { | ||
DeleteType string `xml:"DeleteType,attr,omitempty"` | ||
SendMeetingCancellations string `xml:"SendMeetingCancellations,attr,omitempty"` | ||
} | ||
|
||
type DeleteItem struct { | ||
XMLName struct{} `xml:"m:DeleteItem"` | ||
ItemIds ItemIds `xml:"m:ItemIds"` | ||
|
||
DeleteStrategy | ||
} | ||
|
||
type ItemIds struct { | ||
XMLName struct{} `xml:"m:ItemIds"` | ||
|
||
ItemId []ItemId `xml:"t:ItemId"` | ||
} | ||
|
||
type deleteItemResponseBodyEnvelop struct { | ||
XMLName struct{} `xml:"Envelope"` | ||
Body deleteItemResponseBody `xml:"Body"` | ||
} | ||
|
||
type deleteItemResponseBody struct { | ||
DeleteItemResponse ItemOperationResponse `xml:"DeleteItemResponse"` | ||
} | ||
|
||
// DeleteItems | ||
// https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-delete-appointments-and-cancel-meetings-by-using-ews-in-exchange | ||
func DeleteItems(c Client, id []ItemId, strategy ...DeleteStrategy) error { | ||
|
||
strategy = append(strategy, DeleteStrategy{ | ||
DeleteType: "MoveToDeletedItems", | ||
SendMeetingCancellations: "SendToAllAndSaveCopy", | ||
}) | ||
|
||
item := DeleteItem{ | ||
ItemIds: ItemIds{ | ||
ItemId: id, | ||
}, | ||
DeleteStrategy: strategy[0], | ||
} | ||
|
||
xmlBytes, err := xml.MarshalIndent(item, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bb, err := c.SendAndReceive(xmlBytes) | ||
if err != nil { | ||
return err | ||
} | ||
return checkDeleteItemResponseForErrors(bb) | ||
} | ||
|
||
func checkDeleteItemResponseForErrors(bb []byte) (err error) { | ||
var soapResp deleteItemResponseBodyEnvelop | ||
if err = xml.Unmarshal(bb, &soapResp); err != nil { | ||
return | ||
} | ||
|
||
resp := soapResp.Body.DeleteItemResponse.ResponseMessages.DeleteItemResponseMessage | ||
if resp.ResponseClass == ResponseClassError { | ||
err = errors.New(resp.MessageText) | ||
} | ||
return | ||
} |
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 |
---|---|---|
|
@@ -105,7 +105,12 @@ func (c *client) SendAndReceive(body []byte) ([]byte, error) { | |
|
||
func applyConfig(config *Config, client *http.Client) { | ||
if config.NTLM { | ||
client.Transport = ntlmssp.Negotiator{} | ||
client.Transport = ntlmssp.Negotiator{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate more on this? |
||
RoundTripper: &http.Transport{ | ||
TLSNextProto: map[string]func(authority string, c *tls.Conn) http.RoundTripper{}, | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.SkipTLS}, | ||
}, | ||
} | ||
} | ||
if config.SkipTLS { | ||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} | ||
|
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 |
---|---|---|
@@ -1,26 +1,27 @@ | ||
package ewsutil | ||
|
||
import ( | ||
"github.com/mhewedy/ews" | ||
"time" | ||
|
||
"github.com/mhewedy/ews" | ||
) | ||
|
||
func CreateHTMLEvent( | ||
c ews.Client, to, optional []string, subject, body, location string, from time.Time, duration time.Duration, | ||
) error { | ||
) ([]ews.ItemId, 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 { | ||
) ([]ews.ItemId, 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 { | ||
) ([]ews.ItemId, error) { | ||
|
||
requiredAttendees := make([]ews.Attendee, len(to)) | ||
for i, tt := range to { | ||
|
@@ -41,16 +42,16 @@ func createEvent( | |
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}}, | ||
// ReminderIsSet: duration != 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you commenting these? at least you might want to pass as options instead. |
||
// ReminderMinutesBeforeStart: 15, | ||
Start: from, | ||
End: from.Add(duration), | ||
IsAllDayEvent: duration == 0, | ||
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) | ||
|
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,11 @@ | ||
package ewsutil | ||
|
||
import ( | ||
"github.com/mhewedy/ews" | ||
) | ||
|
||
func DeleteEvent( | ||
c ews.Client, id ...ews.ItemId, | ||
) error { | ||
return ews.DeleteItems(c, id) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ewsutil | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/mhewedy/ews" | ||
) | ||
|
||
func UpdateHTMLEvent( | ||
c ews.Client, id ews.ItemId, to, optional []string, subject, body, location string, from time.Time, duration time.Duration, | ||
) ([]ews.ItemId, error) { | ||
return updateEvent(c, id, to, optional, subject, body, location, "HTML", from, duration) | ||
} | ||
|
||
// UpdateEvent helper method to update Message | ||
func UpdateEvent( | ||
c ews.Client, id ews.ItemId, to, optional []string, subject, body, location string, from time.Time, duration time.Duration, | ||
) ([]ews.ItemId, error) { | ||
return updateEvent(c, id, to, optional, subject, body, location, "Text", from, duration) | ||
} | ||
|
||
func updateEvent( | ||
c ews.Client, id ews.ItemId, to, optional []string, subject, body, location, bodyType string, from time.Time, duration time.Duration, | ||
) ([]ews.ItemId, 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: duration != 0, | ||
// ReminderMinutesBeforeStart: 15, | ||
Start: from, | ||
End: from.Add(duration), | ||
IsAllDayEvent: duration == 0, | ||
LegacyFreeBusyStatus: ews.BusyTypeBusy, | ||
Location: location, | ||
RequiredAttendees: []ews.Attendees{{Attendee: requiredAttendees}}, | ||
OptionalAttendees: []ews.Attendees{{Attendee: optionalAttendees}}, | ||
Resources: []ews.Attendees{{Attendee: room}}, | ||
} | ||
|
||
return ews.UpdateCalendarItem(c, id, m) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move
ItemId
fromget_room_lists.go
tocommon.go
?