diff --git a/cgi-bin/meissner-wohnen.py b/cgi-bin/meissner-wohnen.py index 1c975df..4b41cce 100755 --- a/cgi-bin/meissner-wohnen.py +++ b/cgi-bin/meissner-wohnen.py @@ -10,6 +10,7 @@ from subprocess import call from datetime import datetime from fnmatch import fnmatch from string import Template +import json def escapeTags(text): @@ -53,7 +54,7 @@ class Mail: try: self.filename = "../data/email_" + datetime.now().strftime('%d-%m-%Y_%H-%M-%S-%f') + ".txt" fp = open(self.filename, 'wb') - fp.write(self.msg.as_string()) + fp.write(self.msg) fp.close() except IOError: http = HttpResponse(url) @@ -61,8 +62,14 @@ class Mail: exit() def sendMail(self): - # send mail on strato powerweb - call(["mail", self.buchung['receiver']], stdin=open(self.filename)) + with open(os.devnull, 'wb') as DEVNULL: + # send mail on strato powerweb + #call(["mail", self.buchung['receiver']], stdin=open(self.filename)) + # what's with content type: '-a', "Content-Type: text/plain; charset=utf-8" + self.ret = call(["mail", '-s', "Buchungsanfrage von " + self.buchung['name'], \ + '-r', self.buchung['sender'], self.buchung['receiver']], \ + stdin=open(self.filename), stdout=DEVNULL) + return self.ret def genMail(self): # replace evil html tags @@ -79,11 +86,7 @@ class Mail: "\nAnreise: " + self.buchung['begin'] + "\nAbreise: " + self.buchung['end'] + "\nPersonen: " + self.buchung['persons'] + "\n\nNachricht:\n" + self.buchung['msg']) # gen mail - self.msg = MIMEText(self.text, 'plain', 'utf-8') - self.msg['Subject'] = 'Buchungsanfrage von %s' % self.buchung['name'] - self.msg['From'] = self.buchung['sender'] - self.msg['To'] = self.buchung['receiver'] - + self.msg = self.text class HttpResponse: @@ -91,14 +94,14 @@ class HttpResponse: self.url = url def sendRedirect(self): - # redirect to buchung.html - print 'Status: 301' + # redirect to given url print 'Location: https://www.meissner-wohnen.de/%s' % self.url print '' def sendError(self): print "Content-type: text/html\n" - print "

Uuups, da ist ein Fehler aufgetreten. Bitte zur Startseite zurückkehren

" + print "

Uuups, da ist ein Fehler aufgetreten. Bitte zur Startseite zurückkehren

" + print "

Falls Sie eine Buchungsanfrage stellen möchten, bitte per Mail an: kontakt@meissner-wohnen.de

" def main(): @@ -127,7 +130,7 @@ def main(): exit() # get form values if exist - for index in range(0, 8): + for index in range(0, len(blub)): if form.getvalue(str(index)): buchung[blub[index]] = form.getvalue(str(index)) else: @@ -142,14 +145,20 @@ def main(): msg = Mail(buchung, receiver) msg.genMail() msg.genMailFile() - msg.sendMail() + if msg.sendMail() != 0: + http = HttpResponse(url) + http.sendError() + exit() if buchung['reply'] == 'true': receiver, buchung['sender'] = buchung['sender'], 'kontakt@meissner-wohnen.de' msg = Mail(buchung, receiver, True) msg.genMail() msg.genMailFile() - msg.sendMail() + if msg.sendMail() != 0: + http = HttpResponse(url) + http.sendError() + exit() url = url + '_erfolgreich.html' @@ -188,7 +197,8 @@ def main(): # gen and send http response http = HttpResponse(url) http.sendRedirect() - + exit() if __name__ == '__main__': main() +