-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
from .distance import cosine_distance, euclidean_distance | ||
from .smtp import SMTPClient | ||
|
||
__all__ = ["cosine_distance", "euclidean_distance"] | ||
__all__ = [ | ||
"cosine_distance", | ||
"euclidean_distance", | ||
"SMTPClient", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from typing import Optional, Union, Sequence | ||
import smtplib | ||
import ssl as ssl_lib | ||
|
||
|
||
class SMTPClient: | ||
def __init__( | ||
self, | ||
host: str, | ||
port: Optional[int] = None, | ||
ssl: bool = True, | ||
ssl_context: Optional[ssl_lib.SSLContext] = None, | ||
) -> None: | ||
if not port: | ||
port = smtplib.SMTP_SSL_PORT if ssl else smtplib.SMTP_PORT | ||
|
||
self.host = host | ||
self.port = port | ||
self.ssl = ssl | ||
self.ssl_context = ssl_context | ||
|
||
self._smtp = self._create_SMTP() | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self._smtp.quit() | ||
|
||
def _create_SMTP(self) -> Union[smtplib.SMTP_SSL, smtplib.SMTP]: | ||
if self.ssl: | ||
return smtplib.SMTP_SSL( | ||
host=self.host, port=self.port, context=self.ssl_context | ||
) | ||
return smtplib.SMTP(host=self.host, port=self.port) | ||
|
||
def login(self, user: str, password: str): | ||
self._smtp.login(user, password) | ||
|
||
def sendmail(self, from_addr: str, to_addrs: str | Sequence[str], msg: str): | ||
self._smtp.sendmail(from_addr, to_addrs, msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ keywords = [ | |
"genai", | ||
"llm", | ||
"ai", | ||
"responsible-ai", | ||
"pentest", | ||
"cybersecurity", | ||
] | ||
|