goews

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 15 Imported by: 0

README

GO-EWS

golang library for interacion with EWS Exchange Web Service

Elements

All elements from EWS elements has been described and are accessible! (to the ReadMe update time=, and there are several shortcomings))

Operations

Some operations from EWS operations has been described and are accessible!. 100% of fields are mapped.

But you can use all of operation, which you need by the interaction with elements. Example

Described operations
  • GetFolder
  • FindItem
  • FindPeople
  • CreteItem

Usage

some usable examples you can find in Examples folder in this example you can create draft with operation(in examples you can find how to do anything without predefined operation)

package main

import (
    "fmt"
    "os"

    goews "github.com/beorereleverion/go-ews"
    "github.com/beorereleverion/go-ews/elements"
    log "github.com/sirupsen/logrus"
)

var (
    url, user, password string
)

func main() {
    setOSEnvs()
    client := goews.NewClient(url, user, password, goews.Config{
        Dump:    true,
        NTLM:    true,
        SkipTLS: false,
    })
    createItemResponse, err := client.CreateItem(&elements.CreateItem{
        MessageDisposition: getPTR("SendAndSaveCopy"),
        Items: &elements.ItemsNonEmptyArrayOfAllItemsType{
            Message: &elements.Message{
                
                ItemClass: &elements.ItemClass{
                    TEXT: "IPM.Note",
                },
                Subject: &elements.Subject{
                    TEXT: "Project Action",
                },
                Body: &elements.Body{
                    BodyType: getPTR("Text"),
                    TEXT:     "Priority - Update specification",
                },
                ToRecipients: &elements.ToRecipients{
                    Mailbox: &elements.Mailbox{
                        EmailAddress: &elements.EmailAddressNonEmptyStringType{
                            TEXT: "sschmidt@example.com",
                        },
                    },
                },
                IsRead: &elements.IsRead{
                    TEXT: false,
                },
            },
        },
        SavedItemFolderId: &elements.SavedItemFolderId{DistinguishedFolderId: &elements.DistinguishedFolderId{
            Id: getPTR(elements.DistinguishedFolderIddrafts),
        }},
    })
    if err != nil {
        panic(err)
    }
    fmt.Printf("%#v\n", createItemResponse)
}

func setOSEnvs() {
    url = os.Getenv("URL")
    if url == "" {
        log.Fatal("url can not be empty")
    }
    user = os.Getenv("USER")
    if user == "" {
        log.Fatal("user can not be empty")
    }
    password = os.Getenv("PASSWORD")
    if password == "" {
        log.Fatal("password can not be empty")
    }
}

