Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
839a58bfb0 | |||
8fe42e9163 |
@ -1,17 +1,17 @@
|
|||||||
# NOTE: Sample config is provided in yaml format for easy editing
|
# NOTE: Sample config is provided in yaml format for easy editing
|
||||||
# mail4one needs a json config, Please convert the config to json before passing to app
|
# mail4one needs a json config, Please convert the config to json before passing to app
|
||||||
# This is to avoid yaml depependency in the app
|
# This is to avoid yaml dependency in the app
|
||||||
#
|
#
|
||||||
# Some tools to convert to json:
|
# Some tools to convert to json:
|
||||||
# If you have go in your system (https://go.dev/)
|
# If you have `go` in your system (https://go.dev/)
|
||||||
# go run github.com/mikefarah/yq/v4@latest -oj -P . config.sample > config.json
|
# go run github.com/mikefarah/yq/v4@latest -oj -P . config.sample > config.json
|
||||||
#
|
#
|
||||||
# If you have pipx in your system (https://pypa.github.io/pipx/)
|
# If you have `pipx` in your system (https://pypa.github.io/pipx/)
|
||||||
# pipx run yq . config.sample > config.json
|
# pipx run yq . config.sample > config.json
|
||||||
#
|
#
|
||||||
# or a browser:
|
# or a browser:
|
||||||
# https://onlineyamltools.com/convert-yaml-to-json
|
# https://onlineyamltools.com/convert-yaml-to-json
|
||||||
#
|
|
||||||
default_tls: # Will be used by both pop and smtp servers
|
default_tls: # Will be used by both pop and smtp servers
|
||||||
# If using certbot(https://certbot.eff.org/),
|
# If using certbot(https://certbot.eff.org/),
|
||||||
# the following files will be here /etc/letsencrypt/live/<domain name>
|
# the following files will be here /etc/letsencrypt/live/<domain name>
|
||||||
|
@ -25,6 +25,8 @@ logger = logging.getLogger("smtp")
|
|||||||
|
|
||||||
|
|
||||||
class MyHandler(AsyncMessage):
|
class MyHandler(AsyncMessage):
|
||||||
|
peer_addr: Optional[str]
|
||||||
|
|
||||||
def __init__(self, mails_path: Path, mbox_finder: Callable[[str], list[str]]):
|
def __init__(self, mails_path: Path, mbox_finder: Callable[[str], list[str]]):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.mails_path = mails_path
|
self.mails_path = mails_path
|
||||||
@ -34,7 +36,11 @@ class MyHandler(AsyncMessage):
|
|||||||
self, server: SMTPServer, session: SMTPSession, envelope: SMTPEnvelope
|
self, server: SMTPServer, session: SMTPSession, envelope: SMTPEnvelope
|
||||||
) -> str:
|
) -> str:
|
||||||
self.rcpt_tos = envelope.rcpt_tos
|
self.rcpt_tos = envelope.rcpt_tos
|
||||||
self.peer = session.peer
|
match session.peer:
|
||||||
|
case addr, port:
|
||||||
|
self.peer_addr = addr
|
||||||
|
case _:
|
||||||
|
self.peer_addr = session.peer
|
||||||
return await super().handle_DATA(server, session, envelope)
|
return await super().handle_DATA(server, session, envelope)
|
||||||
|
|
||||||
async def handle_message(self, m: Message): # type: ignore[override]
|
async def handle_message(self, m: Message): # type: ignore[override]
|
||||||
@ -43,7 +49,7 @@ class MyHandler(AsyncMessage):
|
|||||||
for mbox in self.mbox_finder(addr.lower()):
|
for mbox in self.mbox_finder(addr.lower()):
|
||||||
all_mboxes.add(mbox)
|
all_mboxes.add(mbox)
|
||||||
if not all_mboxes:
|
if not all_mboxes:
|
||||||
logger.warning(f"dropping message from: {self.peer}")
|
logger.warning(f"dropping message from: {self.peer_addr}")
|
||||||
return
|
return
|
||||||
for mbox in all_mboxes:
|
for mbox in all_mboxes:
|
||||||
for sub in ("new", "tmp", "cur"):
|
for sub in ("new", "tmp", "cur"):
|
||||||
@ -58,7 +64,7 @@ class MyHandler(AsyncMessage):
|
|||||||
for mbox in all_mboxes:
|
for mbox in all_mboxes:
|
||||||
shutil.copy(temp_email_path, self.mails_path / mbox / "new")
|
shutil.copy(temp_email_path, self.mails_path / mbox / "new")
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Saved mail at {filename} addrs: {','.join(self.rcpt_tos)}, mboxes: {','.join(all_mboxes)} peer: {self.peer}"
|
f"Saved mail at {filename} addrs: {','.join(self.rcpt_tos)}, mboxes: {','.join(all_mboxes)} peer: {self.peer_addr}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user