mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-07-03 15:34:19 +00:00
support custom port for gmail oauth2 local server (#341)
This commit is contained in:
@@ -295,6 +295,7 @@ The full set of configuration options are:
|
||||
- ``token_file`` - str: Path to save the token file (Default: .token)
|
||||
- ``include_spam_trash`` - bool: Include messages in Spam and Trash when searching reports (Default: False)
|
||||
- ``scopes`` - str: Comma separated list of scopes to use when acquiring credentials (Default: https://www.googleapis.com/auth/gmail.modify)
|
||||
- ``oauth2_port`` - int: The TCP port for the local server to listen on for the OAuth2 response (Default: 8080)
|
||||
|
||||
.. warning::
|
||||
|
||||
|
||||
@@ -294,6 +294,7 @@ The full set of configuration options are:
|
||||
- ``token_file`` - str: Path to save the token file (Default: .token)
|
||||
- ``include_spam_trash`` - bool: Include messages in Spam and Trash when searching reports (Default: False)
|
||||
- ``scopes`` - str: Comma separated list of scopes to use when acquiring credentials (Default: https://www.googleapis.com/auth/gmail.modify)
|
||||
- ``oauth2_port`` - int: The TCP port for the local server to listen on for the OAuth2 response (Default: 8080)
|
||||
|
||||
.. warning::
|
||||
|
||||
|
||||
+6
-1
@@ -334,6 +334,7 @@ def _main():
|
||||
gmail_api_token_file=None,
|
||||
gmail_api_include_spam_trash=False,
|
||||
gmail_api_scopes=[],
|
||||
gmail_api_oauth2_port=8080,
|
||||
log_file=args.log_file,
|
||||
n_procs=1,
|
||||
chunk_size=1,
|
||||
@@ -733,6 +734,9 @@ def _main():
|
||||
default_gmail_api_scope)
|
||||
opts.gmail_api_scopes = \
|
||||
_str_to_list(opts.gmail_api_scopes)
|
||||
if "oauth2_port" in gmail_api_config:
|
||||
opts.gmail_api_oauth2_port = \
|
||||
gmail_api_config.get("oauth2_port", 8080)
|
||||
|
||||
logger.setLevel(logging.WARNING)
|
||||
|
||||
@@ -925,7 +929,8 @@ def _main():
|
||||
token_file=opts.gmail_api_token_file,
|
||||
scopes=opts.gmail_api_scopes,
|
||||
include_spam_trash=opts.gmail_api_include_spam_trash,
|
||||
reports_folder=opts.mailbox_reports_folder
|
||||
reports_folder=opts.mailbox_reports_folder,
|
||||
oauth2_port=opts.gmail_api_oauth2_port
|
||||
)
|
||||
|
||||
except Exception as error:
|
||||
|
||||
@@ -16,7 +16,7 @@ from parsedmarc.mail.mailbox_connection import MailboxConnection
|
||||
logger = logging.getLogger("parsedmarc")
|
||||
|
||||
|
||||
def _get_creds(token_file, credentials_file, scopes):
|
||||
def _get_creds(token_file, credentials_file, scopes, oauth2_port):
|
||||
creds = None
|
||||
|
||||
if Path(token_file).exists():
|
||||
@@ -29,7 +29,7 @@ def _get_creds(token_file, credentials_file, scopes):
|
||||
else:
|
||||
flow = InstalledAppFlow.from_client_secrets_file(
|
||||
credentials_file, scopes)
|
||||
creds = flow.run_local_server(open_browser=False)
|
||||
creds = flow.run_local_server(open_browser=False, oauth2_port=oauth2_port)
|
||||
# Save the credentials for the next run
|
||||
with Path(token_file).open('w') as token:
|
||||
token.write(creds.to_json())
|
||||
@@ -42,8 +42,9 @@ class GmailConnection(MailboxConnection):
|
||||
credentials_file: str,
|
||||
scopes: List[str],
|
||||
include_spam_trash: bool,
|
||||
reports_folder: str):
|
||||
creds = _get_creds(token_file, credentials_file, scopes)
|
||||
reports_folder: str,
|
||||
oauth2_port: int):
|
||||
creds = _get_creds(token_file, credentials_file, scopes, oauth2_port)
|
||||
self.service = build('gmail', 'v1', credentials=creds)
|
||||
self.include_spam_trash = include_spam_trash
|
||||
self.reports_label_id = self._find_label_id_for_label(reports_folder)
|
||||
|
||||
Reference in New Issue
Block a user