@ -10,6 +10,7 @@ from subprocess import call
from datetime import datetime
from datetime import datetime
from fnmatch import fnmatch
from fnmatch import fnmatch
from string import Template
from string import Template
import json
def escapeTags ( text ) :
def escapeTags ( text ) :
@ -53,7 +54,7 @@ class Mail:
try :
try :
self . filename = " ../data/email_ " + datetime . now ( ) . strftime ( ' %d - % m- % Y_ % H- % M- % S- %f ' ) + " .txt "
self . filename = " ../data/email_ " + datetime . now ( ) . strftime ( ' %d - % m- % Y_ % H- % M- % S- %f ' ) + " .txt "
fp = open ( self . filename , ' wb ' )
fp = open ( self . filename , ' wb ' )
fp . write ( self . msg . as_string ( ) )
fp . write ( self . msg )
fp . close ( )
fp . close ( )
except IOError :
except IOError :
http = HttpResponse ( url )
http = HttpResponse ( url )
@ -61,8 +62,14 @@ class Mail:
exit ( )
exit ( )
def sendMail ( self ) :
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 ) :
def genMail ( self ) :
# replace evil html tags
# replace evil html tags
@ -79,11 +86,7 @@ class Mail:
" \n Anreise: " + self . buchung [ ' begin ' ] + " \n Abreise: " + self . buchung [ ' end ' ] +
" \n Anreise: " + self . buchung [ ' begin ' ] + " \n Abreise: " + self . buchung [ ' end ' ] +
" \n Personen: " + self . buchung [ ' persons ' ] + " \n \n Nachricht: \n " + self . buchung [ ' msg ' ] )
" \n Personen: " + self . buchung [ ' persons ' ] + " \n \n Nachricht: \n " + self . buchung [ ' msg ' ] )
# gen mail
# 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 :
class HttpResponse :
@ -91,14 +94,14 @@ class HttpResponse:
self . url = url
self . url = url
def sendRedirect ( self ) :
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 ' Location: https://www.meissner-wohnen.de/ %s ' % self . url
print ' '
print ' '
def sendError ( self ) :
def sendError ( self ) :
print " Content-type: text/html \n "
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 ( ) :
def main ( ) :
@ -127,7 +130,7 @@ def main():
exit ( )
exit ( )
# get form values if exist
# get form values if exist
for index in range ( 0 , 8 ) :
for index in range ( 0 , len ( blub ) ) :
if form . getvalue ( str ( index ) ) :
if form . getvalue ( str ( index ) ) :
buchung [ blub [ index ] ] = form . getvalue ( str ( index ) )
buchung [ blub [ index ] ] = form . getvalue ( str ( index ) )
else :
else :
@ -142,14 +145,20 @@ def main():
msg = Mail ( buchung , receiver )
msg = Mail ( buchung , receiver )
msg . genMail ( )
msg . genMail ( )
msg . genMailFile ( )
msg . genMailFile ( )
msg . sendMail ( )
if msg . sendMail ( ) != 0 :
http = HttpResponse ( url )
http . sendError ( )
exit ( )
if buchung [ ' reply ' ] == ' true ' :
if buchung [ ' reply ' ] == ' true ' :
receiver , buchung [ ' sender ' ] = buchung [ ' sender ' ] , ' kontakt@meissner-wohnen.de '
receiver , buchung [ ' sender ' ] = buchung [ ' sender ' ] , ' kontakt@meissner-wohnen.de '
msg = Mail ( buchung , receiver , True )
msg = Mail ( buchung , receiver , True )
msg . genMail ( )
msg . genMail ( )
msg . genMailFile ( )
msg . genMailFile ( )
msg . sendMail ( )
if msg . sendMail ( ) != 0 :
http = HttpResponse ( url )
http . sendError ( )
exit ( )
url = url + ' _erfolgreich.html '
url = url + ' _erfolgreich.html '
@ -188,7 +197,8 @@ def main():
# gen and send http response
# gen and send http response
http = HttpResponse ( url )
http = HttpResponse ( url )
http . sendRedirect ( )
http . sendRedirect ( )
exit ( )
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
main ( )
main ( )