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

fix gmail-list-labels command XSUP-29195 #30222

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Packs/Gmail/Integrations/Gmail/Gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ def set_autoreply_command():
file_content = ''
if response_body_entry_id and not args.get('response-body'):
file_entry = demisto.getFilePath(response_body_entry_id)
with open(file_entry['path'], 'r') as f:
with open(file_entry['path']) as f:
file_content = str(f.read())
response_body_plain_text = file_content if file_content else args.get('response-body')
response_body_type = args.get('response-body-type')
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def create_user(primary_email, first_name, family_name, password):
'name': {
'givenName': first_name,
'familyName': family_name,
'fullName': '%s %s' % (first_name, family_name,),
'fullName': f'{first_name} {family_name}',
},
'password': password
}
Expand Down Expand Up @@ -1190,7 +1190,8 @@ def list_labels(user_key):
service = get_service(
'gmail',
'v1',
['https://www.googleapis.com/auth/gmail.readonly'])
['https://www.googleapis.com/auth/gmail.readonly'],
delegated_user=user_key)
results = service.users().labels().list(userId=user_key).execute()
labels = results.get('labels', [])
return labels
Expand All @@ -1205,7 +1206,7 @@ def get_user_role_command():
raise ValueError('Must provide Immutable GoogleApps Id')

roles = get_user_role(user_key, GAPPS_ID)
return user_roles_to_entry('User Roles of %s:' % (user_key,), roles)
return user_roles_to_entry(f'User Roles of {user_key}:', roles)


def get_user_role(user_key, customer):
Expand Down Expand Up @@ -1398,7 +1399,7 @@ def search_command(mailbox: str = None, only_return_account_names: bool = False)

