Compare commits

..

2 Commits

Author SHA1 Message Date
youshitsune
e7512312ad Update config.ini 2023-06-09 08:59:25 +02:00
youshitsune
0163e54e6d Finalize the script 2023-06-09 08:58:57 +02:00
2 changed files with 7 additions and 4 deletions

View File

@ -4,4 +4,4 @@ PASS_MAIL = password
URL_MAIL = example.org URL_MAIL = example.org
PORT_MAIL = 993 PORT_MAIL = 993
TOKEN = token TOKEN = token
URL = example1.org URL = https://example1.org

View File

@ -2,8 +2,9 @@
# Bot that mirrors emails to Mastodon account # Bot that mirrors emails to Mastodon account
import argparse import argparse
import configparser import configparser
import email
import imaplib import imaplib
from mastodon import Mastodon import mastodon
CONFIG_PATH = "./config.ini" CONFIG_PATH = "./config.ini"
@ -16,7 +17,7 @@ def show_version():
print("There is NO WARRANTY, to the extent permitted by law.") print("There is NO WARRANTY, to the extent permitted by law.")
def publish(ctx, token, url): def publish(ctx, token, url):
m = Mastodon(access_token=token, api_base_url=url) m = mastodon.Mastodon(access_token=token, api_base_url=url)
m.toot(ctx) m.toot(ctx)
def listen(user, passwd, url, port): def listen(user, passwd, url, port):
@ -32,7 +33,7 @@ def listen(user, passwd, url, port):
_, 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.message_from_bytes(resp[1])
body = msg.get_payload(decode=True).decode() body = msg.get_payload(decode=True).decode()
ctx.append(body) ctx.append(body)
publish("".join(ctx), TOKEN, URL) publish("".join(ctx), TOKEN, URL)
@ -58,3 +59,5 @@ if __name__ == '__main__':
PORT_MAIL = config.get('credentials', 'PORT_MAIL') PORT_MAIL = config.get('credentials', 'PORT_MAIL')
TOKEN = config.get('credentials', 'TOKEN') TOKEN = config.get('credentials', 'TOKEN')
URL = config.get('credentials', 'URL') URL = config.get('credentials', 'URL')
listen(USER_MAIL, PASS_MAIL, URL_MAIL, PORT_MAIL)