func getPTR[T comparable](t T) *T {
    return &t
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPTR added in v0.0.2

func GetPTR[T comparable](t T) *T

func NewError

func NewError(resp *http.Response) error

Types

type Calendar

type Calendar struct {
	// 日程开始时间,Unix时间戳
	StartTime int `json:"startTime" form:"startTime"`
	// 日程结束时间,Unix时间戳
	EndTime int `json:"endTime" form:"endTime"`
	// 参与人
	Attendees []*ScheduleAttend
	// 主题
	Summary string `json:"summary" form:"summary"`
	// 日程描述 不多于512个字符
	Description string `json:"description" form:"description"`
	// 提醒相关信息
	Reminder *Reminder `json:"reminder" form:"reminder"`
	// 日程地址 不多于128个字符
	Location string `json:"location" form:"location"`

	StartTimeUnix int `json:"startTimeUnix"`
	EndTimeUnix   int `json:"endTimeUnix"`

	ChangeKey string
	Id        string
}

type Client

type Client interface {
	Connect() error
	SendAndReceive(e Envelope) ([]byte, error)
	GetServerAddr() string
	GetUsername() string
	DoRequest(e Envelope, oe operations.Element) error
	FindPeople(eItem *elements.FindPeople) (*elements.FindPeopleResponse, error)
	GetFolder(eItem *elements.GetFolder) (*elements.GetFolderResponse, error)
	FindFolder(eItem *elements.FindFolder) (*elements.FindFolderResponse, error)
	FindItem(eItem *elements.FindItem) (*elements.FindItemResponse, error)
	CreateItem(eItem *elements.CreateItem) (*elements.CreateItemResponse, error)
	GetItem(eItem *elements.GetItem) (*elements.GetItemResponse, error)
	// 自定义
	CreateCalendar(req *CreateCalendarReq)
	GetCalendars(req *GetCalendarsReq) ([]*elements.CalendarItem, error)
	GetCalendar(req *GetCalendarReq) (*elements.CalendarItem, error)
	CreateEmailToDrafts(req *CreateEmailReq) (*IdChangeKeyResp, error)
	SendEmail(req *CommanReq) error
	CreateAttachment(req *CreateAttachmentReq) error
	GetIdByOldId(req *CommanReq) (*IdChangeKeyResp, error)
}

func NewClient

func NewClient(serverAddress, username, password string, config Config) Client

type ClientError

type ClientError struct {
	// Code 错误码,0表示成功,非0表示调用失败。
	// 开发者需根据errcode是否为0判断是否调用成功(errcode意义请见全局错误码)。
	Code errcodes.ErrCode
	// Msg 错误信息,调用失败会有相关的错误信息返回。
	// 仅作参考,后续可能会有变动,因此不可作为是否调用成功的判据。
	Msg string
}

ClientError 企业微信客户端 SDK 的响应错误

func (*ClientError) Error

func (e *ClientError) Error() string

type CommanReq added in v0.0.2

type CommanReq struct {
	ID        string
	ChangeKey string
}

type CommonResp

type CommonResp struct {
	ErrTpye         string `json:"_type"`
	ErrorIdentifier string `json:"errorIdentifier"`
	Message         string `json:"message"`
	Status          string `json:"status"`
}

type Config

type Config struct {
	Dump    bool
	NTLM    bool
	SkipTLS bool
}

type CreateAttachmentReq added in v0.0.2

type CreateAttachmentReq struct {
	*CommanReq
	Name          string
	Base64Content string
}

type CreateCalendarReq

type CreateCalendarReq struct {
	// 主题属性。该主题限制在255个字符以内。
	Summary string
	// 描述创建会议请求后如何处理这些请求。 日历项需要此属性。
	// SendToNone: 如果项目是会议请求,则会将其保存为日历项目,但不会发送。
	// SendOnlyToAll: 会议请求将发送给所有与会者,但不保存在“已发送邮件”文件夹中。
	// SendToAllAndSaveCopy: 会议请求将发送给所有与会者,副本将保存在 SavedItemFolderId 元素标识的文件夹中。
	SendMeetingInvitations string
	// 表示一个持续时间的开始。
	Start time.Time
	// 表示一个持续时间的结束。
	End time.Time
	// 日历项目和会议请求的循环模式。
	Recurrence *struct {
		// 表示定期任务或日历项的开始日期。
		EndDate string
		// 表示定期任务或日历项的结束日期。
		StartDate       string
		DailyRecurrence *struct {
			Interval int64
		}
		WeeklyRecurrence *struct {
			DaysOfWeek     string
			FirstDayOfWeek string
			Interval       int64
		}
		RelativeMonthlyRecurrence *struct {
			DaysOfWeek     string
			DayOfWeekIndex string
			Interval       int64
		}
		RelativeYearlyRecurrence *struct {
			DayOfWeekIndex string
			DaysOfWeek     string
			Month          string
		}
	}
}

func (*CreateCalendarReq) CreateRecurrenceRecurrenceType

func (req *CreateCalendarReq) CreateRecurrenceRecurrenceType() *elements.RecurrenceRecurrenceType

type CreateEmailReq added in v0.0.2

type CreateEmailReq struct {
	Subject  string
	Body     string
	ToEmails []string
}

type Envelope

type Envelope interface {
	GetEnvelopeBytes() ([]byte, error)
}

type Fault

type Fault struct {
	Faultcode   string `xml:"faultcode"`
	Faultstring string `xml:"faultstring"`
	Detail      detail `xml:"detail"`
}

type GetCalendarReq

type GetCalendarReq struct {
	ItemID    string
	ChangeKey string
}

type GetCalendarsReq

type GetCalendarsReq struct {
	StartDate string
	EndDate   string
	ChangeKey string
	ID        string
}

type HTTPError

type HTTPError struct {
	Status     string
	StatusCode int
}

func (HTTPError) Error

func (s HTTPError) Error() string

type IdChangeKeyResp added in v0.0.2

type IdChangeKeyResp struct {
	ID        string
	ChangeKey string
}

type RecallEmailReq added in v0.0.2

type RecallEmailReq struct {
	Subject  string
	Body     string
	ToEmails []string
}

type Reminder

type Reminder struct {
	ScheduleID uint `json:"scheduleID" form:"scheduleID"`
	// 是否需要提醒。0-否;1-是
	IsRemind int `json:"isRemind" form:"isRemind"`
	/*
		日程开始(start_time)前多少秒提醒,当is_remind为1时有效。
		例如: 300表示日程开始前5分钟提醒。目前仅支持以下数值:
		0 - 事件开始时
		300 - 事件开始前5分钟
		900 - 事件开始前15分钟
		3600 - 事件开始前1小时
		86400 - 事件开始前1天
	*/
	RemindBeforeEventSecs uint32 `json:"remindBeforeEventSecs" form:"remindBeforeEventSecs"`
	/*
		日程开始(start_time)与提醒时间的差值,当is_remind为1时有效。例如:-300表示日程开始前5分钟提醒。
		特殊情况:企业微信终端设置的“全天”类型的日程,由于start_time是0点时间戳,提醒如果设置了当天9点,则会出现正数32400。
		取值范围:-604800 ~ 86399
	*/
	RemindTimeDiffs string `json:"remindTimeDiffs" format:"remindTimeDiffs"`
	// 是否重复日程。0-否;1-是
	IsRepeat int `json:"isRepeat" format:"isRepeat"`
	/*
		重复类型,当is_repeat为1时有效。目前支持如下类型:
		0 - 每日
		1 - 每周
		2 - 每月
		5 - 每年
		7 - 工作日
	*/
	RepeatType uint32 `json:"repeatType" form:"repeatType"`
	// 重复结束时刻,Unix时间戳,当is_repeat为1时有效。不填或填0表示一直重复
	RepeatUntil int `json:"repeatUntil" form:"repeatUntil"`
	// 是否自定义重复。0-否;1-是。当is_repeat为1时有效。
	IsCustomRepeat int `json:"isCustomRepeat" form:"isCustomRepeat"`
	/*
		重复间隔
		仅当指定为自定义重复时有效
		该字段随repeat_type不同而含义不同
		例如:
		repeat_interval指定为3,repeat_type指定为每周重复,那么每3周重复一次;
		repeat_interval指定为3,repeat_type指定为每月重复,那么每3个月重复一次
	*/
	RepeatInterval int `json:"repeatInterval" format:"repeatInterval"`
	/*
		每周周几重复
		仅当指定为自定义重复且重复类型为每周时有效
		取值范围:1 ~ 7,分别表示周一至周日
	*/
	RepeatDayOfWeek string `json:"repeatDayOfWeek" form:"repeatDayOfWeek"`
	/*
		每月哪几天重复
		仅当指定为自定义重复且重复类型为每月时有效
		取值范围:1 ~ 31,分别表示1~31号
	*/
	RepeatDayOfMonth string `json:"repeatDayOfMonth" form:"repeatDayOfMonth"`
	/*
		时区。UTC偏移量表示(即偏离零时区的小时数),东区为正数,西区为负数。
		例如:+8 表示北京时间东八区
		默认为北京时间东八区
		取值范围:-12 ~ +12
	*/
	Timezone int `json:"timezone" form:"timezone"`

	ExcludeTimeList string `json:"excludeTimeList" form:"excludeTimeList"`
}

type ScheduleAttend

type ScheduleAttend struct {
	Email string
}

type SoapError

type SoapError struct {
	Fault *Fault
}

func (SoapError) Error

func (s SoapError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL