@ -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:
" \n Anreise: " + self . buchung [ ' begin ' ] + " \n Abreise: " + self . buchung [ ' end ' ] +
" \n Personen: " + self . buchung [ ' persons ' ] + " \n \n Nachricht: \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 " <p>Uuups, da ist ein Fehler aufgetreten. Bitte zur <a href= ' https://www.meissner-wohnen.de ' >Startseite</a> zurückkehren</p> "
print " <p>Uuups, da ist ein Fehler aufgetreten. Bitte zur <a href= ' https://www.meissner-wohnen.de ' >Startseite</a> zurückkehren</p> "
print " <p>Falls Sie eine Buchungsanfrage stellen möchten, bitte per Mail an: <a href= ' mailto:kontakt@meissner-wohnen.de ' >kontakt@meissner-wohnen.de</a></p> "
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 ( )