Skip to content

Commit

Permalink
Add support for labelIds in _postMailMIMEMessage and _postMessage fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
yannicktrinh committed Mar 25, 2024
1 parent 46298c2 commit 9769df6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Project/Sources/Classes/GoogleMail.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Function _postJSONMessage($inURL : Text; $inMail : Object; $inHeader : Object) :
// ----------------------------------------------------


Function _postMailMIMEMessage($inURL : Text; $inMail : Variant) : Object
Function _postMailMIMEMessage($inURL : Text; $inMail : Variant; $inLabelIds : Collection) : Object

var $requestBody : Text
var $headers : Object:={}
Expand All @@ -61,7 +61,11 @@ Function _postMailMIMEMessage($inURL : Text; $inMail : Variant) : Object
End case
BASE64 ENCODE($requestBody)

var $response : Object:=Super._sendRequestAndWaitResponse("POST"; $inURL; $headers; {raw: $requestBody})
var $message : Object:={raw: $requestBody}
If ((Value type($inLabelIds)=Is collection) && ($inLabelIds.length>0))
$message.labelIds:=$inLabelIds
End if
var $response : Object:=Super._sendRequestAndWaitResponse("POST"; $inURL; $headers; $message)
This._internals._response:=$response

return This._returnStatus()
Expand All @@ -70,20 +74,25 @@ Function _postMailMIMEMessage($inURL : Text; $inMail : Variant) : Object
// ----------------------------------------------------


Function _postMessage($inFunction : Text; $inURL : Text; $inMail : Variant; $inHeader : Object) : Object
Function _postMessage($inFunction : Text; $inURL : Text; $inMail : Variant; $inLabelIds : Collection) : Object

var $status : Object
var $labelIds : Collection:=Null

Super._throwErrors(False)

If ($inFunction="append")
$labelIds:=((Value type($inLabelIds)=Is collection) && ($inLabelIds.length>0)) ? $inLabelIds : ["DRAFT"]
End if

Case of
: ((This.mailType="MIME") && (\
(Value type($inMail)=Is text) || \
(Value type($inMail)=Is BLOB)))
$status:=This._postMailMIMEMessage($inURL; $inMail)
$status:=This._postMailMIMEMessage($inURL; $inMail; $labelIds)

: ((This.mailType="JMAP") && (Value type($inMail)=Is object))
$status:=This._postMailMIMEMessage($inURL; $inMail)
$status:=This._postMailMIMEMessage($inURL; $inMail; $labelIds)

Else
Super._throwError(10; {which: 1; function: $inFunction})
Expand All @@ -101,14 +110,14 @@ Function _postMessage($inFunction : Text; $inURL : Text; $inMail : Variant; $inH
// ----------------------------------------------------


Function append($inMail : Variant) : Object
Function append($inMail : Variant; $inLabelIds : Collection) : Object

var $URL : Text:=Super._getURL()
var $userId : Text:=(Length(String(This.userId))>0) ? This.userId : "me"
$URL+="users/"+$userId+"/messages/"

var $status : Object:=This._postMessage("append"; $URL; $inMail)
If (Length(String(This._internals._response.id))>0)
var $status : Object:=This._postMessage("append"; $URL; $inMail; $inLabelIds)
If ((Value type(This._internals._response)=Is object) && (Length(String(This._internals._response.id))>0))
$status.id:=String(This._internals._response.id)
End if

Expand Down

0 comments on commit 9769df6

Please sign in to comment.