if max_results > 500:
raise ValueError(
'maxResults must be lower than 500, got %s' % (max_results,))
f'maxResults must be lower than 500, got {max_results}')
try:
mails, q = search(user_id, subject, _from, to,
before, after, filename, _in, query,
Expand Down Expand Up @@ -1434,9 +1435,9 @@ def search(user_id, subject='', _from='', to='', before='', after='', filename='
'in': _in,
'has': 'attachment' if has_attachments else ''
}
q = ' '.join('%s:%s ' % (name, value,)
q = ' '.join(f'{name}:{value} '
for name, value in list(query_values.items()) if value != '')
q = ('%s %s' % (q, query,)).strip()
q = (f'{q} {query}').strip()

command_args = {
'userId': user_id,
Expand Down Expand Up @@ -1952,6 +1953,7 @@ def collect_inline_attachments(attach_cids):
})

return inline_attachment
return None


def collect_manual_attachments():
Expand Down Expand Up @@ -2627,7 +2629,7 @@ def fetch_incidents():
demisto.info(
f'skipped incident with lower date: {occurred} than fetch: {last_fetch} name: {incident.get("name")}')

demisto.info('extract {} incidents'.format(len(incidents)))
demisto.info(f'extract {len(incidents)} incidents')
next_page_token = result.get('nextPageToken', '')
if next_page_token:
# we still have more results
Expand Down
70 changes: 35 additions & 35 deletions Packs/Gmail/Integrations/Gmail/Gmail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ script:
description: The user's email address. The "me" special value can be used to indicate the authenticated user.
name: user-id
required: true
- description: 'Returns messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid: is:unread". For more syntax information see "https://support.google.com/mail/answer/7190?hl=en"'
- description: 'Returns messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid: is:unread". For more syntax information see "https://support.google.com/mail/answer/7190?hl=en".'
name: query
- defaultValue: '100'
description: The maximum number of results to return. Default is 100. Maximum is 500. Can be 1 to 500, inclusive.
name: max-results
- description: 'Enables partial responses to be retrieved, separated by commas. Valid fields are only from the following list: Type, Mailbox, ThreadId, Labels, Headers, Attachments, RawData, Format, Subject, From, To, Body, Cc, Bcc, Date, Html, Attachment Names'
- description: 'Enables partial responses to be retrieved, separated by commas. Valid fields are only from the following list: Type, Mailbox, ThreadId, Labels, Headers, Attachments, RawData, Format, Subject, From, To, Body, Cc, Bcc, Date, Html, Attachment Names.'
isArray: true
name: fields
- description: Returns messages with labels that match all of the specified label IDs in a comma-separated list.
Expand All @@ -318,24 +318,24 @@ script:
name: page-token
- auto: PREDEFINED
defaultValue: 'False'
description: 'Include messages from SPAM and TRASH in the results. (Default: false)'
description: 'Include messages from SPAM and TRASH in the results. (Default: false).'
name: include-spam-trash
predefined:
- 'False'
- 'True'
- description: Specifies the sender. For example, "john"
- description: Specifies the sender. For example, "john".
name: from
- description: Specifies the receiver. For example, "john"
- description: Specifies the receiver. For example, "john".
name: to
- description: Words in the subject line. For example, "alert"
- description: Words in the subject line. For example, "alert".
name: subject
- description: Attachments with a certain name or file type. For example, "pdf" or "report.pdf"
- description: Attachments with a certain name or file type. For example, "pdf" or "report.pdf".
name: filename
- description: 'Messages in any folder, including Spam and Trash. For example: shopping'
- description: 'Messages in any folder, including Spam and Trash. For example: shopping.'
name: in
- description: 'Search for messages sent after a specific date. For example: 2018/05/06'
- description: 'Search for messages sent after a specific date. For example: 2018/05/06.'
name: after
- description: 'Search for messages sent before a specific date. for example: 2018/05/09'
- description: 'Search for messages sent before a specific date. for example: 2018/05/09.'
name: before
- auto: PREDEFINED
description: Whether to search for messages sent with attachments (boolean value).
Expand Down Expand Up @@ -419,12 +419,12 @@ script:
description: The date the email was received.
type: String
- arguments:
- description: 'Returns messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid: is:unread". For more syntax information,see "https://support.google.com/mail/answer/7190?hl=en"'
- description: 'Returns messages matching the specified query. Supports the same query format as the Gmail search box. For example, "from:[email protected] rfc822msgid: is:unread". For more syntax information,see "https://support.google.com/mail/answer/7190?hl=en".'
name: query
- defaultValue: '100'
description: The maximum number of results to return. Default is 100. Maximum is 500. Can be 1 to 500, inclusive.
name: max-results
- description: 'Enables partial responses to be retrieved, separated by commas. Valid fields are only from the following list: Type, Mailbox, ThreadId, Labels, Headers, Attachments, RawData, Format, Subject, From, To, Body, Cc, Bcc, Date, Html, Attachment Names'
- description: 'Enables partial responses to be retrieved, separated by commas. Valid fields are only from the following list: Type, Mailbox, ThreadId, Labels, Headers, Attachments, RawData, Format, Subject, From, To, Body, Cc, Bcc, Date, Html, Attachment Names.'
isArray: true
name: fields
- description: Returns messages with labels that match all of the specified label IDs in a comma-separated list.
Expand All @@ -433,24 +433,24 @@ script:
name: page-token
- auto: PREDEFINED
defaultValue: 'False'
description: 'Includes messages from SPAM and TRASH in the results. (Default: false)'
description: 'Includes messages from SPAM and TRASH in the results. (Default: false).'
name: include-spam-trash
predefined:
- 'False'
- 'True'
- description: Specifies the sender. For example, "john"
- description: Specifies the sender. For example, "john".
name: from
- description: Specifies the receiver. For example, "john"
- description: Specifies the receiver. For example, "john".
name: to
- description: Words in the subject line. For example, "alert"
- description: Words in the subject line. For example, "alert".
name: subject
- description: Attachments with a certain name or file type. For example, "pdf" or "report.pdf"
- description: Attachments with a certain name or file type. For example, "pdf" or "report.pdf".
name: filename
- description: Messages in any folder, including Spam and Trash. For example, shopping
- description: Messages in any folder, including Spam and Trash. For example, shopping.
name: in
- description: Search for messages sent after a specific date. For example, 2018/05/06
- description: Search for messages sent after a specific date. For example, 2018/05/06.
name: after
- description: Search for messages sent before a specific date. For example, 2018/05/09
- description: Search for messages sent before a specific date. For example, 2018/05/09.
name: before
- auto: PREDEFINED
description: Whether to search for messages sent with attachments.
Expand All @@ -471,7 +471,7 @@ script:
name: search_from
- description: Used to track search progress.
name: search_to
description: Searches the Gmail records for all Google users. (For more than 2500 accounts, use with the `Search all mailboxes - Gmail with polling` playbook)
description: Searches the Gmail records for all Google users. (For more than 2500 accounts, use with the `Search all mailboxes - Gmail with polling` playbook).
polling: true
name: gmail-search-all-mailboxes
outputs:
Expand Down Expand Up @@ -585,7 +585,7 @@ script:
- 'False'
- 'True'
- auto: PREDEFINED
description: How to sort the results. Can be ASCENDING/DESCENDING
description: How to sort the results. Can be ASCENDING/DESCENDING.
name: sort-order
predefined:
- ASCENDING
Expand Down Expand Up @@ -709,7 +709,7 @@ script:
required: true
- auto: PREDEFINED
defaultValue: full
description: 'The format in which to return the message. Can be: "full": Returns the full email message data with body content parsed in the payload field; the raw field is not used. (default) / "metadata": Returns only email message ID, labels, and email headers / "minimal": Returns only email message ID and labels; does not return the email headers, body, or payload / "raw": Returns the full email message data with body content in the raw field as a base64url encoded string; the payload field is not used'
description: 'The format in which to return the message. Can be: "full": Returns the full email message data with body content parsed in the payload field; the raw field is not used. (default) / "metadata": Returns only email message ID, labels, and email headers / "minimal": Returns only email message ID and labels; does not return the email headers, body, or payload / "raw": Returns the full email message data with body content in the raw field as a base64url encoded string; the payload field is not used.'
name: format
predefined:
- full
Expand Down Expand Up @@ -1047,7 +1047,7 @@ script:
- description: The user's email address. The "me" special value can be used to indicate the authenticated user.
name: user-id
required: true
- description: A comma-separated list of filter IDs (can be retrieve using `gmail-list-filters` command)
- description: A comma-separated list of filter IDs (can be retrieve using `gmail-list-filters` command).
isArray: true
name: filter_ids
required: true
Expand Down Expand Up @@ -1248,7 +1248,7 @@ script:
- description: |-
A comma-separated list of new names to rename attachments corresponding to the order that they were attached to the email.
Examples - To rename first and third file attachNames=new_fileName1,,new_fileName3
To rename second and fifth files attachNames=,new_fileName2,,,new_fileName5
To rename second and fifth files attachNames=,new_fileName2,,,new_fileName5.
isArray: true
name: attachNames
- description: |-
Expand All @@ -1258,19 +1258,19 @@ script:
- description: |-
Textual name for an attached file. Multiple files are supported as a
comma-separated list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test
2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFile
- description: |-
Content for the attached file. Multiple files are supported as a comma-separated
list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test
2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFileContent
- description: |-
CID image for an attached file to include within the email body. Multiple files are
supported as a comma-separated list. (e.g. transientFile="t1.txt,temp.txt,t3.txt"
transientFileContent="test 2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
transientFileContent="test 2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFileCID
- description: 'A CSV list of additional headers in the format: headerName=headerValue. For example: "headerName1=headerValue1,headerName2=headerValue2".'
Expand All @@ -1290,7 +1290,7 @@ script:
- 'HTML'
- 'Text'
defaultValue: Text
- description: Indicates whether to render the email body
- description: Indicates whether to render the email body.
name: renderBody
auto: PREDEFINED
predefined:
Expand Down Expand Up @@ -1364,22 +1364,22 @@ script:
- description: |-
A comma-separated list of new names used to rename attachments corresponding to the order in which they were attached to the email.
Examples - To rename the first and third file: attachNames=new_fileName1,,new_fileName3
To rename the second and fifth files: attachNames=,new_fileName2,,,new_fileName5
To rename the second and fifth files: attachNames=,new_fileName2,,,new_fileName5.
isArray: true
name: attachNames
- description: A comma-separated list of CID images to embed as attachments inside the email.
isArray: true
name: attachCIDs
- description: |-
Textual name for an attached file. Multiple files are supported as a comma-separated list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
Textual name for an attached file. Multiple files are supported as a comma-separated list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFile
- description: |-
Content for the attached file. Multiple files are supported as a comma-separated list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
Content for the attached file. Multiple files are supported as a comma-separated list. For example, transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFileContent
- description: |-
CID image for an attached file to include within the email body. Multiple files are supported as a comma-separated list. (e.g. transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test 2,temporary file content,third file content" transientFileCID="[email protected],[email protected]")
CID image for an attached file to include within the email body. Multiple files are supported as a comma-separated list. (e.g. transientFile="t1.txt,temp.txt,t3.txt" transientFileContent="test 2,temporary file content,third file content" transientFileCID="[email protected],[email protected]").
isArray: true
name: transientFileCID
- description: 'A comma-separated list of additional headers in the format: headerName=headerValue. For example: "headerName1=headerValue1,headerName2=headerValue2".'
Expand All @@ -1395,7 +1395,7 @@ script:
predefined:
- HTML
- Text
- description: Indicates whether to render the email body
- description: Indicates whether to render the email body.
name: renderBody
description: Replies to a mail using Gmail.
name: reply-mail
Expand Down Expand Up @@ -1659,7 +1659,7 @@ script:
- contextPath: Gmail.ForwardingAddress.verificationStatus
description: Indicates whether this address has been verified and is usable for forwarding.
type: String
dockerimage: demisto/google-api-py3:1.0.0.68841
dockerimage: demisto/google-api-py3:1.0.0.77314
isfetch: true
runonce: false
script: '-'
Expand Down
7 changes: 7 additions & 0 deletions Packs/Gmail/ReleaseNotes/1_3_14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### Gmail

- Fixed an issue where *gmail-list-labels* command was unable to run with delegate user.
- Updated the Docker image to: *demisto/google-api-py3:1.0.0.77314*.
2 changes: 1 addition & 1 deletion Packs/Gmail/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Gmail",
"description": "Gmail API and user management (This integration replaces the Gmail functionality in the GoogleApps API and G Suite integration).",
"support": "xsoar",
"currentVersion": "1.3.13",
"currentVersion": "1.3.14",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down