Fix errors

This commit is contained in:
youshitsune 2023-06-09 08:24:40 +02:00
parent 3009007e48
commit 6eaa6a19d5

View File

@ -21,36 +21,25 @@ def publish(ctx, token, url):
def listen(user, passwd, url, port): def listen(user, passwd, url, port):
mail = imaplib.IMAP4_SSL(url, port=port) mail = imaplib.IMAP4_SSL(url, port=port)
mail.login(user, passwd) mail.login(user, passwd)
mail.select("INBOX") _, messages = mail.select()
status, messages = mail.select() past_messages = int(messages[0].decode())
past_messages = messages
while True: while True:
ctx = [] ctx = []
status, messages = mail.select() _, messages = mail.select()
if past_messages != messages: if past_messages != int(messages[0].decode()):
for i in range(past_messages+1, messages+1): for i in range(past_messages+1, int(messages[0].decode())+1):
res, msg = mail.fetch(str(i), "(RFC822)") _, msg = mail.fetch(str(i), "(RFC822)")
for resp in msg: for resp in msg:
if isinstance(resp, tuple): if isinstance(resp, tuple):
msg = email.messages_from_bytes(response[1]) msg = email.messages_from_bytes(response[1])
for part in msg.walk(): body = msg.get_payload(decode=True).decode()
try:
body = part.get_payload(decode=True).decode()
except Exception:
pass
else:
ctx.append(body) ctx.append(body)
publish("".join(ctx), TOKEN, URL) publish("".join(ctx), TOKEN, URL)
past_messages = messages past_messages = int(messages[0].decode())
else: else:
continue continue
if __name__ == '__main__': if __name__ == '__main__':
argparser = argparse.ArgumentParser(description="Bot that mirrors emails to Mastodon account") argparser = argparse.ArgumentParser(description="Bot that mirrors emails to Mastodon account")
argparser.add_argument("--version", dest="version", help="print version information and exit", action="store_true") argparser.add_argument("--version", dest="version", help="print version information and exit", action="store_true")