-
Notifications
You must be signed in to change notification settings - Fork 2
/
funcs.py
54 lines (37 loc) · 1.73 KB
/
funcs.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
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
from smtplib import SMTP
import socket
def send_mail(to_addr, banned, countries, host, port):
hostname = socket.gethostname()
smtp = SMTP()
smtp.connect(host, port)
from_addr = "pcc@" + hostname
countrylist = []
for country in countries:
countrylist.append(country.country)
subj = "User %s has been banned due to suspicion of compromised account" % banned
message_text = "User %s has been banned on %s due to suspicion of compromised account\n\nList of countries: %s\n" % (banned, hostname, countrylist)
msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (from_addr, to_addr, subj, message_text)
smtp.sendmail(from_addr, to_addr, msg)
def notify_unban(to_addr, host, port, user, unbanned, released=False, deleted=False):
if (not unbanned) and (isinstance(released, bool) and not released) and (isinstance(deleted, bool) and not deleted):
return False
hostname = socket.gethostname()
smtp = SMTP()
smtp.connect(host, port)
from_addr = "pcc@" + hostname
countrylist = []
subj = ""
message_text = ""
if unbanned:
subj = "User ban release (%s)" % user
message_text = "User %s has been unbanned on %s by an administrador\n" % (user, hostname)
else:
subj = "Messages on hold messages managed"
message_text = "Messages on hold on %s have been managed by an administrator\n" % (hostname)
if not isinstance(released, bool):
message_text += "Released mails: %d\n" % (released)
if not isinstance(deleted, bool):
message_text += "Deleted mails: %d\n" % (deleted)
msg = "From: %s\nTo: %s\nSubject: %s\n\n%s" % (from_addr, to_addr, subj, message_text)
smtp.sendmail(from_addr, to_addr, msg)