-
-
Save anonymous/4acd8ebc24ba75f2bf13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import email | |
import imaplib | |
import time | |
from github import Github | |
from secrets import * | |
g = Github(GITHUB_TOKEN) | |
dbr = g.get_user().get_repo(GITHUB_REPO) | |
while True: | |
mail = imaplib.IMAP4_SSL(MAIL_SERVER) | |
mail.login(MAIL_LOGIN, MAIL_PW) | |
num_messages = mail.select() | |
typ, data = mail.search(None, 'ALL') | |
for msg_id in data[0].split(): | |
typ, data = mail.fetch(msg_id, 'RFC822') | |
if typ == "OK": | |
message = email.message_from_string(data[0][1]) | |
to = message["To"].lower() | |
if to not in ["bugs@example.com", "features@example.com", "github@example.com"]: | |
print "Bad message, send a reply to %s" % message["From"] | |
continue | |
else: | |
labels = [] | |
if to == "bugs@example.com": | |
labels.append(dbr.get_label("bug")) | |
elif to == "features@example.com": | |
label = labels.append(dbr.get_label("enhancement")) | |
labels.append(dbr.get_label("suggestion box")) | |
title = message["Subject"] | |
print title | |
if title.lower().startswith("freecell:"): | |
title = title.replace("freecell:","") | |
if message.is_multipart(): | |
for part in message.get_payload(): | |
if part.get_content_type() == 'text/plain': | |
body = part.get_payload() | |
break | |
else: | |
body = message.get_payload() | |
print body | |
dbr.create_issue(title, body, labels=labels) | |
mail.store(msg_id, '+FLAGS', '\\Deleted') | |
print "message %s deleted" % msg_id | |
mail.expunge() | |
mail.close() | |
mail.logout() | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment