-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailcGyver.py
42 lines (32 loc) · 928 Bytes
/
MailcGyver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
MailcGyver - no shit
Created on Thu Nov 3 09:23:56 2016
@author: markus
"""
# python 3 libs
import socket, sys, _thread
# MailcGyver stuff
from IncommingThread import IncommingThread
from users import KNOWN
# localhost only on some high port
HOST = '127.0.0.1'
PORT = 2525
REPLY = dict(ready = "220 service ready\n".encode(),
ok = "250 OK\n".encode(),
start = "354: start mail input\n".encode(),
close = "221: closing channel".encode())
# start socket
s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind ((HOST, PORT))
except socket.error as msg:
print ("socket failure: " + str(msg[0]) + ' Message ' + msg[1])
sys.exit ()
s.listen (10)
# main
while True:
conn, addr = s.accept ()
print ("Connected with " + addr[0] + ":" + str(addr[1]))
_thread.start_new_thread (IncommingThread , (conn, REPLY, KNOWN))
s.close()