Skip to content
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

label-management/forR4 #44

Merged
merged 14 commits into from
Jan 10, 2024
14 changes: 7 additions & 7 deletions Project/Sources/Classes/GoogleMail.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,24 @@ Function getMails($inMailIds : Collection; $inParameters : Object) : Collection
Else

var $result : Collection:=Null
var $mailIds : Collection:=(Value type($inMailIds)=Is collection) ? $inMailIds : []

If ($inMailIds.length=1)
If (($mailIds.length>0) && (Value type($mailIds[0])=Is object))
$mailIds:=$mailIds.extract("id")
End if

If ($mailIds.length=1)

var $response : Variant:=This.getMail($inMailIds[0]; $inParameters)
var $response : Variant:=This.getMail($mailIds[0]; $inParameters)
If ($response#Null)
$result:=New collection($response)
End if

Else

var $URL; $urlParams; $userId; $mailType; $mailId; $format : Text
var $mailIds : Collection:=(Value type($inMailIds)=Is collection) ? $inMailIds : []
var $parameters : Object

If (($mailIds.length>0) && (Value type($mailIds[0])=Is object))
$mailIds:=$mailIds.extract("id")
End if

$URL:=Super._getURL()
$userId:=(Length(String(This.userId))>0) ? This.userId : "me"
$mailType:=(Length(String($inParameters.mailType))>0) ? $inParameters.mailType : This.mailType
Expand Down
183 changes: 171 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@
- [Office365.user.list()](#office365userlist)
* [Google class](#google)
- [cs.NetKit.Google.new()](#csnetkitgooglenew)
- [Google.mail.createLabel()](#googlemailcreatelabel)
- [Google.mail.delete()](#googlemaildelete)
- [Google.mail.deleteLabel()](#googlemaildeletelabel)
- [Google.mail.getLabel()](#googlemailgetlabel)
- [Google.mail.getLabelList()](#googlemailgetlabellist)
- [Google.mail.getMail()](#googlemailgetmail)
- [Google.mail.getMailIds()](#googlemailgetmailids)
- [Google.mail.getMails()](#googlemailgetmails)
- [Google.mail.send()](#googlemailsend)
- [Google.mail.untrash()](#googlemailuntrash)
- [Google.mail.update()](#googlemailupdate)
- [Google.mail.updateLabel()](#googlemailupdatelabel)
- [labelInfo object](#labelinfo-object)
- [Status object (Google Class)](#status-object-google-class)

* [Tutorial : Authenticate to the Microsoft Graph API in service mode](#authenticate-to-the-microsoft-graph-api-in-service-mode)
Expand Down Expand Up @@ -220,7 +225,7 @@ The returned `Office365` object contains the following properties:
||userId|Text|User identifier, used to identify the user in Service mode. Can be the `id` or the `userPrincipalName`|


#### Example
#### Example 1

To create the OAuth2 connection object and an Office365 object:

Expand All @@ -232,6 +237,9 @@ $oAuth2:=New OAuth2 provider($param)
$office365:=New Office365 provider($oAuth2;New object("mailType"; "Microsoft"))
```

#### Example 2

Refer to [this tutorial](#authenticate-to-the-microsoft-graph-api-in-service-mode) for an example of connection in Service mode.

### Office365.mail.append()

Expand Down Expand Up @@ -1256,6 +1264,40 @@ $oAuth2:=New OAuth2 provider($param)
$google:=cs.NetKit.Google.new($oAuth2;New object("mailType"; "MIME"))
```

### Google.mail.createLabel()

**Google.mail.createLabel**( *labelInfo* : Object ) : Object

#### Parameters
|Parameter|Type||Description|
|---------|--- |:---:|------|
|[labelInfo](#labelinfo-object)|Object|->|Label information.|
|Result|Object|<-|[Status object](#status-object-google-class)|

#### Description

`Google.mail.createLabel()` creates a new label.

#### Returned object

The method returns a [**status object**](status-object-google-class) with an additional "label" property:

|Property|Type|Description|
|---------|--- |------|
|label|Object|contains a newly created instance of Label (see [labelInfo](#labelinfo-object))|
|success|Boolean| [see Status object](#status-object-google-class)|
|statusText|Text| [see Status object](#status-object-google-class)|
|errors|Collection| [see Status object](#status-object-google-class)|

#### Example

To create a label named 'Backup':

```4d
$status:=$google.mail.createLabel({name: "Backup"})
$labelId:=$status.label.id
```

### Google.mail.delete()

**Google.mail.delete**( *mailID* : Text { ; *permanently* : Boolean } ) : Object
Expand Down Expand Up @@ -1293,6 +1335,71 @@ To delete an email permanently:
$status:=$google.mail.delete($mailId; True)
```

### Google.mail.deleteLabel()

**Google.mail.deleteLabel**( *labelId* : Text ) : Object

#### Parameters
|Parameter|Type||Description|
|---------|--- |:---:|------|
|labelId|Text|->|The ID of the label|
|Result|Object|<-|[Status object](#status-object-google-class)|

#### Description

`Google.mail.deleteLabel()` immediately and permanently deletes the specified label and removes it from any messages and threads that it is applied to.
> This method is only available for labels with type="user".

#### Returned object

The method returns a standard [**status object**](#status-object-google-class).

#### Example

To delete a label:

```4d
$status:=$google.mail.deleteLabel($labelId)

```

### Google.mail.getLabel()

**Google.mail.getLabel**( *labelId* : Text ) : Object

#### Parameters
|Parameter|Type||Description|
|---------|--- |:---:|------|
|labelId|Text|->|The ID of the label|
|Result|Object|<-|[labelInfo](#labelinfo-object)|

#### Description

`Google.mail.getLabel()` returns the information of a label as a [labelInfo](#labelinfo-object) object.

#### Returned object

The returned [**labelInfo**](#labelinfo-object) object contains the following additional properties:


|Property|Type|Description|
|---------|---|------|
|messagesTotal|Integer|The total number of messages with the label.|
|messagesUnread|Integer|The number of unread messages with the label.|
|threadsTotal|Integer|The total number of threads with the label.|
|threadsUnread|Integer|The number of unread threads with the label.|

#### Example

To retrieve the label name, total message count, and unread messages:

```4d
$info:=$google.mail.getLabel($labelId)
$name:=$info.name
$emailNumber:=$info.messagesTotal
$unread:=$info.messagesUnread
```

### Google.mail.getLabelList()

**Google.mail.getLabelList**() : Object
Expand Down Expand Up @@ -1560,6 +1667,54 @@ To mark a collection of emails as "unread":
$result:=$google.mail.update($mailIds; {addLabelIds: ["UNREAD"]})
```

### Google.mail.updateLabel()

**Google.mail.updateLabel**( *labelId* : Text ; *labelInfo* : Object ) : Object

#### Parameters
|Parameter|Type||Description|
|---------|--- |:---:|------|
|labelId|Text|->|The ID of the label|
|[labelInfo](#labelinfo-object)|Object|->|Label information to update|
|Result|Object|<-|[Status object](#status-object-google-class)|

#### Description

`Google.mail.updateLabel()` updates the specified label.
> This method is only available for labels with type="user".

#### Returned object

The method returns a [**status object**](status-object-google-class) with an additional "label" property:

|Property|Type|Description|
|---------|--- |------|
|label|Object|contains an instance of Label (see [labelInfo](#labelinfo-object))|
|success|Boolean| [see Status object](#status-object-google-class)|
|statusText|Text| [see Status object](#status-object-google-class)|
|errors|Collection| [see Status object](#status-object-google-class)|

#### Example

To update a previously created label to 'Backup January':

```4d
$status:=$google.mail.updateLabel($labelId; {name:"Backup January"})

```
### labelInfo object

Several Google.mail label management methods use a `labelInfo` object, containing the following properties:

|Property|Type|Description|
|---------|--- |------|
|id|Text|The ID of the label.|
|name|Text|The display name of the label. (mandatory)|
|messageListVisibility|Text|The visibility of messages with this label in the message list.<br></br> Can be: <ul><li>"show": Show the label in the message list. </li><li>"hide": Do not show the label in the message list. </li></ul>|
|labelListVisibility|Text|The visibility of the label in the label list. <br></br> Can be:<ul><li>"labelShow": Show the label in the label list. </li><li>"labelShowIfUnread" : Show the label if there are any unread messages with that label. </li><li>"labelHide": Do not show the label in the label list. </li></ul>|
|[color](https://developers.google.com/gmail/api/reference/rest/v1/users.labels?hl=en#color)|Object|The color to assign to the label (color is only available for labels that have their type set to user). <br></br> The color object has 2 attributes : <ul><li> textColor: text: The text color of the label, represented as hex string. This field is required in order to set the color of a label. </li><li> backgroundColor: text: The background color represented as hex string #RRGGBB (ex for black: #000000). This field is required in order to set the color of a label. </li></ul>|
|type|Text|The owner type for the label. <br></br> Can be: <ul><li>"system": Labels created by Gmail.</li><li>"user": Custom labels created by the user or application.</li></ul>System labels are internally created and cannot be added, modified, or deleted. They're may be able to be applied to or removed from messages and threads under some circumstances but this is not guaranteed. For example, users can apply and remove the INBOX and UNREAD labels from messages and threads, but cannot apply or remove the DRAFTS or SENT labels from messages or threads. </br>User labels are created by the user and can be modified and deleted by the user and can be applied to any message or thread. |


### Status object (Google class)

Expand Down Expand Up @@ -1598,21 +1753,25 @@ Once you have your client ID and client secret, you're ready to establish a conn

```4d
var $oAuth2 : cs.NetKit.OAuth2Provider
var $token : Object
var $office365 : cs.NetKit.Office365

$param:=New object()
$param.name:="Microsoft"
$param.permission:="service"
var $credential:={}
$credential.name:="Microsoft"
$credential.permission:="service"

$param.clientId:="your-client-id" // Replace with your Microsoft identity platform client ID
$param.clientSecret:="your-client-secret" // Replace with your client secret
$param.tenant:="your-tenant-id" // Replace with your tenant ID
$param.tokenURI:="https://login.microsoftonline.com/your-tenant-id/oauth2/v2.0/token/" //Replace ID
$param.scope:="https://graph.microsoft.com/.default"
$credential.clientId:="your-client-id" //Replace with your Microsoft identity platform client ID
$credential.clientSecret:="your-client-secret" //Replace with your client secret
$credential.tenant:="your-tenant-id" // Replace with your tenant ID
$credential.scope:="https://graph.microsoft.com/.default"

$oAuth2:=New OAuth2 provider($param)
$oAuth2:=New OAuth2 provider($credential)

$office365:=$cs.NetKit.Office365.new($oAuth2; {mailType: "MIME"})
// In service mode, you need to indicate on behalf of which user you are sending the request:
$office365.mail.UserId:="MyUserPrincipalName"
// Get mails of MyUserPrincipalName account
$mailList:=$office.mail.getMails()

$token:=$oAuth2.getToken()
```

2. Execute the method to establish the connection.
Expand Down
Loading