コード例 #1
0
def main():

    with open(os.path.join(os.path.dirname(__file__), "config.json"), "r") as fp:
        config = json.loads(fp.read())

    b.url = "https://basecamp.com/%s" % config["account_id"]

    b.headers = {}
    b.headers["content-type"] = "application/json"
    b.headers["user-agent"] = config["user-agent"]

    b.creds = [config["username"], config["password"]]

    login = Watcher(
        config["username"],
        config["password"],
        config["imap_server"],
        config["smtp_server"],
        smtp_port=587,
        confirm_from="BasecampHelper",
        smtp_tls=True,
    )

    login.connect()
    results = login.search("POST, ")

    for e in results:
        uid, email = e
        # Email subject: POST, Projects_search_string, MessageTitle
        header, query, title = email["subject"].split(", ")

        if email.get_content_maintype() == "text":
            body = email.get_payload(decode=True)  # added decode=True
            body = decode_email(body)

        elif email.get_content_maintype() == "multipart":
            for part in email.walk():
                if part.get_content_maintype() == "text":
                    body = part.get_payload(decode=True)
                    body = decode_email(body)
                    break

        projects = b.get_all_groups(query)
        for project_id in projects:
            b.post_message(project_id, title, body)

        login.confirm(uid, email)
    login.logout()
コード例 #2
0
def email_loaner(item):
	login = Watcher(config['username'], config['password'],
		config['imap_server'], config['smtp_server'], 
		smtp_port=587, confirm_from='Your Equipment On Loan', smtp_tls=True)
	login.connect()
	due = item['due_on'].strftime('%d-%m-%Y')

	with open(os.path.join(os.path.dirname(__file__), 'message.txt'), 'r') as fp:
		message = fp.read()
	message = message.replace('{{ item }}', item['name']).replace('{{ due_date }}', due)
	print item['last_comment']
	try:
		login.send_confirmation(message, [creds[0], item['last_comment']])
	except:
		try:
			login.send_confirmation('ERROR: UNABLE TO SEND:\n\n\n' + message, [creds[0]])
		except:
			raise