Hallo
Ich habe eine Mail ausgelesen mit dem folgenden Code:
[code=php]
running = True
def checkMails():
try:
print("read mails")
m = imaplib.IMAP4_SSL(MailReceiveSRV)
m.login(MailReceiveUSER, MailReceivePWD)
if running:
m.select("Inbox")
status, unreadcount = m.status('INBOX', "(UNSEEN)")
unreadcount = int(unreadcount[0].split()[2].strip(').,]'))
if unreadcount > 0:
items = m.search(None, "UNSEEN")
items = str(items[1]).strip('[\']').split(' ')
for index, emailid in enumerate(items):
#print "emailid: " + emailid
resp, data = m.fetch(emailid, "(RFC822)")
email_body = data[0][1]
mail = email.message_from_string(email_body)
if mail["Subject"] == 'Code':
print "New mail received: Code-Word accepted"
for part in mail.walk():
if part.get_content_type() == 'text/plain':
body = part.get_payload()
# For each line in message execute instructions
for line in body.split('\r\n'):
if line != " ":
#print "lese..."
if line[0:5] == "Mail:":
adresse = line[6:len(line)]
print "Adresse aus der Mail gelesen"
with open("/home/pi/adresse.txt","w") as f:
f.write(adresse)
if line[0:5] == "Zahl:":
zahl = line[6:len(line)]
print "Zahl aus der Mail gelesen"
with open("/home/pi/zahl.txt","w") as f:
f.write(zahl)
time.sleep(0.2)
except Exception, e1:
print("Error...: " + str(e1))
except (KeyboardInterrupt, SystemExit):
exit()[/php]
Das hat funktioniert und in der Datei adresse.txt stand z.B. drin muster.hans@gmail.com.
Aber plötzlich klappts nicht mehr und an den String in der Datei wird noch '=0A=' angehängt.
Also der Inhalt der Datei ist dann:
Und bei der Zahl dasselbe, z.B.:
8=0A=
Dann plötzlich klapps es wieder und das '=0A=' erscheint nicht mehr..
Hat jemand eine Idee woran das liegen könnte? Hab echt keine Ahnung was das sein könnte.. :s