Beispiel #1
0
def work(login, password, project_id):
    git = Gitlab(gitlab, token=token)
    create_label(git, project_id)
    box = imaplib.IMAP4_SSL(imap_server)
    box.login(login, password)
    box.select('inbox')
    result, data = box.search(None, 'ALL')
    for _id in data[0].split():
        # Reset sudo before each run
        git.setsudo()

        result, data = box.fetch(_id, '(RFC822)')
        mail = email.message_from_string(data[0][1].decode('ascii',
                                                           errors='ignore'))
        body = """```
%s
```""" % (get_first_text_block(mail).decode('utf-8'))

        if sudo(git, mail) is True:
            body = push_attachments(mail, body, project_id)
            subject = email.header.decode_header(mail['Subject'])[0][0]
            issue = git.createissue(project_id, title=subject, labels=label)
            git.createissuewallnote(project_id, issue['id'], body)

        box.store(_id, '+FLAGS', '\\Deleted')
    box.expunge()