Compare commits
3 Commits
1c1c9acc8d
...
6eaa6a19d5
Author | SHA1 | Date | |
---|---|---|---|
|
6eaa6a19d5 | ||
|
3009007e48 | ||
|
c0b220959f |
7
config.ini
Normal file
7
config.ini
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[credentials]
|
||||||
|
USER_MAIL = username
|
||||||
|
PASS_MAIL = password
|
||||||
|
URL_MAIL = example.org
|
||||||
|
PORT_MAIL = 993
|
||||||
|
TOKEN = token
|
||||||
|
URL = example1.org
|
59
emailmastodon
Executable file
59
emailmastodon
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Bot that mirrors emails to Mastodon account
|
||||||
|
import argparse
|
||||||
|
import configparser
|
||||||
|
import imaplib
|
||||||
|
from mastodon import Mastodon
|
||||||
|
|
||||||
|
CONFIG_PATH = "./config.ini"
|
||||||
|
|
||||||
|
VERSION = '0.1.0'
|
||||||
|
|
||||||
|
def show_version():
|
||||||
|
print("EmailMastodon " + VERSION)
|
||||||
|
print("License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>")
|
||||||
|
print("This is free software: you are free to change and redistribute it.")
|
||||||
|
print("There is NO WARRANTY, to the extent permitted by law.")
|
||||||
|
|
||||||
|
def publish(ctx, token, url):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def listen(user, passwd, url, port):
|
||||||
|
mail = imaplib.IMAP4_SSL(url, port=port)
|
||||||
|
mail.login(user, passwd)
|
||||||
|
_, messages = mail.select()
|
||||||
|
past_messages = int(messages[0].decode())
|
||||||
|
while True:
|
||||||
|
ctx = []
|
||||||
|
_, messages = mail.select()
|
||||||
|
if past_messages != int(messages[0].decode()):
|
||||||
|
for i in range(past_messages+1, int(messages[0].decode())+1):
|
||||||
|
_, msg = mail.fetch(str(i), "(RFC822)")
|
||||||
|
for resp in msg:
|
||||||
|
if isinstance(resp, tuple):
|
||||||
|
msg = email.messages_from_bytes(response[1])
|
||||||
|
body = msg.get_payload(decode=True).decode()
|
||||||
|
ctx.append(body)
|
||||||
|
publish("".join(ctx), TOKEN, URL)
|
||||||
|
past_messages = int(messages[0].decode())
|
||||||
|
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
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")
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
if args.version:
|
||||||
|
show_version()
|
||||||
|
exit()
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(CONFIG_PATH)
|
||||||
|
USER_MAIL = config.get('credentials', 'USER_MAIL')
|
||||||
|
PASS_MAIL = config.get('credentials', 'PASS_MAIL')
|
||||||
|
URL_MAIL = config.get('credentials', 'URL_MAIL')
|
||||||
|
PORT_MAIL = config.get('credentials', 'PORT_MAIL')
|
||||||
|
TOKEN = config.get('credentials', 'TOKEN')
|
||||||
|
URL = config.get('credentials', 'URL')
|
Loading…
Reference in New Issue
Block a user