mirror of
https://seed.flo-the.dev/z3gWc1qgaeZaoGwL4WTstLNoqjayM.git
synced 2025-12-06 04:47:35 +01:00
add reading password from file
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
@@ -107,6 +107,22 @@ class Config:
|
||||
email_certs[email] = cert
|
||||
return email_certs
|
||||
|
||||
@classmethod
|
||||
def _read_from_file(cls, file: Union[Path, str]) -> str:
|
||||
"""Read string from file"""
|
||||
if len(file) == 0:
|
||||
# empty string (which is our fallback), so return empty string
|
||||
return ""
|
||||
# file is non-empty and should provide a path
|
||||
file = Path(file)
|
||||
if not file.exists():
|
||||
raise OSError("File wasn't found: " + str(file))
|
||||
with open(file, "r", encoding="utf8") as fp:
|
||||
line = fp.readline().strip("\n")
|
||||
if len(line) == 0:
|
||||
raise OSError("Empty file supplied: " + str(file))
|
||||
return line
|
||||
|
||||
@classmethod
|
||||
def _from_config(cls, config: configparser.RawConfigParser) -> "Config":
|
||||
email_certs = cls._get_emails_and_certs(config.items("emails"))
|
||||
@@ -120,7 +136,9 @@ class Config:
|
||||
port=config.getint("client", "port"),
|
||||
sender=config.get("client", "sender"),
|
||||
username=config.get("client", "username"),
|
||||
password=config.get("client", "password"),
|
||||
password=cls._read_from_file(
|
||||
(config.get("client", "password_file", fallback=""))
|
||||
),
|
||||
set_reply_to=config.getboolean(
|
||||
"client", "set_reply_to", fallback=False
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user