Thomas Richardson commited on
Commit
cc2210e
·
1 Parent(s): cfc54bd

feature: proxy setup for imap access in hugging face.

Browse files
Brain/src/common/utils.py CHANGED
@@ -9,6 +9,10 @@ PINECONE_KEY = os.getenv("PINECONE_KEY")
9
  PINECONE_ENV = os.getenv("PINECONE_ENV")
10
  FIREBASE_ENV = os.getenv("FIREBASE_SERVICE_ACCOUNT_TEST3_83FFC")
11
 
 
 
 
 
12
  # swagger
13
  swagger_destination_path = "./src/static/swagger.json"
14
  SWAGGER_URL = "/api/docs" # URL for exposing Swagger UI (without trailing '/')
 
9
  PINECONE_ENV = os.getenv("PINECONE_ENV")
10
  FIREBASE_ENV = os.getenv("FIREBASE_SERVICE_ACCOUNT_TEST3_83FFC")
11
 
12
+ # proxy for imap access from hugging face.
13
+ PROXY_IP = os.getenv("PROXY_IP")
14
+ PROXY_PORT = os.getenv("PROXY_PORT")
15
+
16
  # swagger
17
  swagger_destination_path = "./src/static/swagger.json"
18
  SWAGGER_URL = "/api/docs" # URL for exposing Swagger UI (without trailing '/')
Brain/src/rising_plugin/gmail/email_plugin.py CHANGED
@@ -9,9 +9,13 @@ import time
9
  import base64
10
  from email.header import decode_header
11
  from email.message import EmailMessage
 
12
 
 
13
  from bs4 import BeautifulSoup
14
 
 
 
15
  # email variables
16
  EMAIL_SMTP_HOST = "smtp.gmail.com"
17
  EMAIL_SMTP_PORT = 1587
@@ -279,6 +283,11 @@ class EmailPlugin:
279
  def imap_open(
280
  self, imap_folder: str, email_sender: str, email_password: str
281
  ) -> imaplib.IMAP4_SSL:
 
 
 
 
 
282
  imap_server = EMAIL_IMAP_SERVER
283
  conn = imaplib.IMAP4_SSL(imap_server)
284
  conn.login(user=email_sender, password=email_password)
 
9
  import base64
10
  from email.header import decode_header
11
  from email.message import EmailMessage
12
+ from socket import socket
13
 
14
+ import socks
15
  from bs4 import BeautifulSoup
16
 
17
+ from Brain.src.common.utils import PROXY_IP, PROXY_PORT
18
+
19
  # email variables
20
  EMAIL_SMTP_HOST = "smtp.gmail.com"
21
  EMAIL_SMTP_PORT = 1587
 
283
  def imap_open(
284
  self, imap_folder: str, email_sender: str, email_password: str
285
  ) -> imaplib.IMAP4_SSL:
286
+ # Create a new socket object for later connections as a proxy
287
+ socks.set_default_proxy(socks.SOCKS5, PROXY_IP, PROXY_PORT)
288
+ socket.socket = socks.socksocket
289
+
290
+ # IMAP Server Connect
291
  imap_server = EMAIL_IMAP_SERVER
292
  conn = imaplib.IMAP4_SSL(imap_server)
293
  conn.login(user=email_sender, password=email_password)
Brain/src/router/email_router.py CHANGED
@@ -69,7 +69,11 @@ def construct_blueprint_email_api() -> APIRouter:
69
  except Exception as e:
70
  if isinstance(e, BrainException):
71
  return e.get_response_exp()
72
- return assembler.to_response(400, "Failed to read emails", "")
 
 
 
 
73
  return assembler.to_response(200, "", result)
74
 
75
  """@generator.request_body(
 
69
  except Exception as e:
70
  if isinstance(e, BrainException):
71
  return e.get_response_exp()
72
+ return assembler.to_response(
73
+ 400,
74
+ "Failed to read emails",
75
+ "ConnectionResetError occurred for IMAP Server",
76
+ )
77
  return assembler.to_response(200, "", result)
78
 
79
  """@generator.request_body(
requirements.txt CHANGED
@@ -75,4 +75,5 @@ google-search-results==2.4.2
75
  tiktoken==0.4.0
76
  tiktoken==0.4.0
77
  gradio-client==0.2.7
78
- gradio==3.14.0
 
 
75
  tiktoken==0.4.0
76
  tiktoken==0.4.0
77
  gradio-client==0.2.7
78
+ gradio==3.14.0
79
+ PySocks==1.7.1