Skip to content

Commit ff1f74e

Browse files
committed
Fix SMTP sink body logging and drop Molecule pycache.
1 parent 607fd23 commit ff1f74e

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ id_ed25519*
1919
.ansible/
2020
ansible.log
2121
ansible/collections/
22+
**/__pycache__/
23+
*.py[cod]
2224

2325
# Editor / OS
2426
.idea/
Binary file not shown.

ansible/molecule/default/files/smtp_sink.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
def handle(conn: socket.socket) -> None:
1111
conn.sendall(b"220 molecule-sink ESMTP\r\n")
1212
data_mode = False
13+
data_buf: list[str] = []
1314
buf = b""
1415
while True:
1516
chunk = conn.recv(4096)
@@ -23,7 +24,13 @@ def handle(conn: socket.socket) -> None:
2324
if data_mode:
2425
if text == ".":
2526
data_mode = False
27+
body = "\n".join(data_buf)
28+
sys.stderr.write(f"DATA received:\n{body}\n")
29+
sys.stderr.flush()
30+
data_buf = []
2631
conn.sendall(b"250 OK\r\n")
32+
else:
33+
data_buf.append(text)
2734
continue
2835
if upper.startswith("EHLO") or upper.startswith("HELO"):
2936
conn.sendall(b"250-molecule-sink\r\n250 OK\r\n")
@@ -32,6 +39,7 @@ def handle(conn: socket.socket) -> None:
3239
elif upper == "DATA":
3340
conn.sendall(b"354 End data with <CR><LF>.<CR><LF>\r\n")
3441
data_mode = True
42+
data_buf = []
3543
elif upper in {"QUIT", "RSET"}:
3644
conn.sendall(b"221 Bye\r\n" if upper == "QUIT" else b"250 OK\r\n")
3745
if upper == "QUIT":

0 commit comments

Comments
 (0)