[Dovecot] notify scripts migrated to python3

This commit is contained in:
zekeriya
2019-09-13 21:14:30 +03:00
parent 48081ff5b7
commit b9e7d12a5e
3 changed files with 30 additions and 30 deletions

View File

@@ -1,10 +1,10 @@
#!/usr/bin/python
#!/usr/bin/python3
import smtplib
import os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
import jinja2
from jinja2 import Template
import redis
@@ -17,7 +17,7 @@ if len(sys.argv) > 2:
percent = int(sys.argv[1])
username = str(sys.argv[2])
else:
print "Args missing"
print("Args missing")
sys.exit(1)
while True:
@@ -25,7 +25,7 @@ while True:
r = redis.StrictRedis(host='redis', decode_responses=True, port=6379, db=0)
r.ping()
except Exception as ex:
print '%s - trying again...' % (ex)
print('%s - trying again...' % (ex))
time.sleep(3)
else:
break
@@ -34,7 +34,7 @@ if r.get('QW_HTML'):
try:
template = Template(r.get('QW_HTML'))
except:
print "Error: Cannot parse quarantine template, falling back to default template."
print("Error: Cannot parse quarantine template, falling back to default template.")
with open('/templates/quota.tpl') as file_:
template = Template(file_.read())
else:
@@ -55,10 +55,10 @@ try:
msg.attach(html_part)
msg['To'] = username
p = Popen(['/usr/lib/dovecot/dovecot-lda', '-d', username, '-o', '"plugin/quota=maildir:User quota:noenforcing"'], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
p.communicate(input=msg.as_string())
p.communicate(input=bytes(msg.as_string(), 'utf-8'))
except Exception as ex:
print 'Failed to send quota notification: %s' % (ex)
print('Failed to send quota notification: %s' % (ex))
sys.exit(1)
try: