Merge branch 'master' of github.com:ennorehling/eressea

This commit is contained in:
Enno Rehling 2019-05-07 19:36:50 +02:00
commit 618247e4bf
1 changed files with 27 additions and 13 deletions

View File

@ -13,7 +13,7 @@ import logging
import sys import sys
import subprocess import subprocess
from sys import stdin from sys import stdin
from time import ctime, sleep, time import time
from socket import gethostname from socket import gethostname
from rfc822 import parsedate_tz, mktime_tz from rfc822 import parsedate_tz, mktime_tz
@ -57,6 +57,9 @@ sendmail = True
maxfiles = 30 maxfiles = 30
# write headers to file? # write headers to file?
writeheaders = True writeheaders = True
# write received files to datrabase?
tooldir = os.path.join(rootdir, 'orders-php')
writedb = os.path.exists(tooldir)
# reject all html email? # reject all html email?
rejecthtml = True rejecthtml = True
@ -223,18 +226,24 @@ def write_part(outfile, part):
outfile.write("\n"); outfile.write("\n");
return True return True
def copy_orders(message, filename, sender): def copy_orders(message, filename, sender, mtime):
# print the header first # print the header first
dirname, basename = os.path.split(filename)
if writeheaders: if writeheaders:
from os.path import split header_dir = dirname + '/headers'
dirname, basename = split(filename) if not os.path.exists(header_dir): os.mkdir(header_dir)
dirname = dirname + '/headers' outfile = open(header_dir + '/' + basename, "w")
if not os.path.exists(dirname): os.mkdir(dirname)
outfile = open(dirname + '/' + basename, "w")
for name, value in message.items(): for name, value in message.items():
outfile.write(name + ": " + value + "\n") outfile.write(name + ": " + value + "\n")
outfile.close() outfile.close()
if writedb:
dirname, basename = os.path.split(filename)
cli = os.path.join(tooldir, 'cli.php');
dbname = os.path.join(dirname, 'orders.db')
datestr = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(mtime))
subprocess.call(['php', cli, '-d', dbname, 'insert', basename, sender, datestr])
found = False found = False
outfile = open(filename, "w") outfile = open(filename, "w")
if message.is_multipart(): if message.is_multipart():
@ -283,18 +292,23 @@ def accept(game, locale, stream, extend=None):
logger.warning("more than " + str(maxfiles) + " orders from " + email) logger.warning("more than " + str(maxfiles) + " orders from " + email)
return -1 return -1
# copy the orders to the file # copy the orders to the file
text_ok = copy_orders(message, filename, email)
turndate = None
warning, msg, fail = None, "", False
maildate = message.get("Date") maildate = message.get("Date")
if maildate != None: if maildate is None:
turndate = time.time()
else:
turndate = mktime_tz(parsedate_tz(maildate)) turndate = mktime_tz(parsedate_tz(maildate))
text_ok = copy_orders(message, filename, email, turndate)
warning, msg, fail = None, "", False
if not maildate is None:
os.utime(filename, (turndate, turndate)) os.utime(filename, (turndate, turndate))
logger.debug("mail date is '%s' (%d)" % (maildate, turndate)) logger.debug("mail date is '%s' (%d)" % (maildate, turndate))
if False and turndate < maxdate: if False and turndate < maxdate:
logger.warning("inconsistent message date " + email) logger.warning("inconsistent message date " + email)
warning = " (" + messages["warning-" + locale] + ")" warning = " (" + messages["warning-" + locale] + ")"
msg = msg + formatpar(messages["maildate-" + locale] % (ctime(maxdate),ctime(turndate)), 76, 2) + "\n" msg = msg + formatpar(messages["maildate-" + locale] % (time.ctime(maxdate), time.ctime(turndate)), 76, 2) + "\n"
else: else:
logger.warning("missing message date " + email) logger.warning("missing message date " + email)
warning = " (" + messages["warning-" + locale] + ")" warning = " (" + messages["warning-" + locale] + ")"