Skip to content

Instantly share code, notes, and snippets.

@qwell
Created October 26, 2023 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwell/48c27a57198992ac0721ea266a652d26 to your computer and use it in GitHub Desktop.
Save qwell/48c27a57198992ac0721ea266a652d26 to your computer and use it in GitHub Desktop.
parsedmarc-dockerized - gmail_api.diff
--- cli.py 2023-10-26 05:18:00.720172400 -0400
+++ cli.py 2023-05-30 21:53:38.526227000 -0400
@@ -336,6 +333,7 @@
gmail_api_include_spam_trash=False,
gmail_api_scopes=[],
gmail_api_oauth2_port=8080,
+ gmail_api_bind_addr='localhost',
log_file=args.log_file,
n_procs=1,
chunk_size=1,
@@ -753,7 +751,10 @@
_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)
+ gmail_api_config.getint("oauth2_port", 8080)
+ if "bind_addr" in gmail_api_config:
+ opts.gmail_api_bind_addr = \
+ gmail_api_config.get("bind_addr", "localhost")
if "log_analytics" in config.sections():
log_analytics_config = config["log_analytics"]
opts.la_client_id = \
@@ -1005,7 +1006,8 @@
scopes=opts.gmail_api_scopes,
include_spam_trash=opts.gmail_api_include_spam_trash,
reports_folder=opts.mailbox_reports_folder,
- oauth2_port=opts.gmail_api_oauth2_port
+ oauth2_port=opts.gmail_api_oauth2_port,
+ bind_addr=opts.gmail_api_bind_addr
)
except Exception:
--- mail/gmail.py 2023-10-26 05:19:25.532362700 -0400
+++ mail/gmail.py 2023-10-26 04:29:51.184397400 -0400
@@ -14,7 +14,7 @@
from parsedmarc.mail.mailbox_connection import MailboxConnection
-def _get_creds(token_file, credentials_file, scopes, oauth2_port):
+def _get_creds(token_file, credentials_file, scopes, oauth2_port, bind_addr):
creds = None
if Path(token_file).exists():
@@ -28,7 +28,8 @@
flow = InstalledAppFlow.from_client_secrets_file(
credentials_file, scopes)
creds = flow.run_local_server(open_browser=False,
- oauth2_port=oauth2_port)
+ port=oauth2_port,
+ bind_addr=bind_addr)
# Save the credentials for the next run
with Path(token_file).open('w') as token:
token.write(creds.to_json())
@@ -42,8 +43,9 @@
scopes: List[str],
include_spam_trash: bool,
reports_folder: str,
- oauth2_port: int):
- creds = _get_creds(token_file, credentials_file, scopes, oauth2_port)
+ oauth2_port: int,
+ bind_addr: str):
+ creds = _get_creds(token_file, credentials_file, scopes, oauth2_port, bind_addr)
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment