Skip to content

Commit d18f271

Browse files
committed
Provide paginate_messages option to allow use of previous behavior
1 parent d30f9f3 commit d18f271

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

docs/source/usage.md

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ The full set of configuration options are:
292292
(Default: `https://www.googleapis.com/auth/gmail.modify`)
293293
- `oauth2_port` - int: The TCP port for the local server to
294294
listen on for the OAuth2 response (Default: `8080`)
295+
- `paginate_messages` - bool: When `True`, fetch all applicable Gmail messages.
296+
When `False`, only fetch up to 100 new messages per run (Default: `True`)
295297
- `log_analytics`
296298
- `client_id` - str: The app registration's client ID
297299
- `client_secret` - str: The app registration's client secret

parsedmarc/cli.py

+4
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def process_reports(reports_):
335335
gmail_api_credentials_file=None,
336336
gmail_api_token_file=None,
337337
gmail_api_include_spam_trash=False,
338+
gmail_api_paginate_messages=True,
338339
gmail_api_scopes=[],
339340
gmail_api_oauth2_port=8080,
340341
log_file=args.log_file,
@@ -750,6 +751,8 @@ def process_reports(reports_):
750751
gmail_api_config.get("token_file", ".token")
751752
opts.gmail_api_include_spam_trash = \
752753
gmail_api_config.getboolean("include_spam_trash", False)
754+
opts.gmail_api_paginate_messages = \
755+
gmail_api_config.getboolean("paginate_messages", True)
753756
opts.gmail_api_scopes = \
754757
gmail_api_config.get("scopes",
755758
default_gmail_api_scope)
@@ -1009,6 +1012,7 @@ def process_reports(reports_):
10091012
token_file=opts.gmail_api_token_file,
10101013
scopes=opts.gmail_api_scopes,
10111014
include_spam_trash=opts.gmail_api_include_spam_trash,
1015+
paginate_messages=opts.gmail_api_paginate_messages,
10121016
reports_folder=opts.mailbox_reports_folder,
10131017
oauth2_port=opts.gmail_api_oauth2_port
10141018
)

parsedmarc/mail/gmail.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ def __init__(self,
4242
scopes: List[str],
4343
include_spam_trash: bool,
4444
reports_folder: str,
45-
oauth2_port: int):
45+
oauth2_port: int,
46+
paginate_messages: bool):
4647
creds = _get_creds(token_file, credentials_file, scopes, oauth2_port)
4748
self.service = build('gmail', 'v1', credentials=creds)
4849
self.include_spam_trash = include_spam_trash
4950
self.reports_label_id = self._find_label_id_for_label(reports_folder)
51+
self.paginate_messages = paginate_messages
5052

5153
def create_folder(self, folder_name: str):
5254
# Gmail doesn't support the name Archive
@@ -81,7 +83,7 @@ def _fetch_all_message_ids(self, reports_label_id, page_token=None):
8183
for message in messages:
8284
yield message["id"]
8385

84-
if "nextPageToken" in results:
86+
if "nextPageToken" in results and self.paginate_messages:
8587
yield from self._fetch_all_message_ids(
8688
reports_label_id, results["nextPageToken"]
8789
)

0 commit comments

Comments
 (0)